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