Skip to content

Commit 675b834

Browse files
committed
test(realtime-transcription): tighten payload cap proof
1 parent a1282d6 commit 675b834

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/realtime-transcription/websocket-session.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ describe("createRealtimeTranscriptionWebSocketSession", () => {
407407
expect(closeError.message).toBe("test realtime transcription connection closed before ready");
408408
});
409409

410-
it("delivers a legitimate large inbound frame below the payload cap", async () => {
411-
// Well above any real transcript frame yet far under the 16 MiB cap: proves
410+
it("delivers a legitimate large inbound message below the payload cap", async () => {
411+
// Well above any real transcript message yet far under the 16 MiB cap: proves
412412
// the bound does not reject legitimate large provider traffic.
413413
const largeText = "x".repeat(2 * 1024 * 1024);
414414
const server = await createRealtimeServer({
@@ -430,14 +430,14 @@ describe("createRealtimeTranscriptionWebSocketSession", () => {
430430
await vi.waitFor(() => {
431431
expect(onMessage).toHaveBeenCalledTimes(1);
432432
});
433-
const event = requireFirstMockArg(onMessage, "large inbound frame");
433+
const event = requireFirstMockArg(onMessage, "large inbound message");
434434
expect(event).toEqual({ type: "transcript", text: largeText });
435435
session.close();
436436
});
437437

438-
it("drops an oversized inbound frame before it reaches the provider parser", async () => {
439-
// ws rejects a frame above maxPayload with an error + 1009 close, so an
440-
// oversized upstream frame never reaches onMessage/JSON parse.
438+
it("drops an oversized inbound message before it reaches the provider parser", async () => {
439+
// ws rejects a message above maxPayload with an error + 1009 close, so an
440+
// oversized upstream message never reaches onMessage/JSON parse.
441441
const oversized = "x".repeat(REALTIME_TRANSCRIPTION_WS_MAX_PAYLOAD_BYTES + 1);
442442
const server = await createRealtimeServer({ initialText: oversized });
443443
const onError = vi.fn();
@@ -460,8 +460,9 @@ describe("createRealtimeTranscriptionWebSocketSession", () => {
460460
expect(onError).toHaveBeenCalledTimes(1);
461461
});
462462
expect(onMessage).not.toHaveBeenCalled();
463-
const overflowError = requireFirstMockArg(onError, "oversized inbound frame error");
463+
const overflowError = requireFirstMockArg(onError, "oversized inbound message error");
464464
expect(overflowError).toBeInstanceOf(Error);
465+
expect(overflowError).toHaveProperty("code", "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
465466
expect(overflowError.message).toMatch(/max payload/i);
466467
session.close();
467468
});

src/realtime-transcription/websocket-session.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ const DEFAULT_CLOSE_TIMEOUT_MS = 5_000;
5050
const DEFAULT_MAX_RECONNECT_ATTEMPTS = 5;
5151
const DEFAULT_RECONNECT_DELAY_MS = 1000;
5252
const DEFAULT_MAX_QUEUED_BYTES = 2 * 1024 * 1024;
53-
// Bound inbound frames before ws buffers them for JSON parsing. Transcript
54-
// provider frames are small text/JSON; 16 MiB matches the realtime voice ws cap
55-
// and caps ws's 100 MiB default. ws emits an error + 1009 close on overflow, so
56-
// an oversized frame never reaches onMessage/parseMessage.
53+
// Bound inbound messages before ws buffers them for JSON parsing. The 16 MiB cap
54+
// matches realtime voice; ws rejects larger messages with close 1009 before
55+
// they reach onMessage, replacing its 100 MiB client default.
5756
export const REALTIME_TRANSCRIPTION_WS_MAX_PAYLOAD_BYTES = 16 * 1024 * 1024;
5857

5958
function rawWsDataToBuffer(data: RawData): Buffer {

0 commit comments

Comments
 (0)