Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

settingsSearch.test.ts

586 lines22.5 KB

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