





















@@ -119,21 +119,16 @@ async function emitTranscriptUpdateAndCollectEvents(params: {
119119120120async function expectNoMessageWithin(params: {
121121action?: () => Promise<void> | void;
122-watch: () => Promise<unknown>;
122+watch: (timeoutMs: number) => Promise<unknown>;
123123timeoutMs?: number;
124124}): Promise<void> {
125125const timeoutMs = params.timeoutMs ?? 300;
126-let received = false;
127-const watch = params
128-.watch()
129-.then(() => {
130-received = true;
131-})
132-.catch(() => undefined);
126+const received = params.watch(timeoutMs).then(
127+() => true,
128+() => false,
129+);
133130await params.action?.();
134-await new Promise((resolve) => setTimeout(resolve, timeoutMs));
135-expect(received).toBe(false);
136-await watch;
131+await expect(received).resolves.toBe(false);
137132}
138133139134describe("session.message websocket events", () => {
@@ -226,19 +221,19 @@ describe("session.message websocket events", () => {
226221event: "session.message",
227222});
228223await expectNoMessageWithin({
229-watch: () =>
224+watch: (timeoutMs) =>
230225onceMessage(
231226unsubscribedWs,
232227(message) => message.type === "event" && message.event === "session.message",
233-300,
228+timeoutMs,
234229),
235230});
236231await expectNoMessageWithin({
237-watch: () =>
232+watch: (timeoutMs) =>
238233onceMessage(
239234nodeWs,
240235(message) => message.type === "event" && message.event === "session.message",
241-300,
236+timeoutMs,
242237),
243238});
244239} finally {
@@ -644,15 +639,15 @@ describe("session.message websocket events", () => {
644639expect(mainAppend.ok).toBe(true);
645640646641await expectNoMessageWithin({
647-watch: () =>
642+watch: (timeoutMs) =>
648643onceMessage(
649644ws,
650645(message) =>
651646message.type === "event" &&
652647message.event === "session.message" &&
653648(message.payload as { sessionKey?: string } | undefined)?.sessionKey ===
654649"agent:main:worker",
655-300,
650+timeoutMs,
656651),
657652action: async () => {
658653const workerAppend = await appendAssistantMessageToSessionTranscript({
@@ -671,15 +666,15 @@ describe("session.message websocket events", () => {
671666expect(unsubscribeRes.payload?.subscribed).toBe(false);
672667673668await expectNoMessageWithin({
674-watch: () =>
669+watch: (timeoutMs) =>
675670onceMessage(
676671ws,
677672(message) =>
678673message.type === "event" &&
679674message.event === "session.message" &&
680675(message.payload as { sessionKey?: string } | undefined)?.sessionKey ===
681676"agent:main:main",
682-300,
677+timeoutMs,
683678),
684679action: async () => {
685680const hiddenAppend = await appendAssistantMessageToSessionTranscript({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。