Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3
4import { type CommandId, ProjectId } from "./baseSchemas.ts";
5import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
6import {
7 ClientSettingsSchema,
8 ClientSettingsPatch,
9 ClaudeSettings,
10 DEFAULT_SERVER_SETTINGS,
11 requiredScopesForProjectMutation,
12 resolveProjectProviderInstanceEnabled,
13 resolveProviderInstanceEnabled,
14 ServerSettings,
15 ServerSettingsPatch,
16} from "./settings.ts";
17
18const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
19const decodeClientSettingsPatch = Schema.decodeUnknownSync(ClientSettingsPatch);
20const encodeClientSettings = Schema.encodeSync(ClientSettingsSchema);
21const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
22const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
23const encodeServerSettings = Schema.encodeSync(ServerSettings);
24const decodeClaudeSettings = Schema.decodeUnknownSync(ClaudeSettings);
25
26describe("ServerSettings response streaming", () => {
27 it("defaults to paragraph buffering", () => {
28 expect(decodeServerSettings({}).responseStreamingMode).toBe("paragraph");
29 });
30
31 it.each(["turn", "paragraph"])(
32 "round-trips %s as an environment setting and project override",
33 (responseStreamingMode) => {
34 const input = {
35 responseStreamingMode,
36 projectSettingsOverrides: { project: { responseStreamingMode } },
37 };
38 expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
39 expect(decodeServerSettingsPatch(input)).toEqual(input);
40 },
41 );
42
43 it.each(["token", "unsupported"])("rejects %s in settings snapshots and writes", (mode) => {
44 for (const input of [
45 { responseStreamingMode: mode },
46 { projectSettingsOverrides: { project: { responseStreamingMode: mode } } },
47 ]) {
48 expect(() => decodeServerSettings(input)).toThrow();
49 expect(() => decodeServerSettingsPatch(input)).toThrow();
50 }
51 });
52});
53
54describe("storage cleanup settings", () => {
55 it("keeps cleanup disabled for existing installations", () => {
56 expect(decodeServerSettings({}).worktreeCleanup).toBeNull();
57 expect(decodeServerSettings({}).storageCleanup).toEqual({
58 worktreeAfterDays: null,
59 worktreeSettledAfterDays: null,
60 worktreeOnMerge: false,
61 worktreeOnDelete: false,
62 worktreeUnchanged: false,
63 worktreeKeepWhen: "uncommitted-changes",
64 browserArtifactsAfterDays: null,
65 logsAfterDays: null,
66 });
67 });
68
69 it("accepts eight-day retention and disabling one rule without resetting others", () => {
70 expect(decodeServerSettingsPatch({ storageCleanup: { worktreeAfterDays: 8 } })).toEqual({
71 storageCleanup: { worktreeAfterDays: 8 },
72 });
73 expect(decodeServerSettingsPatch({ storageCleanup: { worktreeAfterDays: null } })).toEqual({
74 storageCleanup: { worktreeAfterDays: null },
75 });
76 expect(decodeServerSettingsPatch({ storageCleanup: { worktreeSettledAfterDays: 0 } })).toEqual({
77 storageCleanup: { worktreeSettledAfterDays: 0 },
78 });
79 });
80
81 it("accepts partial custom patches but requires complete stored project rules", () => {
82 expect(
83 decodeServerSettingsPatch({
84 worktreeCleanup: { mode: "custom", rules: { worktreeAfterDays: 8 } },
85 }),
86 ).toEqual({ worktreeCleanup: { mode: "custom", rules: { worktreeAfterDays: 8 } } });
87 expect(() =>
88 decodeServerSettings({
89 projectSettingsOverrides: {
90 project: { worktreeCleanup: { mode: "custom", rules: { worktreeAfterDays: 8 } } },
91 },
92 }),
93 ).toThrow();
94 expect(
95 decodeServerSettings({
96 projectSettingsOverrides: {
97 project: {
98 worktreeCleanup: {
99 mode: "custom",
100 rules: {
101 worktreeAfterDays: null,
102 worktreeOnMerge: false,
103 worktreeOnDelete: false,
104 worktreeUnchanged: false,
105 },
106 },
107 },
108 },
109 }).projectSettingsOverrides[ProjectId.make("project")]?.worktreeCleanup,
110 ).toMatchObject({
111 mode: "custom",
112 rules: { worktreeSettledAfterDays: null, worktreeKeepWhen: "uncommitted-changes" },
113 });
114 });
115
116 it("decodes older custom rules with the default local-file policy", () => {
117 const settings = decodeServerSettings({
118 worktreeCleanup: {
119 mode: "custom",
120 rules: {
121 worktreeAfterDays: 8,
122 worktreeOnMerge: false,
123 worktreeOnDelete: false,
124 worktreeUnchanged: false,
125 },
126 },
127 });
128 expect(settings.worktreeCleanup).toMatchObject({
129 rules: { worktreeKeepWhen: "uncommitted-changes" },
130 });
131 expect(
132 decodeServerSettingsPatch({ storageCleanup: { worktreeKeepWhen: "tracked-changes" } }),
133 ).toEqual({ storageCleanup: { worktreeKeepWhen: "tracked-changes" } });
134 expect(() =>
135 decodeServerSettingsPatch({ storageCleanup: { worktreeKeepWhen: "unknown" } }),
136 ).toThrow();
137 });
138
139 it.each([0, -1, 1.5, 3651])("rejects invalid retention %s", (days) => {
140 expect(() =>
141 decodeServerSettingsPatch({ storageCleanup: { browserArtifactsAfterDays: days } }),
142 ).toThrow();
143 });
144
145 it.each([-1, 1.5, 3651])("rejects invalid settled retention %s", (days) => {
146 expect(() =>
147 decodeServerSettingsPatch({ storageCleanup: { worktreeSettledAfterDays: days } }),
148 ).toThrow();
149 });
150});
151
152describe("ClientSettings rich text composer", () => {
153 it("enables rich text for new and existing settings without a saved preference", () => {
154 expect(decodeClientSettings({}).composerRichTextEnabled).toBe(true);
155 expect(decodeClientSettings({ sendShortcut: "mod-enter" }).composerRichTextEnabled).toBe(true);
156 });
157
158 it("preserves an explicit opt-out through patches and persistence", () => {
159 const preference = { composerRichTextEnabled: false };
160 expect(decodeClientSettingsPatch(preference)).toEqual(preference);
161 expect(encodeClientSettings(decodeClientSettings(preference))).toMatchObject(preference);
162 });
163});
164
165describe("ServerSettings default permissions", () => {
166 it("keeps full access for settings saved before a default was configured", () => {
167 expect(decodeServerSettings({}).defaultRuntimeMode).toBe("full-access");
168 expect(DEFAULT_SERVER_SETTINGS.defaultRuntimeMode).toBe("full-access");
169 });
170
171 it.each(["approval-required", "auto-accept-edits", "auto", "full-access"])(
172 "round-trips %s as an environment default and project override",
173 (defaultRuntimeMode) => {
174 const input = {
175 defaultRuntimeMode,
176 projectSettingsOverrides: { project: { defaultRuntimeMode } },
177 };
178 expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
179 expect(decodeServerSettingsPatch(input)).toEqual(input);
180 },
181 );
182
183 it("rejects unsupported permission defaults", () => {
184 expect(() => decodeServerSettings({ defaultRuntimeMode: "unsupported" })).toThrow();
185 expect(() => decodeServerSettingsPatch({ defaultRuntimeMode: "unsupported" })).toThrow();
186 expect(() =>
187 decodeServerSettingsPatch({
188 projectSettingsOverrides: { project: { defaultRuntimeMode: "unsupported" } },
189 }),
190 ).toThrow();
191 });
192});
193
194describe("ServerSettings usage price overrides", () => {
195 const prices = { inputCostPerMillionTokens: 2, outputCostPerMillionTokens: 8 };
196
197 it("defaults to automatic pricing and round-trips arbitrary model IDs", () => {
198 expect(decodeServerSettings({}).usagePriceOverrides).toEqual({});
199 const settings = decodeServerSettings({
200 usagePriceOverrides: { " vendor/example-model ": prices },
201 });
202 expect(encodeServerSettings(settings).usagePriceOverrides).toEqual({
203 "vendor/example-model": prices,
204 });
205 });
206
207 it("accepts zero rates, optional cache rates, and per-model deletion", () => {
208 const overrides = {
209 "example-model": {
210 inputCostPerMillionTokens: 0,
211 outputCostPerMillionTokens: 0,
212 cacheReadCostPerMillionTokens: 0.5,
213 cacheWriteCostPerMillionTokens: 3,
214 },
215 "removed-model": null,
216 };
217 expect(
218 decodeServerSettingsPatch({ usagePriceOverrides: overrides }).usagePriceOverrides,
219 ).toEqual(overrides);
220 });
221
222 it.each([
223 "inputCostPerMillionTokens",
224 "outputCostPerMillionTokens",
225 "cacheReadCostPerMillionTokens",
226 "cacheWriteCostPerMillionTokens",
227 ])("rejects invalid %s rates at the settings boundary", (field) => {
228 for (const value of [-1, Number.NaN, Number.POSITIVE_INFINITY, "2"]) {
229 const usagePriceOverrides = { "example-model": { ...prices, [field]: value } };
230 expect(() => decodeServerSettings({ usagePriceOverrides })).toThrow();
231 expect(() => decodeServerSettingsPatch({ usagePriceOverrides })).toThrow();
232 }
233 });
234
235 it("rejects empty model IDs and incomplete input/output pricing", () => {
236 for (const usagePriceOverrides of [
237 { " ": prices },
238 { "example-model": { inputCostPerMillionTokens: 2 } },
239 { "example-model": { outputCostPerMillionTokens: 8 } },
240 ]) {
241 expect(() => decodeServerSettingsPatch({ usagePriceOverrides })).toThrow();
242 }
243 });
244});
245
246describe("custom model settings", () => {
247 const capabilities = {
248 optionDescriptors: [
249 {
250 id: "effort",
251 label: "Reasoning",
252 type: "select",
253 options: [{ id: "high", label: "High", isDefault: true }],
254 },
255 ],
256 };
257
258 it("accepts legacy bare slugs alongside full entries", () => {
259 const decoded = decodeClaudeSettings({
260 customModels: ["bare-slug", { slug: "named", name: "Named", capabilities }],
261 });
262 expect(decoded.customModels).toEqual([
263 "bare-slug",
264 { slug: "named", name: "Named", capabilities },
265 ]);
266 });
267});
268
269describe("ClaudeSettings auto-compaction", () => {
270 it("uses Claude's default threshold when no override is configured", () => {
271 expect(decodeClaudeSettings({}).autoCompactWindow).toBe("");
272 });
273
274 it.each(["100000", "300000", "1000000"])(
275 "accepts a supported auto-compaction threshold: %s",
276 (value) => {
277 expect(decodeClaudeSettings({ autoCompactWindow: value }).autoCompactWindow).toBe(value);
278 },
279 );
280
281 it.each(["99999", "1000001", "300k", "invalid"])(
282 "rejects an unsupported auto-compaction threshold: %s",
283 (value) => {
284 expect(() => decodeClaudeSettings({ autoCompactWindow: value })).toThrow();
285 },
286 );
287});
288
289describe("ClientSettings notifications", () => {
290 it("requires opt-in when existing settings omit notification preferences", () => {
291 expect(decodeClientSettings({}).notificationMode).toBe("off");
292 expect(decodeClientSettings({}).inAppNotificationsEnabled).toBe(false);
293 expect(decodeClientSettingsPatch({})).not.toHaveProperty("inAppNotificationsEnabled");
294 expect(decodeClientSettingsPatch({})).not.toHaveProperty("notificationMode");
295 });
296
297 it.each([true, false])(
298 "round-trips in-app notifications set to %s",
299 (inAppNotificationsEnabled) => {
300 const settings = decodeClientSettings({ inAppNotificationsEnabled });
301 expect(encodeClientSettings(settings).inAppNotificationsEnabled).toBe(
302 inAppNotificationsEnabled,
303 );
304 expect(
305 decodeClientSettingsPatch({ inAppNotificationsEnabled }).inAppNotificationsEnabled,
306 ).toBe(inAppNotificationsEnabled);
307 },
308 );
309
310 it.each(["true", 1, null])(
311 "rejects an invalid in-app notification preference %s",
312 (inAppNotificationsEnabled) => {
313 expect(() => decodeClientSettings({ inAppNotificationsEnabled })).toThrow();
314 expect(() => decodeClientSettingsPatch({ inAppNotificationsEnabled })).toThrow();
315 },
316 );
317
318 it.each(["off", "notifications", "sound", "notifications-and-sound"])(
319 "round-trips the %s mode",
320 (notificationMode) => {
321 const settings = decodeClientSettings({ notificationMode });
322 expect(encodeClientSettings(settings).notificationMode).toBe(notificationMode);
323 expect(decodeClientSettingsPatch({ notificationMode }).notificationMode).toBe(
324 notificationMode,
325 );
326 },
327 );
328
329 it.each(["always", true, null])(
330 "rejects unsupported notification mode %s",
331 (notificationMode) => {
332 expect(() => decodeClientSettings({ notificationMode })).toThrow();
333 expect(() => decodeClientSettingsPatch({ notificationMode })).toThrow();
334 },
335 );
336});
337
338describe("ClientSettings default diff file state", () => {
339 it("keeps files collapsed when existing settings omit the preference", () => {
340 expect(decodeClientSettings({}).diffFilesCollapsed).toBe(true);
341 });
342
343 it.each([true, false])("preserves a saved collapsed preference of %s", (diffFilesCollapsed) => {
344 const settings = decodeClientSettings({ diffFilesCollapsed });
345 expect(encodeClientSettings(settings).diffFilesCollapsed).toBe(diffFilesCollapsed);
346 expect(decodeClientSettingsPatch({ diffFilesCollapsed }).diffFilesCollapsed).toBe(
347 diffFilesCollapsed,
348 );
349 });
350});
351
352describe("ClientSettings diff colors", () => {
353 it("keeps red and green for existing settings without a saved palette", () => {
354 expect(decodeClientSettings({}).diffColorScheme).toBe("red-green");
355 });
356
357 it.each(["red-green", "blue-orange"])("round-trips the %s palette", (diffColorScheme) => {
358 const settings = decodeClientSettings({ diffColorScheme });
359 expect(encodeClientSettings(settings).diffColorScheme).toBe(diffColorScheme);
360 expect(decodeClientSettingsPatch({ diffColorScheme }).diffColorScheme).toBe(diffColorScheme);
361 });
362
363 it("rejects unsupported palettes", () => {
364 expect(() => decodeClientSettings({ diffColorScheme: "purple-yellow" })).toThrow();
365 expect(() => decodeClientSettingsPatch({ diffColorScheme: "purple-yellow" })).toThrow();
366 });
367});
368
369describe("ClientSettings chat width", () => {
370 it("keeps the comfortable width for existing settings without a saved width", () => {
371 expect(decodeClientSettings({}).chatWidth).toBe("comfortable");
372 });
373
374 it.each(["comfortable", "wide", "full"])("round-trips the %s width", (chatWidth) => {
375 const settings = decodeClientSettings({ chatWidth });
376 expect(encodeClientSettings(settings).chatWidth).toBe(chatWidth);
377 expect(decodeClientSettingsPatch({ chatWidth }).chatWidth).toBe(chatWidth);
378 });
379
380 it("rejects unsupported widths", () => {
381 expect(() => decodeClientSettings({ chatWidth: "huge" })).toThrow();
382 expect(() => decodeClientSettingsPatch({ chatWidth: "huge" })).toThrow();
383 });
384});
385
386describe("ClientSettings load balancing", () => {
387 it("requires opt-in when settings are new or omit load balancing", () => {
388 expect(decodeClientSettings({}).loadBalancingEnabled).toBe(false);
389 expect(decodeClientSettings({ loadBalancingWeights: {} }).loadBalancingEnabled).toBe(false);
390 });
391
392 it.each([true, false])("preserves a saved choice of %s", (loadBalancingEnabled) => {
393 const settings = decodeClientSettings({ loadBalancingEnabled });
394 expect(encodeClientSettings(settings).loadBalancingEnabled).toBe(loadBalancingEnabled);
395 expect(decodeClientSettingsPatch({ loadBalancingEnabled }).loadBalancingEnabled).toBe(
396 loadBalancingEnabled,
397 );
398 });
399});
400
401describe("ClientSettings composer context strip", () => {
402 it("defaults to draft-only and accepts a persistent strip preference", () => {
403 expect(decodeClientSettings({}).persistComposerContextStrip).toBe(false);
404 expect(
405 decodeClientSettingsPatch({ persistComposerContextStrip: true }).persistComposerContextStrip,
406 ).toBe(true);
407 });
408});
409
410describe("ClientSettings word wrap", () => {
411 it("defaults word wrap on", () => {
412 expect(decodeClientSettings({}).wordWrap).toBe(true);
413 });
414
415 it("ignores obsolete wrapping preferences", () => {
416 const decoded = decodeClientSettings({
417 chatWordWrap: false,
418 diffWordWrap: false,
419 });
420
421 expect(decoded.wordWrap).toBe(true);
422 expect(decoded).not.toHaveProperty("chatWordWrap");
423 expect(decoded).not.toHaveProperty("diffWordWrap");
424 });
425});
426
427describe("ClientSettings window capture", () => {
428 it("defaults capture off while keeping its feedback enabled", () => {
429 const settings = decodeClientSettings({});
430
431 expect(settings.snapShotEnabled).toBe(false);
432 expect(settings.snapShotIncludeAccessibility).toBe(true);
433 expect(settings.snapShotShortcut).toEqual({ kind: "both-shift-keys" });
434 expect(settings.snapShotPlaySound).toBe(true);
435 expect(settings.snapShotSound).toBe("soft-pop");
436 expect(settings.snapShotFlash).toBe(true);
437 expect(settings.snapShotAnimations).toBe(true);
438 });
439
440 it("accepts capture preference updates", () => {
441 expect(
442 decodeClientSettingsPatch({
443 snapShotEnabled: true,
444 snapShotIncludeAccessibility: false,
445 snapShotShortcut: {
446 key: "w",
447 metaKey: false,
448 ctrlKey: false,
449 shiftKey: true,
450 altKey: true,
451 modKey: false,
452 },
453 snapShotPlaySound: false,
454 snapShotSound: "camera-shutter",
455 snapShotFlash: false,
456 snapShotAnimations: false,
457 }),
458 ).toEqual({
459 snapShotEnabled: true,
460 snapShotIncludeAccessibility: false,
461 snapShotShortcut: {
462 key: "w",
463 metaKey: false,
464 ctrlKey: false,
465 shiftKey: true,
466 altKey: true,
467 modKey: false,
468 },
469 snapShotPlaySound: false,
470 snapShotSound: "camera-shutter",
471 snapShotFlash: false,
472 snapShotAnimations: false,
473 });
474 });
475
476 it("rejects unknown capture sounds", () => {
477 expect(() => decodeClientSettingsPatch({ snapShotSound: "doorbell" })).toThrow();
478 });
479
480 it("accepts modifier pair shortcuts", () => {
481 expect(
482 decodeClientSettingsPatch({
483 snapShotShortcut: { kind: "modifier-pair", modifier: "meta" },
484 }),
485 ).toEqual({
486 snapShotShortcut: { kind: "modifier-pair", modifier: "meta" },
487 });
488 expect(() =>
489 decodeClientSettingsPatch({
490 snapShotShortcut: { kind: "modifier-pair", modifier: "hyper" },
491 }),
492 ).toThrow();
493 });
494
495 it("rejects a capture shortcut with no modifier", () => {
496 expect(() =>
497 decodeClientSettingsPatch({
498 snapShotShortcut: {
499 key: "w",
500 metaKey: false,
501 ctrlKey: false,
502 shiftKey: false,
503 altKey: false,
504 modKey: false,
505 },
506 }),
507 ).toThrow();
508 });
509});
510
511describe("ClientSettings proactive panels", () => {
512 it("is opt-in and accepts client-local updates", () => {
513 expect(decodeClientSettings({}).proactivePanelsEnabled).toBe(false);
514 expect(decodeClientSettingsPatch({ proactivePanelsEnabled: true }).proactivePanelsEnabled).toBe(
515 true,
516 );
517 });
518});
519
520describe("ClientSettings quit confirmation", () => {
521 it("defaults to hold", () => {
522 expect(decodeClientSettings({}).confirmQuit).toBe("hold");
523 });
524
525 it.each(["direct", "hold", "double-click"] as const)("accepts the %s mode", (mode) => {
526 expect(decodeClientSettings({ confirmQuit: mode }).confirmQuit).toBe(mode);
527 expect(decodeClientSettingsPatch({ confirmQuit: mode }).confirmQuit).toBe(mode);
528 });
529
530 it.each([
531 [true, "hold"],
532 [false, "direct"],
533 ] as const)("migrates the legacy %s value to %s", (legacyValue, mode) => {
534 const settings = decodeClientSettings({ confirmQuit: legacyValue });
535
536 expect(settings.confirmQuit).toBe(mode);
537 expect(encodeClientSettings(settings).confirmQuit).toBe(mode);
538 });
539
540 it("rejects legacy booleans at the patch boundary", () => {
541 expect(() => decodeClientSettingsPatch({ confirmQuit: true })).toThrow();
542 });
543});
544
545describe("ClientSettings browser recording frame rate", () => {
546 it("defaults to 30 fps", () => {
547 expect(decodeClientSettings({}).browserRecordingFrameRate).toBe(30);
548 });
549
550 it.each([30, 60])("accepts a supported frame rate: %s", (frameRate) => {
551 expect(
552 decodeClientSettings({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
553 ).toBe(frameRate);
554 expect(
555 decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
556 ).toBe(frameRate);
557 });
558
559 it.each([24, 59, 120])("rejects an unsupported frame rate: %s", (frameRate) => {
560 expect(() => decodeClientSettings({ browserRecordingFrameRate: frameRate })).toThrow();
561 expect(() => decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate })).toThrow();
562 });
563});
564
565describe("ClientSettings recording input overlays", () => {
566 it("defaults both overlays off and accepts independent opt-ins", () => {
567 const settings = decodeClientSettings({});
568 expect(settings.browserRecordingShowKeyPresses).toBe(false);
569 expect(settings.browserRecordingShowMousePresses).toBe(false);
570 expect(
571 decodeClientSettingsPatch({
572 browserRecordingShowKeyPresses: true,
573 browserRecordingShowMousePresses: false,
574 }),
575 ).toMatchObject({
576 browserRecordingShowKeyPresses: true,
577 browserRecordingShowMousePresses: false,
578 });
579 });
580});
581
582describe("ClientSettings glass opacity", () => {
583 it("defaults to a readable translucent surface", () => {
584 expect(decodeClientSettings({}).glassOpacity).toBe(80);
585 });
586
587 it.each([39, 101, 72.5])("rejects an invalid glass opacity: %s", (value) => {
588 expect(() => decodeClientSettings({ glassOpacity: value })).toThrow();
589 expect(() => decodeClientSettingsPatch({ glassOpacity: value })).toThrow();
590 });
591
592 it.each([40, 75, 100])("accepts a glass opacity within the supported range: %s", (value) => {
593 expect(decodeClientSettings({ glassOpacity: value }).glassOpacity).toBe(value);
594 expect(decodeClientSettingsPatch({ glassOpacity: value }).glassOpacity).toBe(value);
595 });
596});
597
598describe("ClientSettings appearance contrast", () => {
599 it("defaults to the theme's original contrast", () => {
600 expect(decodeClientSettings({}).appearanceContrast).toBe(100);
601 });
602
603 it.each([49, 201, 92.5])("rejects an invalid appearance contrast: %s", (value) => {
604 expect(() => decodeClientSettings({ appearanceContrast: value })).toThrow();
605 expect(() => decodeClientSettingsPatch({ appearanceContrast: value })).toThrow();
606 });
607
608 it.each([50, 100, 150, 200])("accepts an appearance contrast in range: %s", (value) => {
609 expect(decodeClientSettings({ appearanceContrast: value }).appearanceContrast).toBe(value);
610 expect(decodeClientSettingsPatch({ appearanceContrast: value }).appearanceContrast).toBe(value);
611 });
612});
613
614describe("ClientSettings panel animations", () => {
615 it("defaults to instant changes", () => {
616 expect(decodeClientSettings({}).panelAnimationDurationMs).toBe(0);
617 });
618
619 it.each([0, 400])("accepts a panel animation duration: %s", (value) => {
620 expect(decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toEqual({
621 panelAnimationDurationMs: value,
622 });
623 });
624
625 it.each([-1, 401, 150.5])("rejects an invalid panel animation duration: %s", (value) => {
626 expect(() => decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toThrow();
627 });
628});
629
630describe("ClientSettings environment identification", () => {
631 it("defaults to artwork and accepts each presentation mode", () => {
632 expect(decodeClientSettings({}).environmentIdentificationMode).toBe("artwork");
633
634 for (const mode of ["artwork", "pill", "none"] as const) {
635 expect(
636 decodeClientSettingsPatch({ environmentIdentificationMode: mode })
637 .environmentIdentificationMode,
638 ).toBe(mode);
639 }
640 });
641
642 it("rejects unsupported presentation modes", () => {
643 expect(() => decodeClientSettings({ environmentIdentificationMode: "badge" })).toThrow();
644 expect(() => decodeClientSettingsPatch({ environmentIdentificationMode: "badge" })).toThrow();
645 });
646});
647
648describe("ClientSettings sidebar", () => {
649 it("defaults to the current sidebar", () => {
650 expect(decodeClientSettings({}).legacySidebarEnabled).toBe(false);
651 });
652
653 it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
654 const decoded = decodeClientSettings({
655 sidebarV2Enabled: false,
656 sidebarV2ConfiguredByUser: true,
657 });
658 expect(decoded.legacySidebarEnabled).toBe(false);
659 expect(decoded).not.toHaveProperty("sidebarV2Enabled");
660 expect(decoded).not.toHaveProperty("sidebarV2ConfiguredByUser");
661 });
662
663 it("drops the retired compact sidebar keys for users who opted in", () => {
664 const stored = { compactSidebarEnabled: true, sidebarCompactThreadRows: true };
665 const decoded = decodeClientSettings(stored);
666 expect(decoded).not.toHaveProperty("compactSidebarEnabled");
667 expect(decoded).not.toHaveProperty("sidebarCompactThreadRows");
668 expect(decodeClientSettingsPatch(stored)).toEqual({});
669 });
670
671 it("preserves an explicit legacy sidebar opt-in", () => {
672 expect(decodeClientSettings({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(true);
673 expect(decodeClientSettingsPatch({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(
674 true,
675 );
676 });
677
678 it("keeps unpin confirmation opt-in and patchable", () => {
679 expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
680 expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
681 expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
682 });
683});
684
685describe("ClientSettings context window meter", () => {
686 it("defaults off and preserves an explicit legacy opt-in", () => {
687 expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
688 expect(
689 decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
690 ).toBe(true);
691 expect(
692 decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
693 ).toBe(true);
694 });
695});
696
697describe("ClientSettings send shortcut", () => {
698 it("defaults to Enter and validates the supported choices", () => {
699 expect(decodeClientSettings({}).sendShortcut).toBe("enter");
700 for (const sendShortcut of ["enter", "mod-enter-multiline", "mod-enter"]) {
701 expect(decodeClientSettings({ sendShortcut }).sendShortcut).toBe(sendShortcut);
702 expect(decodeClientSettingsPatch({ sendShortcut }).sendShortcut).toBe(sendShortcut);
703 }
704 expect(() => decodeClientSettingsPatch({ sendShortcut: "invalid" })).toThrow();
705 });
706});
707
708describe("ClientSettings follow-up behavior", () => {
709 it("defaults to queue and accepts either behavior", () => {
710 expect(decodeClientSettings({}).followUpBehavior).toBe("queue");
711 for (const followUpBehavior of ["queue", "steer"]) {
712 expect(decodeClientSettings({ followUpBehavior }).followUpBehavior).toBe(followUpBehavior);
713 expect(decodeClientSettingsPatch({ followUpBehavior }).followUpBehavior).toBe(
714 followUpBehavior,
715 );
716 }
717 expect(() => decodeClientSettingsPatch({ followUpBehavior: "invalid" })).toThrow();
718 });
719});
720
721describe("ClientSettings composer collapse", () => {
722 it("collapses on scroll by default and accepts opting out", () => {
723 expect(decodeClientSettings({}).composerCollapseOnScroll).toBe(true);
724 expect(
725 decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
726 ).toBe(false);
727 });
728
729 it("drops the retired blur trigger key", () => {
730 const decoded = decodeClientSettings({ composerCollapseOnBlur: false });
731 expect(decoded.composerCollapseOnScroll).toBe(true);
732 expect(decoded).not.toHaveProperty("composerCollapseOnBlur");
733 });
734});
735
736describe("ServerSettings thread settlement", () => {
737 it("defaults merge settlement on and inactivity settlement to three days", () => {
738 const settings = decodeServerSettings({});
739 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
740 expect(settings.sidebarAutoSettleOnMerge).toBe(true);
741 });
742
743 it("allows both automatic rules to be disabled", () => {
744 expect(
745 decodeServerSettings({
746 sidebarAutoSettleAfterDays: null,
747 sidebarAutoSettleOnMerge: false,
748 }),
749 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
750 expect(
751 decodeServerSettingsPatch({
752 sidebarAutoSettleAfterDays: null,
753 sidebarAutoSettleOnMerge: false,
754 }),
755 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
756 });
757
758 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
759 expect(() => decodeServerSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
760 expect(() => decodeServerSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
761 });
762});
763
764describe("ClientSettings pull request merge methods", () => {
765 it("defaults to no project overrides and accepts supported methods", () => {
766 expect(decodeClientSettings({}).pullRequestMergeMethodOverrides).toEqual({});
767 expect(
768 decodeClientSettingsPatch({
769 pullRequestMergeMethodOverrides: { project: "squash" },
770 }).pullRequestMergeMethodOverrides,
771 ).toEqual({ project: "squash" });
772 });
773
774 it("rejects unsupported project merge methods", () => {
775 expect(() =>
776 decodeClientSettingsPatch({
777 pullRequestMergeMethodOverrides: { project: "fast-forward" },
778 }),
779 ).toThrow();
780 });
781});
782
783describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
784 it("defaults to an empty record so legacy configs without the key still decode", () => {
785 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
786 });
787
788 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
789 const decoded = decodeServerSettings({});
790 expect(decoded.providerInstances).toEqual({});
791 });
792
793 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
794 const decoded = decodeServerSettings({
795 providerInstances: {
796 codex_personal: {
797 driver: "codex",
798 displayName: "Codex (personal)",
799 config: { homePath: "~/.codex_personal" },
800 },
801 codex_work: {
802 driver: "codex",
803 config: { homePath: "~/.codex_work" },
804 },
805 ollama_local: {
806 driver: "ollama",
807 displayName: "Ollama (local)",
808 config: { endpoint: "http://localhost:11434" },
809 },
810 },
811 });
812 const personalId = ProviderInstanceId.make("codex_personal");
813 const workId = ProviderInstanceId.make("codex_work");
814 const ollamaId = ProviderInstanceId.make("ollama_local");
815
816 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
817 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
818 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
819 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
820 endpoint: "http://localhost:11434",
821 });
822 });
823
824 it("rejects instance keys that violate the slug pattern", () => {
825 expect(() =>
826 decodeServerSettings({
827 providerInstances: { "1bad": { driver: "codex" } },
828 }),
829 ).toThrow();
830 });
831});
832
833describe("provider enabled defaults", () => {
834 it("keeps Muse disabled until a configured instance opts in", () => {
835 const muse = ProviderDriverKind.make("muse");
836 expect(resolveProviderInstanceEnabled({ driver: muse, config: {} })).toBe(false);
837 expect(resolveProviderInstanceEnabled({ driver: muse, enabled: true, config: {} })).toBe(true);
838 expect(
839 resolveProviderInstanceEnabled({ driver: muse, enabled: true, config: { enabled: false } }),
840 ).toBe(false);
841 });
842
843 it("enables only the stable bindings by default", () => {
844 const enabledByDefault = (driver: string) =>
845 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make(driver), config: {} });
846 expect(enabledByDefault("codex")).toBe(true);
847 expect(enabledByDefault("claudeAgent")).toBe(true);
848 for (const driver of ["cursor", "grok", "muse", "pi", "opencode", "antigravity"]) {
849 expect(enabledByDefault(driver)).toBe(false);
850 }
851 });
852
853 it("resolves instance enabled state with explicit false winning", () => {
854 const grok = ProviderDriverKind.make("grok");
855 const codex = ProviderDriverKind.make("codex");
856 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
857 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
858 expect(
859 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
860 ).toBe(true);
861 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
862 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
863 false,
864 );
865 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
866 expect(
867 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
868 ).toBe(false);
869 expect(
870 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
871 ).toBe(false);
872 });
873});
874
875describe("ServerSettings worktree defaults", () => {
876 it("defaults the thread env mode to inherit and keeps stored values", () => {
877 expect(decodeServerSettings({}).defaultThreadEnvMode).toBeNull();
878 expect(decodeServerSettings({ defaultThreadEnvMode: "worktree" }).defaultThreadEnvMode).toBe(
879 "worktree",
880 );
881 expect(
882 decodeServerSettings({ defaultThreadEnvMode: "remote" }).defaultThreadEnvMode,
883 ).toBeNull();
884 expect(
885 decodeServerSettingsPatch({ defaultThreadEnvMode: null }).defaultThreadEnvMode,
886 ).toBeNull();
887 });
888
889 it("keeps an inherited thread env mode off the wire for older clients", () => {
890 const encode = Schema.encodeSync(ServerSettings);
891 expect("defaultThreadEnvMode" in encode(decodeServerSettings({}))).toBe(false);
892 expect(
893 encode(decodeServerSettings({ defaultThreadEnvMode: "worktree" })).defaultThreadEnvMode,
894 ).toBe("worktree");
895 });
896
897 it("defaults start-from-origin on for legacy configs", () => {
898 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
899 });
900
901 it("accepts start-from-origin updates", () => {
902 expect(
903 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
904 ).toBe(false);
905 });
906
907 it("defaults worktree submodules to inherit and tolerates unknown modes", () => {
908 expect(decodeServerSettings({}).worktreeSubmodules).toBeNull();
909 expect(decodeServerSettings({ worktreeSubmodules: "top-level" }).worktreeSubmodules).toBe(
910 "top-level",
911 );
912 expect(decodeServerSettings({ worktreeSubmodules: "shallow" }).worktreeSubmodules).toBeNull();
913 expect(decodeServerSettingsPatch({ worktreeSubmodules: null }).worktreeSubmodules).toBeNull();
914 });
915});
916
917describe("ServerSettings.sourceControlWritingStyle", () => {
918 it("defaults all style settings for legacy configs", () => {
919 const settings = decodeServerSettings({});
920
921 expect(settings.sourceControlWritingStyle).toEqual({
922 mode: "repo_conventions",
923 customInstructions: "",
924 followChangeRequestTemplates: true,
925 });
926 expect(settings.sourceControlWriterModelSelection).toBeNull();
927 });
928
929 it("trims partial style updates", () => {
930 const patch = decodeServerSettingsPatch({
931 sourceControlWritingStyle: {
932 mode: "custom",
933 customInstructions: " Prefer concise wording. ",
934 },
935 });
936
937 expect(patch.sourceControlWritingStyle).toEqual({
938 mode: "custom",
939 customInstructions: "Prefer concise wording.",
940 });
941 });
942});
943
944describe("ServerSettingsPatch.providerInstances", () => {
945 it("treats providerInstances as an optional whole-map replacement", () => {
946 const patch = decodeServerSettingsPatch({});
947 expect(patch.providerInstances).toBeUndefined();
948
949 const replacement = decodeServerSettingsPatch({
950 providerInstances: {
951 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
952 },
953 });
954 expect(replacement.providerInstances).toBeDefined();
955 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
956 "codex",
957 );
958 });
959
960 it("preserves a fork-defined driver entry through patch decoding", () => {
961 const patch = decodeServerSettingsPatch({
962 providerInstances: {
963 ollama_local: {
964 driver: "ollama",
965 config: { endpoint: "http://localhost:11434" },
966 },
967 },
968 });
969 const ollamaId = ProviderInstanceId.make("ollama_local");
970 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
971 });
972});
973
974describe("ServerSettingsPatch string normalization", () => {
975 it("trims string settings while decoding patches", () => {
976 const patch = decodeServerSettingsPatch({
977 addProjectBaseDirectory: " ~/Development ",
978 textGenerationModelSelection: { model: " gpt-5.4-mini " },
979 observability: {
980 otlpTracesUrl: " http://localhost:4318/v1/traces ",
981 },
982 providerInstances: {
983 codex_personal: {
984 driver: " codex ",
985 displayName: " Codex Personal ",
986 config: { homePath: " ~/.codex-personal " },
987 },
988 },
989 });
990
991 expect(patch.addProjectBaseDirectory).toBe("~/Development");
992 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
993 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
994 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
995 "codex",
996 );
997 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
998 "Codex Personal",
999 );
1000 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
1001 homePath: " ~/.codex-personal ",
1002 });
1003 });
1004
1005 it("trims encoded server settings values before validation", () => {
1006 const defaultSettings = decodeServerSettings({});
1007 const encoded = encodeServerSettings({
1008 ...defaultSettings,
1009 addProjectBaseDirectory: " ~/Development ",
1010 });
1011
1012 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
1013 });
1014});
1015
1016describe("ServerSettings environment icon", () => {
1017 it("defaults to null", () => {
1018 expect(decodeServerSettings({}).environmentIcon).toBeNull();
1019 });
1020
1021 it("keeps a kind this build knows", () => {
1022 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
1023 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
1024 });
1025
1026 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
1027 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
1028 });
1029
1030 it("round-trips through encode", () => {
1031 const settings = decodeServerSettings({ environmentIcon: "laptop" });
1032 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
1033
1034 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
1035 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
1036 });
1037});
1038
1039const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
1040
1041it("validates remote device hosts and rejects ambiguous host ids", () => {
1042 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
1043 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
1044 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
1045 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
1046 expect(() =>
1047 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
1048 ).toThrow();
1049 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
1050});
1051
1052describe("branch naming settings", () => {
1053 it("defaults existing settings to the t3 static prefix", () => {
1054 expect(decodeServerSettings({})).toMatchObject({
1055 branchNamingMode: "static",
1056 branchNamePrefix: "t3",
1057 branchNameInstructions: "",
1058 });
1059 });
1060 it.each(["static", "semantic", "custom"])(
1061 "round-trips %s and project overrides",
1062 (branchNamingMode) => {
1063 const naming = {
1064 branchNamingMode,
1065 branchNamePrefix: "team/",
1066 branchNameInstructions: "Include the issue ID.",
1067 };
1068 const input = { ...naming, projectSettingsOverrides: { project: naming } };
1069 expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
1070 expect(decodeServerSettingsPatch(input)).toEqual(input);
1071 },
1072 );
1073});
1074
1075describe("ServerSettings.removeAgentCreditsOnMerge", () => {
1076 it("keeps agent credits by default and accepts opt-in patches", () => {
1077 expect(decodeServerSettings({}).removeAgentCreditsOnMerge).toBe(false);
1078 expect(
1079 decodeServerSettingsPatch({ removeAgentCreditsOnMerge: true }).removeAgentCreditsOnMerge,
1080 ).toBe(true);
1081 expect(
1082 decodeServerSettings({
1083 projectSettingsOverrides: { project: { removeAgentCreditsOnMerge: true } },
1084 }).projectSettingsOverrides["project" as ProjectId]?.removeAgentCreditsOnMerge,
1085 ).toBe(true);
1086 });
1087});
1088
1089describe("resolveProjectProviderInstanceEnabled", () => {
1090 const projectId = "project-a" as ProjectId;
1091 const instanceId = ProviderInstanceId.make("codex_work");
1092
1093 it("inherits the machine value when the project has no override", () => {
1094 const settings: ServerSettings = {
1095 ...DEFAULT_SERVER_SETTINGS,
1096 providerInstances: {
1097 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false },
1098 },
1099 };
1100 expect(resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)).toBe(false);
1101 });
1102
1103 it("lets a project enable an instance the machine disabled", () => {
1104 const settings: ServerSettings = {
1105 ...DEFAULT_SERVER_SETTINGS,
1106 providerInstances: {
1107 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false },
1108 },
1109 projectSettingsOverrides: {
1110 [projectId]: { providerInstances: { [instanceId]: { enabled: true } } },
1111 },
1112 };
1113 expect(resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)).toBe(true);
1114 });
1115
1116 it("lets a project disable an instance the machine enabled", () => {
1117 const settings: ServerSettings = {
1118 ...DEFAULT_SERVER_SETTINGS,
1119 providerInstances: {
1120 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
1121 },
1122 projectSettingsOverrides: {
1123 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
1124 },
1125 };
1126 expect(resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)).toBe(false);
1127 });
1128
1129 it("always resolves to the machine value when no project is in scope", () => {
1130 const settings: ServerSettings = {
1131 ...DEFAULT_SERVER_SETTINGS,
1132 providerInstances: {
1133 [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
1134 },
1135 projectSettingsOverrides: {
1136 [projectId]: { providerInstances: { [instanceId]: { enabled: false } } },
1137 },
1138 };
1139 expect(resolveProjectProviderInstanceEnabled(settings, null, instanceId)).toBe(true);
1140 });
1141
1142 it("falls back to the unconfigured default when the instance has no settings entry", () => {
1143 const settings: ServerSettings = { ...DEFAULT_SERVER_SETTINGS, providerInstances: {} };
1144 expect(resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)).toBe(
1145 resolveProjectProviderInstanceEnabled(settings, null, instanceId),
1146 );
1147
1148 const overridden = {
1149 ...settings,
1150 projectSettingsOverrides: {
1151 [projectId]: { providerInstances: { [instanceId]: { enabled: true } } },
1152 },
1153 };
1154 expect(resolveProjectProviderInstanceEnabled(overridden, projectId, instanceId)).toBe(true);
1155 });
1156});
1157
1158describe("requiredScopesForProjectMutation", () => {
1159 it("adds the settings scope only when a mutation carries scripts", () => {
1160 const projectId = "project-1" as ProjectId;
1161 const commandId = "command-1" as CommandId;
1162 expect(
1163 requiredScopesForProjectMutation({ type: "project.update", commandId, projectId }),
1164 ).toEqual(["orchestration:operate"]);
1165 expect(
1166 requiredScopesForProjectMutation({
1167 type: "project.update",
1168 commandId,
1169 projectId,
1170 scripts: [],
1171 }),
1172 ).toEqual(["orchestration:operate", "settings:write"]);
1173 });
1174});
1175
1176describe("server model preferences", () => {
1177 it("decodes a visibility update scoped to a provider instance and model", () => {
1178 const patch = { setModelsHidden: [{ provider: "codex_work", model: "sol", hidden: false }] };
1179 expect(decodeServerSettingsPatch(patch)).toEqual(patch);
1180 expect(() =>
1181 decodeServerSettingsPatch({ setModelsHidden: [{ provider: "codex_work", model: "sol" }] }),
1182 ).toThrow();
1183 });
1184 it("distinguishes unmigrated lists from deliberately cleared lists", () => {
1185 expect(decodeServerSettings({})).toMatchObject({
1186 favorites: null,
1187 providerModelPreferences: null,
1188 });
1189 const input = { favorites: [], providerModelPreferences: {} };
1190 expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
1191 expect(decodeServerSettingsPatch(input)).toEqual(input);
1192 });
1193
1194 it("round trips favorites and hidden models keyed by provider instance", () => {
1195 const input = {
1196 favorites: [{ provider: "codex_work", model: "sol" }],
1197 providerModelPreferences: { codex_work: { hiddenModels: ["astra"], modelOrder: ["sol"] } },
1198 };
1199 expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
1200 expect(decodeServerSettingsPatch(input)).toEqual(input);
1201 expect(decodeServerSettingsPatch({ migrateModelPreferences: input })).toEqual({
1202 migrateModelPreferences: input,
1203 });
1204 });
1205});