mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:01:23 +00:00
Models/Config: default missing Anthropic model api fields
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { validateConfigObject } from "../config/validation.js";
|
||||
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
||||
import {
|
||||
CUSTOM_PROXY_MODELS_CONFIG,
|
||||
@@ -13,6 +14,37 @@ import { ensureOpenClawModelsJson } from "./models-config.js";
|
||||
installModelsConfigTestHooks();
|
||||
|
||||
describe("models-config", () => {
|
||||
it("keeps anthropic api defaults when model entries omit api", async () => {
|
||||
await withTempHome(async () => {
|
||||
const validated = validateConfigObject({
|
||||
models: {
|
||||
providers: {
|
||||
anthropic: {
|
||||
baseUrl: "https://relay.example.com/api",
|
||||
apiKey: "cr_xxxx",
|
||||
models: [{ id: "claude-opus-4-6", name: "Claude Opus 4.6" }],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(validated.ok).toBe(true);
|
||||
if (!validated.ok) {
|
||||
throw new Error("expected config to validate");
|
||||
}
|
||||
|
||||
await ensureOpenClawModelsJson(validated.config);
|
||||
|
||||
const modelPath = path.join(resolveOpenClawAgentDir(), "models.json");
|
||||
const raw = await fs.readFile(modelPath, "utf8");
|
||||
const parsed = JSON.parse(raw) as {
|
||||
providers: Record<string, { api?: string; models?: Array<{ id: string; api?: string }> }>;
|
||||
};
|
||||
|
||||
expect(parsed.providers.anthropic?.api).toBe("anthropic-messages");
|
||||
expect(parsed.providers.anthropic?.models?.[0]?.api).toBe("anthropic-messages");
|
||||
});
|
||||
});
|
||||
|
||||
it("fills missing provider.apiKey from env var name when models exist", async () => {
|
||||
await withTempHome(async () => {
|
||||
const prevKey = process.env.MINIMAX_API_KEY;
|
||||
|
||||
Reference in New Issue
Block a user