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

settings.test.ts

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