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 const browser = filterAvailableSettingsSearchItems(availability).map((item) => item.id);
246 expect(browser).toContain("publish-agent-activity");
247 });
248
249 it("offers webhook holding only while the managed tunnel is on, like its row", () => {
250 const availability = {
251 hasCloudPublicConfig: true,
252 hasEnvironment: true,
253 hasProviderSettingsEnvironment: true,
254 hasMacProviderSettingsEnvironment: false,
255 canManageLocalBackend: true,
256 isWslSettingsRowVisible: false,
257 hasThreadAutoSettlement: false,
258 };
259 const itemIds = (managedTunnelActive: boolean) =>
260 filterAvailableSettingsSearchItems({ ...availability, managedTunnelActive }).map(
261 (item) => item.id,
262 );
263 expect(itemIds(false)).not.toContain("hold-webhooks-while-offline");
264 expect(itemIds(true)).toContain("hold-webhooks-while-offline");
265 });
266
267 it("shows automatic settlement settings when the server supports them", () => {
268 const available = filterAvailableSettingsSearchItems({
269 hasCloudPublicConfig: false,
270 hasEnvironment: false,
271 hasProviderSettingsEnvironment: false,
272 hasMacProviderSettingsEnvironment: false,
273 canManageLocalBackend: false,
274 isWslSettingsRowVisible: false,
275 hasThreadAutoSettlement: true,
276 });
277
278 expect(searchSettings("auto-settle", available).map((item) => item.id)).toEqual([
279 "auto-settle-inactive-threads",
280 "auto-settle-merged-threads",
281 "days-before-auto-settle",
282 ]);
283 });
284
285 it("finds keybinding commands by label, command id, and default key", () => {
286 expect(searchSettings("toggle sidebar")[0]?.id).toBe("keybinding-sidebar.toggle");
287 expect(searchSettings("sidebar.toggle")[0]?.id).toBe("keybinding-sidebar.toggle");
288 expect(searchSettings("mod+b")[0]?.id).toBe("keybinding-sidebar.toggle");
289 expect(searchSettings("copy link")[0]).toMatchObject({
290 id: "keybinding-thread.copyReference",
291 to: "/settings/keybindings",
292 });
293 });
294
295 it("ranks keybinding commands after other settings", () => {
296 const ids = searchSettings("model").map((item) => item.id);
297 expect(ids[0]).toBe("default-model");
298 expect(ids.indexOf("keybinding-modelPicker.toggle")).toBeGreaterThan(
299 ids.indexOf("text-generation-model"),
300 );
301 });
302
303 it("sends commands without a default binding to the section", () => {
304 expect(searchSettings("thread.stop")[0]).toMatchObject({
305 id: "keybinding-thread.stop",
306 targetId: "keybindings",
307 });
308 expect(searchSettings("sidebar.toggle")[0]?.targetId).toBeUndefined();
309 });
310
311 it("keeps catalog result ids unique", () => {
312 const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id);
313 expect(new Set(ids).size).toBe(ids.length);
314 });
315
316 it("serves anchor props to panels from the catalog", () => {
317 expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
318 expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
319 });
320
321 it("routes appearance settings to their current section", () => {
322 expect(searchSettings("theme")[0]).toMatchObject({
323 id: "theme",
324 to: "/settings/appearance",
325 });
326 expect(searchSettings("word wrap")[0]).toMatchObject({
327 id: "word-wrap",
328 to: "/settings/appearance",
329 });
330 expect(searchSettings("composer context")[0]).toMatchObject({
331 id: "composer-context",
332 to: "/settings/appearance",
333 });
334 expect(searchSettings("environment identification")[0]).toMatchObject({
335 id: "environment-identification",
336 to: "/settings/appearance",
337 targetId: "appearance-interface",
338 });
339 });
340
341 it("routes conditional window capture settings to the stable toggle row", () => {
342 const targets = [
343 "capture accessibility data",
344 "capture shortcut",
345 "capture sound",
346 "capture flash",
347 "capture animations",
348 ].map((query) => {
349 const match = searchSettings(query)[0];
350 return [match?.id, match?.targetId];
351 });
352
353 expect(targets).toEqual([
354 ["snap-shot-accessibility", "snap-shot-enabled"],
355 ["snap-shot-shortcut", "snap-shot-enabled"],
356 ["snap-shot-sound", "snap-shot-enabled"],
357 ["snap-shot-flash", "snap-shot-enabled"],
358 ["snap-shot-animations", "snap-shot-enabled"],
359 ]);
360 });
361
362 it("routes browser recording quality to integrations", () => {
363 const result = searchSettings("recording frame rate")[0];
364 expect(result).toMatchObject({
365 id: "browser-recording-frame-rate",
366 to: "/settings/integrations",
367 });
368 expect(result).not.toHaveProperty("targetId");
369 });
370
371 it("routes where links open to integrations", () => {
372 expect(searchSettings("open links in")[0]).toMatchObject({
373 id: "browser-link-target",
374 to: "/settings/integrations",
375 });
376 expect(searchSettings("external links")[0]).toMatchObject({ id: "browser-link-target" });
377 });
378
379 it("finds the default browser profile action in the profiles list", () => {
380 expect(searchSettings("default profile")[0]).toMatchObject({
381 id: "browser-default-profile",
382 to: "/settings/integrations",
383 targetId: "browser-profiles",
384 });
385 });
386
387 it.each([
388 ["default model", "default-model", "/settings/general"],
389 ["new threads", "new-threads", "/settings/general"],
390 ["agent browser access", "agent-browser-access", "/settings/integrations"],
391 ["automatically pull", "automatic-pull", "/settings/source-control"],
392 ["actions", "project-actions", "/settings/projects"],
393 ["project overview", "project-overview", "/settings/projects"],
394 ])("routes %s to its owning category", (query, id, to) => {
395 expect(searchSettings(query)[0]).toMatchObject({ id, to });
396 });
397
398 it("keeps environment settings discoverable without a primary environment", () => {
399 const available = filterAvailableSettingsSearchItems({
400 hasCloudPublicConfig: false,
401 hasEnvironment: true,
402 hasProviderSettingsEnvironment: true,
403 hasMacProviderSettingsEnvironment: false,
404 canManageLocalBackend: false,
405 isWslSettingsRowVisible: false,
406 hasThreadAutoSettlement: true,
407 });
408 expect(searchSettings("writing style", available)[0]?.id).toBe("source-control-writing-style");
409 expect(searchSettings("auto-settle", available)).toHaveLength(3);
410 });
411});
412
413describe("settings search targets", () => {
414 it("requires an environment for the resolved telemetry export destination", () => {
415 const result = searchSettings("OpenTelemetry export").find(
416 (item) => item.id === "telemetry-export",
417 )!;
418 const target = getSettingsSearchTargetScope(result.targetId ?? result.id)!;
419 expect(isSettingsSearchScopeAvailable(target.scope, "all")).toBe(false);
420 expect(isSettingsSearchScopeAvailable(target.scope, "project")).toBe(false);
421 expect(isSettingsSearchScopeAvailable(target.scope, "environment")).toBe(true);
422 });
423 it.each([
424 "auto-settle-inactive-threads",
425 "auto-settle-merged-threads",
426 "days-before-auto-settle",
427 ])("retains the capability requirement for %s", (targetId) => {
428 expect(getSettingsSearchTargetScope(targetId)).toMatchObject({
429 scope: "project-defaults",
430 requiresThreadAutoSettlement: true,
431 });
432 });
433
434 it("treats device-local rows as reachable from every selection", () => {
435 const setting = getSettingsSearchTargetScope("time-format")!;
436 expect(setting).toEqual({ title: "Time format", scope: null });
437 expect(isSettingsSearchScopeAvailable(setting.scope, "project")).toBe(true);
438 expect(isSettingsSearchScopeAvailable(setting.scope, "all")).toBe(true);
439 expect(getSettingsSearchTargetScope("appearance")).toMatchObject({ scope: null });
440 expect(getSettingsSearchTargetScope("missing-setting")).toBeNull();
441 });
442
443 it.each(["all", "environment", "project", "checkout"] as const)(
444 "makes browser access editable at the %s scope",
445 (kind) => {
446 const setting = getSettingsSearchTargetScope("agent-browser-access")!;
447 expect(isSettingsSearchScopeAvailable(setting.scope, kind)).toBe(true);
448 expect(isSettingsSearchScopeAvailable(setting.scope, "unavailable")).toBe(false);
449 },
450 );
451
452 it("lets project-scopable rows resolve at every server-backed scope", () => {
453 const model = getSettingsSearchTargetScope("text-generation-model")!;
454 expect(isSettingsSearchScopeAvailable(model.scope, "all")).toBe(true);
455 expect(isSettingsSearchScopeAvailable(model.scope, "environment")).toBe(true);
456 expect(isSettingsSearchScopeAvailable(model.scope, "project")).toBe(true);
457 });
458
459 it("reaches source control discovery and git fetch interval from the default scope", () => {
460 for (const id of ["source-control", "git-fetch-interval"]) {
461 const item = getSettingsSearchTargetScope(id)!;
462 expect(isSettingsSearchScopeAvailable(item.scope, "all")).toBe(true);
463 expect(isSettingsSearchScopeAvailable(item.scope, "environment")).toBe(true);
464 expect(isSettingsSearchScopeAvailable(item.scope, "project")).toBe(false);
465 }
466 });
467
468 it("keeps environment-wide settings out of project scopes", () => {
469 const updates = getSettingsSearchTargetScope("provider-update-checks")!;
470 expect(updates.scope).toBe("environment-defaults");
471 expect(isSettingsSearchScopeAvailable(updates.scope, "environment")).toBe(true);
472 expect(isSettingsSearchScopeAvailable(updates.scope, "all")).toBe(true);
473 expect(isSettingsSearchScopeAvailable(updates.scope, "project")).toBe(false);
474 const streaming = getSettingsSearchTargetScope("response-streaming")!;
475 expect(streaming.scope).toBe("project-defaults");
476 expect(isSettingsSearchScopeAvailable(streaming.scope, "project")).toBe(true);
477 for (const id of ["legacy-plan-mode", "legacy-context-window-indicator", "legacy-sidebar"]) {
478 expect(getSettingsSearchTargetScope(id)!.scope).toBeNull();
479 }
480 });
481});
482
483describe("auto-settlement search availability", () => {
484 function environment(id: string, { connected = true, loaded = true, supported = true } = {}) {
485 return {
486 environmentId: EnvironmentId.make(id),
487 connection: { phase: connected ? ("connected" as const) : ("offline" as const) },
488 serverConfig: loaded
489 ? { environment: { capabilities: { threadAutoSettlement: supported } } }
490 : null,
491 };
492 }
493
494 const capable = environment("capable");
495 const unsupported = environment("unsupported", { supported: false });
496 const offline = environment("offline", { connected: false });
497 const loading = environment("loading", { loaded: false });
498 const environments = [capable, unsupported, offline, loading];
499
500 it("keeps results discoverable when one connected environment supports them", () => {
501 const availability = getThreadAutoSettlementSearchAvailability(environments);
502 expect(availability.eligibleEnvironmentIds).toEqual([capable.environmentId]);
503 const items = filterAvailableSettingsSearchItems({
504 hasCloudPublicConfig: false,
505 hasEnvironment: true,
506 hasProviderSettingsEnvironment: true,
507 hasMacProviderSettingsEnvironment: false,
508 canManageLocalBackend: false,
509 isWslSettingsRowVisible: false,
510 hasThreadAutoSettlement: availability.eligibleEnvironmentIds.length > 0,
511 });
512 expect(searchSettings("auto-settle", items).map((item) => item.id)).toEqual([
513 "auto-settle-inactive-threads",
514 "auto-settle-merged-threads",
515 "days-before-auto-settle",
516 ]);
517 });
518
519 it("offers only capable environments when an aggregate has mixed capabilities", () => {
520 expect(
521 getThreadAutoSettlementSearchAvailability(environments, {
522 kind: "all",
523 environmentIds: environments.map((entry) => entry.environmentId),
524 }),
525 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
526 });
527
528 it("allows a capable named environment regardless of other environments' capabilities", () => {
529 expect(
530 getThreadAutoSettlementSearchAvailability(environments, {
531 kind: "environment",
532 environmentIds: [capable.environmentId],
533 }).isTargetAvailable,
534 ).toBe(true);
535 });
536
537 it.each([unsupported, offline, loading])(
538 "does not render the target on $environmentId or silently fall back",
539 (selected) => {
540 expect(
541 getThreadAutoSettlementSearchAvailability(environments, {
542 kind: "environment",
543 environmentIds: [selected.environmentId],
544 }),
545 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
546 },
547 );
548
549 it("offers a capable environment instead of a dead target at an unavailable scope", () => {
550 expect(
551 getThreadAutoSettlementSearchAvailability(environments, {
552 kind: "unavailable",
553 environmentIds: [capable.environmentId],
554 }),
555 ).toEqual({ eligibleEnvironmentIds: [capable.environmentId], isTargetAvailable: false });
556 });
557
558 it("ignores offline and unloaded targets when all connected targets support the setting", () => {
559 const selected = [capable, offline, loading];
560 expect(
561 getThreadAutoSettlementSearchAvailability(selected, {
562 kind: "all",
563 environmentIds: selected.map((entry) => entry.environmentId),
564 }).isTargetAvailable,
565 ).toBe(true);
566 });
567
568 it("offers no unavailable environments when none can render the setting", () => {
569 const selected = [unsupported, offline, loading];
570 expect(
571 getThreadAutoSettlementSearchAvailability(selected, {
572 kind: "all",
573 environmentIds: selected.map((entry) => entry.environmentId),
574 }),
575 ).toEqual({ eligibleEnvironmentIds: [], isTargetAvailable: false });
576 expect(getThreadAutoSettlementSearchAvailability([]).eligibleEnvironmentIds).toEqual([]);
577 });
578});
579
580describe("settings sidebar scope", () => {
581 it("shows Overview only for project and checkout targets", () => {
582 expect(isSettingsOverviewVisible({})).toBe(false);
583 expect(isSettingsOverviewVisible({ machine: "remote" })).toBe(false);
584 expect(isSettingsOverviewVisible({ project: "project" })).toBe(true);
585 expect(isSettingsOverviewVisible({ project: "project", checkout: "checkout" })).toBe(true);
586 });
587});