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.each(["send shortcut", "multiline", "new line"])("finds Send shortcut for %s", (query) => {
49 expect(searchSettings(query).map((item) => item.id)).toContain("send-shortcut");
50 });
51
52 it("matches titles, sections, and remembered setting details", () => {
53 expect(searchSettings("word", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
54 expect(searchSettings("network", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
55 expect(searchSettings("connections", ITEMS).map((item) => item.id)).toEqual(["network-access"]);
56 expect(searchSettings("claude", ITEMS).map((item) => item.id)).toEqual(["providers"]);
57 expect(searchSettings("long lines", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
58 });
59
60 it("matches normalized title substrings", () => {
61 expect(searchSettings(" WORD WRAP ", ITEMS).map((item) => item.id)).toEqual(["word-wrap"]);
62 expect(searchSettings("glass").map((item) => item.id)).toEqual(["setting-glass-opacity"]);
63 expect(searchSettings("panel animations").map((item) => item.id)).toEqual(["panel-animations"]);
64 expect(searchSettings("thè\u{1ab0}mes")[0]?.id).toBe("theme");
65 const localeLowerCase = vi.spyOn(String.prototype, "toLocaleLowerCase").mockReturnValue("gıt");
66 try {
67 expect(searchSettings("GIT")[0]?.id).toBe("git-fetch-interval");
68 expect(localeLowerCase).not.toHaveBeenCalled();
69 } finally {
70 localeLowerCase.mockRestore();
71 }
72 expect(searchSettings("xyzzy")).toEqual([]);
73 });
74
75 it("keeps catalog order for multiple title matches", () => {
76 expect(searchSettings("update", ITEMS).map((item) => item.id)).toEqual([
77 "provider-updates",
78 "automatic-updates",
79 ]);
80 });
81
82 it("matches query words across fields and ranks the strongest result first", () => {
83 expect(searchSettings("pairing remote", ITEMS).map((item) => item.id)).toEqual([
84 "network-access",
85 ]);
86 expect(
87 searchSettings("remote pairing")
88 .slice(0, 2)
89 .map((item) => item.id),
90 ).toEqual(["network-access", "connections-environment"]);
91 });
92
93 it("finds settings that used to be reachable only through their section", () => {
94 expect(searchSettings("pull request template")[0]?.id).toBe("follow-change-request-templates");
95 expect(searchSettings("git security keys")[0]?.id).toBe("git-fetch-interval");
96 expect(searchSettings("push notifications")[0]?.id).toBe("publish-agent-activity");
97 expect(searchSettings("battery saver")[0]?.id).toBe("background-activity");
98 expect(searchSettings("binary path")[0]?.id).toBe("providers");
99 expect(searchSettings("Antigravity")[0]?.id).toBe("providers");
100 expect(searchSettings("Google sign in")[0]?.id).toBe("providers");
101 expect(searchSettings("authorized clients")[0]?.id).toBe("connections-environment");
102 expect(searchSettings("administrative access")[0]?.id).toBe("connections-environment");
103 });
104
105 it("lists thread confirmations in panel order", () => {
106 expect(searchSettings("confirmation").map((item) => item.id)).toEqual([
107 "unpin-confirmation",
108 "archive-confirmation",
109 "delete-confirmation",
110 ]);
111 });
112
113 it.each(["usage providers", "CLIProxyAPI", "CLI proxy hub", "management key"])(
114 "finds usage-provider management by %s",
115 (query) => {
116 expect(searchSettings(query)[0]).toMatchObject({
117 id: "usage-providers",
118 to: "/settings/providers",
119 });
120 },
121 );
122
123 it("returns no results for an empty query", () => {
124 expect(searchSettings(" ", ITEMS)).toEqual([]);
125 });
126
127 it("hides desktop-only settings from browser search", () => {
128 expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
129 expect(searchSettings("hold to quit")).toEqual([]);
130 expect(searchSettings("wsl")).toEqual([]);
131 });
132
133 it("hides macOS-only settings on other platforms", () => {
134 vi.stubGlobal("navigator", { platform: "Win32" });
135 try {
136 expect(searchSettings("font smoothing")).toEqual([]);
137 } finally {
138 vi.unstubAllGlobals();
139 }
140 });
141
142 it("registers the WSL backend as a desktop-only setting", () => {
143 expect(SETTINGS_SEARCH_ITEMS.find((item) => item.id === "wsl-backend")).toMatchObject({
144 id: "wsl-backend",
145 title: "WSL backend",
146 to: "/settings/connections",
147 desktopOnly: true,
148 windowsOnly: true,
149 });
150 });
151
152 it("hides settings whose controls are unavailable", () => {
153 const available = filterAvailableSettingsSearchItems({
154 hasCloudPublicConfig: false,
155 hasEnvironment: false,
156 hasProviderSettingsEnvironment: false,
157 hasMacProviderSettingsEnvironment: false,
158 canManageLocalBackend: false,
159 isWslSettingsRowVisible: false,
160 hasThreadAutoSettlement: false,
161 });
162
163 const gatedIds = new Set<string>([
164 "follow-change-request-templates",
165 "git-fetch-interval",
166 "network-access",
167 "publish-agent-activity",
168 "provider-health-check-interval",
169 "cursor-keychain-usage",
170 "source-control-writer-model",
171 "source-control-writing-style",
172 "t3-connect",
173 "hold-webhooks-while-offline",
174 "tailscale-https",
175 "wsl-backend",
176 "auto-settle-inactive-threads",
177 "auto-settle-merged-threads",
178 "days-before-auto-settle",
179 ]);
180 expect(available.map((item) => item.id).filter((id) => gatedIds.has(id))).toEqual([]);
181 });
182
183 it("offers Cursor Keychain settings only when a macOS provider environment is available", () => {
184 const availability = {
185 hasCloudPublicConfig: false,
186 hasEnvironment: true,
187 hasProviderSettingsEnvironment: true,
188 hasMacProviderSettingsEnvironment: false,
189 canManageLocalBackend: false,
190 isWslSettingsRowVisible: false,
191 hasThreadAutoSettlement: false,
192 };
193 const itemIds = (macAvailable: boolean) =>
194 filterAvailableSettingsSearchItems({
195 ...availability,
196 hasMacProviderSettingsEnvironment: macAvailable,
197 }).map((item) => item.id);
198 expect(itemIds(false)).not.toContain("cursor-keychain-usage");
199 expect(itemIds(true)).toContain("cursor-keychain-usage");
200 });
201
202 it("keeps the local toggle searchable without offering hidden host publishing controls", () => {
203 const availability = {
204 hasCloudPublicConfig: true,
205 hasEnvironment: true,
206 hasProviderSettingsEnvironment: true,
207 hasMacProviderSettingsEnvironment: false,
208 canManageLocalBackend: false,
209 isWslSettingsRowVisible: false,
210 hasThreadAutoSettlement: false,
211 };
212 const remoteOnly = filterAvailableSettingsSearchItems({
213 ...availability,
214 localEnvironmentDisabled: true,
215 }).map((item) => item.id);
216 expect(remoteOnly).toContain("local-environment");
217 expect(remoteOnly).not.toContain("t3-connect");
218 expect(remoteOnly).not.toContain("publish-agent-activity");
219 expect(remoteOnly).not.toContain("wsl-backend");
220 // Browsers without access:write still render CloudLinkRow for their host.
221 const browser = filterAvailableSettingsSearchItems(availability).map((item) => item.id);
222 expect(browser).toContain("publish-agent-activity");
223 });
224
225 it("offers webhook holding only while the managed tunnel is on, like its row", () => {
226 const availability = {
227 hasCloudPublicConfig: true,
228 hasEnvironment: true,
229 hasProviderSettingsEnvironment: true,
230 hasMacProviderSettingsEnvironment: false,
231 canManageLocalBackend: true,
232 isWslSettingsRowVisible: false,
233 hasThreadAutoSettlement: false,
234 };
235 const itemIds = (managedTunnelActive: boolean) =>
236 filterAvailableSettingsSearchItems({ ...availability, managedTunnelActive }).map(
237 (item) => item.id,
238 );
239 expect(itemIds(false)).not.toContain("hold-webhooks-while-offline");
240 expect(itemIds(true)).toContain("hold-webhooks-while-offline");
241 });
242
243 it("shows automatic settlement settings when the server supports them", () => {
244 const available = filterAvailableSettingsSearchItems({
245 hasCloudPublicConfig: false,
246 hasEnvironment: false,
247 hasProviderSettingsEnvironment: false,
248 hasMacProviderSettingsEnvironment: false,
249 canManageLocalBackend: false,
250 isWslSettingsRowVisible: false,
251 hasThreadAutoSettlement: true,
252 });
253
254 expect(searchSettings("auto-settle", available).map((item) => item.id)).toEqual([
255 "auto-settle-inactive-threads",
256 "auto-settle-merged-threads",
257 "days-before-auto-settle",
258 ]);
259 });
260
261 it("finds keybinding commands by label, command id, and default key", () => {
262 expect(searchSettings("toggle sidebar")[0]?.id).toBe("keybinding-sidebar.toggle");
263 expect(searchSettings("sidebar.toggle")[0]?.id).toBe("keybinding-sidebar.toggle");
264 expect(searchSettings("mod+b")[0]?.id).toBe("keybinding-sidebar.toggle");
265 expect(searchSettings("copy link")[0]).toMatchObject({
266 id: "keybinding-thread.copyReference",
267 to: "/settings/keybindings",
268 });
269 });
270
271 it("ranks keybinding commands after other settings", () => {
272 const ids = searchSettings("model").map((item) => item.id);
273 expect(ids[0]).toBe("default-model");
274 expect(ids.indexOf("keybinding-modelPicker.toggle")).toBeGreaterThan(
275 ids.indexOf("text-generation-model"),
276 );
277 });
278
279 it("sends commands without a default binding to the section", () => {
280 expect(searchSettings("thread.stop")[0]).toMatchObject({
281 id: "keybinding-thread.stop",
282 targetId: "keybindings",
283 });
284 expect(searchSettings("sidebar.toggle")[0]?.targetId).toBeUndefined();
285 });
286
287 it("keeps catalog result ids unique", () => {
288 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
289 expect(new Set(ids).size).toBe(ids.length);
290 });
291
292 it("serves anchor props to panels from the catalog", () => {
293 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
294 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
295 });
296
297 it("routes appearance settings to their current section", () => {
298 expect(searchSettings("theme")[0]).toMatchObject({
299 id: "theme",
300 to: "/settings/appearance",
301 });
302 expect(searchSettings("word wrap")[0]).toMatchObject({
303 id: "word-wrap",
304 to: "/settings/appearance",
305 });
306 expect(searchSettings("composer context")[0]).toMatchObject({
307 id: "composer-context",
308 to: "/settings/appearance",
309 });
310 expect(searchSettings("environment identification")[0]).toMatchObject({
311 id: "environment-identification",
312 to: "/settings/appearance",
313 targetId: "appearance-interface",
314 });
315 });
316
317 it("routes conditional window capture settings to the stable toggle row", () => {
318 const targets = [
319 "capture accessibility data",
320 "capture shortcut",
321 "capture sound",
322 "capture flash",
323 "capture animations",
324 ].map((query) => {
325 const match = searchSettings(query)[0];
326 return [match?.id, match?.targetId];
327 });
328
329 expect(targets).toEqual([
330 ["snap-shot-accessibility", "snap-shot-enabled"],
331 ["snap-shot-shortcut", "snap-shot-enabled"],
332 ["snap-shot-sound", "snap-shot-enabled"],
333 ["snap-shot-flash", "snap-shot-enabled"],
334 ["snap-shot-animations", "snap-shot-enabled"],
335 ]);
336 });
337
338 it("routes browser recording quality to integrations", () => {
339 const result = searchSettings("recording frame rate")[0];
340 expect(result).toMatchObject({
341 id: "browser-recording-frame-rate",
342 to: "/settings/integrations",
343 });
344 expect(result).not.toHaveProperty("targetId");
345 });
346
347 it("routes where links open to integrations", () => {
348 expect(searchSettings("open links in")[0]).toMatchObject({
349 id: "browser-link-target",
350 to: "/settings/integrations",
351 });
352 expect(searchSettings("external links")[0]).toMatchObject({ id: "browser-link-target" });
353 });
354
355 it("finds the default browser profile action in the profiles list", () => {
356 expect(searchSettings("default profile")[0]).toMatchObject({
357 id: "browser-default-profile",
358 to: "/settings/integrations",
359 targetId: "browser-profiles",
360 });
361 });
362
363 it.each([
364 ["default model", "default-model", "/settings/general"],
365 ["new threads", "new-threads", "/settings/general"],
366 ["agent browser access", "agent-browser-access", "/settings/integrations"],
367 ["automatically pull", "automatic-pull", "/settings/source-control"],
368 ["actions", "project-actions", "/settings/projects"],
369 ["project overview", "project-overview", "/settings/projects"],
370 ])("routes %s to its owning category", (query, id, to) => {
371 expect(searchSettings(query)[0]).toMatchObject({ id, to });
372 });
373
374 it("keeps environment settings discoverable without a primary environment", () => {
375 const available = filterAvailableSettingsSearchItems({
376 hasCloudPublicConfig: false,
377 hasEnvironment: true,
378 hasProviderSettingsEnvironment: true,
379 hasMacProviderSettingsEnvironment: false,
380 canManageLocalBackend: false,
381 isWslSettingsRowVisible: false,
382 hasThreadAutoSettlement: true,
383 });
384 expect(searchSettings("writing style", available)[0]?.id).toBe("source-control-writing-style");
385 expect(searchSettings("auto-settle", available)).toHaveLength(3);
386 });
387});
388
389describe("settings search targets", () => {
390 it.each([
391 "auto-settle-inactive-threads",
392 "auto-settle-merged-threads",
393 "days-before-auto-settle",
394 ])("retains the capability requirement for %s", (targetId) => {
395 expect(getSettingsSearchTargetScope(targetId)).toMatchObject({
396 scope: "project-defaults",
397 requiresThreadAutoSettlement: true,
398 });
399 });
400
401 it("treats device-local rows as reachable from every selection", () => {
402 const setting = getSettingsSearchTargetScope("time-format")!;
403 expect(setting).toEqual({ title: "Time format", scope: null });
404 expect(isSettingsSearchScopeAvailable(setting.scope, "project")).toBe(true);
405 expect(isSettingsSearchScopeAvailable(setting.scope, "all")).toBe(true);
406 expect(getSettingsSearchTargetScope("appearance")).toMatchObject({ scope: null });
407 expect(getSettingsSearchTargetScope("missing-setting")).toBeNull();
408 });
409
410 it.each(["all", "environment", "project", "checkout"] as const)(
411 "makes browser access editable at the %s scope",
412 (kind) => {
413 const setting = getSettingsSearchTargetScope("agent-browser-access")!;
414 expect(isSettingsSearchScopeAvailable(setting.scope, kind)).toBe(true);
415 expect(isSettingsSearchScopeAvailable(setting.scope, "unavailable")).toBe(false);
416 },
417 );
418
419 it("lets project-scopable rows resolve at every server-backed scope", () => {
420 const model = getSettingsSearchTargetScope("text-generation-model")!;
421 expect(isSettingsSearchScopeAvailable(model.scope, "all")).toBe(true);
422 expect(isSettingsSearchScopeAvailable(model.scope, "environment")).toBe(true);
423 expect(isSettingsSearchScopeAvailable(model.scope, "project")).toBe(true);
424 });
425
426 it("reaches source control discovery and git fetch interval from the default scope", () => {
427 for (const id of ["source-control", "git-fetch-interval"]) {
428 const item = getSettingsSearchTargetScope(id)!;
429 expect(isSettingsSearchScopeAvailable(item.scope, "all")).toBe(true);
430 expect(isSettingsSearchScopeAvailable(item.scope, "environment")).toBe(true);
431 expect(isSettingsSearchScopeAvailable(item.scope, "project")).toBe(false);
432 }
433 });
434
435 it("keeps environment-wide settings out of project scopes", () => {
436 const updates = getSettingsSearchTargetScope("provider-update-checks")!;
437 expect(updates.scope).toBe("environment-defaults");
438 expect(isSettingsSearchScopeAvailable(updates.scope, "environment")).toBe(true);
439 expect(isSettingsSearchScopeAvailable(updates.scope, "all")).toBe(true);
440 expect(isSettingsSearchScopeAvailable(updates.scope, "project")).toBe(false);
441 const streaming = getSettingsSearchTargetScope("response-streaming")!;
442 expect(streaming.scope).toBe("project-defaults");
443 expect(isSettingsSearchScopeAvailable(streaming.scope, "project")).toBe(true);
444 for (const id of ["legacy-plan-mode", "legacy-context-window-indicator", "legacy-sidebar"]) {
445 expect(getSettingsSearchTargetScope(id)!.scope).toBeNull();
446 }
447 });
448});
449
450describe("auto-settlement search availability", () => {
451 function environment(id: string, { connected = true, loaded = true, supported = true } = {}) {
452 return {
453 environmentId: EnvironmentId.make(id),
454 connection: { phase: connected ? ("connected" as const) : ("offline" as const) },
455 serverConfig: loaded
456 ? { environment: { capabilities: { threadAutoSettlement: supported } } }
457 : null,
458 };
459 }
460
461 const capable = environment("capable");
462 const unsupported = environment("unsupported", { supported: false });
463 const offline = environment("offline", { connected: false });
464 const loading = environment("loading", { loaded: false });
465 const environments = [capable, unsupported, offline, loading];
466
467 it("keeps results discoverable when one connected environment supports them", () => {
468 const availability = getThreadAutoSettlementSearchAvailability(environments);
469 expect(availability.eligibleEnvironmentIds).toEqual([capable.environmentId]);
470 const items = filterAvailableSettingsSearchItems({
471 hasCloudPublicConfig: false,
472 hasEnvironment: true,
473 hasProviderSettingsEnvironment: true,
474 hasMacProviderSettingsEnvironment: false,
475 canManageLocalBackend: false,
476 isWslSettingsRowVisible: false,
477 hasThreadAutoSettlement: availability.eligibleEnvironmentIds.length > 0,
478 });
479 expect(searchSettings("auto-settle", items).map((item) => item.id)).toEqual([
480 "auto-settle-inactive-threads",
481 "auto-settle-merged-threads",
482 "days-before-auto-settle",
483 ]);
484 });
485
486 it("offers only capable environments when an aggregate has mixed capabilities", () => {
487 expect(
488 getThreadAutoSettlementSearchAvailability(environments, {
489 kind: "all",
490 environmentIds: environments.map((entry) => entry.environmentId),
491 }),
492 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
493 });
494
495 it("allows a capable named environment regardless of other environments' capabilities", () => {
496 expect(
497 getThreadAutoSettlementSearchAvailability(environments, {
498 kind: "environment",
499 environmentIds: [capable.environmentId],
500 }).isTargetAvailable,
501 ).toBe(true);
502 });
503
504 it.each([unsupported, offline, loading])(
505 "does not render the target on $environmentId or silently fall back",
506 (selected) => {
507 expect(
508 getThreadAutoSettlementSearchAvailability(environments, {
509 kind: "environment",
510 environmentIds: [selected.environmentId],
511 }),
512 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
513 },
514 );
515
516 it("offers a capable environment instead of a dead target at an unavailable scope", () => {
517 expect(
518 getThreadAutoSettlementSearchAvailability(environments, {
519 kind: "unavailable",
520 environmentIds: [capable.environmentId],
521 }),
522 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
523 });
524
525 it("ignores offline and unloaded targets when all connected targets support the setting", () => {
526 const selected = [capable, offline, loading];
527 expect(
528 getThreadAutoSettlementSearchAvailability(selected, {
529 kind: "all",
530 environmentIds: selected.map((entry) => entry.environmentId),
531 }).isTargetAvailable,
532 ).toBe(true);
533 });
534
535 it("offers no unavailable environments when none can render the setting", () => {
536 const selected = [unsupported, offline, loading];
537 expect(
538 getThreadAutoSettlementSearchAvailability(selected, {
539 kind: "all",
540 environmentIds: selected.map((entry) => entry.environmentId),
541 }),
542 ).toEqual({ eligibleEnvironmentIds: [], isTargetAvailable: false });
543 expect(getThreadAutoSettlementSearchAvailability([]).eligibleEnvironmentIds).toEqual([]);
544 });
545});
546
547describe("settings sidebar scope", () => {
548 it("shows Overview only for project and checkout targets", () => {
549 expect(isSettingsOverviewVisible({})).toBe(false);
550 expect(isSettingsOverviewVisible({ machine: "remote" })).toBe(false);
551 expect(isSettingsOverviewVisible({ project: "project" })).toBe(true);
552 expect(isSettingsOverviewVisible({ project: "project", checkout: "checkout" })).toBe(true);
553 });
554});