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

settings.test.ts

360 lines12.9 KB

1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3​
4import { ProviderInstanceId } from "./providerInstance.ts";
5import {
6 ClientSettingsSchema,
7 ClientSettingsPatch,
8 DEFAULT_SERVER_SETTINGS,
9 ServerSettings,
10 ServerSettingsPatch,
11} from "./settings.ts";
12​
13const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
14const decodeClientSettingsPatch = Schema.decodeUnknownSync(ClientSettingsPatch);
15const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
16const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
17const encodeServerSettings = Schema.encodeSync(ServerSettings);
18​
19describe("ClientSettings Cua integration", () => {
20 it("defaults computer use off", () => {
21 expect(decodeClientSettings({}).enableCua).toBe(false);
22 });
23​
24 it("accepts computer use updates", () => {
25 expect(decodeClientSettingsPatch({ enableCua: true }).enableCua).toBe(true);
26 });
27});
28​
29describe("ClientSettings composer context strip", () => {
30 it("defaults to draft-only and accepts a persistent strip preference", () => {
31 expect(decodeClientSettings({}).persistComposerContextStrip).toBe(false);
32 expect(
33 decodeClientSettingsPatch({ persistComposerContextStrip: true }).persistComposerContextStrip,
34 ).toBe(true);
35 });
36});
37​
38describe("ClientSettings word wrap", () => {
39 it("defaults word wrap on", () => {
40 expect(decodeClientSettings({}).wordWrap).toBe(true);
41 });
42​
43 it("ignores obsolete wrapping preferences", () => {
44 const decoded = decodeClientSettings({
45 chatWordWrap: false,
46 diffWordWrap: false,
47 });
48​
49 expect(decoded.wordWrap).toBe(true);
50 expect(decoded).not.toHaveProperty("chatWordWrap");
51 expect(decoded).not.toHaveProperty("diffWordWrap");
52 });
53});
54​
55describe("ClientSettings glass opacity", () => {
56 it("defaults to a readable translucent surface", () => {
57 expect(decodeClientSettings({}).glassOpacity).toBe(80);
58 });
59​
60 it.each([39, 101, 72.5])("rejects an invalid glass opacity: %s", (value) => {
61 expect(() => decodeClientSettings({ glassOpacity: value })).toThrow();
62 expect(() => decodeClientSettingsPatch({ glassOpacity: value })).toThrow();
63 });
64​
65 it.each([40, 75, 100])("accepts a glass opacity within the supported range: %s", (value) => {
66 expect(decodeClientSettings({ glassOpacity: value }).glassOpacity).toBe(value);
67 expect(decodeClientSettingsPatch({ glassOpacity: value }).glassOpacity).toBe(value);
68 });
69});
70​
71describe("ClientSettings environment identification", () => {
72 it("defaults to artwork and accepts each presentation mode", () => {
73 expect(decodeClientSettings({}).environmentIdentificationMode).toBe("artwork");
74​
75 for (const mode of ["artwork", "pill", "none"] as const) {
76 expect(
77 decodeClientSettingsPatch({ environmentIdentificationMode: mode })
78 .environmentIdentificationMode,
79 ).toBe(mode);
80 }
81 });
82​
83 it("rejects unsupported presentation modes", () => {
84 expect(() => decodeClientSettings({ environmentIdentificationMode: "badge" })).toThrow();
85 expect(() => decodeClientSettingsPatch({ environmentIdentificationMode: "badge" })).toThrow();
86 });
87});
88​
89describe("ClientSettings sidebar v2", () => {
90 it("defaults the beta off with a three-day auto-settle threshold", () => {
91 const settings = decodeClientSettings({});
92 expect(settings.sidebarV2Enabled).toBe(false);
93 expect(settings.sidebarAutoSettleAfterDays).toBe(3);
94 });
95​
96 it("treats settings written before the beta had a per-channel default as unconfigured", () => {
97 // The stored blob always carries `sidebarV2Enabled`, so only the companion
98 // flag can distinguish "user opted out" from "never touched it".
99 expect(decodeClientSettings({ sidebarV2Enabled: false }).sidebarV2ConfiguredByUser).toBe(false);
100 expect(decodeClientSettings({ sidebarV2Enabled: true }).sidebarV2ConfiguredByUser).toBe(false);
101 });
102​
103 it("preserves an explicit beta choice", () => {
104 const settings = decodeClientSettings({
105 sidebarV2Enabled: false,
106 sidebarV2ConfiguredByUser: true,
107 });
108 expect(settings.sidebarV2Enabled).toBe(false);
109 expect(settings.sidebarV2ConfiguredByUser).toBe(true);
110 });
111​
112 it("carries an explicit beta opt-out through the patch the beta toggle writes", () => {
113 const patch = decodeClientSettingsPatch({
114 sidebarV2Enabled: false,
115 sidebarV2ConfiguredByUser: true,
116 });
117 expect(patch.sidebarV2Enabled).toBe(false);
118 expect(patch.sidebarV2ConfiguredByUser).toBe(true);
119 });
120​
121 it("allows auto-settle by inactivity to be disabled", () => {
122 expect(
123 decodeClientSettings({ sidebarAutoSettleAfterDays: null }).sidebarAutoSettleAfterDays,
124 ).toBeNull();
125 });
126​
127 it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
128 expect(() => decodeClientSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
129 expect(() => decodeClientSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
130 });
131});
132​
133describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
134 it("defaults text generation to Luna at low reasoning effort", () => {
135 expect(DEFAULT_SERVER_SETTINGS.textGenerationModelSelection).toEqual({
136 instanceId: ProviderInstanceId.make("codex"),
137 model: "gpt-5.6-luna",
138 options: [{ id: "reasoningEffort", value: "low" }],
139 });
140 });
141​
142 it("defaults to an empty record so legacy configs without the key still decode", () => {
143 expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
144 });
145​
146 it("decodes a fully empty config (legacy on-disk shape) without complaint", () => {
147 const decoded = decodeServerSettings({});
148 expect(decoded.providerInstances).toEqual({});
149 // Legacy `providers` struct is still hydrated with its per-driver defaults
150 // so existing call sites keep working through the migration.
151 expect(decoded.providers.codex.enabled).toBe(true);
152 });
153​
154 it("decodes a multi-instance map mixing first-party and fork drivers", () => {
155 const decoded = decodeServerSettings({
156 providerInstances: {
157 codex_personal: {
158 driver: "codex",
159 displayName: "Codex (personal)",
160 config: { homePath: "~/.codex_personal" },
161 },
162 codex_work: {
163 driver: "codex",
164 config: { homePath: "~/.codex_work" },
165 },
166 ollama_local: {
167 driver: "ollama",
168 displayName: "Ollama (local)",
169 config: { endpoint: "http://localhost:11434" },
170 },
171 },
172 });
173 const personalId = ProviderInstanceId.make("codex_personal");
174 const workId = ProviderInstanceId.make("codex_work");
175 const ollamaId = ProviderInstanceId.make("ollama_local");
176​
177 expect(decoded.providerInstances[personalId]?.driver).toBe("codex");
178 expect(decoded.providerInstances[workId]?.config).toEqual({ homePath: "~/.codex_work" });
179 // Critical: a config naming a driver this build does not know about
180 // (`ollama` is not in `ProviderDriverKind`) must round-trip without loss.
181 // The runtime handles "driver not installed" — the schema must not.
182 expect(decoded.providerInstances[ollamaId]?.driver).toBe("ollama");
183 expect(decoded.providerInstances[ollamaId]?.config).toEqual({
184 endpoint: "http://localhost:11434",
185 });
186 });
187​
188 it("rejects instance keys that violate the slug pattern", () => {
189 expect(() =>
190 decodeServerSettings({
191 providerInstances: { "1bad": { driver: "codex" } },
192 }),
193 ).toThrow();
194 });
195});
196​
197describe("ServerSettings worktree defaults", () => {
198 it("defaults start-from-origin on for legacy configs", () => {
199 expect(decodeServerSettings({}).newWorktreesStartFromOrigin).toBe(true);
200 });
201​
202 it("accepts start-from-origin updates", () => {
203 expect(
204 decodeServerSettingsPatch({ newWorktreesStartFromOrigin: false }).newWorktreesStartFromOrigin,
205 ).toBe(false);
206 });
207});
208​
209describe("ServerSettings Cursor legacy settings", () => {
210 it("ignores obsolete Cursor CLI settings when reading server settings", () => {
211 const decoded = decodeServerSettings({
212 providers: {
213 cursor: {
214 enabled: true,
215 binaryPath: "cursor-agent",
216 apiEndpoint: "http://127.0.0.1:3774",
217 },
218 },
219 });
220​
221 expect(decoded.providers.cursor.enabled).toBe(true);
222 expect(decoded.providers.cursor).not.toHaveProperty("binaryPath");
223 expect(decoded.providers.cursor).not.toHaveProperty("apiEndpoint");
224 });
225​
226 it("ignores obsolete Cursor CLI settings in patches", () => {
227 const patch = decodeServerSettingsPatch({
228 providers: {
229 cursor: {
230 enabled: true,
231 binaryPath: "cursor-agent",
232 apiEndpoint: "http://127.0.0.1:3774",
233 },
234 },
235 });
236​
237 expect(patch.providers?.cursor?.enabled).toBe(true);
238 expect(patch.providers?.cursor).not.toHaveProperty("binaryPath");
239 expect(patch.providers?.cursor).not.toHaveProperty("apiEndpoint");
240 });
241});
242​
243describe("ServerSettings.sourceControlWritingStyle", () => {
244 it("defaults all style settings for legacy configs", () => {
245 const settings = decodeServerSettings({});
246​
247 expect(settings.sourceControlWritingStyle).toEqual({
248 mode: "repo_conventions",
249 customInstructions: "",
250 followChangeRequestTemplates: true,
251 });
252 expect(settings.sourceControlWriterModelSelection).toBeNull();
253 });
254​
255 it("trims partial style updates", () => {
256 const patch = decodeServerSettingsPatch({
257 sourceControlWritingStyle: {
258 mode: "custom",
259 customInstructions: " Prefer concise wording. ",
260 },
261 });
262​
263 expect(patch.sourceControlWritingStyle).toEqual({
264 mode: "custom",
265 customInstructions: "Prefer concise wording.",
266 });
267 });
268});
269​
270describe("ServerSettingsPatch.providerInstances", () => {
271 it("treats providerInstances as an optional whole-map replacement", () => {
272 const patch = decodeServerSettingsPatch({});
273 expect(patch.providerInstances).toBeUndefined();
274​
275 const replacement = decodeServerSettingsPatch({
276 providerInstances: {
277 codex_personal: { driver: "codex", config: { homePath: "~/.codex" } },
278 },
279 });
280 expect(replacement.providerInstances).toBeDefined();
281 expect(replacement.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
282 "codex",
283 );
284 });
285​
286 it("preserves a fork-defined driver entry through patch decoding", () => {
287 const patch = decodeServerSettingsPatch({
288 providerInstances: {
289 ollama_local: {
290 driver: "ollama",
291 config: { endpoint: "http://localhost:11434" },
292 },
293 },
294 });
295 const ollamaId = ProviderInstanceId.make("ollama_local");
296 expect(patch.providerInstances?.[ollamaId]?.driver).toBe("ollama");
297 });
298});
299​
300describe("ServerSettingsPatch string normalization", () => {
301 it("trims string settings while decoding patches", () => {
302 const patch = decodeServerSettingsPatch({
303 addProjectBaseDirectory: " ~/Development ",
304 textGenerationModelSelection: { model: " gpt-5.4-mini " },
305 observability: {
306 otlpTracesUrl: " http://localhost:4318/v1/traces ",
307 },
308 providers: {
309 codex: {
310 binaryPath: " /opt/homebrew/bin/codex ",
311 homePath: " ~/.codex ",
312 launchArgs: " --strict-config --enable foo ",
313 },
314 },
315 providerInstances: {
316 codex_personal: {
317 driver: " codex ",
318 displayName: " Codex Personal ",
319 config: { homePath: " ~/.codex-personal " },
320 },
321 },
322 });
323​
324 expect(patch.addProjectBaseDirectory).toBe("~/Development");
325 expect(patch.textGenerationModelSelection?.model).toBe("gpt-5.4-mini");
326 expect(patch.observability?.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
327 expect(patch.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
328 expect(patch.providers?.codex?.homePath).toBe("~/.codex");
329 expect(patch.providers?.codex?.launchArgs).toBe("--strict-config --enable foo");
330 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.driver).toBe(
331 "codex",
332 );
333 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.displayName).toBe(
334 "Codex Personal",
335 );
336 expect(patch.providerInstances?.[ProviderInstanceId.make("codex_personal")]?.config).toEqual({
337 homePath: " ~/.codex-personal ",
338 });
339 });
340​
341 it("trims encoded server settings values before validation", () => {
342 const defaultSettings = decodeServerSettings({});
343 const encoded = encodeServerSettings({
344 ...defaultSettings,
345 addProjectBaseDirectory: " ~/Development ",
346 providers: {
347 ...defaultSettings.providers,
348 codex: {
349 ...defaultSettings.providers.codex,
350 binaryPath: " /opt/homebrew/bin/codex ",
351 launchArgs: " --strict-config ",
352 },
353 },
354 });
355​
356 expect(encoded.addProjectBaseDirectory).toBe("~/Development");
357 expect(encoded.providers?.codex?.binaryPath).toBe("/opt/homebrew/bin/codex");
358 expect(encoded.providers?.codex?.launchArgs).toBe("--strict-config");
359 });
360});