





























@@ -110,6 +110,28 @@ function expectOllamaWebSearchRequest(
110110expect(request.init.signal).toBeInstanceOf(AbortSignal);
111111}
112112113+function fetchCall(index = 0): unknown[] {
114+const call = fetchWithSsrFGuardMock.mock.calls.at(index);
115+if (!call) {
116+throw new Error(`expected guarded fetch call ${index}`);
117+}
118+return call;
119+}
120+121+function fetchRequest(index = 0): {
122+init?: { headers?: Record<string, string> };
123+url?: string;
124+} {
125+const request = fetchCall(index).at(0);
126+if (!request || typeof request !== "object") {
127+throw new Error(`expected guarded fetch request ${index}`);
128+}
129+return request as {
130+init?: { headers?: Record<string, string> };
131+url?: string;
132+};
133+}
134+113135function expectSingleSearchResultUrl(results: unknown, url: string) {
114136if (!Array.isArray(results)) {
115137throw new Error("Expected search results array");
@@ -220,7 +242,7 @@ describe("ollama web search provider", () => {
220242}
221243const result = await tool.execute({ query: "openclaw docs", count: 3 });
222244223-expectOllamaWebSearchRequest(fetchWithSsrFGuardMock.mock.calls[0], {
245+expectOllamaWebSearchRequest(fetchCall(), {
224246url: "http://ollama.local:11434/api/experimental/web_search",
225247query: "openclaw docs",
226248maxResults: 3,
@@ -293,8 +315,8 @@ describe("ollama web search provider", () => {
293315294316expect(result.count).toBe(1);
295317expect(fetchWithSsrFGuardMock.mock.calls).toHaveLength(1);
296-expect(fetchWithSsrFGuardMock.mock.calls[0]?.[0].url).toBe("https://ollama.com/api/web_search");
297-expectOllamaWebSearchRequest(fetchWithSsrFGuardMock.mock.calls[0], {
318+expect(fetchRequest().url).toBe("https://ollama.com/api/web_search");
319+expectOllamaWebSearchRequest(fetchCall(), {
298320url: "https://ollama.com/api/web_search",
299321headers: {
300322"Content-Type": "application/json",
@@ -339,22 +361,16 @@ describe("ollama web search provider", () => {
339361});
340362341363expect(result.count).toBe(1);
342-const firstHeaders = fetchWithSsrFGuardMock.mock.calls[0]?.[0].init?.headers as
343-| Record<string, string>
344-| undefined;
345-const cloudHeaders = fetchWithSsrFGuardMock.mock.calls[2]?.[0].init?.headers as
346-| Record<string, string>
347-| undefined;
364+const firstHeaders = fetchRequest().init?.headers;
365+const cloudHeaders = fetchRequest(2).init?.headers;
348366expect(firstHeaders?.Authorization).toBeUndefined();
349367expect(cloudHeaders?.Authorization).toBe("Bearer cloud-secret");
350368expect(fetchWithSsrFGuardMock.mock.calls.map((call) => call[0].url)).toEqual([
351369"http://ollama.local:11434/api/experimental/web_search",
352370"http://ollama.local:11434/api/web_search",
353371"https://ollama.com/api/web_search",
354372]);
355-expect(fetchWithSsrFGuardMock.mock.calls[2]?.[0].url).toBe(
356-"https://ollama.com/api/web_search",
357-);
373+expect(fetchRequest(2).url).toBe("https://ollama.com/api/web_search");
358374} finally {
359375if (original === undefined) {
360376delete process.env.OLLAMA_API_KEY;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。