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

settings.test.ts

526 lines19.9 KB

1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3​
4import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
5import {
6 ClientSettingsSchema,
7 ClientSettingsPatch,
8 ClaudeSettings,
9 DEFAULT_SERVER_SETTINGS,
10 defaultEnabledForDriver,
11 resolveProviderInstanceEnabled,
12 ServerSettings,
13 ServerSettingsPatch,
14} from "./settings.ts";
15​
16const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
17const decodeClientSettingsPatch = Schema.decodeUnknownSync(ClientSettingsPatch);
18const encodeClientSettings = Schema.encodeSync(ClientSettingsSchema);
19const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
20const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
21const encodeServerSettings = Schema.encodeSync(ServerSettings);
22const decodeClaudeSettings = Schema.decodeUnknownSync(ClaudeSettings);
23​
24describe("ClaudeSettings auto-compaction", () => {
25 it("uses Claude's default threshold when no override is configured", () => {
26 expect(decodeClaudeSettings({}).autoCompactWindow).toBe("");
27 });
28​
29 it.each(["100000", "300000", "1000000"])(
30 "accepts a supported auto-compaction threshold: %s",
31 (value) => {
32 expect(decodeClaudeSettings({ autoCompactWindow: value }).autoCompactWindow).toBe(value);
33 },
34 );
35​
36 it.each(["99999", "1000001", "300k", "invalid"])(
37 "rejects an unsupported auto-compaction threshold: %s",
38 (value) => {
39 expect(() => decodeClaudeSettings({ autoCompactWindow: value })).toThrow();
40 },
41 );
42​
43 it("rejects an unsupported threshold at the settings patch boundary", () => {
44 expect(() =>
45 decodeServerSettingsPatch({ providers: { claudeAgent: { autoCompactWindow: "300k" } } }),
46 ).toThrow();
47 expect(
48 decodeServerSettingsPatch({ providers: { claudeAgent: { autoCompactWindow: "300000" } } }),
49 ).toBeDefined();
50 });
51});
52​
53describe("ClientSettings word wrap", () => {
54 it("defaults word wrap on", () => {
55 expect(decodeClientSettings({}).wordWrap).toBe(true);
56 });
57​
58 it("ignores obsolete wrapping preferences", () => {
59 const decoded = decodeClientSettings({
60 chatWordWrap: false,
61 diffWordWrap: false,
62 });
63​
64 expect(decoded.wordWrap).toBe(true);
65 expect(decoded).not.toHaveProperty("chatWordWrap");
66 expect(decoded).not.toHaveProperty("diffWordWrap");
67 });
68});
69​
70describe("ClientSettings proactive panels", () => {
71 it("is opt-in and accepts client-local updates", () => {
72 expect(decodeClientSettings({}).proactivePanelsEnabled).toBe(false);
73 expect(decodeClientSettingsPatch({ proactivePanelsEnabled: true }).proactivePanelsEnabled).toBe(
74 true,
75 );
76 });
77});
78​
79describe("ClientSettings quit confirmation", () => {
80 it("defaults to hold", () => {
81 expect(decodeClientSettings({}).confirmQuit).toBe("hold");
82 });
83​
84 it.each(["direct", "hold", "double-click"] as const)("accepts the %s mode", (mode) => {
85 expect(decodeClientSettings({ confirmQuit: mode }).confirmQuit).toBe(mode);
86 expect(decodeClientSettingsPatch({ confirmQuit: mode }).confirmQuit).toBe(mode);
87 });
88​
89 it.each([
90 [true, "hold"],
91 [false, "direct"],
92 ] as const)("migrates the legacy %s value to %s", (legacyValue, mode) => {
93 const settings = decodeClientSettings({ confirmQuit: legacyValue });
94​
95 expect(settings.confirmQuit).toBe(mode);
96 expect(encodeClientSettings(settings).confirmQuit).toBe(mode);
97 });
98​
99 it("rejects legacy booleans at the patch boundary", () => {
100 expect(() => decodeClientSettingsPatch({ confirmQuit: true })).toThrow();
101 });
102});
103​
104describe("ClientSettings browser recording frame rate", () => {
105 it("defaults to 30 fps", () => {
106 expect(decodeClientSettings({}).browserRecordingFrameRate).toBe(30);
107 });
108​
109 it.each([30, 60])("accepts a supported frame rate: %s", (frameRate) => {
110 expect(
111 decodeClientSettings({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
112 ).toBe(frameRate);
113 expect(
114 decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate }).browserRecordingFrameRate,
115 ).toBe(frameRate);
116 });
117​
118 it.each([24, 59, 120])("rejects an unsupported frame rate: %s", (frameRate) => {
119 expect(() => decodeClientSettings({ browserRecordingFrameRate: frameRate })).toThrow();
120 expect(() => decodeClientSettingsPatch({ browserRecordingFrameRate: frameRate })).toThrow();
121 });
122});
123​
124describe("ClientSettings glass opacity", () => {
125 it("defaults to a readable translucent surface", () => {
126 expect(decodeClientSettings({}).glassOpacity).toBe(80);
127 });
128​
129 it.each([39, 101, 72.5])("rejects an invalid glass opacity: %s", (value) => {
130 expect(() => decodeClientSettings({ glassOpacity: value })).toThrow();
131 expect(() => decodeClientSettingsPatch({ glassOpacity: value })).toThrow();
132 });
133​
134 it.each([40, 75, 100])("accepts a glass opacity within the supported range: %s", (value) => {
135 expect(decodeClientSettings({ glassOpacity: value }).glassOpacity).toBe(value);
136 expect(decodeClientSettingsPatch({ glassOpacity: value }).glassOpacity).toBe(value);
137 });
138});
139​
140describe("ClientSettings appearance contrast", () => {
141 it("defaults to the theme's original contrast", () => {
142 expect(decodeClientSettings({}).appearanceContrast).toBe(100);
143 });
144​
145 it.each([49, 201, 92.5])("rejects an invalid appearance contrast: %s", (value) => {
146 expect(() => decodeClientSettings({ appearanceContrast: value })).toThrow();
147 expect(() => decodeClientSettingsPatch({ appearanceContrast: value })).toThrow();
148 });
149​
150 it.each([50, 100, 150, 200])("accepts an appearance contrast in range: %s", (value) => {
151 expect(decodeClientSettings({ appearanceContrast: value }).appearanceContrast).toBe(value);
152 expect(decodeClientSettingsPatch({ appearanceContrast: value }).appearanceContrast).toBe(value);
153 });
154});
155​
156describe("ClientSettings panel animations", () => {
157 it("defaults to instant changes", () => {
158 expect(decodeClientSettings({}).panelAnimationDurationMs).toBe(0);
159 });
160​
161 it.each([0, 400])("accepts a panel animation duration: %s", (value) => {
162 expect(decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toEqual({
163 panelAnimationDurationMs: value,
164 });
165 });
166​
167 it.each([-1, 401, 150.5])("rejects an invalid panel animation duration: %s", (value) => {
168 expect(() => decodeClientSettingsPatch({ panelAnimationDurationMs: value })).toThrow();
169 });
170});
171​
172describe("ClientSettings environment identification", () => {
173 it("defaults to artwork and accepts each presentation mode", () => {
174 expect(decodeClientSettings({}).environmentIdentificationMode).toBe("artwork");
175​
176 for (const mode of ["artwork", "pill", "none"] as const) {
177 expect(
178 decodeClientSettingsPatch({ environmentIdentificationMode: mode })
179 .environmentIdentificationMode,
180 ).toBe(mode);
181 }
182 });
183​
184 it("rejects unsupported presentation modes", () => {
185 expect(() => decodeClientSettings({ environmentIdentificationMode: "badge" })).toThrow();
186 expect(() => decodeClientSettingsPatch({ environmentIdentificationMode: "badge" })).toThrow();
187 });
188});
189​
190describe("ClientSettings sidebar", () => {
191 it("defaults to the current sidebar", () => {
192 expect(decodeClientSettings({}).legacySidebarEnabled).toBe(false);
193 });
194​
195 it("drops the retired sidebar v2 beta keys, resetting everyone to the default", () => {
196 const decoded = decodeClientSettings({
197 sidebarV2Enabled: false,
198 sidebarV2ConfiguredByUser: true,
199 });
200 expect(decoded.legacySidebarEnabled).toBe(false);
201 expect(decoded).not.toHaveProperty("sidebarV2Enabled");
202 expect(decoded).not.toHaveProperty("sidebarV2ConfiguredByUser");
203 });
204​
205 it("preserves an explicit legacy sidebar opt-in", () => {
206 expect(decodeClientSettings({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(true);
207 expect(decodeClientSettingsPatch({ legacySidebarEnabled: true }).legacySidebarEnabled).toBe(
208 true,
209 );
210 });
211​
212 it("keeps unpin confirmation opt-in and patchable", () => {
213 expect(decodeClientSettings({}).confirmThreadUnpin).toBe(false);
214 expect(decodeClientSettingsPatch({ confirmThreadUnpin: true }).confirmThreadUnpin).toBe(true);
215 expect(() => decodeClientSettingsPatch({ confirmThreadUnpin: "yes" })).toThrow();
216 });
217});
218​
219describe("ClientSettings context window meter", () => {
220 it("defaults off and preserves an explicit legacy opt-in", () => {
221 expect(decodeClientSettings({}).contextWindowMeterEnabled).toBe(false);
222 expect(
223 decodeClientSettings({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
224 ).toBe(true);
225 expect(
226 decodeClientSettingsPatch({ contextWindowMeterEnabled: true }).contextWindowMeterEnabled,
227 ).toBe(true);
228 });
229});
230​
231describe("ServerSettings thread settlement", () => {
232 it("defaults merge settlement on and inactivity settlement to three days", () => {
233 const settings = decodeServerSettings({});
234 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
235 expect(settings.sidebarAutoSettleOnMerge).toBe(true);
236 });
237​
238 it("allows both automatic rules to be disabled", () => {
239 expect(
240 decodeServerSettings({
241 sidebarAutoSettleAfterDays: null,
242 sidebarAutoSettleOnMerge: false,
243 }),
244 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
245 expect(
246 decodeServerSettingsPatch({
247 sidebarAutoSettleAfterDays: null,
248 sidebarAutoSettleOnMerge: false,
249 }),
250 ).toMatchObject({ sidebarAutoSettleAfterDays: null, sidebarAutoSettleOnMerge: false });
251 });
252​
253 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
254 expect(() => decodeServerSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
255 expect(() => decodeServerSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
256 });
257});
258​
259describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
260 it("defaults text generation to Luna at low reasoning effort", () => {
261 expect(DEFAULT_SERVER_SETTINGS.textGenerationModelSelection).toEqual({
262 instanceId: ProviderInstanceId.make("codex"),
263 model: "gpt-5.6-luna",
264 options: [{ id: "reasoningEffort", value: "low" }],
265 });
266 });
267​
268 it("defaults to an empty record so legacy configs without the key still decode", () => {
269 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
270 });
271​
272 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
273 const decoded = decodeServerSettings({});
274 expect(decoded.providerInstances).toEqual({});
275 // Legacy `providers` struct is still hydrated with its per-driver defaults
276 // so existing call sites keep working through the migration.
277 expect(decoded.providers.codex.enabled).toBe(true);
278 });
279​
280 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
281 const decoded = decodeServerSettings({
282 providerInstances: {
283 codex_personal: {
284 driver: "codex",
285 displayName: "Codex (personal)",
286 config: { homePath: "~/.codex_personal" },
287 },
288 codex_work: {
289 driver: "codex",
290 config: { homePath: "~/.codex_work" },
291 },
292 ollama_local: {
293 driver: "ollama",
294 displayName: "Ollama (local)",
295 config: { endpoint: "http://localhost:11434" },
296 },
297 },
298 });
299 const personalId = ProviderInstanceId.make("codex_personal");
300 const workId = ProviderInstanceId.make("codex_work");
301 const ollamaId = ProviderInstanceId.make("ollama_local");
302​
303 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
304 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
305 // Critical: a config naming a driver this build does not know about
306 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
307 // The runtime handles "driver not installed" — the schema must not.
308 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
309 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
310 endpoint: "http://localhost:11434",
311 });
312 });
313​
314 it("rejects instance keys that violate the slug pattern", () => {
315 expect(() =>
316 decodeServerSettings({
317 providerInstances: { "1bad": { driver: "codex" } },
318 }),
319 ).toThrow();
320 });
321});
322​
323describe("provider enabled defaults", () => {
324 it("enables only the stable bindings by default", () => {
325 const decoded = decodeServerSettings({});
326 expect(decoded.providers.codex.enabled).toBe(true);
327 expect(decoded.providers.claudeAgent.enabled).toBe(true);
328 expect(decoded.providers.cursor.enabled).toBe(false);
329 expect(decoded.providers.grok.enabled).toBe(false);
330 expect(decoded.providers.opencode.enabled).toBe(false);
331 });
332​
333 it("derives per-driver defaults from the settings schemas", () => {
334 expect(defaultEnabledForDriver(ProviderDriverKind.make("codex"))).toBe(true);
335 expect(defaultEnabledForDriver(ProviderDriverKind.make("cursor"))).toBe(false);
336 expect(defaultEnabledForDriver(ProviderDriverKind.make("grok"))).toBe(false);
337 // Unknown fork drivers stay enabled; their own build decides otherwise.
338 expect(defaultEnabledForDriver(ProviderDriverKind.make("ollama"))).toBe(true);
339 });
340​
341 it("keeps Cursor enabled when an existing user explicitly opted in", () => {
342 const cursor = ProviderDriverKind.make("cursor");
343 const cursorId = ProviderInstanceId.make("cursor");
344 const decoded = decodeServerSettings({
345 providers: { cursor: { enabled: true } },
346 providerInstances: {
347 [cursorId]: { driver: cursor, enabled: true, config: {} },
348 },
349 });
350​
351 expect(decoded.providers.cursor.enabled).toBe(true);
352 expect(resolveProviderInstanceEnabled(decoded.providerInstances[cursorId]!)).toBe(true);
353 });
354​
355 it("resolves instance enabled state with explicit false winning", () => {
356 const grok = ProviderDriverKind.make("grok");
357 const codex = ProviderDriverKind.make("codex");
358 // No flags anywhere: driver default applies.
359 expect(resolveProviderInstanceEnabled({ driver: grok, config: {} })).toBe(false);
360 expect(resolveProviderInstanceEnabled({ driver: codex, config: {} })).toBe(true);
361 // Envelope flag wins over the driver default.
362 expect(resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: {} })).toBe(true);
363 expect(resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: {} })).toBe(
364 false,
365 );
366 // Legacy in-config flag fills in when the envelope is silent.
367 expect(resolveProviderInstanceEnabled({ driver: grok, config: { enabled: true } })).toBe(true);
368 // Conflicting flags: the explicit false wins, whichever side it is on.
369 expect(
370 resolveProviderInstanceEnabled({ driver: grok, enabled: true, config: { enabled: false } }),
371 ).toBe(false);
372 expect(
373 resolveProviderInstanceEnabled({ driver: codex, enabled: false, config: { enabled: true } }),
374 ).toBe(false);
375 });
376});
377​
378describe("ServerSettings worktree defaults", () => {
379 it("defaults start-from-origin on for legacy configs", () => {
380 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
381 });
382​
383 it("accepts start-from-origin updates", () => {
384 expect(
385 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
386 ).toBe(false);
387 });
388});
389​
390describe("ServerSettings.sourceControlWritingStyle", () => {
391 it("defaults all style settings for legacy configs", () => {
392 const settings = decodeServerSettings({});
393​
394 expect(settings.sourceControlWritingStyle).toEqual({
395 mode: "repo_conventions",
396 customInstructions: "",
397 followChangeRequestTemplates: true,
398 });
399 expect(settings.sourceControlWriterModelSelection).toBeNull();
400 });
401​
402 it("trims partial style updates", () => {
403 const patch = decodeServerSettingsPatch({
404 sourceControlWritingStyle: {
405 mode: "custom",
406 customInstructions: " Prefer concise wording. ",
407 },
408 });
409​
410 expect(patch.sourceControlWritingStyle).toEqual({
411 mode: "custom",
412 customInstructions: "Prefer concise wording.",
413 });
414 });
415});
416​
417describe("ServerSettingsPatch.providerInstances", () => {
418 it("treats providerInstances as an optional whole-map replacement", () => {
419 const patch = decodeServerSettingsPatch({});
420 expect(patch.providerInstances).toBeUndefined();
421​
422 const replacement = decodeServerSettingsPatch({
423 providerInstances: {
424 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
425 },
426 });
427 expect(replacement.providerInstances).toBeDefined();
428 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
429 "codex",
430 );
431 });
432​
433 it("preserves a fork-defined driver entry through patch decoding", () => {
434 const patch = decodeServerSettingsPatch({
435 providerInstances: {
436 ollama_local: {
437 driver: "ollama",
438 config: { endpoint: "http://localhost:11434" },
439 },
440 },
441 });
442 const ollamaId = ProviderInstanceId.make("ollama_local");
443 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
444 });
445});
446​
447describe("ServerSettingsPatch string normalization", () => {
448 it("trims string settings while decoding patches", () => {
449 const patch = decodeServerSettingsPatch({
450 addProjectBaseDirectory: " ~/Development ",
451 textGenerationModelSelection: { model: " gpt-5.4-mini " },
452 observability: {
453 otlpTracesUrl: " http://localhost:4318/v1/traces ",
454 },
455 providers: {
456 codex: {
457 binaryPath: " /opt/homebrew/bin/codex ",
458 homePath: " ~/.codex ",
459 launchArgs: " --strict-config --enable foo ",
460 },
461 },
462 providerInstances: {
463 codex_personal: {
464 driver: " codex ",
465 displayName: " Codex Personal ",
466 config: { homePath: " ~/.codex-personal " },
467 },
468 },
469 });
470​
471 expect(patch.addProjectBaseDirectory).toBe("~/Development");
472 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
473 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
474 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
475 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
476 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
477 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
478 "codex",
479 );
480 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
481 "Codex Personal",
482 );
483 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
484 homePath: " ~/.codex-personal ",
485 });
486 });
487​
488 it("trims encoded server settings values before validation", () => {
489 const defaultSettings = decodeServerSettings({});
490 const encoded = encodeServerSettings({
491 ...defaultSettings,
492 addProjectBaseDirectory: " ~/Development ",
493 providers: {
494 ...defaultSettings.providers,
495 codex: {
496 ...defaultSettings.providers.codex,
497 binaryPath: " /opt/homebrew/bin/codex ",
498 launchArgs: " --strict-config ",
499 },
500 },
501 });
502​
503 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
504 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
505 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
506 });
507});
508​
509describe("ServerSettings environment icon", () => {
510 it("defaults to null", () => {
511 expect(decodeServerSettings({}).environmentIcon).toBeNull();
512 });
513​
514 it("keeps a kind this build knows", () => {
515 expect(decodeServerSettings({ environmentIcon: "mac-mini" }).environmentIcon).toBe("mac-mini");
516 });
517​
518 it("decodes a kind from a newer server as null instead of failing the snapshot", () => {
519 expect(decodeServerSettings({ environmentIcon: "toaster" }).environmentIcon).toBeNull();
520 });
521​
522 it("round-trips through encode", () => {
523 const settings = decodeServerSettings({ environmentIcon: "laptop" });
524 expect(encodeServerSettings(settings).environmentIcon).toBe("laptop");
525 });
526});