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 blur and scroll by default and accepts opting out of each", () => {
333 const defaults = decodeClientSettings({});
334 expect(defaults.composerCollapseOnBlur).toBe(true);
335 expect(defaults.composerCollapseOnScroll).toBe(true);
336
337 const blurOff = decodeClientSettings({ composerCollapseOnBlur: false });
338 expect(blurOff.composerCollapseOnBlur).toBe(false);
339 expect(blurOff.composerCollapseOnScroll).toBe(true);
340
341 expect(
342 decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
343 ).toBe(false);
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.grok.enabled).toBe(false);
446 expect(decoded.providers.opencode.enabled).toBe(false);
447 });
448
449 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
450 const cursor = ProviderDriverKind.make("cursor");
451 const cursorId = ProviderInstanceId.make("cursor");
452 const decoded = decodeServerSettings({
453 providers: { cursor: { enabled: true } },
454 providerInstances: {
455 [cursorId]: { driver: cursor, enabled: true, config: {} },
456 },
457 });
458
459 expect(decoded.providers.cursor.enabled).toBe(true);
460 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
461 });
462
463 it("resolves instance enabled state with explicit false winning", () => {
464 const grok = ProviderDriverKind.make("grok");
465 const codex = ProviderDriverKind.make("codex");
466 // No flags anywhere: driver default applies.
467 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
468 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
469 // Unknown fork drivers stay enabled.
470 expect(
471 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
472 ).toBe(true);
473 // Envelope flag wins over the driver default.
474 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
475 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
476 false,
477 );
478 // Legacy in-config flag fills in when the envelope is silent.
479 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
480 // Conflicting flags: the explicit false wins, whichever side it is on.
481 expect(
482 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
483 ).toBe(false);
484 expect(
485 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
486 ).toBe(false);
487 });
488});
489
490describe("ServerSettings worktree defaults", () => {
491 it("defaults start-from-origin on for legacy configs", () => {
492 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
493 });
494
495 it("accepts start-from-origin updates", () => {
496 expect(
497 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
498 ).toBe(false);
499 });
500});
501
502describe("ServerSettings.sourceControlWritingStyle", () => {
503 it("defaults all style settings for legacy configs", () => {
504 const settings = decodeServerSettings({});
505
506 expect(settings.sourceControlWritingStyle).toEqual({
507 mode: "repo_conventions",
508 customInstructions: "",
509 followChangeRequestTemplates: true,
510 });
511 expect(settings.sourceControlWriterModelSelection).toBeNull();
512 });
513
514 it("trims partial style updates", () => {
515 const patch = decodeServerSettingsPatch({
516 sourceControlWritingStyle: {
517 mode: "custom",
518 customInstructions: " Prefer concise wording. ",
519 },
520 });
521
522 expect(patch.sourceControlWritingStyle).toEqual({
523 mode: "custom",
524 customInstructions: "Prefer concise wording.",
525 });
526 });
527});
528
529describe("ServerSettingsPatch.providerInstances", () => {
530 it("treats providerInstances as an optional whole-map replacement", () => {
531 const patch = decodeServerSettingsPatch({});
532 expect(patch.providerInstances).toBeUndefined();
533
534 const replacement = decodeServerSettingsPatch({
535 providerInstances: {
536 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
537 },
538 });
539 expect(replacement.providerInstances).toBeDefined();
540 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
541 "codex",
542 );
543 });
544
545 it("preserves a fork-defined driver entry through patch decoding", () => {
546 const patch = decodeServerSettingsPatch({
547 providerInstances: {
548 ollama_local: {
549 driver: "ollama",
550 config: { endpoint: "http://localhost:11434" },
551 },
552 },
553 });
554 const ollamaId = ProviderInstanceId.make("ollama_local");
555 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
556 });
557});
558
559describe("ServerSettingsPatch string normalization", () => {
560 it("trims string settings while decoding patches", () => {
561 const patch = decodeServerSettingsPatch({
562 addProjectBaseDirectory: " ~/Development ",
563 textGenerationModelSelection: { model: " gpt-5.4-mini " },
564 observability: {
565 otlpTracesUrl: " http://localhost:4318/v1/traces ",
566 },
567 providers: {
568 codex: {
569 binaryPath: " /opt/homebrew/bin/codex ",
570 homePath: " ~/.codex ",
571 launchArgs: " --strict-config --enable foo ",
572 },
573 },
574 providerInstances: {
575 codex_personal: {
576 driver: " codex ",
577 displayName: " Codex Personal ",
578 config: { homePath: " ~/.codex-personal " },
579 },
580 },
581 });
582
583 expect(patch.addProjectBaseDirectory).toBe("~/Development");
584 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
585 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
586 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
587 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
588 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
589 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
590 "codex",
591 );
592 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
593 "Codex Personal",
594 );
595 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
596 homePath: " ~/.codex-personal ",
597 });
598 });
599
600 it("trims encoded server settings values before validation", () => {
601 const defaultSettings = decodeServerSettings({});
602 const encoded = encodeServerSettings({
603 ...defaultSettings,
604 addProjectBaseDirectory: " ~/Development ",
605 providers: {
606 ...defaultSettings.providers,
607 codex: {
608 ...defaultSettings.providers.codex,
609 binaryPath: " /opt/homebrew/bin/codex ",
610 launchArgs: " --strict-config ",
611 },
612 },
613 });
614
615 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
616 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
617 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
618 });
619});
620
621describe("ServerSettings environment icon", () => {
622 it("defaults to null", () => {
623 expect(decodeServerSettings({}).environmentIcon).toBeNull();
624 });
625
626 it("keeps a kind this build knows", () => {
627 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
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});