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

settingsSearch.test.ts

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