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
This commit is contained in:
Brandon Wolfgang 2026-10-21 21:13:57 -05:00
parent a00b3134a6
commit ed0630bbc1

View file

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