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

settings.test.ts

919 lines33.8 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 composer context strip", () => {
263 it("defaults to draft-only and accepts a persistent strip preference", () => {
264 expect(decodeClientSettings({}).persistComposerContextStrip).toBe(false);
265 expect(
266 decodeClientSettingsPatch({ persistComposerContextStrip: true }).persistComposerContextStrip,
267 ).toBe(true);
268 });
269});
270​
271describe("ClientSettings word wrap", () => {
272 it("defaults word wrap on", () => {
273 expect(decodeClientSettings({}).wordWrap).toBe(true);
274 });
275​
276 it("ignores obsolete wrapping preferences", () => {
277 const decoded = decodeClientSettings({
278 chatWordWrap: false,
279 diffWordWrap: false,
280 });
281​
282 expect(decoded.wordWrap).toBe(true);
283 expect(decoded).not.toHaveProperty("chatWordWrap");
284 expect(decoded).not.toHaveProperty("diffWordWrap");
285 });
286});
287​
288describe("ClientSettings window capture", () => {
289 it("defaults capture off while keeping its feedback enabled", () => {
290 const settings = decodeClientSettings({});
291​
292 expect(settings.snapShotEnabled).toBe(false);
293 expect(settings.snapShotIncludeAccessibility).toBe(true);
294 expect(settings.snapShotShortcut).toEqual({ kind: "both-shift-keys" });
295 expect(settings.snapShotPlaySound).toBe(true);
296 expect(settings.snapShotSound).toBe("soft-pop");
297 expect(settings.snapShotFlash).toBe(true);
298 expect(settings.snapShotAnimations).toBe(true);
299 });
300​
301 it("accepts capture preference updates", () => {
302 expect(
303 decodeClientSettingsPatch({
304 snapShotEnabled: true,
305 snapShotIncludeAccessibility: false,
306 snapShotShortcut: {
307 key: "w",
308 metaKey: false,
309 ctrlKey: false,
310 shiftKey: true,
311 altKey: true,
312 modKey: false,
313 },
314 snapShotPlaySound: false,
315 snapShotSound: "camera-shutter",
316 snapShotFlash: false,
317 snapShotAnimations: false,
318 }),
319 ).toEqual({
320 snapShotEnabled: true,
321 snapShotIncludeAccessibility: false,
322 snapShotShortcut: {
323 key: "w",
324 metaKey: false,
325 ctrlKey: false,
326 shiftKey: true,
327 altKey: true,
328 modKey: false,
329 },
330 snapShotPlaySound: false,
331 snapShotSound: "camera-shutter",
332 snapShotFlash: false,
333 snapShotAnimations: false,
334 });
335 });
336​
337 it("rejects unknown capture sounds", () => {
338 expect(() => decodeClientSettingsPatch({ snapShotSound: "doorbell" })).toThrow();
339 });
340​
341 it("accepts modifier pair shortcuts", () => {
342 expect(
343 decodeClientSettingsPatch({
344 snapShotShortcut: { kind: "modifier-pair", modifier: "meta" },
345 }),
346 ).toEqual({
347 snapShotShortcut: { kind: "modifier-pair", modifier: "meta" },
348 });
349 expect(() =>
350 decodeClientSettingsPatch({
351 snapShotShortcut: { kind: "modifier-pair", modifier: "hyper" },
352 }),
353 ).toThrow();
354 });
355​
356 it("rejects a capture shortcut with no modifier", () => {
357 expect(() =>
358 decodeClientSettingsPatch({
359 snapShotShortcut: {
360 key: "w",
361 metaKey: false,
362 ctrlKey: false,
363 shiftKey: false,
364 altKey: false,
365 modKey: false,
366 },
367 }),
368 ).toThrow();
369 });
370});
371​
372describe("ClientSettings proactive panels", () => {
373 it("is opt-in and accepts client-local updates", () => {
374 expect(decodeClientSettings({}).proactivePanelsEnabled).toBe(false);
375 expect(decodeClientSettingsPatch({ proactivePanelsEnabled: true }).proactivePanelsEnabled).toBe(
376 true,
377 );
378 });
379});
380​
381describe("ClientSettings quit confirmation", () => {
382 it("defaults to hold", () => {
383 expect(decodeClientSettings({}).confirmQuit).toBe("hold");
384 });
385​
386 it.each(["direct", "hold", "double-click"] as const)("accepts the %s mode", (mode) => {
387 expect(decodeClientSettings({ confirmQuit: mode }).confirmQuit).toBe(mode);
388 expect(decodeClientSettingsPatch({ confirmQuit: mode }).confirmQuit).toBe(mode);
389 });
390​
391 it.each([
392 [true, "hold"],
393 [false, "direct"],
394 ] as const)("migrates the legacy %s value to %s", (legacyValue, mode) => {
395 const settings = decodeClientSettings({ confirmQuit: legacyValue });
396​
397 expect(settings.confirmQuit).toBe(mode);
398 expect(encodeClientSettings(settings).confirmQuit).toBe(mode);
399 });
400​
401 it("rejects legacy booleans at the patch boundary", () => {
402 expect(() => decodeClientSettingsPatch({ confirmQuit: true })).toThrow();
403 });
404});
405​
406describe("ClientSettings browser recording frame rate", () => {
407 it("defaults to 30 fps", () => {
408 expect(decodeClientSettings({}).browserRecordingFrameRate).toBe(30);
409 });
410​
411 it.each([30, 60])("accepts a supported frame rate: %s", (frameRate) => {
412 expect(
413 decodeClientSettings({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
414 ).toBe(frameRate);
415 expect(
416 decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
417 ).toBe(frameRate);
418 });
419​
420 it.each([24, 59, 120])("rejects an unsupported frame rate: %s", (frameRate) => {
421 expect(() => decodeClientSettings({ browserRecordingFrameRate: frameRate })).toThrow();
422 expect(() => decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate })).toThrow();
423 });
424});
425​
426describe("ClientSettings glass opacity", () => {
427 it("defaults to a readable translucent surface", () => {
428 expect(decodeClientSettings({}).glassOpacity).toBe(80);
429 });
430​
431 it.each([39, 101, 72.5])("rejects an invalid glass opacity: %s", (value) => {
432 expect(() => decodeClientSettings({ glassOpacity: value })).toThrow();
433 expect(() => decodeClientSettingsPatch({ glassOpacity: value })).toThrow();
434 });
435​
436 it.each([40, 75, 100])("accepts a glass opacity within the supported range: %s", (value) => {
437 expect(decodeClientSettings({ glassOpacity: value }).glassOpacity).toBe(value);
438 expect(decodeClientSettingsPatch({ glassOpacity: value }).glassOpacity).toBe(value);
439 });
440});
441​
442describe("ClientSettings appearance contrast", () => {
443 it("defaults to the theme's original contrast", () => {
444 expect(decodeClientSettings({}).appearanceContrast).toBe(100);
445 });
446​
447 it.each([49, 201, 92.5])("rejects an invalid appearance contrast: %s", (value) => {
448 expect(() => decodeClientSettings({ appearanceContrast: value })).toThrow();
449 expect(() => decodeClientSettingsPatch({ appearanceContrast: value })).toThrow();
450 });
451​
452 it.each([50, 100, 150, 200])("accepts an appearance contrast in range: %s", (value) => {
453 expect(decodeClientSettings({ appearanceContrast: value }).appearanceContrast).toBe(value);
454 expect(decodeClientSettingsPatch({ appearanceContrast: value }).appearanceContrast).toBe(value);
455 });
456});
457​
458describe("ClientSettings panel animations", () => {
459 it("defaults to instant changes", () => {
460 expect(decodeClientSettings({}).panelAnimationDurationMs).toBe(0);
461 });
462​
463 it.each([0, 400])("accepts a panel animation duration: %s", (value) => {
464 expect(decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toEqual({
465 panelAnimationDurationMs: value,
466 });
467 });
468​
469 it.each([-1, 401, 150.5])("rejects an invalid panel animation duration: %s", (value) => {
470 expect(() => decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toThrow();
471 });
472});
473​
474describe("ClientSettings environment identification", () => {
475 it("defaults to artwork and accepts each presentation mode", () => {
476 expect(decodeClientSettings({}).environmentIdentificationMode).toBe("artwork");
477​
478 for (const mode of ["artwork", "pill", "none"] as const) {
479 expect(
480 decodeClientSettingsPatch({ environmentIdentificationMode: mode })
481 .environmentIdentificationMode,
482 ).toBe(mode);
483 }
484 });
485​
486 it("rejects unsupported presentation modes", () => {
487 expect(() => decodeClientSettings({ environmentIdentificationMode: "badge" })).toThrow();
488 expect(() => decodeClientSettingsPatch({ environmentIdentificationMode: "badge" })).toThrow();
489 });
490});
491​
492describe("ClientSettings sidebar", () => {
493 it("defaults to the current sidebar", () => {
494 expect(decodeClientSettings({}).legacySidebarEnabled).toBe(false);
495 });
496​
497 it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
498 const decoded = decodeClientSettings({
499 sidebarV2Enabled: false,
500 sidebarV2ConfiguredByUser: true,
501 });
502 expect(decoded.legacySidebarEnabled).toBe(false);
503 expect(decoded).not.toHaveProperty("sidebarV2Enabled");
504 expect(decoded).not.toHaveProperty("sidebarV2ConfiguredByUser");
505 });
506​
507 it("drops the retired compact sidebar keys for users who opted in", () => {
508 const stored = { compactSidebarEnabled: true, sidebarCompactThreadRows: true };
509 const decoded = decodeClientSettings(stored);
510 expect(decoded).not.toHaveProperty("compactSidebarEnabled");
511 expect(decoded).not.toHaveProperty("sidebarCompactThreadRows");
512 expect(decodeClientSettingsPatch(stored)).toEqual({});
513 });
514​
515 it("preserves an explicit legacy sidebar opt-in", () => {
516 expect(decodeClientSettings({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(true);
517 expect(decodeClientSettingsPatch({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(
518 true,
519 );
520 });
521​
522 it("keeps unpin confirmation opt-in and patchable", () => {
523 expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
524 expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
525 expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
526 });
527});
528​
529describe("ClientSettings context window meter", () => {
530 it("defaults off and preserves an explicit legacy opt-in", () => {
531 expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
532 expect(
533 decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
534 ).toBe(true);
535 expect(
536 decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
537 ).toBe(true);
538 });
539});
540​
541describe("ClientSettings composer collapse", () => {
542 it("collapses on scroll by default and accepts opting out", () => {
543 expect(decodeClientSettings({}).composerCollapseOnScroll).toBe(true);
544 expect(
545 decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
546 ).toBe(false);
547 });
548​
549 it("drops the retired blur trigger key", () => {
550 const decoded = decodeClientSettings({ composerCollapseOnBlur: false });
551 expect(decoded.composerCollapseOnScroll).toBe(true);
552 expect(decoded).not.toHaveProperty("composerCollapseOnBlur");
553 });
554});
555​
556describe("ServerSettings thread settlement", () => {
557 it("defaults merge settlement on and inactivity settlement to three days", () => {
558 const settings = decodeServerSettings({});
559 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
560 expect(settings.sidebarAutoSettleOnMerge).toBe(true);
561 });
562​
563 it("allows both automatic rules to be disabled", () => {
564 expect(
565 decodeServerSettings({
566 sidebarAutoSettleAfterDays: null,
567 sidebarAutoSettleOnMerge: false,
568 }),
569 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
570 expect(
571 decodeServerSettingsPatch({
572 sidebarAutoSettleAfterDays: null,
573 sidebarAutoSettleOnMerge: false,
574 }),
575 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
576 });
577​
578 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
579 expect(() => decodeServerSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
580 expect(() => decodeServerSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
581 });
582});
583​
584describe("ClientSettings pull request merge methods", () => {
585 it("defaults to no project overrides and accepts supported methods", () => {
586 expect(decodeClientSettings({}).pullRequestMergeMethodOverrides).toEqual({});
587 expect(
588 decodeClientSettingsPatch({
589 pullRequestMergeMethodOverrides: { project: "squash" },
590 }).pullRequestMergeMethodOverrides,
591 ).toEqual({ project: "squash" });
592 });
593​
594 it("rejects unsupported project merge methods", () => {
595 expect(() =>
596 decodeClientSettingsPatch({
597 pullRequestMergeMethodOverrides: { project: "fast-forward" },
598 }),
599 ).toThrow();
600 });
601});
602​
603describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
604 it("defaults text generation to Luna at low reasoning effort", () => {
605 expect(DEFAULT_SERVER_SETTINGS.textGenerationModelSelection).toEqual({
606 instanceId: ProviderInstanceId.make("codex"),
607 model: "gpt-5.6-luna",
608 options: [{ id: "reasoningEffort", value: "low" }],
609 });
610 });
611​
612 it("defaults to an empty record so legacy configs without the key still decode", () => {
613 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
614 });
615​
616 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
617 const decoded = decodeServerSettings({});
618 expect(decoded.providerInstances).toEqual({});
619 // Legacy `providers` struct is still hydrated with its per-driver defaults
620 // so existing call sites keep working through the migration.
621 expect(decoded.providers.codex.enabled).toBe(true);
622 });
623​
624 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
625 const decoded = decodeServerSettings({
626 providerInstances: {
627 codex_personal: {
628 driver: "codex",
629 displayName: "Codex (personal)",
630 config: { homePath: "~/.codex_personal" },
631 },
632 codex_work: {
633 driver: "codex",
634 config: { homePath: "~/.codex_work" },
635 },
636 ollama_local: {
637 driver: "ollama",
638 displayName: "Ollama (local)",
639 config: { endpoint: "http://localhost:11434" },
640 },
641 },
642 });
643 const personalId = ProviderInstanceId.make("codex_personal");
644 const workId = ProviderInstanceId.make("codex_work");
645 const ollamaId = ProviderInstanceId.make("ollama_local");
646​
647 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
648 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
649 // Critical: a config naming a driver this build does not know about
650 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
651 // The runtime handles "driver not installed" — the schema must not.
652 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
653 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
654 endpoint: "http://localhost:11434",
655 });
656 });
657​
658 it("rejects instance keys that violate the slug pattern", () => {
659 expect(() =>
660 decodeServerSettings({
661 providerInstances: { "1bad": { driver: "codex" } },
662 }),
663 ).toThrow();
664 });
665});
666​
667describe("provider enabled defaults", () => {
668 it("enables only the stable bindings by default", () => {
669 const decoded = decodeServerSettings({});
670 expect(decoded.providers.codex.enabled).toBe(true);
671 expect(decoded.providers.claudeAgent.enabled).toBe(true);
672 expect(decoded.providers.cursor.enabled).toBe(false);
673 expect(decoded.providers.grok.enabled).toBe(false);
674 expect(decoded.providers.opencode.enabled).toBe(false);
675 });
676​
677 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
678 const cursor = ProviderDriverKind.make("cursor");
679 const cursorId = ProviderInstanceId.make("cursor");
680 const decoded = decodeServerSettings({
681 providers: { cursor: { enabled: true } },
682 providerInstances: {
683 [cursorId]: { driver: cursor, enabled: true, config: {} },
684 },
685 });
686​
687 expect(decoded.providers.cursor.enabled).toBe(true);
688 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
689 });
690​
691 it("resolves instance enabled state with explicit false winning", () => {
692 const grok = ProviderDriverKind.make("grok");
693 const codex = ProviderDriverKind.make("codex");
694 // No flags anywhere: driver default applies.
695 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
696 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
697 // Unknown fork drivers stay enabled.
698 expect(
699 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
700 ).toBe(true);
701 // Envelope flag wins over the driver default.
702 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
703 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
704 false,
705 );
706 // Legacy in-config flag fills in when the envelope is silent.
707 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
708 // Conflicting flags: the explicit false wins, whichever side it is on.
709 expect(
710 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
711 ).toBe(false);
712 expect(
713 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
714 ).toBe(false);
715 });
716});
717​
718describe("ServerSettings worktree defaults", () => {
719 it("defaults start-from-origin on for legacy configs", () => {
720 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
721 });
722​
723 it("accepts start-from-origin updates", () => {
724 expect(
725 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
726 ).toBe(false);
727 });
728});
729​
730describe("ServerSettings Cursor legacy settings", () => {
731 it("preserves V1 Cursor CLI settings when reading and writing shared settings", () => {
732 const decoded = decodeServerSettings({
733 providers: {
734 cursor: {
735 enabled: true,
736 binaryPath: "cursor-agent",
737 apiEndpoint: "http://127.0.0.1:3774",
738 },
739 },
740 });
741​
742 expect(decoded.providers.cursor.enabled).toBe(true);
743 expect(encodeServerSettings(decoded).providers?.cursor).toMatchObject({
744 binaryPath: "cursor-agent",
745 apiEndpoint: "http://127.0.0.1:3774",
746 });
747 });
748​
749 it("ignores obsolete Cursor CLI settings in patches", () => {
750 const patch = decodeServerSettingsPatch({
751 providers: {
752 cursor: {
753 enabled: true,
754 binaryPath: "cursor-agent",
755 apiEndpoint: "http://127.0.0.1:3774",
756 },
757 },
758 });
759​
760 expect(patch.providers?.cursor?.enabled).toBe(true);
761 expect(patch.providers?.cursor).not.toHaveProperty("binaryPath");
762 expect(patch.providers?.cursor).not.toHaveProperty("apiEndpoint");
763 });
764});
765​
766describe("ServerSettings.sourceControlWritingStyle", () => {
767 it("defaults all style settings for legacy configs", () => {
768 const settings = decodeServerSettings({});
769​
770 expect(settings.sourceControlWritingStyle).toEqual({
771 mode: "repo_conventions",
772 customInstructions: "",
773 followChangeRequestTemplates: true,
774 });
775 expect(settings.sourceControlWriterModelSelection).toBeNull();
776 });
777​
778 it("trims partial style updates", () => {
779 const patch = decodeServerSettingsPatch({
780 sourceControlWritingStyle: {
781 mode: "custom",
782 customInstructions: " Prefer concise wording. ",
783 },
784 });
785​
786 expect(patch.sourceControlWritingStyle).toEqual({
787 mode: "custom",
788 customInstructions: "Prefer concise wording.",
789 });
790 });
791});
792​
793describe("ServerSettingsPatch.providerInstances", () => {
794 it("treats providerInstances as an optional whole-map replacement", () => {
795 const patch = decodeServerSettingsPatch({});
796 expect(patch.providerInstances).toBeUndefined();
797​
798 const replacement = decodeServerSettingsPatch({
799 providerInstances: {
800 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
801 },
802 });
803 expect(replacement.providerInstances).toBeDefined();
804 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
805 "codex",
806 );
807 });
808​
809 it("preserves a fork-defined driver entry through patch decoding", () => {
810 const patch = decodeServerSettingsPatch({
811 providerInstances: {
812 ollama_local: {
813 driver: "ollama",
814 config: { endpoint: "http://localhost:11434" },
815 },
816 },
817 });
818 const ollamaId = ProviderInstanceId.make("ollama_local");
819 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
820 });
821});
822​
823describe("ServerSettingsPatch string normalization", () => {
824 it("trims string settings while decoding patches", () => {
825 const patch = decodeServerSettingsPatch({
826 addProjectBaseDirectory: " ~/Development ",
827 textGenerationModelSelection: { model: " gpt-5.4-mini " },
828 observability: {
829 otlpTracesUrl: " http://localhost:4318/v1/traces ",
830 },
831 providers: {
832 codex: {
833 binaryPath: " /opt/homebrew/bin/codex ",
834 homePath: " ~/.codex ",
835 launchArgs: " --strict-config --enable foo ",
836 },
837 },
838 providerInstances: {
839 codex_personal: {
840 driver: " codex ",
841 displayName: " Codex Personal ",
842 config: { homePath: " ~/.codex-personal " },
843 },
844 },
845 });
846​
847 expect(patch.addProjectBaseDirectory).toBe("~/Development");
848 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
849 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
850 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
851 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
852 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
853 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
854 "codex",
855 );
856 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
857 "Codex Personal",
858 );
859 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
860 homePath: " ~/.codex-personal ",
861 });
862 });
863​
864 it("trims encoded server settings values before validation", () => {
865 const defaultSettings = decodeServerSettings({});
866 const encoded = encodeServerSettings({
867 ...defaultSettings,
868 addProjectBaseDirectory: " ~/Development ",
869 providers: {
870 ...defaultSettings.providers,
871 codex: {
872 ...defaultSettings.providers.codex,
873 binaryPath: " /opt/homebrew/bin/codex ",
874 launchArgs: " --strict-config ",
875 },
876 },
877 });
878​
879 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
880 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
881 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
882 });
883});
884​
885describe("ServerSettings environment icon", () => {
886 it("defaults to null", () => {
887 expect(decodeServerSettings({}).environmentIcon).toBeNull();
888 });
889​
890 it("keeps a kind this build knows", () => {
891 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
892 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
893 });
894​
895 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
896 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
897 });
898​
899 it("round-trips through encode", () => {
900 const settings = decodeServerSettings({ environmentIcon: "laptop" });
901 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
902​
903 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
904 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
905 });
906});
907​
908const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
909​
910it("validates remote device hosts and rejects ambiguous host ids", () => {
911 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
912 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
913 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
914 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
915 expect(() =>
916 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
917 ).toThrow();
918 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
919});