mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:20:43 +00:00
test: share jsonl socket accept helper
This commit is contained in:
@@ -20,6 +20,11 @@ async function listenOnSocket(server: net.Server, socketPath: string): Promise<b
|
||||
}
|
||||
}
|
||||
|
||||
function acceptDoneValue(msg: unknown): number | null | undefined {
|
||||
const value = msg as { type?: string; value?: number };
|
||||
return value.type === "done" ? (value.value ?? null) : undefined;
|
||||
}
|
||||
|
||||
describe.runIf(process.platform !== "win32")("requestJsonlSocket", () => {
|
||||
it("ignores malformed and non-accepted lines until one is accepted", async () => {
|
||||
await withTempDir({ prefix: "openclaw-jsonl-socket-" }, async (dir) => {
|
||||
@@ -42,10 +47,7 @@ describe.runIf(process.platform !== "win32")("requestJsonlSocket", () => {
|
||||
socketPath,
|
||||
requestLine: '{"hello":"world"}',
|
||||
timeoutMs: 500,
|
||||
accept: (msg) => {
|
||||
const value = msg as { type?: string; value?: number };
|
||||
return value.type === "done" ? (value.value ?? null) : undefined;
|
||||
},
|
||||
accept: acceptDoneValue,
|
||||
}),
|
||||
).resolves.toBe(42);
|
||||
} finally {
|
||||
@@ -79,10 +81,7 @@ describe.runIf(process.platform !== "win32")("requestJsonlSocket", () => {
|
||||
socketPath,
|
||||
requestLine: '{"hello":"world"}',
|
||||
timeoutMs: 500,
|
||||
accept: (msg) => {
|
||||
const value = msg as { type?: string; value?: number };
|
||||
return value.type === "done" ? (value.value ?? null) : undefined;
|
||||
},
|
||||
accept: acceptDoneValue,
|
||||
}),
|
||||
).resolves.toBe(7);
|
||||
expect(receivedBuffer).toBe('{"hello":"world"}\n');
|
||||
|
||||
Reference in New Issue
Block a user