From 27b37f18ba99978ed17995daed2b14a1bc7f0d15 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 18:13:50 +0100 Subject: [PATCH] test: share ollama tags fetch fixture --- extensions/ollama/provider-discovery.test.ts | 30 +++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/extensions/ollama/provider-discovery.test.ts b/extensions/ollama/provider-discovery.test.ts index 8fe295e0bcd..79049bd5b1c 100644 --- a/extensions/ollama/provider-discovery.test.ts +++ b/extensions/ollama/provider-discovery.test.ts @@ -92,6 +92,18 @@ describe("Ollama provider", () => { json: async () => ({}), }); + const stubTagsFetch = (names: string[] = []) => { + const fetchMock = vi.fn(async (input: unknown) => { + const url = String(input); + if (url.endsWith("/api/tags")) { + return tagsResponse(names); + } + return notFoundJsonResponse(); + }); + vi.stubGlobal("fetch", withFetchPreconnect(fetchMock)); + return fetchMock; + }; + it("should not include ollama when no API key is configured", async () => { const provider = await runOllamaCatalog({ env: { OLLAMA_API_KEY: undefined }, @@ -101,14 +113,7 @@ describe("Ollama provider", () => { }); it("should use native ollama api type", async () => { - const fetchMock = vi.fn(async (input: unknown) => { - const url = String(input); - if (url.endsWith("/api/tags")) { - return tagsResponse([]); - } - return notFoundJsonResponse(); - }); - vi.stubGlobal("fetch", withFetchPreconnect(fetchMock)); + const fetchMock = stubTagsFetch(); await withOllamaApiKey(async () => { const provider = await runOllamaCatalog({}); @@ -122,14 +127,7 @@ describe("Ollama provider", () => { }); it("should preserve explicit ollama baseUrl on implicit provider injection", async () => { - const fetchMock = vi.fn(async (input: unknown) => { - const url = String(input); - if (url.endsWith("/api/tags")) { - return tagsResponse([]); - } - return notFoundJsonResponse(); - }); - vi.stubGlobal("fetch", withFetchPreconnect(fetchMock)); + const fetchMock = stubTagsFetch(); await withOllamaApiKey(async () => { const provider = await runOllamaCatalog({