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