@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 147 lines 4.99 KB
Raw
1 import { PrimaryConnectionTarget } from "@t3tools/client-runtime/connection";
2 import { EnvironmentId, ProjectId, ServerConfig } from "@t3tools/contracts";
3 import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
4 import * as Option from "effect/Option";
5 import * as Schema from "effect/Schema";
6 import { expect, it, vi } from "vite-plus/test";
7 import { page, userEvent } from "vite-plus/test/browser";
8
9 import { render } from "../../../test/render";
10 import { ensureClientSettingsHydrated, persistClientSettingsPatch } from "../../hooks/useSettings";
11 import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping";
12 import type { EnvironmentPresentation } from "../../state/environments";
13 import type { Project } from "../../types";
14
15 const environmentId = EnvironmentId.make("browser-settings");
16 const config = Schema.decodeSync(ServerConfig)({
17 environment: {
18 environmentId,
19 label: "Desk",
20 platform: { os: "linux", arch: "x64" },
21 serverVersion: "1.0.0",
22 orchestrationProtocolVersion: 2,
23 capabilities: {},
24 },
25 auth: {
26 policy: "loopback-browser",
27 bootstrapMethods: ["one-time-token"],
28 sessionMethods: ["browser-session-cookie"],
29 sessionCookieName: "t3_session",
30 },
31 cwd: "/workspace/browser",
32 keybindingsConfigPath: "/workspace/keybindings.json",
33 keybindings: [],
34 issues: [],
35 providers: [],
36 availableEditors: [],
37 observability: {
38 logsDirectoryPath: "/workspace/logs",
39 localTracingEnabled: false,
40 otlpTracesEnabled: false,
41 otlpMetricsEnabled: false,
42 },
43 settings: {},
44 });
45 const environments: EnvironmentPresentation[] = [
46 {
47 environmentId,
48 label: "Desk",
49 displayUrl: "http://localhost:12345",
50 relayManaged: false,
51 entry: {
52 target: new PrimaryConnectionTarget({
53 environmentId,
54 label: "Desk",
55 httpBaseUrl: "http://localhost:12345",
56 wsBaseUrl: "ws://localhost:12345/ws",
57 }),
58 profile: Option.none(),
59 enabled: true,
60 },
61 connection: { phase: "connected", error: null, traceId: null },
62 refusedRouteIds: [],
63 serverConfig: config,
64 },
65 ];
66 const projects: Project[] = [
67 {
68 id: ProjectId.make("browser-project"),
69 environmentId,
70 title: "Browser project",
71 workspaceRoot: "/workspace/browser",
72 repositoryIdentity: null,
73 defaultModelSelection: null,
74 scripts: [],
75 createdAt: "2026-11-14T00:00:00.000Z",
76 updatedAt: "2026-11-14T00:00:00.000Z",
77 },
78 ];
79
80 // Profiles, link target and the advanced rows only work in the desktop app.
81 vi.mock(import("../../env"), async (original) => ({ ...(await original()), isElectron: true }));
82 vi.mock(import("../../state/environments"), async (original) => ({
83 ...(await original()),
84 useEnvironments: () => ({
85 isReady: true,
86 networkStatus: "online" as const,
87 environments,
88 presentationById: new Map(),
89 }),
90 usePrimaryEnvironmentId: () => environmentId,
91 usePrimaryEnvironment: () => environments[0]!,
92 readEnvironment: () => environments[0]!,
93 }));
94 vi.mock(import("../../state/session"), async (original) => ({
95 ...(await original()),
96 useEnvironmentScope: () => true,
97 useEnvironmentsWithScope: () => new Set([environmentId]),
98 }));
99 vi.mock(import("../../state/entities"), async (original) => ({
100 ...(await original()),
101 useProjects: () => projects,
102 useServerConfigs: () => new Map([[environmentId, config]]),
103 }));
104
105 import { BrowserSettingsPanel } from "./IntegrationsSettings";
106 import { SettingsScopeProvider } from "./SettingsScopeContext";
107
108 const [group] = buildSidebarProjectSnapshots({
109 projects,
110 settings: DEFAULT_CLIENT_SETTINGS,
111 primaryEnvironmentId: environmentId,
112 resolveEnvironmentLabel: () => "Desk",
113 });
114 const isInert = (element: Element) => element.closest("[inert]") !== null;
115
116 it.each([
117 { scope: "a project", search: { project: group!.projectKey } },
118 {
119 scope: "a checkout",
120 search: { project: group!.projectKey, checkout: group!.memberProjects[0]!.physicalProjectKey },
121 },
122 ])("shows device preferences read-only for $scope", async ({ search }) => {
123 await ensureClientSettingsHydrated();
124 await persistClientSettingsPatch(
125 { browserProfiles: [{ id: "work", name: "Work", kind: "persistent" }] },
126 async () => {},
127 );
128 await using screen = await render(
129 <SettingsScopeProvider search={search} onChange={() => {}}>
130 <BrowserSettingsPanel />
131 </SettingsScopeProvider>,
132 { router: "/settings/browser" },
133 );
134
135 for (const name of ["Search engine", "Open links in"]) {
136 expect(isInert(screen.getByRole("combobox", { name }).element())).toBe(true);
137 }
138 expect(isInert(screen.getByRole("switch", { name: "Agent browser access" }).element())).toBe(
139 false,
140 );
141 // Profiles save for this device in every scope, but the default profile is a device preference.
142 await expect.element(screen.getByRole("button", { name: "Add profile" })).toBeEnabled();
143 await userEvent.click(screen.getByRole("button", { name: "Work options" }));
144 await expect
145 .element(page.getByRole("menuitem", { name: "Set as default" }))
146 .toHaveAttribute("aria-disabled", "true");
147 });