


























@@ -8,6 +8,11 @@ function makeLogger() {
88};
99}
101011+function expectConsultRequest(call: unknown, expected: Record<string, unknown>) {
12+expect(call).toMatchObject(expected);
13+expect((call as { signal?: unknown } | undefined)?.signal).toBeInstanceOf(AbortSignal);
14+}
15+1116describe("realtime voice agent talkback queue", () => {
1217it("debounces transcript fragments into one consult", async () => {
1318vi.useFakeTimers();
@@ -29,10 +34,9 @@ describe("realtime voice agent talkback queue", () => {
2934queue.enqueue("second");
3035await vi.advanceTimersByTimeAsync(100);
313632-expect(consult).toHaveBeenCalledWith({
37+expectConsultRequest(consult.mock.calls[0]?.[0], {
3338question: "first\nsecond",
3439responseStyle: "brief",
35-signal: expect.any(AbortSignal),
3640});
3741expect(deliver).toHaveBeenCalledWith("answer:first\nsecond");
3842vi.useRealTimers();
@@ -71,15 +75,13 @@ describe("realtime voice agent talkback queue", () => {
7175finishFirst?.({ text: "first-answer" });
7276await vi.runAllTimersAsync();
737774-expect(consult).toHaveBeenNthCalledWith(1, {
78+expectConsultRequest(consult.mock.calls[0]?.[0], {
7579question: "first",
7680responseStyle: "brief",
77-signal: expect.any(AbortSignal),
7881});
79-expect(consult).toHaveBeenNthCalledWith(2, {
82+expectConsultRequest(consult.mock.calls[1]?.[0], {
8083question: "ignored\nsecond",
8184responseStyle: "brief",
82-signal: expect.any(AbortSignal),
8385});
8486expect(deliver).toHaveBeenCalledWith("first-answer");
8587expect(deliver).toHaveBeenCalledWith("second-answer");
@@ -122,17 +124,15 @@ describe("realtime voice agent talkback queue", () => {
122124finishFirst?.({ text: "first-answer" });
123125await vi.runAllTimersAsync();
124126125-expect(consult).toHaveBeenNthCalledWith(2, {
127+expectConsultRequest(consult.mock.calls[1]?.[0], {
126128question: "owner",
127129metadata: ownerMetadata,
128130responseStyle: "brief",
129-signal: expect.any(AbortSignal),
130131});
131-expect(consult).toHaveBeenNthCalledWith(3, {
132+expectConsultRequest(consult.mock.calls[2]?.[0], {
132133question: "guest",
133134metadata: guestMetadata,
134135responseStyle: "brief",
135-signal: expect.any(AbortSignal),
136136});
137137expect(deliver).toHaveBeenCalledWith("owner-answer");
138138expect(deliver).toHaveBeenCalledWith("guest-answer");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。