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