From 0bc50f76a237eabda3b471bcbd60e50fb4522db2 Mon Sep 17 00:00:00 2001 From: Brandon Wolfgang Date: Wed, 21 Oct 2026 21:38:54 -0500 Subject: [PATCH] test: cover Ollama request timeout errors - Verify generation requests include an abort signal - Assert timeout-related abort errors propagate with the expected error name - Restore the global fetch implementation after the test --- src/ollama.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ollama.test.ts b/src/ollama.test.ts index b111055..e0beba6 100644 --- a/src/ollama.test.ts +++ b/src/ollama.test.ts @@ -62,3 +62,20 @@ it("propagates an error when Ollama is unreachable", async () => { globalThis.fetch = originalFetch; } }); + +it("propagates an error when an Ollama request times out", async () => { + const originalFetch = globalThis.fetch; + + globalThis.fetch = async (_input, init) => { + assert.ok(init?.signal); + throw new DOMException("The operation was aborted", "AbortError"); + }; + + try { + await assert.rejects(generateResponse("Explain a REST API."), { + name: "AbortError", + }); + } finally { + globalThis.fetch = originalFetch; + } +});