diff --git a/tests/ws-upstream.test.ts b/tests/ws-upstream.test.ts index b58472eab..bb8f0061b 100644 --- a/tests/ws-upstream.test.ts +++ b/tests/ws-upstream.test.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, jest, test } from "bun:test"; +import { afterEach, describe, expect, spyOn, test } from "bun:test"; import { providerFetch } from "../src/server/responses/fetch-helpers"; import { codexWsUpstreamFetch, shouldUseCodexWsUpstream } from "../src/server/responses/ws-upstream"; import type { OcxProviderConfig } from "../src/types"; @@ -190,7 +190,12 @@ describe("codexWsUpstreamFetch", () => { }); test("falls back to the HTTP fetch when the upgrade deadline elapses without open or close", async () => { - jest.useFakeTimers(); + let deadline: (() => void) | undefined; + const setTimeoutSpy = spyOn(globalThis, "setTimeout").mockImplementation(((callback: () => void, delay?: number) => { + expect(delay).toBe(10_000); + deadline = callback; + return 0; + }) as typeof setTimeout); try { installFake(() => { /* handshake never settles */ }); const sentinel = new Response("sse-timeout-fallback", { status: 200 }); @@ -202,14 +207,14 @@ describe("codexWsUpstreamFetch", () => { const responsePromise = codexWsUpstreamFetch(CODEX_URL, streamingInit(), fallback); expect(FakeWebSocket.instances).toHaveLength(1); - jest.advanceTimersByTime(10_000); + deadline?.(); const response = await responsePromise; expect(response).toBe(sentinel); expect(fallbackCalls).toBe(1); expect(FakeWebSocket.instances[0].closed).toBe(true); } finally { - jest.useRealTimers(); + setTimeoutSpy.mockRestore(); } });