diff --git a/tests/unit/image-generation-route.test.ts b/tests/unit/image-generation-route.test.ts index 11e3dbb53b..1cae8a7eae 100644 --- a/tests/unit/image-generation-route.test.ts +++ b/tests/unit/image-generation-route.test.ts @@ -19,6 +19,7 @@ const providerChatRoute = await import("../../src/app/api/v1/providers/[provider]/chat/completions/route.ts"); const imageEditRoute = await import("../../src/app/api/v1/images/edits/route.ts"); const v1ModelsCatalog = await import("../../src/app/api/v1/models/catalog.ts"); +const { setPinnedFetchTestOverride } = await import("../../src/shared/network/remoteImageFetch.ts"); const originalFetch = globalThis.fetch; @@ -72,6 +73,7 @@ function createCodexEditForm( async function resetStorage() { globalThis.fetch = originalFetch; + setPinnedFetchTestOverride(undefined); apiKeysDb.resetApiKeyState(); core.resetDbInstance(); fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); @@ -120,6 +122,7 @@ test.beforeEach(async () => { test.after(() => { globalThis.fetch = originalFetch; + setPinnedFetchTestOverride(undefined); apiKeysDb.resetApiKeyState(); core.resetDbInstance(); fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); @@ -234,7 +237,7 @@ test("v1 image models GET exposes current Codex image models and hides inactive test("v1 image generation POST accepts promptless requests for image-only models", async () => { await seedConnection("topaz", { apiKey: "topaz-key" }); - globalThis.fetch = async (url, options: RequestInit = {}) => { + const mockFetchImpl = async (url, options: RequestInit = {}) => { const stringUrl = String(url); if (stringUrl === "https://example.com/topaz-input.png") { return new Response(new Uint8Array([1, 2, 3]), { @@ -254,6 +257,11 @@ test("v1 image generation POST accepts promptless requests for image-only models throw new Error(`Unexpected URL: ${stringUrl}`); }; + // #13883: resolveImageSource now sets `pinDns: true`, which pins the connection via a + // real undici socket and would bypass this mocked globalThis.fetch — route it through + // the test-only pinned-fetch override instead (src/shared/network/remoteImageFetch.ts). + globalThis.fetch = mockFetchImpl; + setPinnedFetchTestOverride(mockFetchImpl); const response = await imageRoute.POST( new Request("http://localhost/api/v1/images/generations", {