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