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("enables only the stable bindings by default", () => {
805 const decoded = decodeServerSettings({});
806 expect(decoded.providers.codex.enabled).toBe(true);
807 expect(decoded.providers.claudeAgent.enabled).toBe(true);
808 expect(decoded.providers.cursor.enabled).toBe(false);
809 expect(decoded.providers.grok.enabled).toBe(false);
810 expect(decoded.providers.opencode.enabled).toBe(false);
811 });
812
813 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
814 const cursor = ProviderDriverKind.make("cursor");
815 const cursorId = ProviderInstanceId.make("cursor");
816 const decoded = decodeServerSettings({
817 providers: { cursor: { enabled: true } },
818 providerInstances: {
819 [cursorId]: { driver: cursor, enabled: true, config: {} },
820 },
821 });
822
823 expect(decoded.providers.cursor.enabled).toBe(true);
824 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
825 });
826
827 it("resolves instance enabled state with explicit false winning", () => {
828 const grok = ProviderDriverKind.make("grok");
829 const codex = ProviderDriverKind.make("codex");
830 // No flags anywhere: driver default applies.
831 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
832 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
833 // Unknown fork drivers stay enabled.
834 expect(
835 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
836 ).toBe(true);
837 // Envelope flag wins over the driver default.
838 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
839 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
840 false,
841 );
842 // Legacy in-config flag fills in when the envelope is silent.
843 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
844 // Conflicting flags: the explicit false wins, whichever side it is on.
845 expect(
846 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
847 ).toBe(false);
848 expect(
849 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
850 ).toBe(false);
851 });
852});
853
854describe("ServerSettings worktree defaults", () => {
855 it("defaults the thread env mode to inherit and keeps stored values", () => {
856 expect(decodeServerSettings({}).defaultThreadEnvMode).toBeNull();
857 expect(decodeServerSettings({ defaultThreadEnvMode: "worktree" }).defaultThreadEnvMode).toBe(
858 "worktree",
859 );
860 expect(
861 decodeServerSettings({ defaultThreadEnvMode: "remote" }).defaultThreadEnvMode,
862 ).toBeNull();
863 expect(
864 decodeServerSettingsPatch({ defaultThreadEnvMode: null }).defaultThreadEnvMode,
865 ).toBeNull();
866 });
867
868 it("keeps an inherited thread env mode off the wire for older clients", () => {
869 const encode = Schema.encodeSync(ServerSettings);
870 expect("defaultThreadEnvMode" in encode(decodeServerSettings({}))).toBe(false);
871 expect(
872 encode(decodeServerSettings({ defaultThreadEnvMode: "worktree" })).defaultThreadEnvMode,
873 ).toBe("worktree");
874 });
875
876 it("defaults start-from-origin on for legacy configs", () => {
877 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
878 });
879
880 it("accepts start-from-origin updates", () => {
881 expect(
882 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
883 ).toBe(false);
884 });
885
886 it("defaults worktree submodules to inherit and tolerates unknown modes", () => {
887 expect(decodeServerSettings({}).worktreeSubmodules).toBeNull();
888 expect(decodeServerSettings({ worktreeSubmodules: "top-level" }).worktreeSubmodules).toBe(
889 "top-level",
890 );
891 expect(decodeServerSettings({ worktreeSubmodules: "shallow" }).worktreeSubmodules).toBeNull();
892 expect(decodeServerSettingsPatch({ worktreeSubmodules: null }).worktreeSubmodules).toBeNull();
893 });
894});
895
896describe("ServerSettings Cursor legacy settings", () => {
897 it("preserves V1 Cursor CLI settings when reading and writing shared settings", () => {
898 const decoded = decodeServerSettings({
899 providers: {
900 cursor: {
901 enabled: true,
902 binaryPath: "cursor-agent",
903 apiEndpoint: "http://127.0.0.1:3774",
904 },
905 },
906 });
907
908 expect(decoded.providers.cursor.enabled).toBe(true);
909 expect(encodeServerSettings(decoded).providers?.cursor).toMatchObject({
910 binaryPath: "cursor-agent",
911 apiEndpoint: "http://127.0.0.1:3774",
912 });
913 });
914
915 it("ignores obsolete Cursor CLI settings in patches", () => {
916 const patch = decodeServerSettingsPatch({
917 providers: {
918 cursor: {
919 enabled: true,
920 binaryPath: "cursor-agent",
921 apiEndpoint: "http://127.0.0.1:3774",
922 },
923 },
924 });
925
926 expect(patch.providers?.cursor?.enabled).toBe(true);
927 expect(patch.providers?.cursor).not.toHaveProperty("binaryPath");
928 expect(patch.providers?.cursor).not.toHaveProperty("apiEndpoint");
929 });
930});
931
932describe("ServerSettings.sourceControlWritingStyle", () => {
933 it("defaults all style settings for legacy configs", () => {
934 const settings = decodeServerSettings({});
935
936 expect(settings.sourceControlWritingStyle).toEqual({
937 mode: "repo_conventions",
938 customInstructions: "",
939 followChangeRequestTemplates: true,
940 });
941 expect(settings.sourceControlWriterModelSelection).toBeNull();
942 });
943
944 it("trims partial style updates", () => {
945 const patch = decodeServerSettingsPatch({
946 sourceControlWritingStyle: {
947 mode: "custom",
948 customInstructions: " Prefer concise wording. ",
949 },
950 });
951
952 expect(patch.sourceControlWritingStyle).toEqual({
953 mode: "custom",
954 customInstructions: "Prefer concise wording.",
955 });
956 });
957});
958
959describe("ServerSettingsPatch.providerInstances", () => {
960 it("treats providerInstances as an optional whole-map replacement", () => {
961 const patch = decodeServerSettingsPatch({});
962 expect(patch.providerInstances).toBeUndefined();
963
964 const replacement = decodeServerSettingsPatch({
965 providerInstances: {
966 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
967 },
968 });
969 expect(replacement.providerInstances).toBeDefined();
970 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
971 "codex",
972 );
973 });
974
975 it("preserves a fork-defined driver entry through patch decoding", () => {
976 const patch = decodeServerSettingsPatch({
977 providerInstances: {
978 ollama_local: {
979 driver: "ollama",
980 config: { endpoint: "http://localhost:11434" },
981 },
982 },
983 });
984 const ollamaId = ProviderInstanceId.make("ollama_local");
985 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
986 });
987});
988
989describe("ServerSettingsPatch string normalization", () => {
990 it("lowercases GitHub hosts and defaults them to enabled", () => {
991 const patch = decodeServerSettingsPatch({
992 github: { hosts: { " GitHub.com ": { account: " work " } } },
993 });
994 expect(patch.github?.hosts).toEqual({ "github.com": { account: "work", enabled: true } });
995 });
996
997 it("trims string settings while decoding patches", () => {
998 const patch = decodeServerSettingsPatch({
999 addProjectBaseDirectory: " ~/Development ",
1000 textGenerationModelSelection: { model: " gpt-5.4-mini " },
1001 observability: {
1002 otlpTracesUrl: " http://localhost:4318/v1/traces ",
1003 },
1004 providers: {
1005 codex: {
1006 binaryPath: " /opt/homebrew/bin/codex ",
1007 homePath: " ~/.codex ",
1008 launchArgs: " --strict-config --enable foo ",
1009 },
1010 },
1011 providerInstances: {
1012 codex_personal: {
1013 driver: " codex ",
1014 displayName: " Codex Personal ",
1015 config: { homePath: " ~/.codex-personal " },
1016 },
1017 },
1018 });
1019
1020 expect(patch.addProjectBaseDirectory).toBe("~/Development");
1021 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
1022 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
1023 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
1024 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
1025 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
1026 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
1027 "codex",
1028 );
1029 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
1030 "Codex Personal",
1031 );
1032 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
1033 homePath: " ~/.codex-personal ",
1034 });
1035 });
1036
1037 it("trims encoded server settings values before validation", () => {
1038 const defaultSettings = decodeServerSettings({});
1039 const encoded = encodeServerSettings({
1040 ...defaultSettings,
1041 addProjectBaseDirectory: " ~/Development ",
1042 providers: {
1043 ...defaultSettings.providers,
1044 codex: {
1045 ...defaultSettings.providers.codex,
1046 binaryPath: " /opt/homebrew/bin/codex ",
1047 launchArgs: " --strict-config ",
1048 },
1049 },
1050 });
1051
1052 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
1053 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
1054 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
1055 });
1056});
1057
1058describe("ServerSettings environment icon", () => {
1059 it("defaults to null", () => {
1060 expect(decodeServerSettings({}).environmentIcon).toBeNull();
1061 });
1062
1063 it("keeps a kind this build knows", () => {
1064 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
1065 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
1066 });
1067
1068 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
1069 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
1070 });
1071
1072 it("round-trips through encode", () => {
1073 const settings = decodeServerSettings({ environmentIcon: "laptop" });
1074 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
1075
1076 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
1077 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
1078 });
1079});
1080
1081const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
1082
1083it("validates remote device hosts and rejects ambiguous host ids", () => {
1084 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
1085 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
1086 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
1087 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
1088 expect(() =>
1089 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
1090 ).toThrow();
1091 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
1092});
1093
1094describe("branch naming settings", () => {
1095 it("defaults existing settings to the t3 static prefix", () => {
1096 expect(decodeServerSettings({})).toMatchObject({
1097 branchNamingMode: "static",
1098 branchNamePrefix: "t3",
1099 branchNameInstructions: "",
1100 });
1101 });
1102 it.each(["static", "semantic", "custom"])(
1103 "round-trips %s and project overrides",
1104 (branchNamingMode) => {
1105 const naming = {
1106 branchNamingMode,
1107 branchNamePrefix: "team/",
1108 branchNameInstructions: "Include the issue ID.",
1109 };
1110 const input = { ...naming, projectSettingsOverrides: { project: naming } };
1111 expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
1112 expect(decodeServerSettingsPatch(input)).toEqual(input);
1113 },
1114 );
1115});
1116
1117describe("ServerSettings.removeAgentCreditsOnMerge", () => {
1118 it("keeps agent credits by default and accepts opt-in patches", () => {
1119 expect(decodeServerSettings({}).removeAgentCreditsOnMerge).toBe(false);
1120 expect(
1121 decodeServerSettingsPatch({ removeAgentCreditsOnMerge: true }).removeAgentCreditsOnMerge,
1122 ).toBe(true);
1123 expect(
1124 decodeServerSettings({
1125 projectSettingsOverrides: { project: { removeAgentCreditsOnMerge: true } },
1126 }).projectSettingsOverrides["project" as ProjectId]?.removeAgentCreditsOnMerge,
1127 ).toBe(true);
1128 });
1129});