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