fix(agents): fall back to agents.defaults.model when agent has no model config (#24210)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 0f272b1027
Co-authored-by: bianbiandashen <16240681+bianbiandashen@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
边黎安
2026-02-23 16:18:55 +08:00
committed by GitHub
parent db32677f1d
commit a4c373935f
39 changed files with 434 additions and 251 deletions

View File

@@ -82,6 +82,25 @@ describe("models set + fallbacks", () => {
});
});
it("preserves primary when adding fallbacks to string defaults.model", async () => {
mockConfigSnapshot({ agents: { defaults: { model: "openai/gpt-4.1-mini" } } });
const runtime = makeRuntime();
await modelsFallbacksAddCommand("anthropic/claude-opus-4-6", runtime);
expect(writeConfigFile).toHaveBeenCalledTimes(1);
const written = getWrittenConfig();
expect(written.agents).toEqual({
defaults: {
model: {
primary: "openai/gpt-4.1-mini",
fallbacks: ["anthropic/claude-opus-4-6"],
},
models: { "anthropic/claude-opus-4-6": {} },
},
});
});
it("normalizes provider casing in models set", async () => {
mockConfigSnapshot({});
const runtime = makeRuntime();
@@ -90,4 +109,20 @@ describe("models set + fallbacks", () => {
expectWrittenPrimaryModel("zai/glm-4.7");
});
it("rewrites string defaults.model to object form when setting primary", async () => {
mockConfigSnapshot({ agents: { defaults: { model: "openai/gpt-4.1-mini" } } });
const runtime = makeRuntime();
await modelsSetCommand("anthropic/claude-opus-4-6", runtime);
expect(writeConfigFile).toHaveBeenCalledTimes(1);
const written = getWrittenConfig();
expect(written.agents).toEqual({
defaults: {
model: { primary: "anthropic/claude-opus-4-6" },
models: { "anthropic/claude-opus-4-6": {} },
},
});
});
});