Open History to see the last commit
1import {
2 ANTIGRAVITY_DEFAULT_MODEL,
3 DEFAULT_TEXT_GENERATION_MODEL,
4 ProviderDriverKind,
5 ProviderInstanceId,
6 type ServerProvider,
7} from "@t3tools/contracts";
8import { DEFAULT_UNIFIED_SETTINGS, type UnifiedSettings } from "@t3tools/contracts/settings";
9import { describe, expect, it } from "vite-plus/test";
10import { createModelSelection } from "@t3tools/shared/model";
11import { deriveEffectiveComposerModelState } from "./composerDraftStore";
12import { getComposerProviderState } from "./components/chat/composerProviderState";
13import { deriveProviderInstanceEntries, NO_PROVIDER_MODEL_SELECTION } from "./providerInstances";
14import {
15 getAppModelOptionsForInstance,
16 resolveAppModelSelectionForInstance,
17 resolveAppModelSelectionState,
18 resolveEffectiveDefaultModelSelection,
19} from "./modelSelection";
20
21function provider(input: {
22 provider?: ProviderDriverKind;
23 instanceId: string;
24 models?: ReadonlyArray<string>;
25 supportsTextGeneration?: boolean;
26}): ServerProvider {
27 const driver =
28 input.provider ??
29 (input.instanceId.startsWith("claude_")
30 ? ProviderDriverKind.make("claudeAgent")
31 : ProviderDriverKind.make("codex"));
32 return {
33 instanceId: ProviderInstanceId.make(input.instanceId),
34 driver,
35 ...(input.supportsTextGeneration === undefined
36 ? {}
37 : { supportsTextGeneration: input.supportsTextGeneration }),
38 enabled: true,
39 installed: true,
40 version: null,
41 status: "ready",
42 auth: { status: "authenticated" },
43 checkedAt: "2026-01-01T00:00:00.000Z",
44 models: (input.models ?? []).map((slug) => ({
45 slug,
46 name: slug,
47 isCustom: false,
48 capabilities: {},
49 })),
50 slashCommands: [],
51 skills: [],
52 };
53}
54
55function settingsWithProviderInstances(): UnifiedSettings {
56 return {
57 ...DEFAULT_UNIFIED_SETTINGS,
58 providerInstances: {
59 [ProviderInstanceId.make("claudeAgent")]: {
60 driver: ProviderDriverKind.make("claudeAgent"),
61 config: { customModels: [] },
62 },
63 [ProviderInstanceId.make("claude_openrouter")]: {
64 driver: ProviderDriverKind.make("claudeAgent"),
65 config: { customModels: ["openai/gpt-5.5"] },
66 },
67 },
68 };
69}
70
71describe("instance-scoped model selection", () => {
72 it("keeps custom models on the provider instance that declared them", () => {
73 const providers = [
74 provider({
75 instanceId: "claudeAgent",
76 models: ["claude-sonnet-4-6"],
77 }),
78 provider({
79 instanceId: "claude_openrouter",
80 models: ["claude-sonnet-4-6"],
81 }),
82 ];
83 const entries = deriveProviderInstanceEntries(providers);
84 const stock = entries.find((entry) => entry.instanceId === "claudeAgent")!;
85 const openrouter = entries.find((entry) => entry.instanceId === "claude_openrouter")!;
86
87 expect(
88 getAppModelOptionsForInstance(settingsWithProviderInstances(), stock).map(
89 (option) => option.slug,
90 ),
91 ).not.toContain("openai/gpt-5.5");
92 expect(
93 getAppModelOptionsForInstance(settingsWithProviderInstances(), openrouter).map(
94 (option) => option.slug,
95 ),
96 ).toContain("openai/gpt-5.5");
97 });
98
99 it("preserves a custom slug that collides with a provider alias", () => {
100 const providers = [
101 provider({
102 provider: ProviderDriverKind.make("claudeAgent"),
103 instanceId: "claude_openrouter",
104 models: ["claude-opus-4-8"],
105 }),
106 ];
107 const settings: UnifiedSettings = {
108 ...settingsWithProviderInstances(),
109 providerInstances: {
110 ...settingsWithProviderInstances().providerInstances,
111 [ProviderInstanceId.make("claude_openrouter")]: {
112 driver: ProviderDriverKind.make("claudeAgent"),
113 config: { customModels: ["opus"] },
114 },
115 },
116 };
117 const openrouter = deriveProviderInstanceEntries(providers)[0]!;
118
119 expect(
120 getAppModelOptionsForInstance(settings, openrouter).map((option) => option.slug),
121 ).toEqual(["claude-opus-4-8", "opus"]);
122 expect(
123 resolveAppModelSelectionForInstance(
124 ProviderInstanceId.make("claude_openrouter"),
125 settings,
126 providers,
127 "opus",
128 ),
129 ).toBe("opus");
130 });
131
132 it("offers and resolves every saved custom model, past the first 32", () => {
133 const providers = [
134 provider({
135 provider: ProviderDriverKind.make("claudeAgent"),
136 instanceId: "claude_openrouter",
137 }),
138 ];
139 const customModels = Array.from({ length: 40 }, (_, index) => `proxy/model-${index + 1}`);
140 const settings: UnifiedSettings = {
141 ...settingsWithProviderInstances(),
142 providerInstances: {
143 ...settingsWithProviderInstances().providerInstances,
144 [ProviderInstanceId.make("claude_openrouter")]: {
145 driver: ProviderDriverKind.make("claudeAgent"),
146 config: { customModels },
147 },
148 },
149 };
150 const openrouter = deriveProviderInstanceEntries(providers)[0]!;
151
152 expect(
153 getAppModelOptionsForInstance(settings, openrouter).map((option) => option.slug),
154 ).toEqual(customModels);
155 expect(
156 resolveAppModelSelectionForInstance(
157 ProviderInstanceId.make("claude_openrouter"),
158 settings,
159 providers,
160 "proxy/model-40",
161 ),
162 ).toBe("proxy/model-40");
163 });
164
165 it("drops server-reported custom rows that are no longer in settings", () => {
166 const baseProvider = provider({
167 instanceId: "claude_openrouter",
168 models: ["claude-sonnet-4-6"],
169 });
170 const providers = [
171 {
172 ...baseProvider,
173 models: [
174 ...baseProvider.models,
175 { slug: "removed/custom", name: "removed/custom", isCustom: true, capabilities: {} },
176 ],
177 },
178 ];
179 const openrouter = deriveProviderInstanceEntries(providers)[0]!;
180
181 expect(
182 getAppModelOptionsForInstance(settingsWithProviderInstances(), openrouter).map(
183 (option) => option.slug,
184 ),
185 ).toEqual(["claude-sonnet-4-6", "openai/gpt-5.5"]);
186 });
187
188 it("falls back when the selected model is hidden", () => {
189 const providers = [
190 provider({
191 instanceId: "claudeAgent",
192 models: ["claude-opus-4-6", "claude-sonnet-4-6"],
193 }),
194 ];
195 const settings: UnifiedSettings = {
196 ...settingsWithProviderInstances(),
197 providerModelPreferences: {
198 [ProviderInstanceId.make("claudeAgent")]: {
199 hiddenModels: ["claude-opus-4-6"],
200 modelOrder: [],
201 },
202 },
203 };
204
205 expect(
206 resolveAppModelSelectionForInstance(
207 ProviderInstanceId.make("claudeAgent"),
208 settings,
209 providers,
210 "claude-opus-4-6",
211 ),
212 ).toBe("claude-sonnet-4-6");
213 expect(
214 resolveAppModelSelectionForInstance(
215 ProviderInstanceId.make("claudeAgent"),
216 settings,
217 providers,
218 "claude-opus-4-6",
219 { preserveUnavailableSelection: true },
220 ),
221 ).toBe("claude-sonnet-4-6");
222 });
223
224 it("falls back instead of resolving a custom slug against the wrong instance", () => {
225 const providers = [
226 provider({
227 instanceId: "claudeAgent",
228 models: ["claude-sonnet-4-6"],
229 }),
230 provider({
231 instanceId: "claude_openrouter",
232 models: ["claude-sonnet-4-6"],
233 }),
234 ];
235
236 expect(
237 resolveAppModelSelectionForInstance(
238 ProviderInstanceId.make("claudeAgent"),
239 settingsWithProviderInstances(),
240 providers,
241 "openai/gpt-5.5",
242 ),
243 ).toBe("claude-sonnet-4-6");
244 });
245
246 describe.each([
247 {
248 driverName: "opencode",
249 availableModel: "opencode/big-pickle",
250 missingModel: "opencode/kimi-k3",
251 },
252 {
253 driverName: "antigravity",
254 availableModel: "gemini-3.1-pro",
255 missingModel: "gemini-3.1-pro-high",
256 },
257 ])("$driverName catalog gaps", ({ driverName, availableModel, missingModel }) => {
258 it("preserves a selected model when a catalog refresh no longer contains it", () => {
259 const providers = [
260 provider({
261 provider: ProviderDriverKind.make(driverName),
262 instanceId: driverName,
263 models: [availableModel],
264 }),
265 ];
266
267 expect(
268 resolveAppModelSelectionForInstance(
269 ProviderInstanceId.make(driverName),
270 settingsWithProviderInstances(),
271 providers,
272 missingModel,
273 { preserveUnavailableSelection: true },
274 ),
275 ).toBe(missingModel);
276 expect(
277 resolveAppModelSelectionForInstance(
278 ProviderInstanceId.make(driverName),
279 settingsWithProviderInstances(),
280 providers,
281 missingModel,
282 ),
283 ).toBe(availableModel);
284 });
285
286 it("adds the selected missing model as an unavailable option", () => {
287 const providers = [
288 provider({
289 provider: ProviderDriverKind.make(driverName),
290 instanceId: driverName,
291 models: [availableModel],
292 }),
293 ];
294 const entry = deriveProviderInstanceEntries(providers)[0]!;
295
296 expect(
297 getAppModelOptionsForInstance(settingsWithProviderInstances(), entry, missingModel),
298 ).toEqual([
299 expect.objectContaining({ slug: availableModel }),
300 expect.objectContaining({
301 slug: missingModel,
302 name: missingModel,
303 isUnavailable: true,
304 }),
305 ]);
306 });
307
308 it("does not resurrect a hidden model when the raw catalog omits it", () => {
309 const instanceId = ProviderInstanceId.make(driverName);
310 const driver = ProviderDriverKind.make(driverName);
311 const settings: UnifiedSettings = {
312 ...settingsWithProviderInstances(),
313 providerModelPreferences: {
314 [instanceId]: {
315 hiddenModels: [missingModel],
316 modelOrder: [],
317 },
318 },
319 };
320 const providers = [provider({ provider: driver, instanceId, models: [] })];
321 const entry = deriveProviderInstanceEntries(providers)[0]!;
322
323 expect(getAppModelOptionsForInstance(settings, entry, missingModel)).toEqual([]);
324 expect(
325 resolveAppModelSelectionForInstance(instanceId, settings, providers, missingModel, {
326 preserveUnavailableSelection: true,
327 }),
328 ).toBeNull();
329 });
330 });
331
332 it("falls back from an explicit non-OpenCode draft with a missing model", () => {
333 const instanceId = ProviderInstanceId.make("codex");
334 const driver = ProviderDriverKind.make("codex");
335 const providers = [provider({ provider: driver, instanceId, models: ["gpt-5.6-sol"] })];
336 const state = deriveEffectiveComposerModelState({
337 draft: {
338 activeProvider: instanceId,
339 modelSelectionByProvider: {
340 [instanceId]: createModelSelection(instanceId, "gpt-missing", [
341 { id: "effort", value: "max" },
342 ]),
343 },
344 },
345 providers,
346 selectedProvider: driver,
347 selectedInstanceId: instanceId,
348 threadModelSelection: null,
349 projectModelSelection: null,
350 settings: settingsWithProviderInstances(),
351 });
352 const dispatch = getComposerProviderState({
353 provider: driver,
354 model: state.selectedModel,
355 models: providers[0]!.models,
356 modelOptions: state.modelOptions?.[instanceId],
357 planModeEnabled: false,
358 });
359
360 expect(state.selectedModel).toBe("gpt-5.6-sol");
361 expect(dispatch.modelOptionsForDispatch).toBeUndefined();
362 });
363
364 it("preserves an explicit draft OpenCode selection while the catalog is empty", () => {
365 const instanceId = ProviderInstanceId.make("opencode_work");
366 const driver = ProviderDriverKind.make("opencode");
367 const draftSelection = createModelSelection(instanceId, "openrouter/kimi-k3", [
368 { id: "variant", value: "max" },
369 { id: "agent", value: "build" },
370 ]);
371 const providers = [provider({ provider: driver, instanceId, models: [] })];
372 const state = deriveEffectiveComposerModelState({
373 draft: {
374 activeProvider: instanceId,
375 modelSelectionByProvider: { [instanceId]: draftSelection },
376 },
377 providers,
378 selectedProvider: driver,
379 selectedInstanceId: instanceId,
380 threadModelSelection: null,
381 projectModelSelection: null,
382 settings: settingsWithProviderInstances(),
383 });
384
385 expect(state.selectedModel).toBe("openrouter/kimi-k3");
386 expect(state.modelOptions?.[instanceId]).toEqual(draftSelection.options);
387 });
388
389 it("preserves the Antigravity model in drafts and existing threads after sign-out", () => {
390 const instanceId = ProviderInstanceId.make("antigravity_work");
391 const driver = ProviderDriverKind.make("antigravity");
392 const saved = createModelSelection(instanceId, "gemini-3.1-pro-high");
393 const providers = [
394 {
395 ...provider({ provider: driver, instanceId, models: [] }),
396 status: "error" as const,
397 auth: { status: "unauthenticated" as const },
398 },
399 ];
400 for (const draft of [
401 null,
402 { activeProvider: instanceId, modelSelectionByProvider: { [instanceId]: saved } },
403 ]) {
404 const state = deriveEffectiveComposerModelState({
405 draft,
406 providers,
407 selectedProvider: driver,
408 selectedInstanceId: instanceId,
409 threadModelSelection: saved,
410 projectModelSelection: null,
411 settings: settingsWithProviderInstances(),
412 });
413 expect(state.selectedModel).toBe(saved.model);
414 }
415 });
416
417 it("does not borrow a default model while a new Antigravity account has no catalog", () => {
418 const driver = ProviderDriverKind.make("antigravity");
419 const instanceId = ProviderInstanceId.make("antigravity_work");
420 const providers = [
421 provider({ instanceId: "codex", models: ["gpt-5.6-sol"] }),
422 provider({ provider: driver, instanceId: "antigravity", models: ["gemini-other-account"] }),
423 provider({ provider: driver, instanceId, models: [] }),
424 ];
425
426 const otherAccountId = ProviderInstanceId.make("antigravity");
427 for (const draft of [
428 null,
429 {
430 activeProvider: instanceId,
431 modelSelectionByProvider: {
432 [otherAccountId]: createModelSelection(otherAccountId, "gemini-other-account"),
433 },
434 },
435 ]) {
436 const state = deriveEffectiveComposerModelState({
437 draft,
438 providers,
439 selectedProvider: driver,
440 selectedInstanceId: instanceId,
441 threadModelSelection: null,
442 projectModelSelection: createModelSelection(
443 ProviderInstanceId.make("codex"),
444 "gpt-5.6-sol",
445 ),
446 settings: settingsWithProviderInstances(),
447 });
448 expect(state.selectedModel).toBe("");
449 }
450 });
451
452 it("offers only account catalog models for Antigravity despite custom model settings", () => {
453 const driver = ProviderDriverKind.make("antigravity");
454 const customId = ProviderInstanceId.make("antigravity_work");
455 const nativeModel = "gemini-3.1-pro";
456 const settings: UnifiedSettings = {
457 ...DEFAULT_UNIFIED_SETTINGS,
458 providerInstances: {
459 [ProviderInstanceId.make("antigravity")]: {
460 driver,
461 config: { customModels: ["api-only-model"] },
462 },
463 [customId]: { driver, config: { customModels: ["unknown-model"] } },
464 },
465 };
466 const entries = deriveProviderInstanceEntries([
467 provider({ provider: driver, instanceId: "antigravity", models: [nativeModel] }),
468 provider({ provider: driver, instanceId: customId, models: [nativeModel] }),
469 ]);
470
471 for (const entry of entries) {
472 expect(getAppModelOptionsForInstance(settings, entry).map((model) => model.slug)).toEqual([
473 nativeModel,
474 ]);
475 }
476 });
477
478 it("resolves the Antigravity default marker without creating an unavailable model", () => {
479 const instanceId = ProviderInstanceId.make("antigravity_work");
480 const nativeModel = "gemini-3.1-pro";
481 const base = provider({
482 provider: ProviderDriverKind.make("antigravity"),
483 instanceId,
484 models: [nativeModel],
485 });
486 const liveProvider = {
487 ...base,
488 models: base.models.map((model) => ({
489 ...model,
490 isDefault: true,
491 aliases: [ANTIGRAVITY_DEFAULT_MODEL],
492 })),
493 };
494 const settings = settingsWithProviderInstances();
495
496 expect(
497 getAppModelOptionsForInstance(
498 settings,
499 deriveProviderInstanceEntries([liveProvider])[0]!,
500 ANTIGRAVITY_DEFAULT_MODEL,
501 ).map((model) => model.slug),
502 ).toEqual([nativeModel]);
503 expect(
504 resolveAppModelSelectionForInstance(
505 instanceId,
506 settings,
507 [liveProvider],
508 ANTIGRAVITY_DEFAULT_MODEL,
509 {
510 preserveUnavailableSelection: true,
511 },
512 ),
513 ).toBe(nativeModel);
514
515 const hiddenSettings: UnifiedSettings = {
516 ...settings,
517 providerModelPreferences: {
518 [instanceId]: { hiddenModels: [nativeModel], modelOrder: [] },
519 },
520 };
521 expect(
522 resolveAppModelSelectionForInstance(
523 instanceId,
524 hiddenSettings,
525 [liveProvider],
526 ANTIGRAVITY_DEFAULT_MODEL,
527 { preserveUnavailableSelection: true },
528 ),
529 ).toBeNull();
530 expect(
531 getAppModelOptionsForInstance(
532 settings,
533 deriveProviderInstanceEntries([{ ...base, models: [] }])[0]!,
534 ANTIGRAVITY_DEFAULT_MODEL,
535 ),
536 ).toEqual([]);
537 });
538
539 it("preserves saved options through dispatch when the model is absent from the catalog", () => {
540 const instanceId = ProviderInstanceId.make("opencode");
541 const driver = ProviderDriverKind.make("opencode");
542 const providers = [provider({ provider: driver, instanceId, models: ["opencode/big-pickle"] })];
543 const saved = createModelSelection(instanceId, "opencode/kimi-k3", [
544 { id: "variant", value: "max" },
545 { id: "agent", value: "build" },
546 ]);
547 const state = deriveEffectiveComposerModelState({
548 draft: null,
549 providers,
550 selectedProvider: driver,
551 selectedInstanceId: instanceId,
552 threadModelSelection: saved,
553 projectModelSelection: null,
554 settings: settingsWithProviderInstances(),
555 });
556 const dispatch = getComposerProviderState({
557 provider: driver,
558 model: state.selectedModel,
559 models: providers[0]!.models,
560 modelOptions: state.modelOptions?.[instanceId],
561 planModeEnabled: false,
562 });
563
564 expect(
565 createModelSelection(instanceId, state.selectedModel, dispatch.modelOptionsForDispatch),
566 ).toEqual(saved);
567 });
568
569 it("keeps a custom-instance draft model while dropping unsupported options", () => {
570 const instanceId = ProviderInstanceId.make("claude_openrouter");
571 const driver = ProviderDriverKind.make("claudeAgent");
572 const providers = [
573 provider({ provider: driver, instanceId: "claudeAgent", models: ["claude-opus-5"] }),
574 provider({ provider: driver, instanceId, models: ["claude-opus-5"] }),
575 ];
576 const threadSelection = createModelSelection(instanceId, "claude-opus-5", [
577 { id: "effort", value: "high" },
578 ]);
579 const draftSelection = createModelSelection(instanceId, "openai/gpt-5.5", [
580 { id: "effort", value: "max" },
581 ]);
582 const state = deriveEffectiveComposerModelState({
583 draft: {
584 activeProvider: instanceId,
585 modelSelectionByProvider: { [instanceId]: draftSelection },
586 },
587 providers,
588 selectedProvider: driver,
589 selectedInstanceId: instanceId,
590 threadModelSelection: threadSelection,
591 projectModelSelection: null,
592 settings: settingsWithProviderInstances(),
593 });
594 const dispatch = getComposerProviderState({
595 provider: driver,
596 model: state.selectedModel,
597 models: providers[1]!.models,
598 modelOptions: state.modelOptions?.[instanceId],
599 planModeEnabled: false,
600 });
601
602 expect(
603 createModelSelection(instanceId, state.selectedModel, dispatch.modelOptionsForDispatch),
604 ).toEqual(createModelSelection(instanceId, "openai/gpt-5.5"));
605 });
606
607 it("self-heals a persisted selection pointing at a text-generation-incapable instance", () => {
608 const providers = [
609 provider({
610 provider: ProviderDriverKind.make("acpRegistry"),
611 instanceId: "acp_gemini",
612 models: ["default"],
613 supportsTextGeneration: false,
614 }),
615 provider({
616 instanceId: "codex",
617 models: ["gpt-5.6-luna"],
618 }),
619 ];
620 const settings: UnifiedSettings = {
621 ...settingsWithProviderInstances(),
622 textGenerationModelSelection: {
623 instanceId: ProviderInstanceId.make("acp_gemini"),
624 model: "default",
625 },
626 };
627
628 expect(resolveAppModelSelectionState(settings, providers).instanceId).toBe(
629 ProviderInstanceId.make("codex"),
630 );
631 });
632 it("falls back to the text generation default, not the chat default, for a removed model", () => {
633 const codex = provider({ instanceId: "codex", models: ["gpt-6-astra", "gpt-6-luna"] });
634 const providers = [
635 { ...codex, models: codex.models.map((m, i) => (i === 0 ? { ...m, isDefault: true } : m)) },
636 ];
637 const settings: UnifiedSettings = {
638 ...settingsWithProviderInstances(),
639 textGenerationModelSelection: createModelSelection(
640 ProviderInstanceId.make("codex"),
641 "gpt-5.6-luna",
642 ),
643 };
644
645 expect(resolveAppModelSelectionState(settings, providers).model).toBe(
646 DEFAULT_TEXT_GENERATION_MODEL,
647 );
648 });
649
650 it("does not select a provider that cannot generate system text", () => {
651 const instanceId = ProviderInstanceId.make("antigravity");
652 const unsupported = {
653 ...provider({
654 provider: ProviderDriverKind.make("antigravity"),
655 instanceId,
656 models: ["gemini-3.1-pro"],
657 }),
658 supportsTextGeneration: false,
659 };
660 const supported = provider({ instanceId: "codex", models: ["gpt-5.6-sol"] });
661 const settings = {
662 ...settingsWithProviderInstances(),
663 textGenerationModelSelection: createModelSelection(instanceId, "gemini-3.1-pro"),
664 };
665
666 expect(resolveAppModelSelectionState(settings, [unsupported, supported])).toEqual(
667 createModelSelection(supported.instanceId, "gpt-5.6-sol"),
668 );
669 expect(resolveAppModelSelectionState(settings, [unsupported])).toEqual(
670 NO_PROVIDER_MODEL_SELECTION,
671 );
672 });
673});
674
675describe("resolveAppModelSelectionState with the opencode plan agent", () => {
676 const instanceId = ProviderInstanceId.make("opencode");
677 const model = "opencode/gpt-5.4";
678 const opencode: ServerProvider = {
679 ...provider({ provider: ProviderDriverKind.make("opencode"), instanceId: "opencode" }),
680 models: [
681 {
682 slug: model,
683 name: model,
684 isCustom: false,
685 capabilities: {
686 optionDescriptors: [
687 {
688 id: "agent",
689 label: "Agent",
690 type: "select",
691 options: [
692 { id: "build", label: "Build", isDefault: true },
693 { id: "plan", label: "Plan" },
694 ],
695 currentValue: "build",
696 },
697 ],
698 },
699 },
700 ],
701 };
702 const settings: UnifiedSettings = {
703 ...DEFAULT_UNIFIED_SETTINGS,
704 planModeEnabled: false,
705 textGenerationModelSelection: createModelSelection(instanceId, model, [
706 { id: "agent", value: "plan" },
707 ]),
708 };
709
710 it("keeps a stored plan agent this device did not pick", () => {
711 expect(resolveAppModelSelectionState(settings, [opencode])).toEqual(
712 createModelSelection(instanceId, model, [{ id: "agent", value: "plan" }]),
713 );
714 });
715});
716
717describe("default model settings and new-thread composer parity", () => {
718 it.each([
719 ["hidden", "claudeAgent", "claude-opus-5", "claude-opus-5-5", "medium"],
720 ["visible", "claudeAgent", "claude-opus-5", "claude-opus-5", "max"],
721 ["unavailable", "opencode", "openrouter/kimi-k3", "openrouter/kimi-k3", null],
722 ] as const)(
723 "resolves the %s default and its traits",
724 (visibility, kind, model, expectedModel, effort) => {
725 const driver = ProviderDriverKind.make(kind);
726 const instanceId = ProviderInstanceId.make(`${kind}_work`);
727 const snapshot = provider({ provider: driver, instanceId });
728 const models: ServerProvider["models"] = ["claude-opus-5-5", "claude-opus-5"].map(
729 (slug, index) => ({
730 slug,
731 name: slug,
732 isCustom: false,
733 capabilities: {
734 optionDescriptors: [
735 {
736 id: "effort",
737 label: "Effort",
738 type: "select",
739 options: (index === 0 ? ["medium", "high"] : ["high", "max"]).map(
740 (id, optionIndex) => ({ id, label: id, isDefault: optionIndex === 0 }),
741 ),
742 },
743 ],
744 },
745 }),
746 );
747 const providers = [{ ...snapshot, models }];
748 const stored = createModelSelection(instanceId, model, [{ id: "effort", value: "max" }]);
749 const settings: UnifiedSettings = {
750 ...settingsWithProviderInstances(),
751 providerModelPreferences: {
752 [instanceId]: { hiddenModels: visibility === "hidden" ? [model] : [], modelOrder: [] },
753 },
754 };
755 // ChatView builds the local draft with the project default as its thread selection.
756 const composer = deriveEffectiveComposerModelState({
757 draft: null,
758 providers,
759 selectedProvider: driver,
760 selectedInstanceId: instanceId,
761 threadModelSelection: stored,
762 projectModelSelection: stored,
763 settings,
764 });
765 const effective = resolveEffectiveDefaultModelSelection(settings, providers, stored);
766 const traits = (model: string, modelOptions: typeof stored.options) =>
767 getComposerProviderState({
768 provider: driver,
769 model,
770 models,
771 modelOptions,
772 planModeEnabled: settings.planModeEnabled,
773 });
774 const composerTraits = traits(composer.selectedModel, composer.modelOptions?.[instanceId]);
775
776 expect(composer.selectedModel).toBe(expectedModel);
777 expect(traits(effective.model, effective.options)).toEqual(composerTraits);
778 expect(effective).toEqual({ ...stored, model: composer.selectedModel });
779 expect(composerTraits.promptEffort).toBe(effort);
780 },
781 );
782});