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