

























@@ -23,6 +23,7 @@ type GuardedFetchCall = {
2323url: string;
2424init?: RequestInit;
2525policy?: unknown;
26+signal?: AbortSignal;
2627timeoutMs?: number;
2728auditContext?: string;
2829};
@@ -333,6 +334,29 @@ describe("createConfiguredOllamaCompatStreamWrapper", () => {
333334);
334335});
335336337+it("passes caller abort signals at guard level when a timeout is present", async () => {
338+await withMockNdjsonFetch(
339+[
340+'{"model":"m","created_at":"t","message":{"role":"assistant","content":"ok"},"done":false}',
341+'{"model":"m","created_at":"t","message":{"role":"assistant","content":""},"done":true,"prompt_eval_count":1,"eval_count":1}',
342+],
343+async (fetchMock) => {
344+const signal = new AbortController().signal;
345+const stream = await createOllamaTestStream({
346+baseUrl: "http://ollama-host:11434",
347+options: { signal, timeoutMs: 123_456 },
348+});
349+350+await collectStreamEvents(stream);
351+352+const request = getGuardedFetchCall(fetchMock);
353+expect(request.timeoutMs).toBe(123_456);
354+expect(request.signal).toBe(signal);
355+expect(request.init?.signal).toBeUndefined();
356+},
357+);
358+});
359+336360it("maps native Ollama max thinking to think=high on the wire", async () => {
337361await withMockNdjsonFetch(
338362[
@@ -1018,6 +1042,7 @@ async function createOllamaTestStream(params: {
10181042maxTokens?: number;
10191043temperature?: number;
10201044signal?: AbortSignal;
1045+timeoutMs?: number;
10211046headers?: Record<string, string>;
10221047};
10231048}) {
@@ -1401,8 +1426,9 @@ describe("createOllamaStreamFn", () => {
14011426const request = getGuardedFetchCall(fetchMock);
14021427expect(request.url).toBe("http://ollama-host:11434/api/chat");
14031428expect(request.auditContext).toBe("ollama-stream.chat");
1429+expect(request.signal).toBe(signal);
14041430const requestInit = request.init ?? {};
1405-expect(requestInit.signal).toBe(signal);
1431+expect(requestInit.signal).toBeUndefined();
14061432if (typeof requestInit.body !== "string") {
14071433throw new Error("Expected string request body");
14081434}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。