Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 DEFAULT_SERVER_SETTINGS,
5 ProjectId,
6 ProviderDriverKind,
7 ProviderInstanceId,
8 type ModelSelection,
9 type ServerConfig,
10 type ServerSettings,
11} from "@t3tools/contracts";
12
13import {
14 buildModelOptions,
15 describeUnavailableModelSelection,
16 groupByProvider,
17 isModelSelectionUnavailable,
18 resolveDefaultableModelSelection,
19 resolveNewTaskModelSelection,
20 resolveSelectableModelSelection,
21 type ModelOption,
22} from "./modelOptions";
23
24describe("mobile model options", () => {
25 it("groups models by provider and flags legacy entries", () => {
26 const config = {
27 providers: [
28 {
29 instanceId: "codex",
30 driver: "codex",
31 displayName: "Codex",
32 enabled: true,
33 installed: true,
34 auth: { status: "authenticated" },
35 models: [
36 {
37 slug: "gpt-5.6-sol",
38 name: "GPT-5.6 Sol",
39 isCustom: false,
40 capabilities: null,
41 },
42 {
43 slug: "gpt-5.4",
44 name: "GPT-5.4",
45 isCustom: false,
46 isLegacy: true,
47 capabilities: null,
48 },
49 ],
50 },
51 ],
52 } as unknown as ServerConfig;
53
54 expect(groupByProvider(buildModelOptions(config, null, undefined, null))).toMatchObject([
55 {
56 providerKey: "codex",
57 providerLabel: "Codex",
58 models: [
59 { key: "codex:gpt-5.6-sol", label: "GPT-5.6 Sol", subtitle: "", isLegacy: false },
60 { key: "codex:gpt-5.4", label: "GPT-5.4", isLegacy: true },
61 ],
62 },
63 ]);
64 });
65
66 it("carries configured ACP identity into model and provider catalogs", () => {
67 const iconUrl = "https://cdn.agentclientprotocol.com/registry/v1/latest/antigravity-acp.svg";
68 const config = {
69 providers: [
70 {
71 instanceId: "acpRegistry_antigravity",
72 driver: "acpRegistry",
73 displayName: "Antigravity",
74 iconUrl,
75 enabled: true,
76 installed: true,
77 auth: { status: "authenticated" },
78 models: [
79 {
80 slug: "default",
81 name: "Default",
82 isCustom: false,
83 capabilities: null,
84 },
85 ],
86 },
87 ],
88 } as unknown as ServerConfig;
89
90 const [group] = groupByProvider(buildModelOptions(config, null, undefined, null));
91
92 expect(group).toMatchObject({
93 providerKey: "acpRegistry_antigravity",
94 providerLabel: "Antigravity",
95 models: [
96 {
97 providerDriver: "acpRegistry",
98 providerIconUrl: iconUrl,
99 },
100 ],
101 });
102 });
103
104 it("distinguishes same-name OpenCode models without changing their routing", () => {
105 const sources = [
106 { id: "anthropic", label: "Anthropic" },
107 { id: "github-copilot", label: "GitHub Copilot" },
108 { id: "opencode", label: "OpenCode Zen" },
109 ];
110 const config = {
111 providers: [
112 {
113 instanceId: "opencode_work",
114 driver: "opencode",
115 displayName: "OpenCode Work",
116 enabled: true,
117 installed: true,
118 auth: { status: "authenticated" },
119 models: sources.map((source) => ({
120 slug: `${source.id}/claude-fable-5`,
121 name: "Claude Fable 5",
122 subProvider: source.label,
123 isCustom: false,
124 capabilities: null,
125 })),
126 },
127 ],
128 } as unknown as ServerConfig;
129 const selection = {
130 instanceId: ProviderInstanceId.make("opencode_work"),
131 model: "github-copilot/claude-fable-5",
132 };
133
134 const options = buildModelOptions(config, selection, undefined, null);
135
136 expect(options).toMatchObject(
137 sources.map((source) => ({
138 key: `opencode_work:${source.id}/claude-fable-5`,
139 label: "Claude Fable 5",
140 subtitle: source.label,
141 providerLabel: "OpenCode Work",
142 selection: {
143 instanceId: "opencode_work",
144 model: `${source.id}/claude-fable-5`,
145 },
146 })),
147 );
148 expect(groupByProvider(options)).toEqual([
149 { providerKey: "opencode_work", providerLabel: "OpenCode Work", models: options },
150 ]);
151 });
152
153 it("does not materialize catalog defaults for missing stored options", () => {
154 const config = {
155 providers: [
156 {
157 instanceId: "codex",
158 driver: "codex",
159 displayName: "Codex",
160 enabled: true,
161 installed: true,
162 auth: { status: "authenticated" },
163 models: [
164 {
165 slug: "gpt-test",
166 name: "GPT Test",
167 isCustom: false,
168 capabilities: {
169 optionDescriptors: [
170 {
171 id: "serviceTier",
172 label: "Service Tier",
173 type: "select",
174 options: [
175 { id: "default", label: "Standard", isDefault: true },
176 { id: "priority", label: "Fast" },
177 ],
178 currentValue: "default",
179 },
180 ],
181 },
182 },
183 ],
184 },
185 ],
186 } as unknown as ServerConfig;
187
188 const [option] = buildModelOptions(
189 config,
190 {
191 instanceId: ProviderInstanceId.make("codex"),
192 model: "gpt-test",
193 },
194 undefined,
195 null,
196 );
197
198 expect(option?.capabilities?.optionDescriptors?.[0]?.id).toBe("serviceTier");
199 expect(option?.selection.options).toBeUndefined();
200
201 const [emptyOption] = buildModelOptions(
202 config,
203 {
204 instanceId: ProviderInstanceId.make("codex"),
205 model: "gpt-test",
206 options: [],
207 },
208 undefined,
209 null,
210 );
211 expect(emptyOption?.selection).toEqual(option?.selection);
212
213 const [explicitOption] = buildModelOptions(
214 config,
215 {
216 instanceId: ProviderInstanceId.make("codex"),
217 model: "gpt-test",
218 options: [{ id: "serviceTier", value: "priority" }],
219 },
220 undefined,
221 null,
222 );
223 expect(explicitOption?.selection.options).toEqual([{ id: "serviceTier", value: "priority" }]);
224 });
225
226 it("limits existing threads to their provider while new tasks keep every provider", () => {
227 const providers = ["codex", "claudeAgent"].map((instanceId) => ({
228 instanceId,
229 driver: instanceId,
230 enabled: true,
231 installed: true,
232 auth: { status: "authenticated" },
233 models: [{ slug: "test", name: instanceId, capabilities: null }],
234 }));
235 const config = { providers } as unknown as ServerConfig;
236 const selection = { instanceId: ProviderInstanceId.make("codex"), model: "test" };
237
238 expect(
239 buildModelOptions(config, selection, undefined, null).map((option) => option.providerKey),
240 ).toEqual(["codex", "claudeAgent"]);
241 expect(buildModelOptions(config, selection, selection.instanceId, null)).toEqual(
242 buildModelOptions(config, selection, undefined, null).filter(
243 (option) => option.providerKey === "codex",
244 ),
245 );
246 });
247
248 it.each(["disabled", "unavailable", "missing"] as const)(
249 "retains the selected %s provider's fallback in a filtered catalog",
250 (state) => {
251 const selection = {
252 instanceId: ProviderInstanceId.make("google_work"),
253 model: "saved-model",
254 options: [{ id: "native-option", value: "saved-choice" }],
255 };
256 const provider = {
257 instanceId: selection.instanceId,
258 driver: "antigravity",
259 displayName: "Google Work",
260 enabled: state !== "disabled",
261 installed: true,
262 availability: state === "unavailable" ? "unavailable" : "available",
263 auth: { status: "authenticated" },
264 models: [{ slug: selection.model, name: "Saved model", capabilities: null }],
265 };
266 const config = {
267 providers: state === "missing" ? [] : [provider],
268 settings: { providerInstances: { google_work: { driver: "antigravity" } } },
269 } as unknown as ServerConfig;
270 const options = buildModelOptions(config, selection, selection.instanceId, null);
271 expect(options).toEqual(buildModelOptions(config, selection, undefined, null));
272 expect(options).toHaveLength(1);
273 expect(options[0]).toMatchObject({ selection, isUnavailable: true });
274 },
275 );
276
277 it("rejects stored selections whose provider is not usable", () => {
278 const config = {
279 providers: [
280 {
281 instanceId: "codex",
282 driver: "codex",
283 enabled: true,
284 installed: true,
285 auth: { status: "authenticated" },
286 models: [],
287 },
288 {
289 instanceId: "claudeAgent",
290 driver: "claudeAgent",
291 enabled: false,
292 installed: true,
293 auth: { status: "authenticated" },
294 models: [],
295 },
296 ],
297 } as unknown as ServerConfig;
298
299 const usable = {
300 instanceId: ProviderInstanceId.make("codex"),
301 model: "gpt-5.6-sol",
302 };
303 const disabled = {
304 instanceId: ProviderInstanceId.make("claudeAgent"),
305 model: "claude-sonnet-5",
306 };
307 const removed = {
308 instanceId: ProviderInstanceId.make("codex_personal"),
309 model: "gpt-5.6-sol",
310 };
311
312 expect(resolveSelectableModelSelection(config, usable, null)).toBe(usable);
313 expect(resolveSelectableModelSelection(config, disabled, null)).toBeNull();
314 expect(resolveSelectableModelSelection(config, removed, null)).toBeNull();
315 expect(isModelSelectionUnavailable(config, disabled, null)).toBe(true);
316 expect(isModelSelectionUnavailable(config, removed, null)).toBe(false);
317 expect(resolveSelectableModelSelection(null, disabled, null)).toBe(disabled);
318 });
319
320 describe("Antigravity selections", () => {
321 const selection = {
322 instanceId: ProviderInstanceId.make("google_work"),
323 model: "gemini-3.1-pro-high",
324 options: [{ id: "native-option", value: "saved/opaque-choice" }],
325 };
326 const model = {
327 slug: selection.model,
328 name: "Gemini 3.1 Pro High",
329 subProvider: "Google",
330 isCustom: false,
331 isDefault: true,
332 isLegacy: true,
333 capabilities: {
334 optionDescriptors: [
335 {
336 id: "native-option",
337 label: "Native option",
338 type: "select",
339 options: [{ id: "current/default", label: "Default", isDefault: true }],
340 currentValue: "current/default",
341 },
342 ],
343 },
344 };
345 const config = {
346 providers: [
347 {
348 instanceId: selection.instanceId,
349 driver: "antigravity",
350 displayName: "Google Work",
351 enabled: true,
352 installed: true,
353 auth: { status: "authenticated" },
354 models: [model],
355 },
356 ],
357 } as unknown as ServerConfig;
358
359 it.each([
360 ["disabled", { enabled: false }],
361 ["uninstalled", { installed: false }],
362 ["signed out", { auth: { status: "unauthenticated" } }],
363 ["unavailable", { availability: "unavailable" }],
364 ] as const)("keeps a %s provider's selection and known model details", (_state, update) => {
365 const unavailableConfig = {
366 ...config,
367 providers: config.providers.map((provider) => ({ ...provider, ...update })),
368 };
369
370 expect(resolveSelectableModelSelection(unavailableConfig, selection, null)).toBe(selection);
371 expect(resolveDefaultableModelSelection(unavailableConfig, selection, null)).toBe(selection);
372 expect(isModelSelectionUnavailable(unavailableConfig, selection, null)).toBe(true);
373 expect(buildModelOptions(unavailableConfig, null, undefined, null)).toEqual([]);
374 const [option] = buildModelOptions(unavailableConfig, selection, undefined, null);
375 expect(option).toMatchObject({
376 key: `google_work:${selection.model}`,
377 label: model.name,
378 subtitle: "Google",
379 providerKey: "google_work",
380 providerLabel: "Google Work",
381 providerDriver: "antigravity",
382 isDefault: false,
383 isLegacy: true,
384 isUnavailable: true,
385 capabilities: model.capabilities,
386 });
387 expect(option?.selection).toBe(selection);
388 });
389
390 it("keeps an exact selection when its model leaves and returns to the catalog", () => {
391 const changedConfig = {
392 ...config,
393 providers: config.providers.map((provider) => ({
394 ...provider,
395 models: provider.models.map((model) => ({ ...model, slug: "gemini-3.1-pro-low" })),
396 })),
397 };
398
399 expect(resolveDefaultableModelSelection(changedConfig, selection, null)).toBe(selection);
400 expect(isModelSelectionUnavailable(changedConfig, selection, null)).toBe(true);
401 const options = buildModelOptions(changedConfig, selection, undefined, null);
402 const missing = options.find((option) => option.selection.model === selection.model);
403 expect(missing).toMatchObject({
404 label: selection.model,
405 providerLabel: "Google Work",
406 providerDriver: "antigravity",
407 isUnavailable: true,
408 capabilities: null,
409 });
410 expect(missing?.selection).toBe(selection);
411 expect(
412 resolveNewTaskModelSelection({
413 draftSelection: null,
414 projectDefaultSelection: resolveDefaultableModelSelection(changedConfig, selection, null),
415 stickySelection: null,
416 modelOptions: options,
417 }),
418 ).toBe(selection);
419
420 const [restored] = buildModelOptions(config, selection, undefined, null);
421 expect(isModelSelectionUnavailable(config, selection, null)).toBe(false);
422 expect(restored?.isUnavailable).not.toBe(true);
423 expect(restored?.selection).toBe(selection);
424 expect(resolveDefaultableModelSelection(config, selection, null)).toBe(selection);
425 expect(
426 buildModelOptions(config, null, undefined, null)[0]?.selection.options,
427 ).toBeUndefined();
428 });
429
430 it("uses configured instance metadata when provider status is missing", () => {
431 const missingStatusConfig = {
432 providers: [],
433 settings: {
434 providerInstances: {
435 [selection.instanceId]: { driver: "antigravity", displayName: "Google Work" },
436 },
437 },
438 } as unknown as ServerConfig;
439
440 expect(resolveDefaultableModelSelection(missingStatusConfig, selection, null)).toBe(
441 selection,
442 );
443 expect(isModelSelectionUnavailable(missingStatusConfig, selection, null)).toBe(true);
444 expect(buildModelOptions(missingStatusConfig, selection, undefined, null)).toMatchObject([
445 {
446 providerDriver: "antigravity",
447 providerLabel: "Google Work",
448 isUnavailable: true,
449 selection,
450 },
451 ]);
452 });
453
454 it("keeps offline selections without assuming that an unknown instance is Antigravity", () => {
455 const unknownConfig = { ...config, providers: [] };
456
457 expect(resolveDefaultableModelSelection(null, selection, null)).toBe(selection);
458 expect(isModelSelectionUnavailable(null, selection, null)).toBe(false);
459 expect(buildModelOptions(null, selection, undefined, null)[0]?.selection).toBe(selection);
460 expect(buildModelOptions(null, selection, undefined, null)[0]?.isUnavailable).not.toBe(true);
461 expect(isModelSelectionUnavailable(unknownConfig, selection, null)).toBe(false);
462 expect(resolveSelectableModelSelection(unknownConfig, selection, null)).toBeNull();
463 });
464 });
465
466 it("keeps legacy models out of implicit defaults", () => {
467 const config = {
468 providers: [
469 {
470 instanceId: "codex",
471 driver: "codex",
472 displayName: "Codex",
473 enabled: true,
474 installed: true,
475 auth: { status: "authenticated" },
476 models: [
477 { slug: "gpt-5.6-sol", name: "GPT-5.6 Sol", isCustom: false, capabilities: null },
478 {
479 slug: "gpt-5.4",
480 name: "GPT-5.4",
481 isCustom: false,
482 isLegacy: true,
483 capabilities: null,
484 },
485 ],
486 },
487 ],
488 } as unknown as ServerConfig;
489
490 const current = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" };
491 const legacy = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" };
492
493 expect(resolveDefaultableModelSelection(config, current, null)).toBe(current);
494 expect(resolveDefaultableModelSelection(config, legacy, null)).toBeNull();
495 expect(resolveDefaultableModelSelection(null, legacy, null)).toBe(legacy);
496 });
497
498 it("resolves new tasks from draft, project, sticky, then provider defaults", () => {
499 const draft = { instanceId: ProviderInstanceId.make("codex"), model: "draft" };
500 const project = { instanceId: ProviderInstanceId.make("codex"), model: "project" };
501 const sticky = { instanceId: ProviderInstanceId.make("codex"), model: "sticky" };
502 const providerDefault = {
503 selection: { instanceId: ProviderInstanceId.make("codex"), model: "default" },
504 isDefault: true,
505 } as ModelOption;
506 const resolve = (
507 draftSelection: ModelSelection | null,
508 projectDefaultSelection: ModelSelection | null,
509 stickySelection: ModelSelection | null,
510 ) =>
511 resolveNewTaskModelSelection({
512 draftSelection,
513 projectDefaultSelection,
514 stickySelection,
515 modelOptions: [providerDefault],
516 });
517
518 expect(resolve(draft, project, sticky)).toBe(draft);
519 expect(resolve(null, project, sticky)).toBe(project);
520 expect(resolve(null, null, sticky)).toBe(sticky);
521 expect(resolve(null, null, null)).toBe(providerDefault.selection);
522
523 const unavailable = { ...providerDefault, isUnavailable: true };
524 expect(
525 resolveNewTaskModelSelection({
526 draftSelection: null,
527 projectDefaultSelection: null,
528 stickySelection: null,
529 modelOptions: [unavailable],
530 }),
531 ).toBeNull();
532 });
533
534 describe("project-aware enablement", () => {
535 const projectId = ProjectId.make("project-a");
536 const instanceId = ProviderInstanceId.make("codex_work");
537
538 function configWith(settings: ServerSettings): ServerConfig {
539 return {
540 providers: [
541 {
542 instanceId,
543 driver: "codex",
544 displayName: "Codex Work",
545 enabled: true,
546 installed: true,
547 auth: { status: "authenticated" },
548 models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: null }],
549 },
550 ],
551 settings,
552 } as unknown as ServerConfig;
553 }
554
555 it("words a project's own turn-off apart from missing setup", () => {
556 const settings: ServerSettings = {
557 ...DEFAULT_SERVER_SETTINGS,
558 providerInstances: {
559 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
560 },
561 projectSettingsOverrides: {
562 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
563 },
564 };
565 const selection = { instanceId, model: "model-a" };
566
567 expect(
568 describeUnavailableModelSelection(configWith(settings), selection, projectId).title,
569 ).toBe("Model turned off for this project");
570 expect(describeUnavailableModelSelection(configWith(settings), selection, null).title).toBe(
571 "Antigravity model unavailable",
572 );
573 });
574
575 it("refuses to send a non-Antigravity model the project turned off", () => {
576 const settings: ServerSettings = {
577 ...DEFAULT_SERVER_SETTINGS,
578 providerInstances: {
579 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
580 },
581 projectSettingsOverrides: {
582 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
583 },
584 };
585 const selection = { instanceId, model: "model-a" };
586
587 expect(isModelSelectionUnavailable(configWith(settings), selection, projectId)).toBe(true);
588 expect(isModelSelectionUnavailable(configWith(settings), selection, null)).toBe(false);
589 });
590
591 it("hides an instance the project disables even though the machine enables it", () => {
592 const settings: ServerSettings = {
593 ...DEFAULT_SERVER_SETTINGS,
594 providerInstances: {
595 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
596 },
597 projectSettingsOverrides: {
598 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
599 },
600 };
601
602 expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toEqual([]);
603 });
604
605 it("shows an instance the project enables even though the machine disables it", () => {
606 const settings: ServerSettings = {
607 ...DEFAULT_SERVER_SETTINGS,
608 providerInstances: {
609 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false },
610 },
611 projectSettingsOverrides: {
612 [projectId]: { providerInstances: { [instanceId]: { enabled: true } } },
613 },
614 };
615
616 expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toHaveLength(1);
617 });
618
619 it("falls back to the machine value with no project in scope", () => {
620 const settings: ServerSettings = {
621 ...DEFAULT_SERVER_SETTINGS,
622 providerInstances: {
623 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
624 },
625 projectSettingsOverrides: {
626 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
627 },
628 };
629
630 expect(buildModelOptions(configWith(settings), null, undefined, null)).toHaveLength(1);
631 });
632
633 it("hides a machine-disabled instance for a project with no override, even though another project's keep-alive left it running", () => {
634 const otherProjectId = ProjectId.make("project-b");
635 const settings: ServerSettings = {
636 ...DEFAULT_SERVER_SETTINGS,
637 providerInstances: {
638 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false },
639 },
640 projectSettingsOverrides: {
641 [otherProjectId]: { providerInstances: { [instanceId]: { enabled: true } } },
642 },
643 };
644
645 expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toEqual([]);
646 });
647
648 it("refuses to send an instance the project merely inherits as disabled, not just an explicit override", () => {
649 const settings: ServerSettings = {
650 ...DEFAULT_SERVER_SETTINGS,
651 providerInstances: {
652 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false },
653 },
654 };
655 const selection = { instanceId, model: "model-a" };
656
657 expect(isModelSelectionUnavailable(configWith(settings), selection, projectId)).toBe(true);
658 expect(
659 describeUnavailableModelSelection(configWith(settings), selection, projectId).title,
660 ).toBe("Model turned off for this project");
661 expect(isModelSelectionUnavailable(configWith(settings), selection, null)).toBe(true);
662 });
663
664 it("marks a project-disabled instance's fallback selection unavailable instead of reviving it", () => {
665 const settings: ServerSettings = {
666 ...DEFAULT_SERVER_SETTINGS,
667 providerInstances: {
668 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
669 },
670 projectSettingsOverrides: {
671 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
672 },
673 };
674 const fallback = { instanceId, model: "model-a" };
675
676 const options = buildModelOptions(configWith(settings), fallback, undefined, projectId);
677
678 expect(options).toHaveLength(1);
679 expect(options[0]).toMatchObject({ selection: fallback, isUnavailable: true });
680 });
681
682 it("rejects a project-disabled instance's selection via resolveSelectableModelSelection", () => {
683 const settings: ServerSettings = {
684 ...DEFAULT_SERVER_SETTINGS,
685 providerInstances: {
686 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
687 },
688 projectSettingsOverrides: {
689 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
690 },
691 };
692 const selection = { instanceId, model: "model-a" };
693
694 expect(
695 resolveSelectableModelSelection(configWith(settings), selection, projectId),
696 ).toBeNull();
697 expect(resolveSelectableModelSelection(configWith(settings), selection, null)).toBe(
698 selection,
699 );
700 });
701
702 it("rejects a project-disabled antigravity instance's selection instead of keeping it", () => {
703 const antigravityInstanceId = ProviderInstanceId.make("antigravity_work");
704 const config = {
705 providers: [
706 {
707 instanceId: antigravityInstanceId,
708 driver: "antigravity",
709 displayName: "Antigravity Work",
710 enabled: true,
711 installed: true,
712 auth: { status: "authenticated" },
713 availability: "available",
714 models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: null }],
715 },
716 ],
717 settings: {
718 ...DEFAULT_SERVER_SETTINGS,
719 providerInstances: {
720 [antigravityInstanceId]: {
721 driver: ProviderDriverKind.make("antigravity"),
722 enabled: true,
723 },
724 },
725 projectSettingsOverrides: {
726 [projectId]: { providerInstances: { [antigravityInstanceId]: { enabled: false } } },
727 },
728 },
729 } as unknown as ServerConfig;
730 const selection = { instanceId: antigravityInstanceId, model: "model-a" };
731
732 expect(resolveSelectableModelSelection(config, selection, projectId)).toBeNull();
733 expect(resolveSelectableModelSelection(config, selection, null)).toBe(selection);
734 expect(
735 resolveSelectableModelSelection({ ...config, providers: [] }, selection, projectId),
736 ).toBeNull();
737 });
738 });
739});
740
741describe("synchronized mobile model visibility", () => {
742 const provider = ProviderInstanceId.make("codex_work");
743 const other = ProviderInstanceId.make("codex_personal");
744 const models = [
745 { slug: "hidden", name: "Hidden", isCustom: false, capabilities: null },
746 { slug: "first", name: "First", isCustom: false, capabilities: null },
747 { slug: "second", name: "Second", isCustom: false, capabilities: null },
748 { slug: "custom", name: "Custom", isCustom: true, capabilities: null },
749 ];
750 const config = {
751 settings: {
752 ...DEFAULT_SERVER_SETTINGS,
753 providerInstances: {
754 [provider]: { driver: ProviderDriverKind.make("codex"), enabled: true },
755 [other]: { driver: ProviderDriverKind.make("codex"), enabled: true },
756 },
757 providerModelPreferences: {
758 [provider]: {
759 hiddenModels: ["hidden", "custom", "missing"],
760 modelOrder: ["second", "first"],
761 },
762 },
763 },
764 providers: [provider, other].map((instanceId) => ({
765 instanceId,
766 driver: "codex",
767 enabled: true,
768 installed: true,
769 auth: { status: "authenticated" },
770 models,
771 })),
772 } as unknown as ServerConfig;
773
774 it("applies server visibility and ordering independently to each provider instance", () => {
775 const options = buildModelOptions(config, null, undefined, null);
776 expect(
777 options
778 .filter((option) => option.providerKey === provider)
779 .map((option) => option.selection.model),
780 ).toEqual(["second", "first", "custom"]);
781 expect(
782 options
783 .filter((option) => option.providerKey === other)
784 .map((option) => option.selection.model),
785 ).toEqual(["hidden", "first", "second", "custom"]);
786 });
787
788 it("exposes hidden built-ins for management without offering custom visibility controls", () => {
789 const options = buildModelOptions(
790 config,
791 { instanceId: provider, model: "hidden" },
792 provider,
793 null,
794 true,
795 );
796 expect(options.map((option) => option.selection.model)).toEqual([
797 "second",
798 "first",
799 "hidden",
800 "custom",
801 ]);
802 expect(options.find((option) => option.selection.model === "hidden")).toMatchObject({
803 isHidden: true,
804 canHide: true,
805 });
806 expect(options.find((option) => option.selection.model === "custom")).toMatchObject({
807 isHidden: false,
808 canHide: false,
809 });
810 });
811
812 it.each(["hidden", "missing"])("does not resurrect the hidden fallback %s", (model) => {
813 expect(
814 buildModelOptions(config, { instanceId: provider, model }, provider, null).map(
815 (option) => option.selection.model,
816 ),
817 ).toEqual(["second", "first", "custom"]);
818 });
819
820 it("keeps custom models visible and restores built-in models when the server clears hidden models", () => {
821 expect(
822 buildModelOptions(config, { instanceId: provider, model: "custom" }, provider, null).map(
823 (option) => option.selection.model,
824 ),
825 ).toContain("custom");
826 const cleared = { ...config, settings: { ...config.settings, providerModelPreferences: {} } };
827 expect(
828 buildModelOptions(cleared, null, provider, null).map((option) => option.selection.model),
829 ).toEqual(["hidden", "first", "second", "custom"]);
830 });
831});