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

settings.test.ts

898 lines33.5 KB

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