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