fix(config): avoid Anthropic startup crash

This commit is contained in:
Val Alexander
2026-03-13 17:24:50 -05:00
parent aab43448ef
commit b2cc50c863
3 changed files with 44 additions and 8 deletions

View File

@@ -121,6 +121,12 @@ describe("model-selection", () => {
defaultProvider: "anthropic",
expected: { provider: "anthropic", model: "claude-sonnet-4-6" },
},
{
name: "keeps dated anthropic model ids unchanged",
variants: ["anthropic/claude-sonnet-4-20250514", "claude-sonnet-4-20250514"],
defaultProvider: "anthropic",
expected: { provider: "anthropic", model: "claude-sonnet-4-20250514" },
},
{
name: "normalizes deprecated google flash preview ids",
variants: ["google/gemini-3.1-flash-preview", "gemini-3.1-flash-preview"],

View File

@@ -31,13 +31,6 @@ export type ModelAliasIndex = {
byKey: Map<string, string[]>;
};
const ANTHROPIC_MODEL_ALIASES: Record<string, string> = {
"opus-4.6": "claude-opus-4-6",
"opus-4.5": "claude-opus-4-5",
"sonnet-4.6": "claude-sonnet-4-6",
"sonnet-4.5": "claude-sonnet-4-5",
};
function normalizeAliasKey(value: string): string {
return value.trim().toLowerCase();
}
@@ -151,7 +144,20 @@ function normalizeAnthropicModelId(model: string): string {
return trimmed;
}
const lower = trimmed.toLowerCase();
return ANTHROPIC_MODEL_ALIASES[lower] ?? trimmed;
// Keep alias resolution local so bundled startup paths cannot trip a TDZ on
// a module-level alias table while config parsing is still initializing.
switch (lower) {
case "opus-4.6":
return "claude-opus-4-6";
case "opus-4.5":
return "claude-opus-4-5";
case "sonnet-4.6":
return "claude-sonnet-4-6";
case "sonnet-4.5":
return "claude-sonnet-4-5";
default:
return trimmed;
}
}
function normalizeProviderModelId(provider: string, model: string): string {

View File

@@ -73,6 +73,30 @@ describe("config pruning defaults", () => {
});
});
it("adds cacheRetention defaults for dated Anthropic primary model refs", async () => {
await withTempHome(async (home) => {
await writeConfigForTest(home, {
auth: {
profiles: {
"anthropic:api": { provider: "anthropic", mode: "api_key" },
},
},
agents: {
defaults: {
model: { primary: "anthropic/claude-sonnet-4-20250514" },
},
},
});
const cfg = loadConfig();
expect(
cfg.agents?.defaults?.models?.["anthropic/claude-sonnet-4-20250514"]?.params
?.cacheRetention,
).toBe("short");
});
});
it("adds default cacheRetention for Anthropic Claude models on Bedrock", async () => {
await withTempHome(async (home) => {
await writeConfigForTest(home, {