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