mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:50:43 +00:00
fix: gate Ollama ambient discovery
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user