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