test(image): route the promptless topaz test through the pinned-fetch override (#13883)

resolveImageSource now sets pinDns: true, so the real undici socket bypassed the
mocked globalThis.fetch in image-generation-route.test.ts and the promptless
image-only request came back 502 (Remote image fetch error 404). Register the
same setPinnedFetchTestOverride() seam the other four image tests already use;
clear it in resetStorage()/after so no test leaks the mock.
This commit is contained in:
diegosouzapw
2026-09-19 00:11:52 -03:00
parent 9d78d35085
commit 5fafc49039

View File

@@ -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", {