refactor: dedupe agent and browser cli helpers

This commit is contained in:
Peter Steinberger
2026-03-03 00:14:48 +00:00
parent fe14be2352
commit fd3ca8a34c
46 changed files with 1051 additions and 1117 deletions

View File

@@ -32,6 +32,14 @@ describe("Ollama auto-discovery", () => {
originalFetch = globalThis.fetch;
}
function mockOllamaUnreachable() {
globalThis.fetch = vi
.fn()
.mockRejectedValue(
new Error("connect ECONNREFUSED 127.0.0.1:11434"),
) as unknown as typeof fetch;
}
it("auto-registers ollama provider when models are discovered locally", async () => {
setupDiscoveryEnv();
globalThis.fetch = vi.fn().mockImplementation(async (url: string | URL) => {
@@ -62,11 +70,7 @@ describe("Ollama auto-discovery", () => {
it("does not warn when Ollama is unreachable and not explicitly configured", async () => {
setupDiscoveryEnv();
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
globalThis.fetch = vi
.fn()
.mockRejectedValue(
new Error("connect ECONNREFUSED 127.0.0.1:11434"),
) as unknown as typeof fetch;
mockOllamaUnreachable();
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
const providers = await resolveImplicitProviders({ agentDir });
@@ -82,11 +86,7 @@ describe("Ollama auto-discovery", () => {
it("warns when Ollama is unreachable and explicitly configured", async () => {
setupDiscoveryEnv();
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
globalThis.fetch = vi
.fn()
.mockRejectedValue(
new Error("connect ECONNREFUSED 127.0.0.1:11434"),
) as unknown as typeof fetch;
mockOllamaUnreachable();
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
await resolveImplicitProviders({