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

settings.test.ts

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