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

settings.test.ts

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