mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-23 10:08:13 +00:00
* fix(providers): respect user-configured baseUrl for kimi-coding The kimi-coding provider was built exclusively from `buildKimiCodingProvider()` defaults, ignoring any user-specified `baseUrl` or other overrides in `openclaw.json` providers config. This caused 404 errors when users configured a custom endpoint. Now merge `explicitProviders["kimi-coding"]` on top of defaults, matching the pattern used by ollama/vllm. User's `baseUrl`, `api`, and `models` take precedence; env/profile API key still wins. Fixes #36353 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Tests: use Kimi implicit provider harness --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
import { mkdtempSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { captureEnv } from "../test-utils/env.js";
|
|
import { resolveImplicitProvidersForTest } from "./models-config.e2e-harness.js";
|
|
import { buildKimiCodingProvider } from "./models-config.providers.js";
|
|
|
|
describe("kimi-coding implicit provider (#22409)", () => {
|
|
it("should include kimi-coding when KIMI_API_KEY is configured", async () => {
|
|
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
|
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
|
process.env.KIMI_API_KEY = "test-key"; // pragma: allowlist secret
|
|
|
|
try {
|
|
const providers = await resolveImplicitProvidersForTest({ agentDir });
|
|
expect(providers?.["kimi-coding"]).toBeDefined();
|
|
expect(providers?.["kimi-coding"]?.api).toBe("anthropic-messages");
|
|
expect(providers?.["kimi-coding"]?.baseUrl).toBe("https://api.kimi.com/coding/");
|
|
} finally {
|
|
envSnapshot.restore();
|
|
}
|
|
});
|
|
|
|
it("should build kimi-coding provider with anthropic-messages API", () => {
|
|
const provider = buildKimiCodingProvider();
|
|
expect(provider.api).toBe("anthropic-messages");
|
|
expect(provider.baseUrl).toBe("https://api.kimi.com/coding/");
|
|
expect(provider.models).toBeDefined();
|
|
expect(provider.models.length).toBeGreaterThan(0);
|
|
expect(provider.models[0].id).toBe("k2p5");
|
|
});
|
|
|
|
it("should not include kimi-coding when no API key is configured", async () => {
|
|
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
|
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
|
delete process.env.KIMI_API_KEY;
|
|
|
|
try {
|
|
const providers = await resolveImplicitProvidersForTest({ agentDir });
|
|
expect(providers?.["kimi-coding"]).toBeUndefined();
|
|
} finally {
|
|
envSnapshot.restore();
|
|
}
|
|
});
|
|
|
|
it("uses explicit kimi-coding baseUrl when provided", async () => {
|
|
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
|
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
|
process.env.KIMI_API_KEY = "test-key";
|
|
|
|
try {
|
|
const providers = await resolveImplicitProvidersForTest({
|
|
agentDir,
|
|
explicitProviders: {
|
|
"kimi-coding": {
|
|
baseUrl: "https://kimi.example.test/coding/",
|
|
api: "anthropic-messages",
|
|
models: buildKimiCodingProvider().models,
|
|
},
|
|
},
|
|
});
|
|
expect(providers?.["kimi-coding"]?.baseUrl).toBe("https://kimi.example.test/coding/");
|
|
} finally {
|
|
envSnapshot.restore();
|
|
}
|
|
});
|
|
});
|