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

settings.test.ts

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