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
This commit is contained in:
Brandon Wolfgang 2026-10-21 21:38:24 -05:00
parent 8cfcb1a3cf
commit 7771359dd4

View file

@ -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;
}
});