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

settingsSearch.test.ts

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