From 5a3eb5ad6289c3646119d4ca9e39bc787edad206 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 12 Jan 2026 16:52:35 +0000 Subject: [PATCH] test: cover models.json apiKey fill --- src/agents/models-config.test.ts | 49 +++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/agents/models-config.test.ts b/src/agents/models-config.test.ts index 72930e0f1..050f485cd 100644 --- a/src/agents/models-config.test.ts +++ b/src/agents/models-config.test.ts @@ -80,12 +80,13 @@ describe("models config", () => { const parsed = JSON.parse(raw) as { providers: Record< string, - { baseUrl?: string; models?: Array<{ id: string }> } + { baseUrl?: string; apiKey?: string; models?: Array<{ id: string }> } >; }; expect(parsed.providers.minimax?.baseUrl).toBe( "https://api.minimax.io/anthropic", ); + expect(parsed.providers.minimax?.apiKey).toBe("MINIMAX_API_KEY"); const ids = parsed.providers.minimax?.models?.map((model) => model.id); expect(ids).toContain("MiniMax-M2.1"); } finally { @@ -95,6 +96,52 @@ describe("models config", () => { }); }); + it("fills missing provider.apiKey from env var name when models exist", async () => { + await withTempHome(async () => { + vi.resetModules(); + const prevKey = process.env.MINIMAX_API_KEY; + process.env.MINIMAX_API_KEY = "sk-minimax-test"; + try { + const { ensureClawdbotModelsJson } = await import("./models-config.js"); + const { resolveClawdbotAgentDir } = await import("./agent-paths.js"); + + const cfg: ClawdbotConfig = { + models: { + providers: { + minimax: { + baseUrl: "https://api.minimax.io/anthropic", + api: "anthropic-messages", + models: [ + { + id: "MiniMax-M2.1", + name: "MiniMax M2.1", + reasoning: false, + input: ["text"], + cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, + contextWindow: 200000, + maxTokens: 8192, + }, + ], + }, + }, + }, + }; + + await ensureClawdbotModelsJson(cfg); + + const modelPath = path.join(resolveClawdbotAgentDir(), "models.json"); + const raw = await fs.readFile(modelPath, "utf8"); + const parsed = JSON.parse(raw) as { + providers: Record; + }; + expect(parsed.providers.minimax?.apiKey).toBe("MINIMAX_API_KEY"); + } finally { + if (prevKey === undefined) delete process.env.MINIMAX_API_KEY; + else process.env.MINIMAX_API_KEY = prevKey; + } + }); + }); + it("merges providers by default", async () => { await withTempHome(async () => { vi.resetModules();