Skip to content

Commit 1dbca95

Browse files
committed
test(voice-call): await notification hangups before teardown
1 parent 7baae4d commit 1dbca95

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎extensions/voice-call/src/manager.notify.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ function expectFirstPlayTtsText(provider: FakeProvider, text: string) {
140140
expect(requireFirstPlayTtsCall(provider).text).toBe(text);
141141
}
142142

143+
async function expectNotifyHangup(manager: HarnessManager, provider: FakeProvider, callId: string) {
144+
// Playback schedules a real auto-hangup. Finish it before the shared worker
145+
// clears the state runtime, or its persistence/logging leaks into another file.
146+
await expect.poll(() => manager.getCall(callId), { timeout: 5_000 }).toBeUndefined();
147+
expect(provider.hangupCalls).toEqual([
148+
{ callId, providerCallId: "call-uuid", reason: "hangup-bot" },
149+
]);
150+
expect(await manager.getCallFromMemoryOrStore(callId)).toMatchObject({
151+
state: "hangup-bot",
152+
endReason: "hangup-bot",
153+
});
154+
}
155+
143156
describe("CallManager notify and mapping", () => {
144157
it("logs a failed notify auto-hangup and leaves the call active for retry", async () => {
145158
vi.useFakeTimers();
@@ -210,6 +223,7 @@ describe("CallManager notify and mapping", () => {
210223
await answerCall(manager, callId, `evt-2-${providerName}`);
211224

212225
expectFirstPlayTtsText(provider, "Hello there");
226+
await expectNotifyHangup(manager, provider, callId);
213227
},
214228
);
215229

@@ -273,6 +287,7 @@ describe("CallManager notify and mapping", () => {
273287
await answerCall(manager, callId, "evt-notify-twilio-realtime");
274288

275289
expectFirstPlayTtsText(provider, "Notify text");
290+
await expectNotifyHangup(manager, provider, callId);
276291
});
277292

278293
it("waits for stream connect in conversation mode when Twilio streaming is enabled", async () => {
@@ -374,6 +389,7 @@ describe("CallManager notify and mapping", () => {
374389
const afterSuccess = requireCall(manager, callId);
375390
expect(provider.playTtsCalls).toHaveLength(2);
376391
expect(afterSuccess.metadata).not.toHaveProperty("initialMessage");
392+
await expectNotifyHangup(manager, provider, callId);
377393
});
378394

379395
it("speaks initial message only once on repeated stream-connect triggers", async () => {

0 commit comments

Comments
 (0)