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

settings.test.ts

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