diff --git a/src/commands/onboard-custom.test.ts b/src/commands/onboard-custom.test.ts index 15c75b4bc462..2d063b511daa 100644 --- a/src/commands/onboard-custom.test.ts +++ b/src/commands/onboard-custom.test.ts @@ -108,6 +108,27 @@ describe("promptCustomApiConfig", () => { expect(prompter.confirm).not.toHaveBeenCalled(); }); + it("cancels custom provider verification response bodies", async () => { + const prompter = createTestPrompter({ + text: ["http://localhost:11434/v1", "", "llama3", "custom", ""], + select: ["plaintext", "openai"], + }); + const cancel = vi.fn(async () => undefined); + vi.stubGlobal( + "fetch", + vi.fn(async () => ({ + ok: true, + status: 200, + headers: new Headers({ "content-type": "application/json; charset=utf-8" }), + body: { cancel }, + })), + ); + + await runPromptCustomApi(prompter); + + expect(cancel).toHaveBeenCalledTimes(1); + }); + it("handles explicit OpenAI Responses flow", async () => { const prompter = createTestPrompter({ text: ["https://proxy.example.com/v1", "test-key", "gpt-5.4", "custom", ""], diff --git a/src/commands/onboard-custom.ts b/src/commands/onboard-custom.ts index 341899b56dea..464a056ea990 100644 --- a/src/commands/onboard-custom.ts +++ b/src/commands/onboard-custom.ts @@ -108,8 +108,9 @@ async function requestVerification(params: { headers: Record; body: Record; }): Promise { + let res: Response | undefined; try { - const res = await fetchWithTimeout( + res = await fetchWithTimeout( params.endpoint, { method: "POST", @@ -133,6 +134,8 @@ async function requestVerification(params: { return { ok: res.ok, status: res.status }; } catch (error) { return { ok: false, error }; + } finally { + await res?.body?.cancel().catch(() => undefined); } }