Skip to content

Commit 3bb6923

Browse files
committed
fix(sessions): restore fallback resolver tests alongside numeric sorting
Preserve the existing findInitialModel and restoreModelFromSession fallback coverage that was removed when adding parseModelPattern numeric alias-ordering tests. Both test groups now coexist. Addresses Codex review finding: removed fallback tests left startup and restored-session model selection unpinned.
1 parent 557db86 commit 3bb6923

1 file changed

Lines changed: 62 additions & 1 deletion

File tree

‎src/agents/sessions/model-resolver.test.ts‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,67 @@
1+
// Model resolver tests pin the startup fallback order for fresh and restored
2+
// agent sessions, plus numeric-aware alias sorting.
13
import { describe, expect, it } from "vitest";
24
import type { Model } from "../../llm/types.js";
3-
import { findExactModelReferenceMatch, parseModelPattern } from "./model-resolver.js";
5+
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../defaults.js";
6+
import type { ModelRegistry } from "./model-registry.js";
7+
import {
8+
findExactModelReferenceMatch,
9+
findInitialModel,
10+
parseModelPattern,
11+
restoreModelFromSession,
12+
} from "./model-resolver.js";
13+
14+
function model(provider: string, id: string): Model {
15+
return {
16+
id,
17+
name: id,
18+
api: "openai-responses",
19+
provider,
20+
baseUrl: `https://${provider}.example.test`,
21+
reasoning: false,
22+
input: ["text"],
23+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
24+
contextWindow: 128_000,
25+
maxTokens: 16_384,
26+
};
27+
}
28+
29+
function registry(models: Model[]): ModelRegistry {
30+
return {
31+
find: (provider: string, modelId: string) =>
32+
models.find((entry) => entry.provider === provider && entry.id === modelId),
33+
getAvailable: () => models,
34+
hasConfiguredAuth: (entry: Model) => models.includes(entry),
35+
} as ModelRegistry;
36+
}
37+
38+
describe("model resolver fallback selection", () => {
39+
it("prefers the product default when no configured or scoped model is selected", async () => {
40+
const productDefault = model(DEFAULT_PROVIDER, DEFAULT_MODEL);
41+
const result = await findInitialModel({
42+
scopedModels: [],
43+
isContinuing: false,
44+
modelRegistry: registry([model("anthropic", "claude-opus-4.7"), productDefault]),
45+
});
46+
47+
expect(result.model).toBe(productDefault);
48+
});
49+
50+
it("falls back to registry order instead of core provider defaults", async () => {
51+
// Restored sessions can reference removed models; choose an authenticated
52+
// registry model rather than reviving a hard-coded provider default.
53+
const firstAvailable = model("anthropic", "claude-haiku");
54+
const result = await restoreModelFromSession(
55+
"openai",
56+
"missing-model",
57+
undefined,
58+
false,
59+
registry([firstAvailable, model("anthropic", "claude-opus-4.7")]),
60+
);
61+
62+
expect(result.model).toBe(firstAvailable);
63+
});
64+
});
465

566
function makeModel(id: string, provider = "anthropic"): Model {
667
return { id, name: id, provider } as Model;

0 commit comments

Comments
 (0)