fix: gate Ollama ambient discovery · openclaw/openclaw@1316ca9
steipete
·
2026-04-27
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -241,7 +241,20 @@ describe("ollama plugin", () => {
|
241 | 241 | }); |
242 | 242 | }); |
243 | 243 | |
244 | | -it("keeps empty default-ish provider stubs quiet", async () => { |
| 244 | +it("skips ambient discovery without Ollama auth or meaningful config", async () => { |
| 245 | +const provider = registerProvider(); |
| 246 | + |
| 247 | +const result = await provider.discovery.run({ |
| 248 | +config: {}, |
| 249 | +env: { NODE_ENV: "development" }, |
| 250 | +resolveProviderApiKey: () => ({ apiKey: "" }), |
| 251 | +} as never); |
| 252 | + |
| 253 | +expect(result).toBeNull(); |
| 254 | +expect(buildOllamaProviderMock).not.toHaveBeenCalled(); |
| 255 | +}); |
| 256 | + |
| 257 | +it("skips empty default-ish provider stubs without probing localhost", async () => { |
245 | 258 | const provider = registerProvider(); |
246 | 259 | buildOllamaProviderMock.mockResolvedValueOnce({ |
247 | 260 | baseUrl: "http://127.0.0.1:11434", |
@@ -266,9 +279,7 @@ describe("ollama plugin", () => {
|
266 | 279 | } as never); |
267 | 280 | |
268 | 281 | expect(result).toBeNull(); |
269 | | -expect(buildOllamaProviderMock).toHaveBeenCalledWith("http://127.0.0.1:11434", { |
270 | | -quiet: true, |
271 | | -}); |
| 282 | +expect(buildOllamaProviderMock).not.toHaveBeenCalled(); |
272 | 283 | }); |
273 | 284 | |
274 | 285 | it("treats non-default baseUrl as explicit discovery config", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -210,10 +210,10 @@ describe("Ollama provider", () => {
|
210 | 210 | vi.stubGlobal("fetch", withFetchPreconnect(fetchMock)); |
211 | 211 | |
212 | 212 | const provider = await runOllamaCatalog({ |
213 | | -env: { VITEST: "", NODE_ENV: "development" }, |
| 213 | +env: { OLLAMA_API_KEY: OLLAMA_LOCAL_AUTH_MARKER, VITEST: "", NODE_ENV: "development" }, |
214 | 214 | }); |
215 | 215 | |
216 | | -expect(provider?.apiKey).toBe(OLLAMA_LOCAL_AUTH_MARKER); |
| 216 | +expect(provider?.apiKey).toBe("OLLAMA_API_KEY"); |
217 | 217 | expect(provider?.api).toBe("ollama"); |
218 | 218 | expect(provider?.baseUrl).toBe("http://127.0.0.1:11434"); |
219 | 219 | expect(provider?.models).toHaveLength(2); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -108,6 +108,7 @@ export async function resolveOllamaDiscoveryResult(params: {
|
108 | 108 | return null; |
109 | 109 | } |
110 | 110 | const ollamaKey = params.ctx.resolveProviderApiKey(OLLAMA_PROVIDER_ID).apiKey; |
| 111 | +const hasOllamaDiscoveryOptIn = typeof ollamaKey === "string" && ollamaKey.trim().length > 0; |
111 | 112 | const hasRealOllamaKey = |
112 | 113 | typeof ollamaKey === "string" && |
113 | 114 | ollamaKey.trim().length > 0 && |
@@ -130,6 +131,9 @@ export async function resolveOllamaDiscoveryResult(params: {
|
130 | 131 | }, |
131 | 132 | }; |
132 | 133 | } |
| 134 | +if (!hasOllamaDiscoveryOptIn && !hasMeaningfulExplicitConfig) { |
| 135 | +return null; |
| 136 | +} |
133 | 137 | if ( |
134 | 138 | !hasRealOllamaKey && |
135 | 139 | !hasMeaningfulExplicitConfig && |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。