fix: gate Ollama ambient discovery

This commit is contained in:
Peter Steinberger
2026-04-27 02:02:30 +01:00
parent acfa9877b3
commit 1316ca9aa8
3 changed files with 21 additions and 6 deletions

View File

@@ -241,7 +241,20 @@ describe("ollama plugin", () => {
});
});
it("keeps empty default-ish provider stubs quiet", async () => {
it("skips ambient discovery without Ollama auth or meaningful config", async () => {
const provider = registerProvider();
const result = await provider.discovery.run({
config: {},
env: { NODE_ENV: "development" },
resolveProviderApiKey: () => ({ apiKey: "" }),
} as never);
expect(result).toBeNull();
expect(buildOllamaProviderMock).not.toHaveBeenCalled();
});
it("skips empty default-ish provider stubs without probing localhost", async () => {
const provider = registerProvider();
buildOllamaProviderMock.mockResolvedValueOnce({
baseUrl: "http://127.0.0.1:11434",
@@ -266,9 +279,7 @@ describe("ollama plugin", () => {
} as never);
expect(result).toBeNull();
expect(buildOllamaProviderMock).toHaveBeenCalledWith("http://127.0.0.1:11434", {
quiet: true,
});
expect(buildOllamaProviderMock).not.toHaveBeenCalled();
});
it("treats non-default baseUrl as explicit discovery config", async () => {

View File

@@ -210,10 +210,10 @@ describe("Ollama provider", () => {
vi.stubGlobal("fetch", withFetchPreconnect(fetchMock));
const provider = await runOllamaCatalog({
env: { VITEST: "", NODE_ENV: "development" },
env: { OLLAMA_API_KEY: OLLAMA_LOCAL_AUTH_MARKER, VITEST: "", NODE_ENV: "development" },
});
expect(provider?.apiKey).toBe(OLLAMA_LOCAL_AUTH_MARKER);
expect(provider?.apiKey).toBe("OLLAMA_API_KEY");
expect(provider?.api).toBe("ollama");
expect(provider?.baseUrl).toBe("http://127.0.0.1:11434");
expect(provider?.models).toHaveLength(2);

View File

@@ -108,6 +108,7 @@ export async function resolveOllamaDiscoveryResult(params: {
return null;
}
const ollamaKey = params.ctx.resolveProviderApiKey(OLLAMA_PROVIDER_ID).apiKey;
const hasOllamaDiscoveryOptIn = typeof ollamaKey === "string" && ollamaKey.trim().length > 0;
const hasRealOllamaKey =
typeof ollamaKey === "string" &&
ollamaKey.trim().length > 0 &&
@@ -130,6 +131,9 @@ export async function resolveOllamaDiscoveryResult(params: {
},
};
}
if (!hasOllamaDiscoveryOptIn && !hasMeaningfulExplicitConfig) {
return null;
}
if (
!hasRealOllamaKey &&
!hasMeaningfulExplicitConfig &&