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

settings.test.ts

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