





























@@ -414,6 +414,23 @@ describe("DiscordVoiceManager", () => {
414414"tts stream args",
415415);
416416417+const sentUserMessages = () =>
418+Array.from(realtimeSessionMock.sendUserMessage.mock.calls).map(([message]) => String(message));
419+420+const expectUserMessageIncludes = (text: string) => {
421+expect(
422+sentUserMessages().some((message) => message.includes(text)),
423+text,
424+).toBe(true);
425+};
426+427+const expectUserMessageNotIncludes = (text: string) => {
428+expect(
429+sentUserMessages().some((message) => message.includes(text)),
430+text,
431+).toBe(false);
432+};
433+417434const emitDecryptFailure = (manager: InstanceType<typeof managerModule.DiscordVoiceManager>) => {
418435const entry = getSessionEntry(manager);
419436(
@@ -1214,9 +1231,7 @@ describe("DiscordVoiceManager", () => {
1214123112151232expect(lastAgentCommandArgs().senderIsOwner).toBe(false);
12161233expect(realtimeSessionMock.handleBargeIn).not.toHaveBeenCalled();
1217-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1218-expect.stringContaining("non-owner answer"),
1219-);
1234+expectUserMessageIncludes("non-owner answer");
12201235});
1221123612221237it("keeps separate forced agent-proxy fallback timers for rapid transcripts", async () => {
@@ -1271,12 +1286,8 @@ describe("DiscordVoiceManager", () => {
12711286const ownerCommandArgs = agentCommandArgsAt(1);
12721287expect(ownerCommandArgs.message).toContain("owner question");
12731288expect(ownerCommandArgs.senderIsOwner).toBe(true);
1274-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1275-expect.stringContaining("guest answer"),
1276-);
1277-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1278-expect.stringContaining("owner answer"),
1279-);
1289+expectUserMessageIncludes("guest answer");
1290+expectUserMessageIncludes("owner answer");
12801291});
1281129212821293it("skips incomplete and non-actionable forced agent-proxy transcripts", async () => {
@@ -1331,9 +1342,7 @@ describe("DiscordVoiceManager", () => {
1331134213321343await new Promise((resolve) => setTimeout(resolve, 260));
13331344expect(lastAgentCommandArgs().message).toContain("ship it.");
1334-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1335-expect.stringContaining("valid answer"),
1336-);
1345+expectUserMessageIncludes("valid answer");
13371346});
1338134713391348it("queues forced agent-proxy answers until current realtime playback idles", async () => {
@@ -1409,55 +1418,37 @@ describe("DiscordVoiceManager", () => {
14091418await new Promise((resolve) => setTimeout(resolve, 260));
1410141914111420resolveFirst?.({ payloads: [{ text: "first answer" }] });
1412-await vi.waitFor(() =>
1413-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1414-expect.stringContaining("first answer"),
1415-),
1416-);
1421+await vi.waitFor(() => expectUserMessageIncludes("first answer"));
14171422bridgeParams?.audioSink?.sendAudio(Buffer.alloc(480));
1418142314191424resolveSecond?.({ payloads: [{ text: "second answer" }] });
14201425resolveThird?.({ payloads: [{ text: "third answer" }] });
14211426await new Promise((resolve) => setTimeout(resolve, 0));
1422-expect(realtimeSessionMock.sendUserMessage).not.toHaveBeenCalledWith(
1423-expect.stringContaining("second answer"),
1424-);
1425-expect(realtimeSessionMock.sendUserMessage).not.toHaveBeenCalledWith(
1426-expect.stringContaining("third answer"),
1427-);
1427+expectUserMessageNotIncludes("second answer");
1428+expectUserMessageNotIncludes("third answer");
1428142914291430bridgeParams?.onEvent?.({ direction: "server", type: "response.done" });
14301431const firstStream = createAudioResourceMock.mock.calls.at(-1)?.[0] as PassThrough | undefined;
14311432await vi.waitFor(() => expect(firstStream?.writableEnded).toBe(true));
14321433await new Promise((resolve) => setTimeout(resolve, 0));
1433-expect(realtimeSessionMock.sendUserMessage).not.toHaveBeenCalledWith(
1434-expect.stringContaining("second answer"),
1435-);
1434+expectUserMessageNotIncludes("second answer");
1436143514371436const idleHandler = player.on.mock.calls.find(([event]) => event === "idle")?.[1] as
14381437| (() => void)
14391438| undefined;
14401439idleHandler?.();
1441-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1442-expect.stringContaining("second answer"),
1443-);
1444-expect(realtimeSessionMock.sendUserMessage).not.toHaveBeenCalledWith(
1445-expect.stringContaining("third answer"),
1446-);
1440+expectUserMessageIncludes("second answer");
1441+expectUserMessageNotIncludes("third answer");
1447144214481443bridgeParams?.audioSink?.sendAudio(Buffer.alloc(480));
14491444bridgeParams?.onEvent?.({ direction: "server", type: "response.done" });
14501445const secondStream = createAudioResourceMock.mock.calls.at(-1)?.[0] as PassThrough | undefined;
14511446await vi.waitFor(() => expect(secondStream?.writableEnded).toBe(true));
14521447await new Promise((resolve) => setTimeout(resolve, 0));
1453-expect(realtimeSessionMock.sendUserMessage).not.toHaveBeenCalledWith(
1454-expect.stringContaining("third answer"),
1455-);
1448+expectUserMessageNotIncludes("third answer");
1456144914571450idleHandler?.();
1458-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1459-expect.stringContaining("third answer"),
1460-);
1451+expectUserMessageIncludes("third answer");
14611452});
1462145314631454it("matches agent-proxy consult tool calls to the pending transcript", async () => {
@@ -1534,9 +1525,7 @@ describe("DiscordVoiceManager", () => {
15341525expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-owner", {
15351526text: "owner answer",
15361527});
1537-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1538-expect.stringContaining("guest fallback answer"),
1539-);
1528+expectUserMessageIncludes("guest fallback answer");
15401529});
1541153015421531it("reuses forced agent-proxy answers for late matching consult tool calls", async () => {
@@ -1597,9 +1586,7 @@ describe("DiscordVoiceManager", () => {
15971586await Promise.resolve();
1598158715991588expect(agentCommandMock).toHaveBeenCalledTimes(1);
1600-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1601-expect.stringContaining("forced answer"),
1602-);
1589+expectUserMessageIncludes("forced answer");
16031590expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith(
16041591"call-late",
16051592{
@@ -1675,9 +1662,7 @@ describe("DiscordVoiceManager", () => {
16751662await new Promise((resolve) => setTimeout(resolve, 20));
1676166316771664expect(agentCommandMock).toHaveBeenCalledTimes(1);
1678-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1679-expect.stringContaining("I hit an error while checking that. Please try again."),
1680-);
1665+expectUserMessageIncludes("I hit an error while checking that. Please try again.");
16811666expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith(
16821667"call-late",
16831668{
@@ -1754,9 +1739,7 @@ describe("DiscordVoiceManager", () => {
17541739await Promise.resolve();
1755174017561741expect(agentCommandMock).toHaveBeenCalledTimes(1);
1757-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1758-expect.stringContaining("forced answer"),
1759-);
1742+expectUserMessageIncludes("forced answer");
17601743expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith("call-late", {
17611744error: "Discord speaker context changed before this realtime consult completed",
17621745});
@@ -1769,9 +1752,7 @@ describe("DiscordVoiceManager", () => {
17691752const followupCommandArgs = agentCommandArgsAt(1);
17701753expect(followupCommandArgs.message).toContain("guest followup");
17711754expect(followupCommandArgs.senderIsOwner).toBe(false);
1772-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1773-expect.stringContaining("guest answer"),
1774-);
1755+expectUserMessageIncludes("guest answer");
17751756});
1776175717771758it("prefers the newest recent agent-proxy consult for repeated questions", async () => {
@@ -1854,9 +1835,7 @@ describe("DiscordVoiceManager", () => {
18541835await Promise.resolve();
1855183618561837expect(agentCommandMock).toHaveBeenCalledTimes(2);
1857-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1858-expect.stringContaining("new forced answer"),
1859-);
1838+expectUserMessageIncludes("new forced answer");
18601839expect(realtimeSessionMock.submitToolResult).toHaveBeenCalledWith(
18611840"call-new",
18621841{
@@ -1911,9 +1890,7 @@ describe("DiscordVoiceManager", () => {
19111890await new Promise((resolve) => setTimeout(resolve, 260));
1912189119131892expect(lastAgentCommandArgs().senderIsOwner).toBe(false);
1914-expect(realtimeSessionMock.sendUserMessage).toHaveBeenCalledWith(
1915-expect.stringContaining("guest answer"),
1916-);
1893+expectUserMessageIncludes("guest answer");
19171894});
1918189519191896it("starts Discord realtime voice in bidi mode with the consult tool", async () => {
@@ -2669,7 +2646,9 @@ describe("DiscordVoiceManager", () => {
26692646expect(lastTtsStreamArgs().disableFallback).toBe(true);
26702647expect(lastTtsStreamArgs().text).toBe("hello back");
26712648expect(textToSpeechMock).not.toHaveBeenCalled();
2672-expect(createAudioResourceMock).toHaveBeenCalledWith(expect.anything());
2649+expect(
2650+lastMockCall(createAudioResourceMock as unknown as MockCallSource, "audio resource")[0],
2651+).toBeDefined();
26732652await vi.waitFor(() => expect(release).toHaveBeenCalledTimes(1));
26742653});
26752654此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。