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

settings.test.ts

994 lines37.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 to an empty record so legacy configs without the key still decode", () => {
694 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
695 });
696​
697 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
698 const decoded = decodeServerSettings({});
699 expect(decoded.providerInstances).toEqual({});
700 // Legacy `providers` struct is still hydrated with its per-driver defaults
701 // so existing call sites keep working through the migration.
702 expect(decoded.providers.codex.enabled).toBe(true);
703 });
704​
705 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
706 const decoded = decodeServerSettings({
707 providerInstances: {
708 codex_personal: {
709 driver: "codex",
710 displayName: "Codex (personal)",
711 config: { homePath: "~/.codex_personal" },
712 },
713 codex_work: {
714 driver: "codex",
715 config: { homePath: "~/.codex_work" },
716 },
717 ollama_local: {
718 driver: "ollama",
719 displayName: "Ollama (local)",
720 config: { endpoint: "http://localhost:11434" },
721 },
722 },
723 });
724 const personalId = ProviderInstanceId.make("codex_personal");
725 const workId = ProviderInstanceId.make("codex_work");
726 const ollamaId = ProviderInstanceId.make("ollama_local");
727​
728 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
729 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
730 // Critical: a config naming a driver this build does not know about
731 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
732 // The runtime handles "driver not installed" — the schema must not.
733 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
734 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
735 endpoint: "http://localhost:11434",
736 });
737 });
738​
739 it("rejects instance keys that violate the slug pattern", () => {
740 expect(() =>
741 decodeServerSettings({
742 providerInstances: { "1bad": { driver: "codex" } },
743 }),
744 ).toThrow();
745 });
746});
747​
748describe("provider enabled defaults", () => {
749 it("enables only the stable bindings by default", () => {
750 const decoded = decodeServerSettings({});
751 expect(decoded.providers.codex.enabled).toBe(true);
752 expect(decoded.providers.claudeAgent.enabled).toBe(true);
753 expect(decoded.providers.cursor.enabled).toBe(false);
754 expect(decoded.providers.grok.enabled).toBe(false);
755 expect(decoded.providers.opencode.enabled).toBe(false);
756 });
757​
758 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
759 const cursor = ProviderDriverKind.make("cursor");
760 const cursorId = ProviderInstanceId.make("cursor");
761 const decoded = decodeServerSettings({
762 providers: { cursor: { enabled: true } },
763 providerInstances: {
764 [cursorId]: { driver: cursor, enabled: true, config: {} },
765 },
766 });
767​
768 expect(decoded.providers.cursor.enabled).toBe(true);
769 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
770 });
771​
772 it("resolves instance enabled state with explicit false winning", () => {
773 const grok = ProviderDriverKind.make("grok");
774 const codex = ProviderDriverKind.make("codex");
775 // No flags anywhere: driver default applies.
776 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
777 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
778 // Unknown fork drivers stay enabled.
779 expect(
780 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
781 ).toBe(true);
782 // Envelope flag wins over the driver default.
783 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
784 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
785 false,
786 );
787 // Legacy in-config flag fills in when the envelope is silent.
788 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
789 // Conflicting flags: the explicit false wins, whichever side it is on.
790 expect(
791 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
792 ).toBe(false);
793 expect(
794 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
795 ).toBe(false);
796 });
797});
798​
799describe("ServerSettings worktree defaults", () => {
800 it("defaults the thread env mode to inherit and keeps stored values", () => {
801 expect(decodeServerSettings({}).defaultThreadEnvMode).toBeNull();
802 expect(decodeServerSettings({ defaultThreadEnvMode: "worktree" }).defaultThreadEnvMode).toBe(
803 "worktree",
804 );
805 expect(
806 decodeServerSettings({ defaultThreadEnvMode: "remote" }).defaultThreadEnvMode,
807 ).toBeNull();
808 expect(
809 decodeServerSettingsPatch({ defaultThreadEnvMode: null }).defaultThreadEnvMode,
810 ).toBeNull();
811 });
812​
813 it("keeps an inherited thread env mode off the wire for older clients", () => {
814 const encode = Schema.encodeSync(ServerSettings);
815 expect("defaultThreadEnvMode" in encode(decodeServerSettings({}))).toBe(false);
816 expect(
817 encode(decodeServerSettings({ defaultThreadEnvMode: "worktree" })).defaultThreadEnvMode,
818 ).toBe("worktree");
819 });
820​
821 it("defaults start-from-origin on for legacy configs", () => {
822 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
823 });
824​
825 it("accepts start-from-origin updates", () => {
826 expect(
827 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
828 ).toBe(false);
829 });
830​
831 it("defaults worktree submodules to inherit and tolerates unknown modes", () => {
832 expect(decodeServerSettings({}).worktreeSubmodules).toBeNull();
833 expect(decodeServerSettings({ worktreeSubmodules: "top-level" }).worktreeSubmodules).toBe(
834 "top-level",
835 );
836 expect(decodeServerSettings({ worktreeSubmodules: "shallow" }).worktreeSubmodules).toBeNull();
837 expect(decodeServerSettingsPatch({ worktreeSubmodules: null }).worktreeSubmodules).toBeNull();
838 });
839});
840​
841describe("ServerSettings.sourceControlWritingStyle", () => {
842 it("defaults all style settings for legacy configs", () => {
843 const settings = decodeServerSettings({});
844​
845 expect(settings.sourceControlWritingStyle).toEqual({
846 mode: "repo_conventions",
847 customInstructions: "",
848 followChangeRequestTemplates: true,
849 });
850 expect(settings.sourceControlWriterModelSelection).toBeNull();
851 });
852​
853 it("trims partial style updates", () => {
854 const patch = decodeServerSettingsPatch({
855 sourceControlWritingStyle: {
856 mode: "custom",
857 customInstructions: " Prefer concise wording. ",
858 },
859 });
860​
861 expect(patch.sourceControlWritingStyle).toEqual({
862 mode: "custom",
863 customInstructions: "Prefer concise wording.",
864 });
865 });
866});
867​
868describe("ServerSettingsPatch.providerInstances", () => {
869 it("treats providerInstances as an optional whole-map replacement", () => {
870 const patch = decodeServerSettingsPatch({});
871 expect(patch.providerInstances).toBeUndefined();
872​
873 const replacement = decodeServerSettingsPatch({
874 providerInstances: {
875 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
876 },
877 });
878 expect(replacement.providerInstances).toBeDefined();
879 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
880 "codex",
881 );
882 });
883​
884 it("preserves a fork-defined driver entry through patch decoding", () => {
885 const patch = decodeServerSettingsPatch({
886 providerInstances: {
887 ollama_local: {
888 driver: "ollama",
889 config: { endpoint: "http://localhost:11434" },
890 },
891 },
892 });
893 const ollamaId = ProviderInstanceId.make("ollama_local");
894 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
895 });
896});
897​
898describe("ServerSettingsPatch string normalization", () => {
899 it("trims string settings while decoding patches", () => {
900 const patch = decodeServerSettingsPatch({
901 addProjectBaseDirectory: " ~/Development ",
902 textGenerationModelSelection: { model: " gpt-5.4-mini " },
903 observability: {
904 otlpTracesUrl: " http://localhost:4318/v1/traces ",
905 },
906 providers: {
907 codex: {
908 binaryPath: " /opt/homebrew/bin/codex ",
909 homePath: " ~/.codex ",
910 launchArgs: " --strict-config --enable foo ",
911 },
912 },
913 providerInstances: {
914 codex_personal: {
915 driver: " codex ",
916 displayName: " Codex Personal ",
917 config: { homePath: " ~/.codex-personal " },
918 },
919 },
920 });
921​
922 expect(patch.addProjectBaseDirectory).toBe("~/Development");
923 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
924 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
925 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
926 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
927 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
928 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
929 "codex",
930 );
931 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
932 "Codex Personal",
933 );
934 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
935 homePath: " ~/.codex-personal ",
936 });
937 });
938​
939 it("trims encoded server settings values before validation", () => {
940 const defaultSettings = decodeServerSettings({});
941 const encoded = encodeServerSettings({
942 ...defaultSettings,
943 addProjectBaseDirectory: " ~/Development ",
944 providers: {
945 ...defaultSettings.providers,
946 codex: {
947 ...defaultSettings.providers.codex,
948 binaryPath: " /opt/homebrew/bin/codex ",
949 launchArgs: " --strict-config ",
950 },
951 },
952 });
953​
954 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
955 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
956 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
957 });
958});
959​
960describe("ServerSettings environment icon", () => {
961 it("defaults to null", () => {
962 expect(decodeServerSettings({}).environmentIcon).toBeNull();
963 });
964​
965 it("keeps a kind this build knows", () => {
966 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
967 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
968 });
969​
970 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
971 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
972 });
973​
974 it("round-trips through encode", () => {
975 const settings = decodeServerSettings({ environmentIcon: "laptop" });
976 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
977​
978 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
979 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
980 });
981});
982​
983const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
984​
985it("validates remote device hosts and rejects ambiguous host ids", () => {
986 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
987 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
988 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
989 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
990 expect(() =>
991 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
992 ).toThrow();
993 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
994});