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