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

settings.test.ts

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