From 8e29160eaa1e6b8a0edaa136b7a3ded9b69b151f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Feb 2026 12:29:08 +0000 Subject: [PATCH] test: remove fixed waits from tool-result ordering tests --- .../reply/agent-runner.runreplyagent.test.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/auto-reply/reply/agent-runner.runreplyagent.test.ts b/src/auto-reply/reply/agent-runner.runreplyagent.test.ts index a740e173b19..3590a624ce8 100644 --- a/src/auto-reply/reply/agent-runner.runreplyagent.test.ts +++ b/src/auto-reply/reply/agent-runner.runreplyagent.test.ts @@ -556,17 +556,16 @@ describe("runReplyAgent typing (heartbeat)", () => { const deliveryOrder: string[] = []; const onToolResult = vi.fn(async (payload: { text?: string }) => { // Simulate variable network latency: first result is slower than second - const delay = payload.text === "first" ? 50 : 10; + const delay = payload.text === "first" ? 5 : 1; await new Promise((r) => setTimeout(r, delay)); deliveryOrder.push(payload.text ?? ""); }); state.runEmbeddedPiAgentMock.mockImplementationOnce(async (params: AgentRunParams) => { - // Fire two tool results without awaiting — simulates concurrent tool completion - void params.onToolResult?.({ text: "first", mediaUrls: [] }); - void params.onToolResult?.({ text: "second", mediaUrls: [] }); - // Small delay to let the chain settle before returning - await new Promise((r) => setTimeout(r, 150)); + // Fire two tool results without awaiting each one; await both at the end. + const first = params.onToolResult?.({ text: "first", mediaUrls: [] }); + const second = params.onToolResult?.({ text: "second", mediaUrls: [] }); + await Promise.all([first, second]); return { payloads: [{ text: "final" }], meta: {} }; }); @@ -591,9 +590,9 @@ describe("runReplyAgent typing (heartbeat)", () => { }); state.runEmbeddedPiAgentMock.mockImplementationOnce(async (params: AgentRunParams) => { - void params.onToolResult?.({ text: "first", mediaUrls: [] }); - void params.onToolResult?.({ text: "second", mediaUrls: [] }); - await new Promise((r) => setTimeout(r, 50)); + const first = params.onToolResult?.({ text: "first", mediaUrls: [] }); + const second = params.onToolResult?.({ text: "second", mediaUrls: [] }); + await Promise.allSettled([first, second]); return { payloads: [{ text: "final" }], meta: {} }; });