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