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