From 61cddefdf02c4d6a6cf6402afa365a0bf5f95186 Mon Sep 17 00:00:00 2001 From: 404oops Date: Sat, 31 Oct 2026 15:53:00 +0100 Subject: [PATCH] test(puter-js): prove microphone chunks hit the closing-socket gap The browser test now counts the chunks the transport refused while the socket read as closing, and requires at least one, so it can't pass without exercising the gap. The socket stays closing until the connection drops instead of going back to open. Co-Authored-By: Claude Opus 5.5 --- src/puter-js/tests/api/realtime/convo.test.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/puter-js/tests/api/realtime/convo.test.ts b/src/puter-js/tests/api/realtime/convo.test.ts index c805d8d11..f1a80bcd3 100644 --- a/src/puter-js/tests/api/realtime/convo.test.ts +++ b/src/puter-js/tests/api/realtime/convo.test.ts @@ -696,7 +696,8 @@ describe('convo built SDK and browser media', () => { ); // The socket reads as closing while the conversation still reads - // connected, for long enough that several chunks arrive. + // connected, until the connection drops below. Chunks that arrive + // meanwhile are refused by the transport. const gap = await page.evaluate(async () => { const t = (globalThis as unknown as { test: any }).test; const socket = t.sockets.at(-1) as WebSocket; @@ -704,9 +705,19 @@ describe('convo built SDK and browser media', () => { configurable: true, get: () => 2, }); + let refused = 0; + const appendAudio = t.c.appendAudio.bind(t.c); + t.c.appendAudio = (pcm: Int16Array) => { + try { + appendAudio(pcm); + } catch (error) { + refused++; + throw error; + } + }; await new Promise((resolve) => setTimeout(resolve, 300)); - delete (socket as { readyState?: number }).readyState; return { + refused, state: t.c.state, live: t.tracks.every( (track: MediaStreamTrack) => @@ -715,6 +726,7 @@ describe('convo built SDK and browser media', () => { events: t.events, }; }); + expect(gap.refused).toBeGreaterThan(0); expect(gap.state).toBe('connected'); expect(gap.live).toBe(true); expect(gap.events).not.toContain('error');