From a00b3134a6f374c538fafe44cd0946b59b69cf16 Mon Sep 17 00:00:00 2001 From: Brandon Wolfgang Date: Wed, 21 Oct 2026 21:10:29 -0500 Subject: [PATCH] test: cover unreachable Ollama service errors - Verify network-level fetch failures propagate from the generation client - Assert the original error type and message are preserved - 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 cf91402..b111055 100644 --- a/src/ollama.test.ts +++ b/src/ollama.test.ts @@ -45,3 +45,20 @@ it("throws an error when Ollama returns a non-OK status", async () => { globalThis.fetch = originalFetch; } }); + +it("propagates an error when Ollama is unreachable", async () => { + const originalFetch = globalThis.fetch; + + globalThis.fetch = async () => { + throw new TypeError("fetch failed"); + }; + + try { + await assert.rejects(generateResponse("Explain a REST API."), { + name: "TypeError", + message: "fetch failed", + }); + } finally { + globalThis.fetch = originalFetch; + } +});