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