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