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