From 8bddf0efe1b59fc335b87dd72e910060be6b7b22 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 03:14:25 +0100 Subject: [PATCH] test: guard voice-call realtime mock calls --- .../src/webhook/realtime-handler.test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/extensions/voice-call/src/webhook/realtime-handler.test.ts b/extensions/voice-call/src/webhook/realtime-handler.test.ts index 2fd3bd07745..064201256c1 100644 --- a/extensions/voice-call/src/webhook/realtime-handler.test.ts +++ b/extensions/voice-call/src/webhook/realtime-handler.test.ts @@ -135,6 +135,14 @@ async function waitForRealtimeTest( await vi.waitFor(callback, { interval: 1, ...options }); } +function requireFirstMockCall(calls: readonly unknown[][], label: string): unknown[] { + const call = calls.at(0); + if (!call) { + throw new Error(`expected ${label} call`); + } + return call; +} + describe("RealtimeCallHandler path routing", () => { it("uses the request host and stream path in TwiML", () => { const handler = makeHandler(); @@ -224,7 +232,9 @@ describe("RealtimeCallHandler path routing", () => { expect(createBridge).toHaveBeenCalled(); }); callbacks?.onReady?.(); - const event = processEvent.mock.calls[0]?.[0] as NormalizedEvent | undefined; + const event = requireFirstMockCall(processEvent.mock.calls, "processed event")[0] as + | NormalizedEvent + | undefined; expect(event?.type).toBe("call.initiated"); if (event?.type !== "call.initiated") { throw new Error("expected outbound realtime stream to emit call.initiated"); @@ -816,7 +826,7 @@ describe("RealtimeCallHandler path routing", () => { await waitForRealtimeTest(() => { expect(consult).toHaveBeenCalledTimes(1); }); - const [args, callId, context] = consult.mock.calls[0] ?? []; + const [args, callId, context] = requireFirstMockCall(consult.mock.calls, "consult"); expect(args).toEqual({ question: "Create a smoke test file for me.", context: @@ -826,7 +836,7 @@ describe("RealtimeCallHandler path routing", () => { expect(context).toEqual({}); await waitForRealtimeTest(() => { expect(sendUserMessage).toHaveBeenCalledTimes(1); - expect(sendUserMessage.mock.calls[0]).toEqual([ + expect(requireFirstMockCall(sendUserMessage.mock.calls, "user message")).toEqual([ "Internal OpenClaw consult result is ready.\nDo not call tools for this internal result.\nSpeak the following answer to the caller now, briefly and naturally:\nI created the smoke test file.", ]); }); @@ -988,7 +998,7 @@ describe("RealtimeCallHandler path routing", () => { }, { timeout: 2_000 }, ); - const [args, callId, context] = consult.mock.calls[0] ?? []; + const [args, callId, context] = requireFirstMockCall(consult.mock.calls, "consult"); const consultArgs = args as { question?: string; context?: string } | undefined; expect(consultArgs?.question).toBe("Send a Discord message."); expect(consultArgs?.context).toBe(