test: stabilize claude cli serialization test
This commit is contained in:
@@ -18,8 +18,20 @@ function createDeferred<T>() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForCalls(
|
||||||
|
mockFn: { mock: { calls: unknown[][] } },
|
||||||
|
count: number,
|
||||||
|
) {
|
||||||
|
for (let i = 0; i < 50; i += 1) {
|
||||||
|
if (mockFn.mock.calls.length >= count) return;
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
}
|
||||||
|
throw new Error(`Expected ${count} calls, got ${mockFn.mock.calls.length}`);
|
||||||
|
}
|
||||||
|
|
||||||
vi.mock("../process/exec.js", () => ({
|
vi.mock("../process/exec.js", () => ({
|
||||||
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
|
runCommandWithTimeout: (...args: unknown[]) =>
|
||||||
|
runCommandWithTimeoutMock(...args),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("runClaudeCliAgent", () => {
|
describe("runClaudeCliAgent", () => {
|
||||||
@@ -120,8 +132,7 @@ describe("runClaudeCliAgent", () => {
|
|||||||
runId: "run-2",
|
runId: "run-2",
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.resolve();
|
await waitForCalls(runCommandWithTimeoutMock, 1);
|
||||||
expect(runCommandWithTimeoutMock).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
firstDeferred.resolve({
|
firstDeferred.resolve({
|
||||||
stdout: JSON.stringify({ message: "ok", session_id: "sid-1" }),
|
stdout: JSON.stringify({ message: "ok", session_id: "sid-1" }),
|
||||||
@@ -131,8 +142,7 @@ describe("runClaudeCliAgent", () => {
|
|||||||
killed: false,
|
killed: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.resolve();
|
await waitForCalls(runCommandWithTimeoutMock, 2);
|
||||||
expect(runCommandWithTimeoutMock).toHaveBeenCalledTimes(2);
|
|
||||||
|
|
||||||
secondDeferred.resolve({
|
secondDeferred.resolve({
|
||||||
stdout: JSON.stringify({ message: "ok", session_id: "sid-2" }),
|
stdout: JSON.stringify({ message: "ok", session_id: "sid-2" }),
|
||||||
|
|||||||
Reference in New Issue
Block a user