Skip to content

Commit 2a20f1d

Browse files
committed
test(ws-upstream): hold the eager-relay marker to the win32 rule, not to a constant
`tests/ws-upstream.test.ts` has two cases failing on Windows since 5a75e57: (fail) an HTTP fallback remains on the configured legacy tee path (fail) an older runtime stays on HTTP SSE without opening a WebSocket Measured, not inferred -- both bisect endpoints were run rather than assumed: dec332c 23 pass / 0 fail 5a75e57 21 pass / 2 fail fix(grok): ... backfill required annotations That commit adds `createResponsesFieldBackfillBlockRewrite()` to `blockRewrites` unconditionally, and the factory returns an `SseBlockRewrite` rather than `undefined`, so the chain is never empty and `needsClientRewrite` in `handleResponses` is now a constant `true`. `isWin32EagerRewrite` is `platform === "win32" && needsClientRewrite` (src/lib/bun-stream-caps.ts:126), so on Windows every Responses stream now takes the eager single-reader relay -- which is exactly what #864 asks for, since all traffic is now rewrite traffic. Instrumented at the gate to confirm the mechanism rather than deduce it: [EAGER] {"forceCodexWsEagerRelay":false,"useEagerRelay":null, "win32EagerRewrite":true,"needsClientRewrite":true, "platform":"win32","blockRewrites":1} So the source behaviour is intended and the assertions are stale. Both cases are about the *WebSocket* path not being taken, and both already assert that directly through `FakeWebSocket.instances`; the `isEagerRelaySseResponse(...)` assertion was a second-order signal that stopped tracking WS selection on win32. Holds it to the documented rule instead of to `false`, so it stays honest on every platform rather than encoding a pre-backfill world. Adds one precondition case pinning the coupling itself -- the rewrite chain being non-empty, and the platform rule -- so if either half moves it fails somewhere that names the real cause instead of inside a WebSocket assertion. Tests only; no src change. 24 pass / 0 fail in the file (was 21/2), and the new case is mutation-checked: forcing `isWin32EagerRewrite` to `false` turns it red. 58 pass / 3 skip / 0 fail across ws-upstream, responses-field-backfill, responses-snapshot-repair-server and subagent-fallback-handle-responses. `bun run typecheck` exit 0.
1 parent fbc6f26 commit 2a20f1d

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

‎tests/ws-upstream.test.ts‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { afterEach, describe, expect, jest, test } from "bun:test";
22
import { providerFetch } from "../src/server/responses/fetch-helpers";
33
import { handleResponses } from "../src/server/responses";
44
import { isEagerRelaySseResponse } from "../src/server/relay";
5+
import { isWin32EagerRewrite } from "../src/lib/bun-stream-caps";
6+
import { createResponsesFieldBackfillBlockRewrite } from "../src/server/responses/responses-field-backfill";
57
import {
68
bunSupportsBoundedCodexWsRelay,
79
codexWsUpstreamFetch as rawCodexWsUpstreamFetch,
@@ -17,6 +19,17 @@ import type { OcxConfig } from "../src/types";
1719
const CODEX_URL = "https://chatgpt.com/backend-api/codex/responses";
1820
const BOUNDED_WS_RUNTIME = "1.4.0";
1921

22+
// #864 keeps win32 rewrite traffic out of the tee()+JS-pull chain, so
23+
// `isWin32EagerRewrite(platform, needsClientRewrite)` sends it through the eager
24+
// single-reader relay instead. Since the annotations backfill became an
25+
// unconditional block rewrite (5a75e57f, `createResponsesFieldBackfillBlockRewrite()`),
26+
// `needsClientRewrite` is true for every Responses stream — so on win32 the eager
27+
// relay marker is set no matter which upstream transport was chosen. Cases below
28+
// that are about *not* taking the WebSocket path assert that directly through
29+
// `FakeWebSocket.instances`; they hold the marker to this rule rather than to a
30+
// constant that only held before the backfill landed.
31+
const EAGER_RELAY_FORCED_BY_PLATFORM = isWin32EagerRewrite(process.platform, true);
32+
2033
function shouldUseCodexWsUpstream(url: string, init?: RequestInit): boolean {
2134
return rawShouldUseCodexWsUpstream(url, init, BOUNDED_WS_RUNTIME);
2235
}
@@ -288,7 +301,7 @@ describe("handleResponses Codex WS relay selection", () => {
288301
});
289302

290303
expect(FakeWebSocket.instances).toHaveLength(1);
291-
expect(isEagerRelaySseResponse(response)).toBe(false);
304+
expect(isEagerRelaySseResponse(response)).toBe(EAGER_RELAY_FORCED_BY_PLATFORM);
292305
expect(await response.text()).toContain("response.completed");
293306
});
294307

@@ -330,12 +343,33 @@ describe("handleResponses Codex WS relay selection", () => {
330343
const response = await handleResponses(request(), forwardConfig(), { model: "", provider: "" });
331344

332345
expect(FakeWebSocket.instances).toHaveLength(0);
333-
expect(isEagerRelaySseResponse(response)).toBe(false);
346+
expect(isEagerRelaySseResponse(response)).toBe(EAGER_RELAY_FORCED_BY_PLATFORM);
334347
expect(await response.text()).toContain("response.completed");
335348
},
336349
);
337350
});
338351

352+
describe("eager-relay marker preconditions", () => {
353+
test("the client rewrite chain is never empty, so win32 always takes the eager path", () => {
354+
// This is the coupling that silently changed the two cases above.
355+
// `createResponsesFieldBackfillBlockRewrite()` is added to `blockRewrites`
356+
// unconditionally and returns a rewrite rather than `undefined`, so
357+
// `needsClientRewrite` in `handleResponses` is a constant `true`. Combined with
358+
// the win32 rule that makes the eager relay the only safe path for rewrite
359+
// traffic, every Responses stream on Windows is marked. If either half changes,
360+
// this fails here rather than in an assertion that looks like it is about
361+
// WebSocket selection.
362+
expect(typeof createResponsesFieldBackfillBlockRewrite()).toBe("function");
363+
364+
expect(isWin32EagerRewrite("win32", true)).toBe(true);
365+
expect(isWin32EagerRewrite("win32", false)).toBe(false);
366+
expect(isWin32EagerRewrite("darwin", true)).toBe(false);
367+
expect(isWin32EagerRewrite("linux", true)).toBe(false);
368+
369+
expect(EAGER_RELAY_FORCED_BY_PLATFORM).toBe(process.platform === "win32");
370+
});
371+
});
372+
339373
describe("codexWsUpstreamFetch", () => {
340374
test("relays event frames as an SSE response and sends one response.create frame", async () => {
341375
installFake(ws => {

0 commit comments

Comments
 (0)