From 45af89e1b7eaf5c29192a280d6dd97886f5f4b8a Mon Sep 17 00:00:00 2001 From: DarkPhilosophy <19309990+DarkPhilosophy@users.noreply.github.com> Date: Sat, 13 Jun 2026 20:36:34 +0300 Subject: [PATCH] test(ai): avoid leaking fetch stubs --- packages/ai/test/azure-openai-responses-stream.test.ts | 5 +++-- packages/ai/test/openai-codex-stream.test.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ai/test/azure-openai-responses-stream.test.ts b/packages/ai/test/azure-openai-responses-stream.test.ts index 84e212e60..6d11e5506 100644 --- a/packages/ai/test/azure-openai-responses-stream.test.ts +++ b/packages/ai/test/azure-openai-responses-stream.test.ts @@ -97,7 +97,7 @@ describe("azure openai responses streaming", () => { it("sends an async onPayload replacement body", async () => { let capturedBody: Record | undefined; - global.fetch = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => { + const fetchMock = vi.fn(async (_input: string | URL | Request, init?: RequestInit) => { capturedBody = typeof init?.body === "string" ? (JSON.parse(init.body) as Record) : undefined; return createSseResponse([ { @@ -113,13 +113,14 @@ describe("azure openai responses streaming", () => { }, }, ]); - }) as unknown as typeof fetch; + }); const result = await streamAzureOpenAIResponses( azureModel, { messages: [{ role: "user", content: "Say hello", timestamp: Date.now() }] }, { apiKey: "test-key", + fetch: fetchMock as unknown as typeof fetch, azureBaseUrl: azureModel.baseUrl, azureApiVersion: "v1", onPayload: async payload => ({ diff --git a/packages/ai/test/openai-codex-stream.test.ts b/packages/ai/test/openai-codex-stream.test.ts index b8ba577d7..154d5de8f 100644 --- a/packages/ai/test/openai-codex-stream.test.ts +++ b/packages/ai/test/openai-codex-stream.test.ts @@ -299,16 +299,17 @@ describe("openai-codex streaming", () => { const context = createCodexTestContext(); const model = { ...createCodexTestModel("https://chatgpt.com/backend-api"), preferWebsockets: false }; let capturedBody: Record | undefined; - global.fetch = vi.fn(async (_input: string | URL, init?: RequestInit) => { + const fetchMock = vi.fn(async (_input: string | URL, init?: RequestInit) => { capturedBody = typeof init?.body === "string" ? (JSON.parse(init.body) as Record) : undefined; return new Response(createCompletedCodexSse("Hello"), { status: 200, headers: { "content-type": "text/event-stream" }, }); - }) as unknown as typeof fetch; + }); const result = await streamOpenAICodexResponses(model, context, { apiKey: token, + fetch: fetchMock as unknown as typeof fetch, onPayload: async payload => ({ ...(payload as Record), input: [{ role: "user", content: [{ type: "input_text", text: "replacement" }] }],