From 07795d57fe87dc703f6ad8c8103d16f03d71b623 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 18:35:59 +0100 Subject: [PATCH] test: wait for discord voice tool results by assertion --- .../discord/src/voice/manager.e2e.test.ts | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/extensions/discord/src/voice/manager.e2e.test.ts b/extensions/discord/src/voice/manager.e2e.test.ts index 13f81e20a562..869e1ea365f2 100644 --- a/extensions/discord/src/voice/manager.e2e.test.ts +++ b/extensions/discord/src/voice/manager.e2e.test.ts @@ -1085,9 +1085,11 @@ describe("DiscordVoiceManager", () => { }, realtimeSessionMock, ); - await Promise.resolve(); - await Promise.resolve(); - await new Promise((resolve) => setTimeout(resolve, 20)); + await vi.waitFor(() => + expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-1", { + text: "agent proxy answer", + }), + ); const commandArgs = lastAgentCommandArgs(); expect(commandArgs.model).toBe("openai-codex/gpt-5.5"); @@ -1103,9 +1105,6 @@ describe("DiscordVoiceManager", () => { "working", ); expect(workingToolResultCall?.[2]).toEqual({ willContinue: true }); - expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-1", { - text: "agent proxy answer", - }); }); it("does not require speaker context for internal exact-speech consults", async () => { @@ -1798,20 +1797,19 @@ describe("DiscordVoiceManager", () => { realtimeSessionMock, ); rejectAgentTurn?.(new Error("agent broke")); - await Promise.resolve(); - await Promise.resolve(); - await new Promise((resolve) => setTimeout(resolve, 20)); + await vi.waitFor(() => + expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith( + "call-late", + { + status: "already_delivered", + message: "OpenClaw already delivered this answer to Discord voice.", + }, + { suppressResponse: true }, + ), + ); expect(agentCommandMock).toHaveBeenCalledTimes(1); expectUserMessageIncludes("I hit an error while checking that. Please try again."); - expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith( - "call-late", - { - status: "already_delivered", - message: "OpenClaw already delivered this answer to Discord voice.", - }, - { suppressResponse: true }, - ); }); it("does not reuse recent agent-proxy answers over newer speaker audio", async () => { @@ -1947,13 +1945,11 @@ describe("DiscordVoiceManager", () => { }, realtimeSessionMock, ); - await Promise.resolve(); - await Promise.resolve(); - await new Promise((resolve) => setTimeout(resolve, 20)); - - expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-old", { - text: "old direct answer", - }); + await vi.waitFor(() => + expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-old", { + text: "old direct answer", + }), + ); const secondTurn = entry.realtime?.beginSpeakerTurn( { extraSystemPrompt: undefined, senderIsOwner: true, speakerLabel: "Owner" }, @@ -2105,9 +2101,11 @@ describe("DiscordVoiceManager", () => { }, realtimeSessionMock, ); - await Promise.resolve(); - await Promise.resolve(); - await new Promise((resolve) => setTimeout(resolve, 20)); + await vi.waitFor(() => + expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-1", { + text: "consult answer", + }), + ); const workingToolResultCall = mockCall( realtimeSessionMock.submitToolResult as unknown as MockCallSource, @@ -2119,9 +2117,6 @@ describe("DiscordVoiceManager", () => { "working", ); expect(workingToolResultCall?.[2]).toEqual({ willContinue: true }); - expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-1", { - text: "consult answer", - }); const commandArgs = lastAgentCommandArgs(); expect(commandArgs.senderIsOwner).toBe(true); expect(commandArgs.toolsAllow).toEqual([ @@ -2206,14 +2201,13 @@ describe("DiscordVoiceManager", () => { }, realtimeSessionMock, ); - await Promise.resolve(); - await Promise.resolve(); - await new Promise((resolve) => setTimeout(resolve, 20)); + await vi.waitFor(() => + expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-1", { + text: "maintainer answer", + }), + ); expect(lastAgentCommandArgs().sessionKey).toBe("agent:main:discord:channel:maintainers"); - expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-1", { - text: "maintainer answer", - }); }); it("keeps bidi realtime consults on the audio turn speaker context", async () => {