Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settings.test.ts

1,045 lines38.7 KB

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 recording input overlays", () => {
512 it("defaults both overlays off and accepts independent opt-ins", () => {
513 const settings = decodeClientSettings({});
514 expect(settings.browserRecordingShowKeyPresses).toBe(false);
515 expect(settings.browserRecordingShowMousePresses).toBe(false);
516 expect(
517 decodeClientSettingsPatch({
518 browserRecordingShowKeyPresses: true,
519 browserRecordingShowMousePresses: false,
520 }),
521 ).toMatchObject({
522 browserRecordingShowKeyPresses: true,
523 browserRecordingShowMousePresses: false,
524 });
525 });
526});
527​
528describe("ClientSettings glass opacity", () => {
529 it("defaults to a readable translucent surface", () => {
530 expect(decodeClientSettings({}).glassOpacity).toBe(80);
531 });
532​
533 it.each([39, 101, 72.5])("rejects an invalid glass opacity: %s", (value) => {
534 expect(() => decodeClientSettings({ glassOpacity: value })).toThrow();
535 expect(() => decodeClientSettingsPatch({ glassOpacity: value })).toThrow();
536 });
537​
538 it.each([40, 75, 100])("accepts a glass opacity within the supported range: %s", (value) => {
539 expect(decodeClientSettings({ glassOpacity: value }).glassOpacity).toBe(value);
540 expect(decodeClientSettingsPatch({ glassOpacity: value }).glassOpacity).toBe(value);
541 });
542});
543​
544describe("ClientSettings appearance contrast", () => {
545 it("defaults to the theme's original contrast", () => {
546 expect(decodeClientSettings({}).appearanceContrast).toBe(100);
547 });
548​
549 it.each([49, 201, 92.5])("rejects an invalid appearance contrast: %s", (value) => {
550 expect(() => decodeClientSettings({ appearanceContrast: value })).toThrow();
551 expect(() => decodeClientSettingsPatch({ appearanceContrast: value })).toThrow();
552 });
553​
554 it.each([50, 100, 150, 200])("accepts an appearance contrast in range: %s", (value) => {
555 expect(decodeClientSettings({ appearanceContrast: value }).appearanceContrast).toBe(value);
556 expect(decodeClientSettingsPatch({ appearanceContrast: value }).appearanceContrast).toBe(value);
557 });
558});
559​
560describe("ClientSettings panel animations", () => {
561 it("defaults to instant changes", () => {
562 expect(decodeClientSettings({}).panelAnimationDurationMs).toBe(0);
563 });
564​
565 it.each([0, 400])("accepts a panel animation duration: %s", (value) => {
566 expect(decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toEqual({
567 panelAnimationDurationMs: value,
568 });
569 });
570​
571 it.each([-1, 401, 150.5])("rejects an invalid panel animation duration: %s", (value) => {
572 expect(() => decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toThrow();
573 });
574});
575​
576describe("ClientSettings environment identification", () => {
577 it("defaults to artwork and accepts each presentation mode", () => {
578 expect(decodeClientSettings({}).environmentIdentificationMode).toBe("artwork");
579​
580 for (const mode of ["artwork", "pill", "none"] as const) {
581 expect(
582 decodeClientSettingsPatch({ environmentIdentificationMode: mode })
583 .environmentIdentificationMode,
584 ).toBe(mode);
585 }
586 });
587​
588 it("rejects unsupported presentation modes", () => {
589 expect(() => decodeClientSettings({ environmentIdentificationMode: "badge" })).toThrow();
590 expect(() => decodeClientSettingsPatch({ environmentIdentificationMode: "badge" })).toThrow();
591 });
592});
593​
594describe("ClientSettings sidebar", () => {
595 it("defaults to the current sidebar", () => {
596 expect(decodeClientSettings({}).legacySidebarEnabled).toBe(false);
597 });
598​
599 it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
600 const decoded = decodeClientSettings({
601 sidebarV2Enabled: false,
602 sidebarV2ConfiguredByUser: true,
603 });
604 expect(decoded.legacySidebarEnabled).toBe(false);
605 expect(decoded).not.toHaveProperty("sidebarV2Enabled");
606 expect(decoded).not.toHaveProperty("sidebarV2ConfiguredByUser");
607 });
608​
609 it("drops the retired compact sidebar keys for users who opted in", () => {
610 const stored = { compactSidebarEnabled: true, sidebarCompactThreadRows: true };
611 const decoded = decodeClientSettings(stored);
612 expect(decoded).not.toHaveProperty("compactSidebarEnabled");
613 expect(decoded).not.toHaveProperty("sidebarCompactThreadRows");
614 expect(decodeClientSettingsPatch(stored)).toEqual({});
615 });
616​
617 it("preserves an explicit legacy sidebar opt-in", () => {
618 expect(decodeClientSettings({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(true);
619 expect(decodeClientSettingsPatch({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(
620 true,
621 );
622 });
623​
624 it("keeps unpin confirmation opt-in and patchable", () => {
625 expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
626 expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
627 expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
628 });
629});
630​
631describe("ClientSettings context window meter", () => {
632 it("defaults off and preserves an explicit legacy opt-in", () => {
633 expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
634 expect(
635 decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
636 ).toBe(true);
637 expect(
638 decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
639 ).toBe(true);
640 });
641});
642​
643describe("ClientSettings send shortcut", () => {
644 it("defaults to Enter and validates the supported choices", () => {
645 expect(decodeClientSettings({}).sendShortcut).toBe("enter");
646 for (const sendShortcut of ["enter", "mod-enter-multiline", "mod-enter"]) {
647 expect(decodeClientSettings({ sendShortcut }).sendShortcut).toBe(sendShortcut);
648 expect(decodeClientSettingsPatch({ sendShortcut }).sendShortcut).toBe(sendShortcut);
649 }
650 expect(() => decodeClientSettingsPatch({ sendShortcut: "invalid" })).toThrow();
651 });
652});
653​
654describe("ClientSettings follow-up behavior", () => {
655 it("defaults to queue and accepts either behavior", () => {
656 expect(decodeClientSettings({}).followUpBehavior).toBe("queue");
657 for (const followUpBehavior of ["queue", "steer"]) {
658 expect(decodeClientSettings({ followUpBehavior }).followUpBehavior).toBe(followUpBehavior);
659 expect(decodeClientSettingsPatch({ followUpBehavior }).followUpBehavior).toBe(
660 followUpBehavior,
661 );
662 }
663 expect(() => decodeClientSettingsPatch({ followUpBehavior: "invalid" })).toThrow();
664 });
665});
666​
667describe("ClientSettings composer collapse", () => {
668 it("collapses on scroll by default and accepts opting out", () => {
669 expect(decodeClientSettings({}).composerCollapseOnScroll).toBe(true);
670 expect(
671 decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
672 ).toBe(false);
673 });
674​
675 it("drops the retired blur trigger key", () => {
676 const decoded = decodeClientSettings({ composerCollapseOnBlur: false });
677 expect(decoded.composerCollapseOnScroll).toBe(true);
678 expect(decoded).not.toHaveProperty("composerCollapseOnBlur");
679 });
680});
681​
682describe("ServerSettings thread settlement", () => {
683 it("defaults merge settlement on and inactivity settlement to three days", () => {
684 const settings = decodeServerSettings({});
685 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
686 expect(settings.sidebarAutoSettleOnMerge).toBe(true);
687 });
688​
689 it("allows both automatic rules to be disabled", () => {
690 expect(
691 decodeServerSettings({
692 sidebarAutoSettleAfterDays: null,
693 sidebarAutoSettleOnMerge: false,
694 }),
695 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
696 expect(
697 decodeServerSettingsPatch({
698 sidebarAutoSettleAfterDays: null,
699 sidebarAutoSettleOnMerge: false,
700 }),
701 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
702 });
703​
704 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
705 expect(() => decodeServerSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
706 expect(() => decodeServerSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
707 });
708});
709​
710describe("ClientSettings pull request merge methods", () => {
711 it("defaults to no project overrides and accepts supported methods", () => {
712 expect(decodeClientSettings({}).pullRequestMergeMethodOverrides).toEqual({});
713 expect(
714 decodeClientSettingsPatch({
715 pullRequestMergeMethodOverrides: { project: "squash" },
716 }).pullRequestMergeMethodOverrides,
717 ).toEqual({ project: "squash" });
718 });
719​
720 it("rejects unsupported project merge methods", () => {
721 expect(() =>
722 decodeClientSettingsPatch({
723 pullRequestMergeMethodOverrides: { project: "fast-forward" },
724 }),
725 ).toThrow();
726 });
727});
728​
729describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
730 it("defaults text generation to Luna at low reasoning effort", () => {
731 expect(DEFAULT_SERVER_SETTINGS.textGenerationModelSelection).toEqual({
732 instanceId: ProviderInstanceId.make("codex"),
733 model: "gpt-5.6-luna",
734 options: [{ id: "reasoningEffort", value: "low" }],
735 });
736 });
737​
738 it("defaults to an empty record so legacy configs without the key still decode", () => {
739 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
740 });
741​
742 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
743 const decoded = decodeServerSettings({});
744 expect(decoded.providerInstances).toEqual({});
745 // Legacy `providers` struct is still hydrated with its per-driver defaults
746 // so existing call sites keep working through the migration.
747 expect(decoded.providers.codex.enabled).toBe(true);
748 });
749​
750 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
751 const decoded = decodeServerSettings({
752 providerInstances: {
753 codex_personal: {
754 driver: "codex",
755 displayName: "Codex (personal)",
756 config: { homePath: "~/.codex_personal" },
757 },
758 codex_work: {
759 driver: "codex",
760 config: { homePath: "~/.codex_work" },
761 },
762 ollama_local: {
763 driver: "ollama",
764 displayName: "Ollama (local)",
765 config: { endpoint: "http://localhost:11434" },
766 },
767 },
768 });
769 const personalId = ProviderInstanceId.make("codex_personal");
770 const workId = ProviderInstanceId.make("codex_work");
771 const ollamaId = ProviderInstanceId.make("ollama_local");
772​
773 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
774 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
775 // Critical: a config naming a driver this build does not know about
776 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
777 // The runtime handles "driver not installed" — the schema must not.
778 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
779 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
780 endpoint: "http://localhost:11434",
781 });
782 });
783​
784 it("rejects instance keys that violate the slug pattern", () => {
785 expect(() =>
786 decodeServerSettings({
787 providerInstances: { "1bad": { driver: "codex" } },
788 }),
789 ).toThrow();
790 });
791});
792​
793describe("provider enabled defaults", () => {
794 it("enables only the stable bindings by default", () => {
795 const decoded = decodeServerSettings({});
796 expect(decoded.providers.codex.enabled).toBe(true);
797 expect(decoded.providers.claudeAgent.enabled).toBe(true);
798 expect(decoded.providers.cursor.enabled).toBe(false);
799 expect(decoded.providers.grok.enabled).toBe(false);
800 expect(decoded.providers.opencode.enabled).toBe(false);
801 });
802​
803 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
804 const cursor = ProviderDriverKind.make("cursor");
805 const cursorId = ProviderInstanceId.make("cursor");
806 const decoded = decodeServerSettings({
807 providers: { cursor: { enabled: true } },
808 providerInstances: {
809 [cursorId]: { driver: cursor, enabled: true, config: {} },
810 },
811 });
812​
813 expect(decoded.providers.cursor.enabled).toBe(true);
814 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
815 });
816​
817 it("resolves instance enabled state with explicit false winning", () => {
818 const grok = ProviderDriverKind.make("grok");
819 const codex = ProviderDriverKind.make("codex");
820 // No flags anywhere: driver default applies.
821 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
822 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
823 // Unknown fork drivers stay enabled.
824 expect(
825 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
826 ).toBe(true);
827 // Envelope flag wins over the driver default.
828 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
829 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
830 false,
831 );
832 // Legacy in-config flag fills in when the envelope is silent.
833 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
834 // Conflicting flags: the explicit false wins, whichever side it is on.
835 expect(
836 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
837 ).toBe(false);
838 expect(
839 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
840 ).toBe(false);
841 });
842});
843​
844describe("ServerSettings worktree defaults", () => {
845 it("defaults start-from-origin on for legacy configs", () => {
846 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
847 });
848​
849 it("accepts start-from-origin updates", () => {
850 expect(
851 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
852 ).toBe(false);
853 });
854});
855​
856describe("ServerSettings Cursor legacy settings", () => {
857 it("preserves V1 Cursor CLI settings when reading and writing shared settings", () => {
858 const decoded = decodeServerSettings({
859 providers: {
860 cursor: {
861 enabled: true,
862 binaryPath: "cursor-agent",
863 apiEndpoint: "http://127.0.0.1:3774",
864 },
865 },
866 });
867​
868 expect(decoded.providers.cursor.enabled).toBe(true);
869 expect(encodeServerSettings(decoded).providers?.cursor).toMatchObject({
870 binaryPath: "cursor-agent",
871 apiEndpoint: "http://127.0.0.1:3774",
872 });
873 });
874​
875 it("ignores obsolete Cursor CLI settings in patches", () => {
876 const patch = decodeServerSettingsPatch({
877 providers: {
878 cursor: {
879 enabled: true,
880 binaryPath: "cursor-agent",
881 apiEndpoint: "http://127.0.0.1:3774",
882 },
883 },
884 });
885​
886 expect(patch.providers?.cursor?.enabled).toBe(true);
887 expect(patch.providers?.cursor).not.toHaveProperty("binaryPath");
888 expect(patch.providers?.cursor).not.toHaveProperty("apiEndpoint");
889 });
890});
891​
892describe("ServerSettings.sourceControlWritingStyle", () => {
893 it("defaults all style settings for legacy configs", () => {
894 const settings = decodeServerSettings({});
895​
896 expect(settings.sourceControlWritingStyle).toEqual({
897 mode: "repo_conventions",
898 customInstructions: "",
899 followChangeRequestTemplates: true,
900 });
901 expect(settings.sourceControlWriterModelSelection).toBeNull();
902 });
903​
904 it("trims partial style updates", () => {
905 const patch = decodeServerSettingsPatch({
906 sourceControlWritingStyle: {
907 mode: "custom",
908 customInstructions: " Prefer concise wording. ",
909 },
910 });
911​
912 expect(patch.sourceControlWritingStyle).toEqual({
913 mode: "custom",
914 customInstructions: "Prefer concise wording.",
915 });
916 });
917});
918​
919describe("ServerSettingsPatch.providerInstances", () => {
920 it("treats providerInstances as an optional whole-map replacement", () => {
921 const patch = decodeServerSettingsPatch({});
922 expect(patch.providerInstances).toBeUndefined();
923​
924 const replacement = decodeServerSettingsPatch({
925 providerInstances: {
926 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
927 },
928 });
929 expect(replacement.providerInstances).toBeDefined();
930 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
931 "codex",
932 );
933 });
934​
935 it("preserves a fork-defined driver entry through patch decoding", () => {
936 const patch = decodeServerSettingsPatch({
937 providerInstances: {
938 ollama_local: {
939 driver: "ollama",
940 config: { endpoint: "http://localhost:11434" },
941 },
942 },
943 });
944 const ollamaId = ProviderInstanceId.make("ollama_local");
945 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
946 });
947});
948​
949describe("ServerSettingsPatch string normalization", () => {
950 it("trims string settings while decoding patches", () => {
951 const patch = decodeServerSettingsPatch({
952 addProjectBaseDirectory: " ~/Development ",
953 textGenerationModelSelection: { model: " gpt-5.4-mini " },
954 observability: {
955 otlpTracesUrl: " http://localhost:4318/v1/traces ",
956 },
957 providers: {
958 codex: {
959 binaryPath: " /opt/homebrew/bin/codex ",
960 homePath: " ~/.codex ",
961 launchArgs: " --strict-config --enable foo ",
962 },
963 },
964 providerInstances: {
965 codex_personal: {
966 driver: " codex ",
967 displayName: " Codex Personal ",
968 config: { homePath: " ~/.codex-personal " },
969 },
970 },
971 });
972​
973 expect(patch.addProjectBaseDirectory).toBe("~/Development");
974 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
975 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
976 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
977 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
978 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
979 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
980 "codex",
981 );
982 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
983 "Codex Personal",
984 );
985 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
986 homePath: " ~/.codex-personal ",
987 });
988 });
989​
990 it("trims encoded server settings values before validation", () => {
991 const defaultSettings = decodeServerSettings({});
992 const encoded = encodeServerSettings({
993 ...defaultSettings,
994 addProjectBaseDirectory: " ~/Development ",
995 providers: {
996 ...defaultSettings.providers,
997 codex: {
998 ...defaultSettings.providers.codex,
999 binaryPath: " /opt/homebrew/bin/codex ",
1000 launchArgs: " --strict-config ",
1001 },
1002 },
1003 });
1004​
1005 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
1006 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
1007 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
1008 });
1009});
1010​
1011describe("ServerSettings environment icon", () => {
1012 it("defaults to null", () => {
1013 expect(decodeServerSettings({}).environmentIcon).toBeNull();
1014 });
1015​
1016 it("keeps a kind this build knows", () => {
1017 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
1018 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
1019 });
1020​
1021 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
1022 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
1023 });
1024​
1025 it("round-trips through encode", () => {
1026 const settings = decodeServerSettings({ environmentIcon: "laptop" });
1027 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
1028​
1029 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
1030 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
1031 });
1032});
1033​
1034const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
1035​
1036it("validates remote device hosts and rejects ambiguous host ids", () => {
1037 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
1038 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
1039 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
1040 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
1041 expect(() =>
1042 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
1043 ).toThrow();
1044 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
1045});