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

settings.test.ts

1,113 lines41.7 KB

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