fix(onboard): cancel custom verification bodies

This commit is contained in:
Vincent Koc
2026-06-19 08:38:48 +02:00
parent 0dbac0d5f9
commit c79a5aa253
2 changed files with 25 additions and 1 deletions

View File

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

View File

@@ -108,8 +108,9 @@ async function requestVerification(params: {
headers: Record<string, string>;
body: Record<string, unknown>;
}): Promise<VerificationResult> {
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);
}
}