fix(model-resolver): use numeric-aware version comparison for model alias resolution

This commit is contained in:
zw-xysk
2026-06-29 09:55:25 +08:00
committed by GitHub
parent bf83ea1394
commit 7ae52dc56e
2 changed files with 15 additions and 3 deletions
+13 -1
View File
@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";
import type { Model } from "../../llm/types.js";
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../defaults.js";
import type { ModelRegistry } from "./model-registry.js";
import { findInitialModel, restoreModelFromSession } from "./model-resolver.js";
import { findInitialModel, parseModelPattern, restoreModelFromSession } from "./model-resolver.js";
function model(provider: string, id: string): Model {
return {
@@ -57,3 +57,15 @@ describe("model resolver fallback selection", () => {
expect(result.model).toBe(firstAvailable);
});
});
describe("parseModelPattern version sorting", () => {
it("selects the numerically highest version when aliases span double-digit minors", () => {
const models = [
model("anthropic", "claude-opus-4-9"),
model("anthropic", "claude-opus-4-10"),
model("anthropic", "claude-opus-4-11"),
];
const result = parseModelPattern("opus", models);
expect(result.model?.id).toBe("claude-opus-4-11");
});
});
+2 -2
View File
@@ -116,11 +116,11 @@ function tryMatchModel(modelPattern: string, availableModels: Model[]): Model |
if (aliases.length > 0) {
// Prefer alias - if multiple aliases, pick the one that sorts highest
aliases.sort((a, b) => b.id.localeCompare(a.id));
aliases.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true }));
return aliases[0];
}
// No alias found, pick latest dated version
datedVersions.sort((a, b) => b.id.localeCompare(a.id));
datedVersions.sort((a, b) => b.id.localeCompare(a.id, undefined, { numeric: true }));
return datedVersions[0];
}