Files
openclaw/src/agents/models-config.providers.ollama.e2e.test.ts
Sunwoo Yu 11702290ff feat(ollama): add native /api/chat provider for streaming + tool calling (#11853)
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 0a723f98e654e6bc2f312f29a8c97c3d63bcedb2
Co-authored-by: BrokenFinger98 <115936166+BrokenFinger98@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
2026-02-14 01:20:42 +01:00

89 lines
3.1 KiB
TypeScript

import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { resolveImplicitProviders, resolveOllamaApiBase } from "./models-config.providers.js";
describe("resolveOllamaApiBase", () => {
it("returns default localhost base when no configured URL is provided", () => {
expect(resolveOllamaApiBase()).toBe("http://127.0.0.1:11434");
});
it("strips /v1 suffix from OpenAI-compatible URLs", () => {
expect(resolveOllamaApiBase("http://ollama-host:11434/v1")).toBe("http://ollama-host:11434");
expect(resolveOllamaApiBase("http://ollama-host:11434/V1")).toBe("http://ollama-host:11434");
});
it("keeps URLs without /v1 unchanged", () => {
expect(resolveOllamaApiBase("http://ollama-host:11434")).toBe("http://ollama-host:11434");
});
it("handles trailing slash before canonicalizing", () => {
expect(resolveOllamaApiBase("http://ollama-host:11434/v1/")).toBe("http://ollama-host:11434");
expect(resolveOllamaApiBase("http://ollama-host:11434/")).toBe("http://ollama-host:11434");
});
});
describe("Ollama provider", () => {
it("should not include ollama when no API key is configured", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
const providers = await resolveImplicitProviders({ agentDir });
expect(providers?.ollama).toBeUndefined();
});
it("should use native ollama api type", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
process.env.OLLAMA_API_KEY = "test-key";
try {
const providers = await resolveImplicitProviders({ agentDir });
expect(providers?.ollama).toBeDefined();
expect(providers?.ollama?.apiKey).toBe("OLLAMA_API_KEY");
expect(providers?.ollama?.api).toBe("ollama");
expect(providers?.ollama?.baseUrl).toBe("http://127.0.0.1:11434");
} finally {
delete process.env.OLLAMA_API_KEY;
}
});
it("should preserve explicit ollama baseUrl on implicit provider injection", async () => {
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
process.env.OLLAMA_API_KEY = "test-key";
try {
const providers = await resolveImplicitProviders({
agentDir,
explicitProviders: {
ollama: {
baseUrl: "http://192.168.20.14:11434/v1",
api: "openai-completions",
models: [],
},
},
});
// Native API strips /v1 suffix via resolveOllamaApiBase()
expect(providers?.ollama?.baseUrl).toBe("http://192.168.20.14:11434");
} finally {
delete process.env.OLLAMA_API_KEY;
}
});
it("should have correct model structure without streaming override", () => {
const mockOllamaModel = {
id: "llama3.3:latest",
name: "llama3.3:latest",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 128000,
maxTokens: 8192,
};
// Native Ollama provider does not need streaming: false workaround
expect(mockOllamaModel).not.toHaveProperty("params");
});
});