























@@ -135,6 +135,14 @@ async function waitForRealtimeTest(
135135await vi.waitFor(callback, { interval: 1, ...options });
136136}
137137138+function requireFirstMockCall(calls: readonly unknown[][], label: string): unknown[] {
139+const call = calls.at(0);
140+if (!call) {
141+throw new Error(`expected ${label} call`);
142+}
143+return call;
144+}
145+138146describe("RealtimeCallHandler path routing", () => {
139147it("uses the request host and stream path in TwiML", () => {
140148const handler = makeHandler();
@@ -224,7 +232,9 @@ describe("RealtimeCallHandler path routing", () => {
224232expect(createBridge).toHaveBeenCalled();
225233});
226234callbacks?.onReady?.();
227-const event = processEvent.mock.calls[0]?.[0] as NormalizedEvent | undefined;
235+const event = requireFirstMockCall(processEvent.mock.calls, "processed event")[0] as
236+| NormalizedEvent
237+| undefined;
228238expect(event?.type).toBe("call.initiated");
229239if (event?.type !== "call.initiated") {
230240throw new Error("expected outbound realtime stream to emit call.initiated");
@@ -816,7 +826,7 @@ describe("RealtimeCallHandler path routing", () => {
816826await waitForRealtimeTest(() => {
817827expect(consult).toHaveBeenCalledTimes(1);
818828});
819-const [args, callId, context] = consult.mock.calls[0] ?? [];
829+const [args, callId, context] = requireFirstMockCall(consult.mock.calls, "consult");
820830expect(args).toEqual({
821831question: "Create a smoke test file for me.",
822832context:
@@ -826,7 +836,7 @@ describe("RealtimeCallHandler path routing", () => {
826836expect(context).toEqual({});
827837await waitForRealtimeTest(() => {
828838expect(sendUserMessage).toHaveBeenCalledTimes(1);
829-expect(sendUserMessage.mock.calls[0]).toEqual([
839+expect(requireFirstMockCall(sendUserMessage.mock.calls, "user message")).toEqual([
830840"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.",
831841]);
832842});
@@ -988,7 +998,7 @@ describe("RealtimeCallHandler path routing", () => {
988998},
989999{ timeout: 2_000 },
9901000);
991-const [args, callId, context] = consult.mock.calls[0] ?? [];
1001+const [args, callId, context] = requireFirstMockCall(consult.mock.calls, "consult");
9921002const consultArgs = args as { question?: string; context?: string } | undefined;
9931003expect(consultArgs?.question).toBe("Send a Discord message.");
9941004expect(consultArgs?.context).toBe(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。