Files
openclaw/extensions/kimi-coding/implicit-provider.test.ts
loong 7bdd1f646b fix(memory-host-sdk): resolve stable execPath for worker fork to survive Homebrew Node upgrades (#99318)
* fix(memory): survive Homebrew Node upgrades

Co-authored-by: 袁龙辉0668001277 <yuan.longhui@xydigit.com>

* test(whatsapp): isolate last-route coverage

* fix(deepinfra): preserve offline model compatibility

* test(memory): isolate migration cleanup lifecycle

* test: stabilize aggregate extension gates

* ci: retrigger pull request workflow

* test: preserve inherited Node options

* test(cli): tolerate cold hosted startup

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-29 06:49:02 -04:00

136 lines
4.1 KiB
TypeScript

// Kimi Coding tests cover implicit provider plugin behavior.
import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime";
import { describe, expect, it } from "vitest";
import plugin from "./index.js";
async function runKimiCatalog(params: {
apiKey?: string;
explicitProvider?: Record<string, unknown>;
}) {
const provider = await registerSingleProviderPlugin(plugin);
const catalogResult = await provider.catalog?.run({
config: {
models: {
providers: params.explicitProvider
? {
"kimi-coding": params.explicitProvider,
}
: {},
},
},
resolveProviderApiKey: () => ({ apiKey: params.apiKey ?? "" }),
} as never);
return catalogResult ?? null;
}
async function runKimiCatalogProvider(params: {
apiKey: string;
explicitProvider?: Record<string, unknown>;
}) {
const result = await runKimiCatalog(params);
if (!result || !("provider" in result)) {
throw new Error("expected Kimi catalog to return one provider");
}
return result.provider;
}
describe("Kimi implicit provider (#22409)", () => {
it("publishes the env vars used by core api-key auto-detection", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(provider.envVars).toEqual(["KIMI_API_KEY", "KIMICODE_API_KEY"]);
});
it("does not publish a provider when no API key is resolved", async () => {
await expect(runKimiCatalog({})).resolves.toBeNull();
});
it("publishes the Kimi provider when an API key is resolved", async () => {
const provider = await runKimiCatalogProvider({ apiKey: "test-key" });
expect(provider).toEqual({
baseUrl: "https://api.kimi.com/coding/",
api: "anthropic-messages",
headers: {
"User-Agent": "claude-code/0.1.0",
},
// Credential-aware catalog assembly may prioritize the configured default.
models: expect.arrayContaining([
{
id: "kimi-for-coding",
name: "Kimi Code",
reasoning: true,
input: ["text", "image"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 262144,
maxTokens: 32768,
},
{
id: "kimi-for-coding-highspeed",
name: "Kimi K2.7 Code HighSpeed",
reasoning: true,
input: ["text", "image"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 262144,
maxTokens: 32768,
},
{
id: "k3",
name: "Kimi K3",
reasoning: true,
thinkingLevelMap: {
off: null,
minimal: "low",
low: "low",
medium: "high",
high: "high",
xhigh: "max",
max: "max",
},
input: ["text", "image"],
compat: { codeMode: "preferred" },
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 0 },
contextWindow: 1048576,
maxTokens: 131072,
},
{
id: "k3-256k",
name: "Kimi K3 (256k)",
reasoning: true,
thinkingLevelMap: {
off: null,
minimal: "low",
low: "low",
medium: "high",
high: "high",
xhigh: "max",
max: "max",
},
input: ["text", "image"],
compat: { codeMode: "preferred" },
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 0 },
contextWindow: 262144,
maxTokens: 131072,
},
]),
apiKey: "test-key",
});
expect(provider.models).toHaveLength(4);
});
it("ignores retired kimi-coding provider overrides", async () => {
const provider = await runKimiCatalogProvider({
apiKey: "test-key",
explicitProvider: {
baseUrl: "https://kimi.example.test/coding/",
headers: {
"User-Agent": "custom-kimi-client/1.0",
},
},
});
expect(provider.baseUrl).toBe("https://api.kimi.com/coding/");
expect(provider.headers).toEqual({ "User-Agent": "claude-code/0.1.0" });
});
});