


























@@ -110,18 +110,30 @@ function expectOllamaWebSearchRequest(
110110expect(request.init.signal).toBeInstanceOf(AbortSignal);
111111}
112112113+function expectSingleSearchResultUrl(results: unknown, url: string) {
114+if (!Array.isArray(results)) {
115+throw new Error("Expected search results array");
116+}
117+expect(results).toHaveLength(1);
118+const [result] = results;
119+if (!result || typeof result !== "object") {
120+throw new Error("Expected search result object");
121+}
122+expect((result as { url?: unknown }).url).toBe(url);
123+}
124+113125describe("ollama web search provider", () => {
114126beforeEach(() => {
115127fetchWithSsrFGuardMock.mockReset();
116128});
117129118130it("registers a keyless web search provider", () => {
119-expect(createContractOllamaWebSearchProvider()).toMatchObject({
120- id: "ollama",
121- label: "Ollama Web Search",
122- requiresCredential: false,
123- envVars: [],
124-});
131+const provider = createContractOllamaWebSearchProvider();
132+133+expect(provider.id).toBe("ollama");
134+expect(provider.label).toBe("Ollama Web Search");
135+expect(provider.requiresCredential).toBe(false);
136+expect(provider.envVars).toEqual([]);
125137});
126138127139it("uses the configured Ollama host and enables the plugin in config", () => {
@@ -217,12 +229,10 @@ describe("ollama web search provider", () => {
217229hostnameAllowlist: ["ollama.local"],
218230},
219231});
220-expect(result).toMatchObject({
221-query: "openclaw docs",
222-provider: "ollama",
223-count: 1,
224-results: [{ url: "https://openclaw.ai/docs" }],
225-});
232+expect(result.query).toBe("openclaw docs");
233+expect(result.provider).toBe("ollama");
234+expect(result.count).toBe(1);
235+expectSingleSearchResultUrl(result.results, "https://openclaw.ai/docs");
226236expect(release).toHaveBeenCalledTimes(1);
227237});
228238@@ -245,13 +255,14 @@ describe("ollama web search provider", () => {
245255release: vi.fn(async () => {}),
246256});
247257248-await expect(
249-runOllamaWebSearch({ config: createOllamaConfig(), query: "openclaw" }),
250-).resolves.toMatchObject({
251-count: 1,
252-results: [{ url: "https://example.com" }],
258+const result = await runOllamaWebSearch({
259+config: createOllamaConfig(),
260+query: "openclaw",
253261});
254262263+expect(result.count).toBe(1);
264+expectSingleSearchResultUrl(result.results, "https://example.com");
265+255266expect(fetchWithSsrFGuardMock.mock.calls.map((call) => call[0].url)).toEqual([
256267"http://ollama.local:11434/api/experimental/web_search",
257268"http://ollama.local:11434/api/web_search",
@@ -272,16 +283,15 @@ describe("ollama web search provider", () => {
272283release: vi.fn(async () => {}),
273284});
274285275-await expect(
276-runOllamaWebSearch({
277-config: createOllamaConfig({
278-baseUrl: "https://ollama.com",
279-apiKey: "cloud-config-secret",
280-}),
281-query: "openclaw",
286+const result = await runOllamaWebSearch({
287+config: createOllamaConfig({
288+baseUrl: "https://ollama.com",
289+apiKey: "cloud-config-secret",
282290}),
283-).resolves.toMatchObject({ count: 1 });
291+query: "openclaw",
292+});
284293294+expect(result.count).toBe(1);
285295expect(fetchWithSsrFGuardMock.mock.calls).toHaveLength(1);
286296expect(fetchWithSsrFGuardMock.mock.calls[0]?.[0].url).toBe("https://ollama.com/api/web_search");
287297expectOllamaWebSearchRequest(fetchWithSsrFGuardMock.mock.calls[0], {
@@ -323,12 +333,12 @@ describe("ollama web search provider", () => {
323333release: vi.fn(async () => {}),
324334});
325335326-await expect(
327-runOllamaWebSearch({ config: createOllamaConfig(), query: "openclaw" }),
328-).resolves.toMatchObject({
329-count: 1,
336+const result = await runOllamaWebSearch({
337+config: createOllamaConfig(),
338+query: "openclaw",
330339});
331340341+expect(result.count).toBe(1);
332342const firstHeaders = fetchWithSsrFGuardMock.mock.calls[0]?.[0].init?.headers as
333343| Record<string, string>
334344| undefined;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。