Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settings.test.ts

671 lines24.8 KB

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