test(gateway): stabilize chat abort

main
Peter Steinberger 2025-12-17 22:04:54 +01:00
parent fe6bf6966b
commit 35214b6dec
1 changed files with 68 additions and 52 deletions

View File

@ -1970,7 +1970,7 @@ describe("gateway server", () => {
await server.close();
});
test("chat.abort cancels an in-flight chat.send", async () => {
test("chat.abort cancels an in-flight chat.send", { timeout: 15000 }, async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-"));
testSessionStorePath = path.join(dir, "sessions.json");
await fs.writeFile(
@ -1989,6 +1989,7 @@ describe("gateway server", () => {
);
const { server, ws } = await startServerWithClient();
try {
await connectOk(ws);
const spy = vi.mocked(agentCommand);
@ -2001,9 +2002,20 @@ describe("gateway server", () => {
});
});
const sendResP = onceMessage(
ws,
(o) => o.type === "res" && o.id === "send-abort-1",
8000,
);
const abortResP = onceMessage(
ws,
(o) => o.type === "res" && o.id === "abort-1",
8000,
);
const abortedEventP = onceMessage(
ws,
(o) => o.type === "event" && o.event === "chat" && o.payload?.state === "aborted",
8000,
);
ws.send(
@ -2020,7 +2032,16 @@ describe("gateway server", () => {
}),
);
await new Promise((r) => setTimeout(r, 10));
await new Promise<void>((resolve, reject) => {
const deadline = Date.now() + 1000;
const tick = () => {
if (spy.mock.calls.length > 0) return resolve();
if (Date.now() > deadline)
return reject(new Error("timeout waiting for agentCommand"));
setTimeout(tick, 5);
};
tick();
});
ws.send(
JSON.stringify({
@ -2031,24 +2052,19 @@ describe("gateway server", () => {
}),
);
const abortRes = await onceMessage(
ws,
(o) => o.type === "res" && o.id === "abort-1",
);
const abortRes = await abortResP;
expect(abortRes.ok).toBe(true);
const sendRes = await onceMessage(
ws,
(o) => o.type === "res" && o.id === "send-abort-1",
);
const sendRes = await sendResP;
expect(sendRes.ok).toBe(true);
const evt = await abortedEventP;
expect(evt.payload?.runId).toBe("idem-abort-1");
expect(evt.payload?.sessionKey).toBe("main");
} finally {
ws.close();
await server.close();
}
});
test("bridge RPC chat.history returns session messages", async () => {