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

settings.test.ts

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