fix: prefer canonical cli backend config keys

This commit is contained in:
Tak Hoffman
2026-03-27 20:38:47 -05:00
parent c364fc8428
commit 02bce20dd0
2 changed files with 44 additions and 0 deletions

View File

@@ -310,3 +310,43 @@ describe("resolveCliBackendConfig google-gemini-cli defaults", () => {
expect(resolved?.config.modelAliases?.pro).toBe("gemini-3.1-pro-preview");
});
});
describe("resolveCliBackendConfig alias precedence", () => {
it("prefers the canonical backend key over legacy aliases when both are configured", () => {
const registry = createEmptyPluginRegistry();
registry.cliBackends = [
createBackendEntry({
pluginId: "moonshot",
id: "kimi",
config: {
command: "kimi",
args: ["--default"],
},
}),
];
setActivePluginRegistry(registry);
const cfg = {
agents: {
defaults: {
cliBackends: {
"kimi-coding": {
command: "kimi-legacy",
args: ["--legacy"],
},
kimi: {
command: "kimi-canonical",
args: ["--canonical"],
},
},
},
},
} satisfies OpenClawConfig;
const resolved = resolveCliBackendConfig("kimi", cfg);
expect(resolved).not.toBeNull();
expect(resolved?.config.command).toBe("kimi-canonical");
expect(resolved?.config.args).toEqual(["--canonical"]);
});
});

View File

@@ -18,6 +18,10 @@ function pickBackendConfig(
config: Record<string, CliBackendConfig>,
normalizedId: string,
): CliBackendConfig | undefined {
const directKey = Object.keys(config).find((key) => key.trim().toLowerCase() === normalizedId);
if (directKey) {
return config[directKey];
}
for (const [key, entry] of Object.entries(config)) {
if (normalizeBackendKey(key) === normalizedId) {
return entry;