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

settings.test.ts

887 lines33.0 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 expect(decodeClientSettings({}).legacySidebarEnabled).toBe(false);
486 });
487​
488 it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
489 const decoded = decodeClientSettings({
490 sidebarV2Enabled: false,
491 sidebarV2ConfiguredByUser: true,
492 });
493 expect(decoded.legacySidebarEnabled).toBe(false);
494 expect(decoded).not.toHaveProperty("sidebarV2Enabled");
495 expect(decoded).not.toHaveProperty("sidebarV2ConfiguredByUser");
496 });
497​
498 it("drops the retired compact sidebar keys for users who opted in", () => {
499 const stored = { compactSidebarEnabled: true, sidebarCompactThreadRows: true };
500 const decoded = decodeClientSettings(stored);
501 expect(decoded).not.toHaveProperty("compactSidebarEnabled");
502 expect(decoded).not.toHaveProperty("sidebarCompactThreadRows");
503 expect(decodeClientSettingsPatch(stored)).toEqual({});
504 });
505​
506 it("preserves an explicit legacy sidebar opt-in", () => {
507 expect(decodeClientSettings({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(true);
508 expect(decodeClientSettingsPatch({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(
509 true,
510 );
511 });
512​
513 it("keeps unpin confirmation opt-in and patchable", () => {
514 expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
515 expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
516 expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
517 });
518});
519​
520describe("ClientSettings context window meter", () => {
521 it("defaults off and preserves an explicit legacy opt-in", () => {
522 expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
523 expect(
524 decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
525 ).toBe(true);
526 expect(
527 decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
528 ).toBe(true);
529 });
530});
531​
532describe("ClientSettings follow-up behavior", () => {
533 it("defaults to queue and accepts either behavior", () => {
534 expect(decodeClientSettings({}).followUpBehavior).toBe("queue");
535 for (const followUpBehavior of ["queue", "steer"]) {
536 expect(decodeClientSettings({ followUpBehavior }).followUpBehavior).toBe(followUpBehavior);
537 expect(decodeClientSettingsPatch({ followUpBehavior }).followUpBehavior).toBe(
538 followUpBehavior,
539 );
540 }
541 expect(() => decodeClientSettingsPatch({ followUpBehavior: "invalid" })).toThrow();
542 });
543});
544​
545describe("ClientSettings composer collapse", () => {
546 it("collapses on scroll by default and accepts opting out", () => {
547 expect(decodeClientSettings({}).composerCollapseOnScroll).toBe(true);
548 expect(
549 decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
550 ).toBe(false);
551 });
552​
553 it("drops the retired blur trigger key", () => {
554 const decoded = decodeClientSettings({ composerCollapseOnBlur: false });
555 expect(decoded.composerCollapseOnScroll).toBe(true);
556 expect(decoded).not.toHaveProperty("composerCollapseOnBlur");
557 });
558});
559​
560describe("ServerSettings thread settlement", () => {
561 it("defaults merge settlement on and inactivity settlement to three days", () => {
562 const settings = decodeServerSettings({});
563 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
564 expect(settings.sidebarAutoSettleOnMerge).toBe(true);
565 });
566​
567 it("allows both automatic rules to be disabled", () => {
568 expect(
569 decodeServerSettings({
570 sidebarAutoSettleAfterDays: null,
571 sidebarAutoSettleOnMerge: false,
572 }),
573 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
574 expect(
575 decodeServerSettingsPatch({
576 sidebarAutoSettleAfterDays: null,
577 sidebarAutoSettleOnMerge: false,
578 }),
579 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
580 });
581​
582 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
583 expect(() => decodeServerSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
584 expect(() => decodeServerSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
585 });
586});
587​
588describe("ClientSettings pull request merge methods", () => {
589 it("defaults to no project overrides and accepts supported methods", () => {
590 expect(decodeClientSettings({}).pullRequestMergeMethodOverrides).toEqual({});
591 expect(
592 decodeClientSettingsPatch({
593 pullRequestMergeMethodOverrides: { project: "squash" },
594 }).pullRequestMergeMethodOverrides,
595 ).toEqual({ project: "squash" });
596 });
597​
598 it("rejects unsupported project merge methods", () => {
599 expect(() =>
600 decodeClientSettingsPatch({
601 pullRequestMergeMethodOverrides: { project: "fast-forward" },
602 }),
603 ).toThrow();
604 });
605});
606​
607describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
608 it("defaults text generation to Luna at low reasoning effort", () => {
609 expect(DEFAULT_SERVER_SETTINGS.textGenerationModelSelection).toEqual({
610 instanceId: ProviderInstanceId.make("codex"),
611 model: "gpt-5.6-luna",
612 options: [{ id: "reasoningEffort", value: "low" }],
613 });
614 });
615​
616 it("defaults to an empty record so legacy configs without the key still decode", () => {
617 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
618 });
619​
620 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
621 const decoded = decodeServerSettings({});
622 expect(decoded.providerInstances).toEqual({});
623 // Legacy `providers` struct is still hydrated with its per-driver defaults
624 // so existing call sites keep working through the migration.
625 expect(decoded.providers.codex.enabled).toBe(true);
626 });
627​
628 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
629 const decoded = decodeServerSettings({
630 providerInstances: {
631 codex_personal: {
632 driver: "codex",
633 displayName: "Codex (personal)",
634 config: { homePath: "~/.codex_personal" },
635 },
636 codex_work: {
637 driver: "codex",
638 config: { homePath: "~/.codex_work" },
639 },
640 ollama_local: {
641 driver: "ollama",
642 displayName: "Ollama (local)",
643 config: { endpoint: "http://localhost:11434" },
644 },
645 },
646 });
647 const personalId = ProviderInstanceId.make("codex_personal");
648 const workId = ProviderInstanceId.make("codex_work");
649 const ollamaId = ProviderInstanceId.make("ollama_local");
650​
651 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
652 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
653 // Critical: a config naming a driver this build does not know about
654 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
655 // The runtime handles "driver not installed" — the schema must not.
656 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
657 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
658 endpoint: "http://localhost:11434",
659 });
660 });
661​
662 it("rejects instance keys that violate the slug pattern", () => {
663 expect(() =>
664 decodeServerSettings({
665 providerInstances: { "1bad": { driver: "codex" } },
666 }),
667 ).toThrow();
668 });
669});
670​
671describe("provider enabled defaults", () => {
672 it("enables only the stable bindings by default", () => {
673 const decoded = decodeServerSettings({});
674 expect(decoded.providers.codex.enabled).toBe(true);
675 expect(decoded.providers.claudeAgent.enabled).toBe(true);
676 expect(decoded.providers.cursor.enabled).toBe(false);
677 expect(decoded.providers.grok.enabled).toBe(false);
678 expect(decoded.providers.opencode.enabled).toBe(false);
679 });
680​
681 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
682 const cursor = ProviderDriverKind.make("cursor");
683 const cursorId = ProviderInstanceId.make("cursor");
684 const decoded = decodeServerSettings({
685 providers: { cursor: { enabled: true } },
686 providerInstances: {
687 [cursorId]: { driver: cursor, enabled: true, config: {} },
688 },
689 });
690​
691 expect(decoded.providers.cursor.enabled).toBe(true);
692 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
693 });
694​
695 it("resolves instance enabled state with explicit false winning", () => {
696 const grok = ProviderDriverKind.make("grok");
697 const codex = ProviderDriverKind.make("codex");
698 // No flags anywhere: driver default applies.
699 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
700 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
701 // Unknown fork drivers stay enabled.
702 expect(
703 resolveProviderInstanceEnabled({ driver: ProviderDriverKind.make("ollama"), config: {} }),
704 ).toBe(true);
705 // Envelope flag wins over the driver default.
706 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
707 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
708 false,
709 );
710 // Legacy in-config flag fills in when the envelope is silent.
711 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
712 // Conflicting flags: the explicit false wins, whichever side it is on.
713 expect(
714 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
715 ).toBe(false);
716 expect(
717 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
718 ).toBe(false);
719 });
720});
721​
722describe("ServerSettings worktree defaults", () => {
723 it("defaults start-from-origin on for legacy configs", () => {
724 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
725 });
726​
727 it("accepts start-from-origin updates", () => {
728 expect(
729 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
730 ).toBe(false);
731 });
732});
733​
734describe("ServerSettings.sourceControlWritingStyle", () => {
735 it("defaults all style settings for legacy configs", () => {
736 const settings = decodeServerSettings({});
737​
738 expect(settings.sourceControlWritingStyle).toEqual({
739 mode: "repo_conventions",
740 customInstructions: "",
741 followChangeRequestTemplates: true,
742 });
743 expect(settings.sourceControlWriterModelSelection).toBeNull();
744 });
745​
746 it("trims partial style updates", () => {
747 const patch = decodeServerSettingsPatch({
748 sourceControlWritingStyle: {
749 mode: "custom",
750 customInstructions: " Prefer concise wording. ",
751 },
752 });
753​
754 expect(patch.sourceControlWritingStyle).toEqual({
755 mode: "custom",
756 customInstructions: "Prefer concise wording.",
757 });
758 });
759});
760​
761describe("ServerSettingsPatch.providerInstances", () => {
762 it("treats providerInstances as an optional whole-map replacement", () => {
763 const patch = decodeServerSettingsPatch({});
764 expect(patch.providerInstances).toBeUndefined();
765​
766 const replacement = decodeServerSettingsPatch({
767 providerInstances: {
768 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
769 },
770 });
771 expect(replacement.providerInstances).toBeDefined();
772 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
773 "codex",
774 );
775 });
776​
777 it("preserves a fork-defined driver entry through patch decoding", () => {
778 const patch = decodeServerSettingsPatch({
779 providerInstances: {
780 ollama_local: {
781 driver: "ollama",
782 config: { endpoint: "http://localhost:11434" },
783 },
784 },
785 });
786 const ollamaId = ProviderInstanceId.make("ollama_local");
787 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
788 });
789});
790​
791describe("ServerSettingsPatch string normalization", () => {
792 it("trims string settings while decoding patches", () => {
793 const patch = decodeServerSettingsPatch({
794 addProjectBaseDirectory: " ~/Development ",
795 textGenerationModelSelection: { model: " gpt-5.4-mini " },
796 observability: {
797 otlpTracesUrl: " http://localhost:4318/v1/traces ",
798 },
799 providers: {
800 codex: {
801 binaryPath: " /opt/homebrew/bin/codex ",
802 homePath: " ~/.codex ",
803 launchArgs: " --strict-config --enable foo ",
804 },
805 },
806 providerInstances: {
807 codex_personal: {
808 driver: " codex ",
809 displayName: " Codex Personal ",
810 config: { homePath: " ~/.codex-personal " },
811 },
812 },
813 });
814​
815 expect(patch.addProjectBaseDirectory).toBe("~/Development");
816 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
817 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
818 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
819 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
820 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
821 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
822 "codex",
823 );
824 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
825 "Codex Personal",
826 );
827 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
828 homePath: " ~/.codex-personal ",
829 });
830 });
831​
832 it("trims encoded server settings values before validation", () => {
833 const defaultSettings = decodeServerSettings({});
834 const encoded = encodeServerSettings({
835 ...defaultSettings,
836 addProjectBaseDirectory: " ~/Development ",
837 providers: {
838 ...defaultSettings.providers,
839 codex: {
840 ...defaultSettings.providers.codex,
841 binaryPath: " /opt/homebrew/bin/codex ",
842 launchArgs: " --strict-config ",
843 },
844 },
845 });
846​
847 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
848 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
849 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
850 });
851});
852​
853describe("ServerSettings environment icon", () => {
854 it("defaults to null", () => {
855 expect(decodeServerSettings({}).environmentIcon).toBeNull();
856 });
857​
858 it("keeps a kind this build knows", () => {
859 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
860 expect(decodeServerSettings({ environmentIcon: "linux" }).environmentIcon).toBe("linux");
861 });
862​
863 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
864 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
865 });
866​
867 it("round-trips through encode", () => {
868 const settings = decodeServerSettings({ environmentIcon: "laptop" });
869 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
870​
871 const linuxSettings = decodeServerSettings({ environmentIcon: "linux" });
872 expect(encodeServerSettings(linuxSettings).environmentIcon).toBe("linux");
873 });
874});
875​
876const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
877​
878it("validates remote device hosts and rejects ambiguous host ids", () => {
879 const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
880 expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
881 expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
882 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
883 expect(() =>
884 decodeDeviceHostSettings({ deviceHosts: [{ ...host, target: "-oProxyCommand=bad" }] }),
885 ).toThrow();
886 expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, port: 0 }] })).toThrow();
887});