From 8416d9738d449ffa9e05c051ec2f8685bc89cfa4 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 a516bc5dd..1736879d4 100644 --- a/src/puter-js/tests/api/realtime/convo.test.ts +++ b/src/puter-js/tests/api/realtime/convo.test.ts @@ -688,7 +688,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; @@ -696,9 +697,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) => @@ -707,6 +718,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');