From 99fa4a2e8539fff260f43b0200197f956851579c Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 9 Oct 2026 15:41:01 -0500 Subject: [PATCH] test(voice): retrieve phone questions with the current call credential Co-Authored-By: Paperclip --- .../__tests__/voice-session-store.integration.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/__tests__/voice-session-store.integration.test.ts b/server/src/__tests__/voice-session-store.integration.test.ts index d07de5ef422..745df3fe02a 100644 --- a/server/src/__tests__/voice-session-store.integration.test.ts +++ b/server/src/__tests__/voice-session-store.integration.test.ts @@ -457,7 +457,7 @@ const support = await getEmbeddedPostgresTestSupport(); configureVoiceDefaults: vi.fn(async () => {}), verifyAgent: vi.fn(async () => ({ id: "agent_test", organizationId: "org_test", name: "Test voice" })), createPhoneSession: vi.fn(async (_input: { to: string; bindingId: string }) => ({ sessionId: randomUUID(), status: "dialing" as const })), - createBrowserSession: vi.fn(async () => ({ sessionId: randomUUID(), transportToken: "short-lived-media-token", transportUrl: "wss://media.example.test" })), + createBrowserSession: vi.fn(async (_input: {toolToken: string}) => ({ sessionId: randomUUID(), transportToken: "short-lived-media-token", transportUrl: "wss://media.example.test" })), inspectSession: vi.fn(async () => ({ status: "active", endedAt: null as string | null })), callReport: vi.fn(async () => ({ complete: true, transcript: [{ id: "turn1", index: 0, speaker: "caller" as const, text: "A test request", startedAt: new Date().toISOString(), endedAt: null, interrupted: false }], costMicroUsd: "120000", durationSeconds: 60, providerUpdatedAt: new Date() })), callDeliveryDiagnostics: vi.fn(async (id: string, deliveries: readonly {messageId: string; acceptedAt: string}[]) => parseSpekoDeliveryDiagnostics( @@ -492,7 +492,12 @@ const support = await getEmbeddedPostgresTestSupport(); expect(f.transport.sendCallMessage.mock.calls[0]?.[1]).toContain("Call get_updates"); const [reply] = await db.select().from(chatVoiceReplies).where(eq(chatVoiceReplies.publicationId, f.publication.id)); expect(reply.deliveredAt).toBeNull(); - expect(await f.store.runTool(f.toolInput("get_updates", {cursor: 0}))).toMatchObject({updates: [{question: {interactionId}}]}); + // The service starts a new call; the first fixture call's token is retired. + const token = f.transport.createBrowserSession.mock.calls[0]![0].toolToken; + const toolId = randomUUID(); + const {sessionId: providerSessionId} = await f.transport.createBrowserSession.mock.results[0]!.value; + const envelope = {session_id: providerSessionId, tool_call_id: toolId, idempotency_key: `${providerSessionId}:${toolId}`, tool: "get_updates" as const, args: {cursor: 0}}; + expect(await f.store.runTool({...f.toolInput("get_updates", {cursor: 0}), sessionId: f.session.id, token, envelope, webhookId: toolId, fingerprint: createHash("sha256").update(JSON.stringify(envelope)).digest("hex")})).toMatchObject({updates: [{question: {interactionId}}]}); await f.push(); expect(f.transport.sendCallMessage).toHaveBeenCalledTimes(2); });