Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import { EnvironmentId } from "@t3tools/contracts";
3
4import {
5 filterAvailableSettingsSearchItems,
6 getSettingsSearchTargetScope,
7 getThreadAutoSettlementSearchAvailability,
8 isSettingsOverviewVisible,
9 isSettingsSearchScopeAvailable,
10 searchableSetting,
11 searchSettings,
12 SETTINGS_SEARCH_ITEMS,
13 type SettingsSearchItem,
14} from "./settingsSearch";
15
16const ITEMS: ReadonlyArray<SettingsSearchItem> = [
17 {
18 id: "word-wrap",
19 title: "Word wrap",
20 to: "/settings/general",
21 searchTerms: ["long lines in code previews"],
22 },
23 {
24 id: "network-access",
25 title: "Network access",
26 to: "/settings/connections",
27 searchTerms: ["remote pairing backend"],
28 },
29 {
30 id: "providers",
31 title: "Providers",
32 to: "/settings/providers",
33 searchTerms: ["claude codex agents"],
34 },
35 {
36 id: "provider-updates",
37 title: "Update checks",
38 to: "/settings/general",
39 },
40 {
41 id: "automatic-updates",
42 title: "Automatic updates",
43 to: "/settings/general",
44 },
45];
46
47describe("searchSettings", () => {
48 it("matches titles, sections, and remembered setting details", () => {
49 expect(searchSettings("word", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
50 expect(searchSettings("network", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
51 expect(searchSettings("connections", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
52 expect(searchSettings("claude", ITEMS).map((item) => item.id)).toEqual(["providers"]);
53 expect(searchSettings("long lines", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
54 });
55
56 it("matches normalized title substrings", () => {
57 expect(searchSettings(" WORD WRAP ", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
58 expect(searchSettings("glass").map((item) => item.id)).toEqual(["setting-glass-opacity"]);
59 expect(searchSettings("panel animations").map((item) => item.id)).toEqual(["panel-animations"]);
60 expect(searchSettings("thè\u{1ab0}mes")[0]?.id).toBe("theme");
61 const localeLowerCase = vi.spyOn(String.prototype, "toLocaleLowerCase").mockReturnValue("gıt");
62 try {
63 expect(searchSettings("GIT")[0]?.id).toBe("git-fetch-interval");
64 expect(localeLowerCase).not.toHaveBeenCalled();
65 } finally {
66 localeLowerCase.mockRestore();
67 }
68 expect(searchSettings("xyzzy")).toEqual([]);
69 });
70
71 it("keeps catalog order for multiple title matches", () => {
72 expect(searchSettings("update", ITEMS).map((item) => item.id)).toEqual([
73 "provider-updates",
74 "automatic-updates",
75 ]);
76 });
77
78 it("matches query words across fields and ranks the strongest result first", () => {
79 expect(searchSettings("pairing remote", ITEMS).map((item) => item.id)).toEqual([
80 "network-access",
81 ]);
82 expect(
83 searchSettings("remote pairing")
84 .slice(0, 2)
85 .map((item) => item.id),
86 ).toEqual(["network-access", "connections-environment"]);
87 });
88
89 it("finds settings that used to be reachable only through their section", () => {
90 expect(searchSettings("pull request template")[0]?.id).toBe("follow-change-request-templates");
91 expect(searchSettings("git security keys")[0]?.id).toBe("git-fetch-interval");
92 expect(searchSettings("push notifications")[0]?.id).toBe("publish-agent-activity");
93 expect(searchSettings("battery saver")[0]?.id).toBe("background-activity");
94 expect(searchSettings("binary path")[0]?.id).toBe("providers");
95 expect(searchSettings("Antigravity")[0]?.id).toBe("providers");
96 expect(searchSettings("Google sign in")[0]?.id).toBe("providers");
97 expect(searchSettings("authorized clients")[0]?.id).toBe("connections-environment");
98 expect(searchSettings("administrative access")[0]?.id).toBe("connections-environment");
99 });
100
101 it("lists thread confirmations in panel order", () => {
102 expect(searchSettings("confirmation").map((item) => item.id)).toEqual([
103 "unpin-confirmation",
104 "archive-confirmation",
105 "delete-confirmation",
106 ]);
107 });
108
109 it.each(["usage providers", "CLIProxyAPI", "CLI proxy hub", "management key"])(
110 "finds usage-provider management by %s",
111 (query) => {
112 expect(searchSettings(query)[0]).toMatchObject({
113 id: "usage-providers",
114 to: "/settings/providers",
115 });
116 },
117 );
118
119 it("returns no results for an empty query", () => {
120 expect(searchSettings(" ", ITEMS)).toEqual([]);
121 });
122
123 it("hides desktop-only settings from browser search", () => {
124 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
125 expect(searchSettings("hold to quit")).toEqual([]);
126 expect(searchSettings("wsl")).toEqual([]);
127 });
128
129 it("hides macOS-only settings on other platforms", () => {
130 vi.stubGlobal("navigator", { platform: "Win32" });
131 try {
132 expect(searchSettings("font smoothing")).toEqual([]);
133 } finally {
134 vi.unstubAllGlobals();
135 }
136 });
137
138 it("registers the WSL backend as a desktop-only setting", () => {
139 expect(SETTINGS_SEARCH_ITEMS.find((item) => item.id === "wsl-backend")).toMatchObject({
140 id: "wsl-backend",
141 title: "WSL backend",
142 to: "/settings/connections",
143 desktopOnly: true,
144 windowsOnly: true,
145 });
146 });
147
148 it("hides settings whose controls are unavailable", () => {
149 const available = filterAvailableSettingsSearchItems({
150 hasCloudPublicConfig: false,
151 hasEnvironment: false,
152 hasProviderSettingsEnvironment: false,
153 canManageLocalBackend: false,
154 isWslSettingsRowVisible: false,
155 hasThreadAutoSettlement: false,
156 });
157
158 const gatedIds = new Set<string>([
159 "follow-change-request-templates",
160 "git-fetch-interval",
161 "network-access",
162 "publish-agent-activity",
163 "provider-health-check-interval",
164 "source-control-writer-model",
165 "source-control-writing-style",
166 "t3-connect",
167 "tailscale-https",
168 "wsl-backend",
169 "auto-settle-inactive-threads",
170 "auto-settle-merged-threads",
171 "days-before-auto-settle",
172 ]);
173 expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]);
174 });
175
176 it("shows automatic settlement settings when the server supports them", () => {
177 const available = filterAvailableSettingsSearchItems({
178 hasCloudPublicConfig: false,
179 hasEnvironment: false,
180 hasProviderSettingsEnvironment: false,
181 canManageLocalBackend: false,
182 isWslSettingsRowVisible: false,
183 hasThreadAutoSettlement: true,
184 });
185
186 expect(searchSettings("auto-settle", available).map((item) => item.id)).toEqual([
187 "auto-settle-inactive-threads",
188 "auto-settle-merged-threads",
189 "days-before-auto-settle",
190 ]);
191 });
192
193 it("keeps catalog result ids unique", () => {
194 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
195 expect(new Set(ids).size).toBe(ids.length);
196 });
197
198 it("serves anchor props to panels from the catalog", () => {
199 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
200 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
201 });
202
203 it("routes appearance settings to their current section", () => {
204 expect(searchSettings("theme")[0]).toMatchObject({
205 id: "theme",
206 to: "/settings/appearance",
207 });
208 expect(searchSettings("word wrap")[0]).toMatchObject({
209 id: "word-wrap",
210 to: "/settings/appearance",
211 });
212 expect(searchSettings("environment identification")[0]).toMatchObject({
213 id: "environment-identification",
214 to: "/settings/appearance",
215 targetId: "appearance-interface",
216 });
217 });
218
219 it("routes conditional window capture settings to the stable toggle row", () => {
220 const targets = [
221 "capture accessibility data",
222 "capture shortcut",
223 "capture sound",
224 "capture flash",
225 "capture animations",
226 ].map((query) => {
227 const match = searchSettings(query)[0];
228 return [match?.id, match?.targetId];
229 });
230
231 expect(targets).toEqual([
232 ["snap-shot-accessibility", "snap-shot-enabled"],
233 ["snap-shot-shortcut", "snap-shot-enabled"],
234 ["snap-shot-sound", "snap-shot-enabled"],
235 ["snap-shot-flash", "snap-shot-enabled"],
236 ["snap-shot-animations", "snap-shot-enabled"],
237 ]);
238 });
239
240 it("routes browser recording quality to integrations", () => {
241 const result = searchSettings("recording frame rate")[0];
242 expect(result).toMatchObject({
243 id: "browser-recording-frame-rate",
244 to: "/settings/integrations",
245 });
246 expect(result).not.toHaveProperty("targetId");
247 });
248
249 it("routes where links open to integrations", () => {
250 expect(searchSettings("open links in")[0]).toMatchObject({
251 id: "browser-link-target",
252 to: "/settings/integrations",
253 });
254 expect(searchSettings("external links")[0]).toMatchObject({ id: "browser-link-target" });
255 });
256
257 it("finds the default browser profile action in the profiles list", () => {
258 expect(searchSettings("default profile")[0]).toMatchObject({
259 id: "browser-default-profile",
260 to: "/settings/integrations",
261 targetId: "browser-profiles",
262 });
263 });
264
265 it.each([
266 ["default model", "default-model", "/settings/general"],
267 ["new threads", "new-threads", "/settings/general"],
268 ["agent browser access", "agent-browser-access", "/settings/integrations"],
269 ["automatically pull", "automatic-pull", "/settings/source-control"],
270 ["actions", "project-actions", "/settings/projects"],
271 ["project overview", "project-overview", "/settings/projects"],
272 ])("routes %s to its owning category", (query, id, to) => {
273 expect(searchSettings(query)[0]).toMatchObject({ id, to });
274 });
275
276 it("keeps environment settings discoverable without a primary environment", () => {
277 const available = filterAvailableSettingsSearchItems({
278 hasCloudPublicConfig: false,
279 hasEnvironment: true,
280 hasProviderSettingsEnvironment: true,
281 canManageLocalBackend: false,
282 isWslSettingsRowVisible: false,
283 hasThreadAutoSettlement: true,
284 });
285 expect(searchSettings("writing style", available)[0]?.id).toBe("source-control-writing-style");
286 expect(searchSettings("auto-settle", available)).toHaveLength(3);
287 });
288});
289
290describe("settings search targets", () => {
291 it.each([
292 "auto-settle-inactive-threads",
293 "auto-settle-merged-threads",
294 "days-before-auto-settle",
295 ])("retains the capability requirement for %s", (targetId) => {
296 expect(getSettingsSearchTargetScope(targetId)).toMatchObject({
297 scope: "project-defaults",
298 requiresThreadAutoSettlement: true,
299 });
300 });
301
302 it("treats device-local rows as reachable from every selection", () => {
303 const setting = getSettingsSearchTargetScope("time-format")!;
304 expect(setting).toEqual({ title: "Time format", scope: null });
305 expect(isSettingsSearchScopeAvailable(setting.scope, "project")).toBe(true);
306 expect(isSettingsSearchScopeAvailable(setting.scope, "all")).toBe(true);
307 expect(getSettingsSearchTargetScope("appearance")).toMatchObject({ scope: null });
308 expect(getSettingsSearchTargetScope("missing-setting")).toBeNull();
309 });
310
311 it.each(["all", "environment", "project", "checkout"] as const)(
312 "makes browser access editable at the %s scope",
313 (kind) => {
314 const setting = getSettingsSearchTargetScope("agent-browser-access")!;
315 expect(isSettingsSearchScopeAvailable(setting.scope, kind)).toBe(true);
316 expect(isSettingsSearchScopeAvailable(setting.scope, "unavailable")).toBe(false);
317 },
318 );
319
320 it("lets project-scopable rows resolve at every server-backed scope", () => {
321 const model = getSettingsSearchTargetScope("text-generation-model")!;
322 expect(isSettingsSearchScopeAvailable(model.scope, "all")).toBe(true);
323 expect(isSettingsSearchScopeAvailable(model.scope, "environment")).toBe(true);
324 expect(isSettingsSearchScopeAvailable(model.scope, "project")).toBe(true);
325 });
326
327 it("reaches source control discovery and git fetch interval from the default scope", () => {
328 for (const id of ["source-control", "git-fetch-interval"]) {
329 const item = getSettingsSearchTargetScope(id)!;
330 expect(isSettingsSearchScopeAvailable(item.scope, "all")).toBe(true);
331 expect(isSettingsSearchScopeAvailable(item.scope, "environment")).toBe(true);
332 expect(isSettingsSearchScopeAvailable(item.scope, "project")).toBe(false);
333 }
334 });
335
336 it("keeps environment-wide settings out of project scopes", () => {
337 const updates = getSettingsSearchTargetScope("provider-update-checks")!;
338 expect(updates.scope).toBe("environment-defaults");
339 expect(isSettingsSearchScopeAvailable(updates.scope, "environment")).toBe(true);
340 expect(isSettingsSearchScopeAvailable(updates.scope, "all")).toBe(true);
341 expect(isSettingsSearchScopeAvailable(updates.scope, "project")).toBe(false);
342 const streaming = getSettingsSearchTargetScope("response-streaming")!;
343 expect(streaming.scope).toBe("project-defaults");
344 expect(isSettingsSearchScopeAvailable(streaming.scope, "project")).toBe(true);
345 for (const id of ["legacy-plan-mode", "legacy-context-window-indicator", "legacy-sidebar"]) {
346 expect(getSettingsSearchTargetScope(id)!.scope).toBeNull();
347 }
348 });
349});
350
351describe("auto-settlement search availability", () => {
352 function environment(id: string, { connected = true, loaded = true, supported = true } = {}) {
353 return {
354 environmentId: EnvironmentId.make(id),
355 connection: { phase: connected ? ("connected" as const) : ("offline" as const) },
356 serverConfig: loaded
357 ? { environment: { capabilities: { threadAutoSettlement: supported } } }
358 : null,
359 };
360 }
361
362 const capable = environment("capable");
363 const unsupported = environment("unsupported", { supported: false });
364 const offline = environment("offline", { connected: false });
365 const loading = environment("loading", { loaded: false });
366 const environments = [capable, unsupported, offline, loading];
367
368 it("keeps results discoverable when one connected environment supports them", () => {
369 const availability = getThreadAutoSettlementSearchAvailability(environments);
370 expect(availability.eligibleEnvironmentIds).toEqual([capable.environmentId]);
371 const items = filterAvailableSettingsSearchItems({
372 hasCloudPublicConfig: false,
373 hasEnvironment: true,
374 hasProviderSettingsEnvironment: true,
375 canManageLocalBackend: false,
376 isWslSettingsRowVisible: false,
377 hasThreadAutoSettlement: availability.eligibleEnvironmentIds.length > 0,
378 });
379 expect(searchSettings("auto-settle", items).map((item) => item.id)).toEqual([
380 "auto-settle-inactive-threads",
381 "auto-settle-merged-threads",
382 "days-before-auto-settle",
383 ]);
384 });
385
386 it("offers only capable environments when an aggregate has mixed capabilities", () => {
387 expect(
388 getThreadAutoSettlementSearchAvailability(environments, {
389 kind: "all",
390 environmentIds: environments.map((entry) => entry.environmentId),
391 }),
392 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
393 });
394
395 it("allows a capable named environment regardless of other environments' capabilities", () => {
396 expect(
397 getThreadAutoSettlementSearchAvailability(environments, {
398 kind: "environment",
399 environmentIds: [capable.environmentId],
400 }).isTargetAvailable,
401 ).toBe(true);
402 });
403
404 it.each([unsupported, offline, loading])(
405 "does not render the target on $environmentId or silently fall back",
406 (selected) => {
407 expect(
408 getThreadAutoSettlementSearchAvailability(environments, {
409 kind: "environment",
410 environmentIds: [selected.environmentId],
411 }),
412 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
413 },
414 );
415
416 it("offers a capable environment instead of a dead target at an unavailable scope", () => {
417 expect(
418 getThreadAutoSettlementSearchAvailability(environments, {
419 kind: "unavailable",
420 environmentIds: [capable.environmentId],
421 }),
422 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
423 });
424
425 it("ignores offline and unloaded targets when all connected targets support the setting", () => {
426 const selected = [capable, offline, loading];
427 expect(
428 getThreadAutoSettlementSearchAvailability(selected, {
429 kind: "all",
430 environmentIds: selected.map((entry) => entry.environmentId),
431 }).isTargetAvailable,
432 ).toBe(true);
433 });
434
435 it("offers no unavailable environments when none can render the setting", () => {
436 const selected = [unsupported, offline, loading];
437 expect(
438 getThreadAutoSettlementSearchAvailability(selected, {
439 kind: "all",
440 environmentIds: selected.map((entry) => entry.environmentId),
441 }),
442 ).toEqual({ eligibleEnvironmentIds: [], isTargetAvailable: false });
443 expect(getThreadAutoSettlementSearchAvailability([]).eligibleEnvironmentIds).toEqual([]);
444 });
445});
446
447describe("settings sidebar scope", () => {
448 it("shows Overview only for project and checkout targets", () => {
449 expect(isSettingsOverviewVisible({})).toBe(false);
450 expect(isSettingsOverviewVisible({ machine: "remote" })).toBe(false);
451 expect(isSettingsOverviewVisible({ project: "project" })).toBe(true);
452 expect(isSettingsOverviewVisible({ project: "project", checkout: "checkout" })).toBe(true);
453 });
454});