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

settings.test.ts

791 lines29.1 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_THREAD_CONTEXT_TOKEN_LIMIT,
10 DEFAULT_SERVER_SETTINGS,
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 thread context token limit", () => {
25 it("defaults to the standard handover threshold", () => {
26 expect(decodeServerSettings({}).threadContextTokenLimit).toBe(
27 DEFAULT_THREAD_CONTEXT_TOKEN_LIMIT,
28 );
29 });
30​
31 it("accepts a custom threshold and rejects values outside the supported range", () => {
32 expect(decodeServerSettingsPatch({ threadContextTokenLimit: 180_000 })).toEqual({
33 threadContextTokenLimit: 180_000,
34 });
35 expect(() => decodeServerSettingsPatch({ threadContextTokenLimit: 49_999 })).toThrow();
36 expect(() => decodeServerSettingsPatch({ threadContextTokenLimit: 1_000_001 })).toThrow();
37 });
38});
39​
40describe("ServerSettings usage price overrides", () => {
41 const prices = { inputCostPerMillionTokens: 2, outputCostPerMillionTokens: 8 };
42​
43 it("defaults to automatic pricing and round-trips arbitrary model IDs", () => {
44 expect(decodeServerSettings({}).usagePriceOverrides).toEqual({});
45 const settings = decodeServerSettings({
46 usagePriceOverrides: { " vendor/example-model ": prices },
47 });
48 expect(encodeServerSettings(settings).usagePriceOverrides).toEqual({
49 "vendor/example-model": prices,
50 });
51 });
52​
53 it("accepts zero rates, optional cache rates, and per-model deletion", () => {
54 const overrides = {
55 "example-model": {
56 inputCostPerMillionTokens: 0,
57 outputCostPerMillionTokens: 0,
58 cacheReadCostPerMillionTokens: 0.5,
59 cacheWriteCostPerMillionTokens: 3,
60 },
61 "removed-model": null,
62 };
63 expect(
64 decodeServerSettingsPatch({ usagePriceOverrides: overrides }).usagePriceOverrides,
65 ).toEqual(overrides);
66 });
67​
68 it.each([
69 "inputCostPerMillionTokens",
70 "outputCostPerMillionTokens",
71 "cacheReadCostPerMillionTokens",
72 "cacheWriteCostPerMillionTokens",
73 ])("rejects invalid %s rates at the settings boundary", (field) => {
74 for (const value of [-1, Number.NaN, Number.POSITIVE_INFINITY, "2"]) {
75 const usagePriceOverrides = { "example-model": { ...prices, [field]: value } };
76 expect(() => decodeServerSettings({ usagePriceOverrides })).toThrow();
77 expect(() => decodeServerSettingsPatch({ usagePriceOverrides })).toThrow();
78 }
79 });
80​
81 it("rejects empty model IDs and incomplete input/output pricing", () => {
82 for (const usagePriceOverrides of [
83 { " ": prices },
84 { "example-model": { inputCostPerMillionTokens: 2 } },
85 { "example-model": { outputCostPerMillionTokens: 8 } },
86 ]) {
87 expect(() => decodeServerSettingsPatch({ usagePriceOverrides })).toThrow();
88 }
89 });
90});
91​
92describe("custom model settings", () => {
93 const capabilities = {
94 optionDescriptors: [
95 {
96 id: "effort",
97 label: "Reasoning",
98 type: "select",
99 options: [{ id: "high", label: "High", isDefault: true }],
100 },
101 ],
102 };
103​
104 it("accepts legacy bare slugs alongside full entries", () => {
105 const decoded = decodeClaudeSettings({
106 customModels: ["bare-slug", { slug: "named", name: "Named", capabilities }],
107 });
108 expect(decoded.customModels).toEqual([
109 "bare-slug",
110 { slug: "named", name: "Named", capabilities },
111 ]);
112 });
113​
114 it("accepts entries at the settings patch boundary", () => {
115 expect(
116 decodeServerSettingsPatch({
117 providers: { codex: { customModels: [{ slug: "x", capabilities }] } },
118 }).providers?.codex?.customModels,
119 ).toEqual([{ slug: "x", capabilities }]);
120 expect(() =>
121 decodeServerSettingsPatch({ providers: { codex: { customModels: [{ name: "no slug" }] } } }),
122 ).toThrow();
123 });
124});
125​
126describe("ClaudeSettings auto-compaction", () => {
127 it("uses Claude's default threshold when no override is configured", () => {
128 expect(decodeClaudeSettings({}).autoCompactWindow).toBe("");
129 });
130​
131 it.each(["100000", "300000", "1000000"])(
132 "accepts a supported auto-compaction threshold: %s",
133 (value) => {
134 expect(decodeClaudeSettings({ autoCompactWindow: value }).autoCompactWindow).toBe(value);
135 },
136 );
137​
138 it.each(["99999", "1000001", "300k", "invalid"])(
139 "rejects an unsupported auto-compaction threshold: %s",
140 (value) => {
141 expect(() => decodeClaudeSettings({ autoCompactWindow: value })).toThrow();
142 },
143 );
144​
145 it("rejects an unsupported threshold at the settings patch boundary", () => {
146 expect(() =>
147 decodeServerSettingsPatch({ providers: { claudeAgent: { autoCompactWindow: "300k" } } }),
148 ).toThrow();
149 expect(
150 decodeServerSettingsPatch({ providers: { claudeAgent: { autoCompactWindow: "300000" } } }),
151 ).toBeDefined();
152 });
153});
154​
155describe("ClientSettings diff colors", () => {
156 it("keeps red and green for existing settings without a saved palette", () => {
157 expect(decodeClientSettings({}).diffColorScheme).toBe("red-green");
158 });
159​
160 it.each(["red-green", "blue-orange"])("round-trips the %s palette", (diffColorScheme) => {
161 const settings = decodeClientSettings({ diffColorScheme });
162 expect(encodeClientSettings(settings).diffColorScheme).toBe(diffColorScheme);
163 expect(decodeClientSettingsPatch({ diffColorScheme }).diffColorScheme).toBe(diffColorScheme);
164 });
165​
166 it("rejects unsupported palettes", () => {
167 expect(() => decodeClientSettings({ diffColorScheme: "purple-yellow" })).toThrow();
168 expect(() => decodeClientSettingsPatch({ diffColorScheme: "purple-yellow" })).toThrow();
169 });
170});
171​
172describe("ClientSettings load balancing", () => {
173 it("requires opt-in when settings are new or omit load balancing", () => {
174 expect(decodeClientSettings({}).loadBalancingEnabled).toBe(false);
175 expect(decodeClientSettings({ loadBalancingWeights: {} }).loadBalancingEnabled).toBe(false);
176 });
177​
178 it.each([true, false])("preserves a saved choice of %s", (loadBalancingEnabled) => {
179 const settings = decodeClientSettings({ loadBalancingEnabled });
180 expect(encodeClientSettings(settings).loadBalancingEnabled).toBe(loadBalancingEnabled);
181 expect(decodeClientSettingsPatch({ loadBalancingEnabled }).loadBalancingEnabled).toBe(
182 loadBalancingEnabled,
183 );
184 });
185});
186​
187describe("ClientSettings word wrap", () => {
188 it("defaults word wrap on", () => {
189 expect(decodeClientSettings({}).wordWrap).toBe(true);
190 });
191​
192 it("ignores obsolete wrapping preferences", () => {
193 const decoded = decodeClientSettings({
194 chatWordWrap: false,
195 diffWordWrap: false,
196 });
197​
198 expect(decoded.wordWrap).toBe(true);
199 expect(decoded).not.toHaveProperty("chatWordWrap");
200 expect(decoded).not.toHaveProperty("diffWordWrap");
201 });
202});
203​
204describe("ClientSettings window capture", () => {
205 it("defaults capture off while keeping its feedback enabled", () => {
206 const settings = decodeClientSettings({});
207​
208 expect(settings.snapShotEnabled).toBe(false);
209 expect(settings.snapShotIncludeAccessibility).toBe(true);
210 expect(settings.snapShotShortcut).toEqual({ kind: "both-shift-keys" });
211 expect(settings.snapShotPlaySound).toBe(true);
212 expect(settings.snapShotSound).toBe("soft-pop");
213 expect(settings.snapShotFlash).toBe(true);
214 expect(settings.snapShotAnimations).toBe(true);
215 });
216​
217 it("accepts capture preference updates", () => {
218 expect(
219 decodeClientSettingsPatch({
220 snapShotEnabled: true,
221 snapShotIncludeAccessibility: false,
222 snapShotShortcut: {
223 key: "w",
224 metaKey: false,
225 ctrlKey: false,
226 shiftKey: true,
227 altKey: true,
228 modKey: false,
229 },
230 snapShotPlaySound: false,
231 snapShotSound: "camera-shutter",
232 snapShotFlash: false,
233 snapShotAnimations: false,
234 }),
235 ).toEqual({
236 snapShotEnabled: true,
237 snapShotIncludeAccessibility: false,
238 snapShotShortcut: {
239 key: "w",
240 metaKey: false,
241 ctrlKey: false,
242 shiftKey: true,
243 altKey: true,
244 modKey: false,
245 },
246 snapShotPlaySound: false,
247 snapShotSound: "camera-shutter",
248 snapShotFlash: false,
249 snapShotAnimations: false,
250 });
251 });
252​
253 it("rejects unknown capture sounds", () => {
254 expect(() => decodeClientSettingsPatch({ snapShotSound: "doorbell" })).toThrow();
255 });
256​
257 it("accepts modifier pair shortcuts", () => {
258 expect(
259 decodeClientSettingsPatch({
260 snapShotShortcut: { kind: "modifier-pair", modifier: "meta" },
261 }),
262 ).toEqual({
263 snapShotShortcut: { kind: "modifier-pair", modifier: "meta" },
264 });
265 expect(() =>
266 decodeClientSettingsPatch({
267 snapShotShortcut: { kind: "modifier-pair", modifier: "hyper" },
268 }),
269 ).toThrow();
270 });
271​
272 it("rejects a capture shortcut with no modifier", () => {
273 expect(() =>
274 decodeClientSettingsPatch({
275 snapShotShortcut: {
276 key: "w",
277 metaKey: false,
278 ctrlKey: false,
279 shiftKey: false,
280 altKey: false,
281 modKey: false,
282 },
283 }),
284 ).toThrow();
285 });
286});
287​
288describe("ClientSettings proactive panels", () => {
289 it("is opt-in and accepts client-local updates", () => {
290 expect(decodeClientSettings({}).proactivePanelsEnabled).toBe(false);
291 expect(decodeClientSettingsPatch({ proactivePanelsEnabled: true }).proactivePanelsEnabled).toBe(
292 true,
293 );
294 });
295});
296​
297describe("ClientSettings quit confirmation", () => {
298 it("defaults to hold", () => {
299 expect(decodeClientSettings({}).confirmQuit).toBe("hold");
300 });
301​
302 it.each(["direct", "hold", "double-click"] as const)("accepts the %s mode", (mode) => {
303 expect(decodeClientSettings({ confirmQuit: mode }).confirmQuit).toBe(mode);
304 expect(decodeClientSettingsPatch({ confirmQuit: mode }).confirmQuit).toBe(mode);
305 });
306​
307 it.each([
308 [true, "hold"],
309 [false, "direct"],
310 ] as const)("migrates the legacy %s value to %s", (legacyValue, mode) => {
311 const settings = decodeClientSettings({ confirmQuit: legacyValue });
312​
313 expect(settings.confirmQuit).toBe(mode);
314 expect(encodeClientSettings(settings).confirmQuit).toBe(mode);
315 });
316​
317 it("rejects legacy booleans at the patch boundary", () => {
318 expect(() => decodeClientSettingsPatch({ confirmQuit: true })).toThrow();
319 });
320});
321​
322describe("ClientSettings browser recording frame rate", () => {
323 it("defaults to 30 fps", () => {
324 expect(decodeClientSettings({}).browserRecordingFrameRate).toBe(30);
325 });
326​
327 it.each([30, 60])("accepts a supported frame rate: %s", (frameRate) => {
328 expect(
329 decodeClientSettings({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
330 ).toBe(frameRate);
331 expect(
332 decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
333 ).toBe(frameRate);
334 });
335​
336 it.each([24, 59, 120])("rejects an unsupported frame rate: %s", (frameRate) => {
337 expect(() => decodeClientSettings({ browserRecordingFrameRate: frameRate })).toThrow();
338 expect(() => decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate })).toThrow();
339 });
340});
341​
342describe("ClientSettings glass opacity", () => {
343 it("defaults to a readable translucent surface", () => {
344 expect(decodeClientSettings({}).glassOpacity).toBe(80);
345 });
346​
347 it.each([39, 101, 72.5])("rejects an invalid glass opacity: %s", (value) => {
348 expect(() => decodeClientSettings({ glassOpacity: value })).toThrow();
349 expect(() => decodeClientSettingsPatch({ glassOpacity: value })).toThrow();
350 });
351​
352 it.each([40, 75, 100])("accepts a glass opacity within the supported range: %s", (value) => {
353 expect(decodeClientSettings({ glassOpacity: value }).glassOpacity).toBe(value);
354 expect(decodeClientSettingsPatch({ glassOpacity: value }).glassOpacity).toBe(value);
355 });
356});
357​
358describe("ClientSettings appearance contrast", () => {
359 it("defaults to the theme's original contrast", () => {
360 expect(decodeClientSettings({}).appearanceContrast).toBe(100);
361 });
362​
363 it.each([49, 201, 92.5])("rejects an invalid appearance contrast: %s", (value) => {
364 expect(() => decodeClientSettings({ appearanceContrast: value })).toThrow();
365 expect(() => decodeClientSettingsPatch({ appearanceContrast: value })).toThrow();
366 });
367​
368 it.each([50, 100, 150, 200])("accepts an appearance contrast in range: %s", (value) => {
369 expect(decodeClientSettings({ appearanceContrast: value }).appearanceContrast).toBe(value);
370 expect(decodeClientSettingsPatch({ appearanceContrast: value }).appearanceContrast).toBe(value);
371 });
372});
373​
374describe("ClientSettings panel animations", () => {
375 it("defaults to instant changes", () => {
376 expect(decodeClientSettings({}).panelAnimationDurationMs).toBe(0);
377 });
378​
379 it.each([0, 400])("accepts a panel animation duration: %s", (value) => {
380 expect(decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toEqual({
381 panelAnimationDurationMs: value,
382 });
383 });
384​
385 it.each([-1, 401, 150.5])("rejects an invalid panel animation duration: %s", (value) => {
386 expect(() => decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toThrow();
387 });
388});
389​
390describe("ClientSettings environment identification", () => {
391 it("defaults to artwork and accepts each presentation mode", () => {
392 expect(decodeClientSettings({}).environmentIdentificationMode).toBe("artwork");
393​
394 for (const mode of ["artwork", "pill", "none"] as const) {
395 expect(
396 decodeClientSettingsPatch({ environmentIdentificationMode: mode })
397 .environmentIdentificationMode,
398 ).toBe(mode);
399 }
400 });
401​
402 it("rejects unsupported presentation modes", () => {
403 expect(() => decodeClientSettings({ environmentIdentificationMode: "badge" })).toThrow();
404 expect(() => decodeClientSettingsPatch({ environmentIdentificationMode: "badge" })).toThrow();
405 });
406});
407​
408describe("ClientSettings sidebar", () => {
409 it("defaults to the current sidebar", () => {
410 expect(decodeClientSettings({}).legacySidebarEnabled).toBe(false);
411 });
412​
413 it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
414 const decoded = decodeClientSettings({
415 sidebarV2Enabled: false,
416 sidebarV2ConfiguredByUser: true,
417 });
418 expect(decoded.legacySidebarEnabled).toBe(false);
419 expect(decoded).not.toHaveProperty("sidebarV2Enabled");
420 expect(decoded).not.toHaveProperty("sidebarV2ConfiguredByUser");
421 });
422​
423 it("preserves an explicit legacy sidebar opt-in", () => {
424 expect(decodeClientSettings({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(true);
425 expect(decodeClientSettingsPatch({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(
426 true,
427 );
428 });
429​
430 it("keeps unpin confirmation opt-in and patchable", () => {
431 expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
432 expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
433 expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
434 });
435});
436​
437describe("ClientSettings context window meter", () => {
438 it("defaults off and preserves an explicit legacy opt-in", () => {
439 expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
440 expect(
441 decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
442 ).toBe(true);
443 expect(
444 decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
445 ).toBe(true);
446 });
447});
448​
449describe("ClientSettings composer collapse", () => {
450 it("collapses on scroll by default and accepts opting out", () => {
451 expect(decodeClientSettings({}).composerCollapseOnScroll).toBe(true);
452 expect(
453 decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
454 ).toBe(false);
455 });
456​
457 it("drops the retired blur trigger key", () => {
458 const decoded = decodeClientSettings({ composerCollapseOnBlur: false });
459 expect(decoded.composerCollapseOnScroll).toBe(true);
460 expect(decoded).not.toHaveProperty("composerCollapseOnBlur");
461 });
462});
463​
464describe("ServerSettings thread settlement", () => {
465 it("defaults merge settlement on and inactivity settlement to three days", () => {
466 const settings = decodeServerSettings({});
467 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
468 expect(settings.sidebarAutoSettleOnMerge).toBe(true);
469 });
470​
471 it("allows both automatic rules to be disabled", () => {
472 expect(
473 decodeServerSettings({
474 sidebarAutoSettleAfterDays: null,
475 sidebarAutoSettleOnMerge: false,
476 }),
477 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
478 expect(
479 decodeServerSettingsPatch({
480 sidebarAutoSettleAfterDays: null,
481 sidebarAutoSettleOnMerge: false,
482 }),
483 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
484 });
485​
486 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
487 expect(() => decodeServerSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
488 expect(() => decodeServerSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
489 });
490});
491​
492describe("ClientSettings pull request merge methods", () => {
493 it("defaults to no project overrides and accepts supported methods", () => {
494 expect(decodeClientSettings({}).pullRequestMergeMethodOverrides).toEqual({});
495 expect(
496 decodeClientSettingsPatch({
497 pullRequestMergeMethodOverrides: { project: "squash" },
498 }).pullRequestMergeMethodOverrides,
499 ).toEqual({ project: "squash" });
500 });
501​
502 it("rejects unsupported project merge methods", () => {
503 expect(() =>
504 decodeClientSettingsPatch({
505 pullRequestMergeMethodOverrides: { project: "fast-forward" },
506 }),
507 ).toThrow();
508 });
509});
510​
511describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
512 it("defaults text generation to Luna at low reasoning effort", () => {
513 expect(DEFAULT_SERVER_SETTINGS.textGenerationModelSelection).toEqual({
514 instanceId: ProviderInstanceId.make("codex"),
515 model: "gpt-5.6-luna",
516 options: [{ id: "reasoningEffort", value: "low" }],
517 });
518 });
519​
520 it("defaults to an empty record so legacy configs without the key still decode", () => {
521 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
522 });
523​
524 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
525 const decoded = decodeServerSettings({});
526 expect(decoded.providerInstances).toEqual({});
527 // Legacy `providers` struct is still hydrated with its per-driver defaults
528 // so existing call sites keep working through the migration.
529 expect(decoded.providers.codex.enabled).toBe(true);
530 });
531​
532 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
533 const decoded = decodeServerSettings({
534 providerInstances: {
535 codex_personal: {
536 driver: "codex",
537 displayName: "Codex (personal)",
538 config: { homePath: "~/.codex_personal" },
539 },
540 codex_work: {
541 driver: "codex",
542 config: { homePath: "~/.codex_work" },
543 },
544 ollama_local: {
545 driver: "ollama",
546 displayName: "Ollama (local)",
547 config: { endpoint: "http://localhost:11434" },
548 },
549 },
550 });
551 const personalId = ProviderInstanceId.make("codex_personal");
552 const workId = ProviderInstanceId.make("codex_work");
553 const ollamaId = ProviderInstanceId.make("ollama_local");
554​
555 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
556 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
557 // Critical: a config naming a driver this build does not know about
558 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
559 // The runtime handles "driver not installed" — the schema must not.
560 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
561 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
562 endpoint: "http://localhost:11434",
563 });
564 });
565​
566 it("rejects instance keys that violate the slug pattern", () => {
567 expect(() =>
568 decodeServerSettings({
569 providerInstances: { "1bad": { driver: "codex" } },
570 }),
571 ).toThrow();
572 });
573});
574​
575describe("provider enabled defaults", () => {
576 it("enables only the stable bindings by default", () => {
577 const decoded = decodeServerSettings({});
578 expect(decoded.providers.codex.enabled).toBe(true);
579 expect(decoded.providers.claudeAgent.enabled).toBe(true);
580 expect(decoded.providers.cursor.enabled).toBe(false);
581 expect(decoded.providers.grok.enabled).toBe(false);
582 expect(decoded.providers.opencode.enabled).toBe(false);
583 });
584​
585 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
586 const cursor = ProviderDriverKind.make("cursor");
587 const cursorId = ProviderInstanceId.make("cursor");
588 const decoded = decodeServerSettings({
589 providers: { cursor: { enabled: true } },
590 providerInstances: {
591 [cursorId]: { driver: cursor, enabled: true, config: {} },
592 },
593 });
594​
595 expect(decoded.providers.cursor.enabled).toBe(true);
596 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
597 });
598​
599 it("resolves instance enabled state with explicit false winning", () => {
600 const grok = ProviderDriverKind.make("grok");
601 const codex = ProviderDriverKind.make("codex");
602 // No flags anywhere: driver default applies.
603 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
604 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
605 // Unknown fork drivers stay enabled.
606 expect(
607 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
608 ).toBe(true);
609 // Envelope flag wins over the driver default.
610 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
611 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
612 false,
613 );
614 // Legacy in-config flag fills in when the envelope is silent.
615 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
616 // Conflicting flags: the explicit false wins, whichever side it is on.
617 expect(
618 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
619 ).toBe(false);
620 expect(
621 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
622 ).toBe(false);
623 });
624});
625​
626describe("ServerSettings worktree defaults", () => {
627 it("defaults start-from-origin on for legacy configs", () => {
628 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
629 });
630​
631 it("accepts start-from-origin updates", () => {
632 expect(
633 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
634 ).toBe(false);
635 });
636});
637​
638describe("ServerSettings.sourceControlWritingStyle", () => {
639 it("defaults all style settings for legacy configs", () => {
640 const settings = decodeServerSettings({});
641​
642 expect(settings.sourceControlWritingStyle).toEqual({
643 mode: "repo_conventions",
644 customInstructions: "",
645 followChangeRequestTemplates: true,
646 });
647 expect(settings.sourceControlWriterModelSelection).toBeNull();
648 });
649​
650 it("trims partial style updates", () => {
651 const patch = decodeServerSettingsPatch({
652 sourceControlWritingStyle: {
653 mode: "custom",
654 customInstructions: " Prefer concise wording. ",
655 },
656 });
657​
658 expect(patch.sourceControlWritingStyle).toEqual({
659 mode: "custom",
660 customInstructions: "Prefer concise wording.",
661 });
662 });
663});
664​
665describe("ServerSettingsPatch.providerInstances", () => {
666 it("treats providerInstances as an optional whole-map replacement", () => {
667 const patch = decodeServerSettingsPatch({});
668 expect(patch.providerInstances).toBeUndefined();
669​
670 const replacement = decodeServerSettingsPatch({
671 providerInstances: {
672 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
673 },
674 });
675 expect(replacement.providerInstances).toBeDefined();
676 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
677 "codex",
678 );
679 });
680​
681 it("preserves a fork-defined driver entry through patch decoding", () => {
682 const patch = decodeServerSettingsPatch({
683 providerInstances: {
684 ollama_local: {
685 driver: "ollama",
686 config: { endpoint: "http://localhost:11434" },
687 },
688 },
689 });
690 const ollamaId = ProviderInstanceId.make("ollama_local");
691 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
692 });
693});
694​
695describe("ServerSettingsPatch string normalization", () => {
696 it("trims string settings while decoding patches", () => {
697 const patch = decodeServerSettingsPatch({
698 addProjectBaseDirectory: " ~/Development ",
699 textGenerationModelSelection: { model: " gpt-5.4-mini " },
700 observability: {
701 otlpTracesUrl: " http://localhost:4318/v1/traces ",
702 },
703 providers: {
704 codex: {
705 binaryPath: " /opt/homebrew/bin/codex ",
706 homePath: " ~/.codex ",
707 launchArgs: " --strict-config --enable foo ",
708 },
709 },
710 providerInstances: {
711 codex_personal: {
712 driver: " codex ",
713 displayName: " Codex Personal ",
714 config: { homePath: " ~/.codex-personal " },
715 },
716 },
717 });
718​
719 expect(patch.addProjectBaseDirectory).toBe("~/Development");
720 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
721 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
722 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
723 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
724 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
725 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
726 "codex",
727 );
728 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
729 "Codex Personal",
730 );
731 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
732 homePath: " ~/.codex-personal ",
733 });
734 });
735​
736 it("trims encoded server settings values before validation", () => {
737 const defaultSettings = decodeServerSettings({});
738 const encoded = encodeServerSettings({
739 ...defaultSettings,
740 addProjectBaseDirectory: " ~/Development ",
741 providers: {
742 ...defaultSettings.providers,
743 codex: {
744 ...defaultSettings.providers.codex,
745 binaryPath: " /opt/homebrew/bin/codex ",
746 launchArgs: " --strict-config ",
747 },
748 },
749 });
750​
751 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
752 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
753 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
754 });
755});
756​
757describe("ServerSettings environment icon", () => {
758 it("defaults to null", () => {
759 expect(decodeServerSettings({}).environmentIcon).toBeNull();
760 });
761​
762 it("keeps a kind this build knows", () => {
763 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
764 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
765 });
766​
767 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
768 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
769 });
770​
771 it("round-trips through encode", () => {
772 const settings = decodeServerSettings({ environmentIcon: "laptop" });
773 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
774​
775 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
776 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
777 });
778});
779​
780const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
781​
782it("validates remote device hosts and rejects ambiguous host ids", () => {
783 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
784 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
785 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
786 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
787 expect(() =>
788 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
789 ).toThrow();
790 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
791});