@devries-cameron20 / t3code-1 / commits / d5b7095a09
Fork 0

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

test(web): every React test runs in a real browser (#20944)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 17, 2026 at 09:54 UTC d5b7095a097101ace362fa88003fff4c6f44200b
13 files changed +522 -738
apps/web/package.json
-3
@@ -84,16 +84,13 @@
84 "@types/mdast": "^4.0.4",
85 "@types/react": "~19.3.0",
86 "@types/react-dom": "~19.2.3",
87 - "@types/react-test-renderer": "19.1.0",
87 "@types/use-sync-external-store": "^0.0.6",
88 "@vercel/config": "^0.3.0",
89 "@vitejs/plugin-react": "^6.1.2",
90 "@vitest/browser-playwright": "5.0.1",
91 "compression": "^1.8.2",
93 - "jsdom": "^30.0.1",
92 "oxc-transform-react": "~0.152.0",
93 "playwright": "1.60.0",
96 - "react-test-renderer": "19.2.6",
94 "tailwindcss": "^4.0.0",
95 "unified": "catalog:",
96 "vite": "catalog:",
apps/web/src/components/BranchToolbar.panel.browser.test.tsx new
+132
@@ -0,0 +1,132 @@
1 +import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
2 +import { act, type ComponentProps } from "react";
3 +import { createRoot, type Root } from "react-dom/client";
4 +import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
5 +import { page, userEvent } from "vite-plus/test/browser";
6 +
7 +import "~/index.css";
8 +
9 +const state = vi.hoisted(() => ({
10 + worktreePath: "/tmp/worktree" as string | null,
11 + showContextMenu: vi.fn(),
12 + writeTextToClipboard: vi.fn(),
13 +}));
14 +
15 +vi.mock(import("../localApi"), async (original) => ({
16 + ...(await original()),
17 + readLocalApi: (() => ({ contextMenu: { show: state.showContextMenu } })) as never,
18 +}));
19 +vi.mock(import("../hooks/useCopyToClipboard"), async (original) => ({
20 + ...(await original()),
21 + writeTextToClipboard: state.writeTextToClipboard,
22 +}));
23 +vi.mock(import("./BranchToolbarBranchSelector"), async (original) => ({
24 + ...(await original()),
25 + BranchToolbarBranchSelector: (() => null) as never,
26 +}));
27 +vi.mock(import("../state/entities"), async (original) => ({
28 + ...(await original()),
29 + useQuietThreadShell: (() => ({
30 + environmentId: "local",
31 + projectId: "project",
32 + worktreePath: state.worktreePath,
33 + })) as never,
34 + useProject: (() => ({ workspaceRoot: "/tmp/project" })) as never,
35 + useThreadShellsForProjectRefs: () => [],
36 +}));
37 +
38 +import { BranchToolbar } from "./BranchToolbar";
39 +
40 +let root: Root;
41 +let container: HTMLDivElement;
42 +
43 +beforeEach(() => {
44 + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
45 + state.worktreePath = "/tmp/worktree";
46 + state.showContextMenu.mockReset().mockResolvedValue("copy-path");
47 + state.writeTextToClipboard.mockReset().mockResolvedValue(true);
48 + container = document.createElement("div");
49 + document.body.append(container);
50 + root = createRoot(container);
51 +});
52 +
53 +afterEach(async () => {
54 + await act(async () => root.unmount());
55 + container.remove();
56 + vi.unstubAllGlobals();
57 +});
58 +
59 +function render(props: Partial<ComponentProps<typeof BranchToolbar>>) {
60 + return act(async () =>
61 + root.render(
62 + <BranchToolbar
63 + layout="panel"
64 + panelSection="workspace"
65 + environmentId={EnvironmentId.make("local")}
66 + threadId={ThreadId.make("thread")}
67 + showGitControls
68 + envMode="local"
69 + envLocked={false}
70 + startFromOrigin={false}
71 + onStartFromOriginChange={vi.fn()}
72 + onEnvModeChange={vi.fn()}
73 + {...props}
74 + />,
75 + ),
76 + );
77 +}
78 +
79 +it("keeps machine choices usable when the combined row's workspace is locked", async () => {
80 + const onEnvironmentChange = vi.fn();
81 + await render({
82 + onEnvironmentChange,
83 + availableEnvironments: ["local", "remote"].map((id) => ({
84 + environmentId: EnvironmentId.make(id),
85 + projectId: ProjectId.make("project"),
86 + label: id,
87 + isPrimary: id === "local",
88 + machine: "server",
89 + })),
90 + });
91 + const trigger = container.querySelector("button")!;
92 + expect(trigger.textContent).toBe("local");
93 + expect(container.querySelectorAll("button")).toHaveLength(1);
94 +
95 + // A ctrl-click is a macOS secondary click; it must not open the menu.
96 + await act(async () => {
97 + trigger.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, ctrlKey: true }));
98 + });
99 + expect(document.querySelector('[role="menu"]')).toBeNull();
100 +
101 + await userEvent.click(trigger);
102 + await expect
103 + .element(page.getByRole("menuitemradio", { name: "New worktree" }))
104 + .toHaveAttribute("aria-disabled", "true");
105 + await userEvent.click(page.getByRole("menuitemradio", { name: "remote" }));
106 + expect(onEnvironmentChange).toHaveBeenCalledWith("remote");
107 +});
108 +
109 +it.each([
110 + ["local", null, "/tmp/project"],
111 + ["worktree", null, null],
112 + ["worktree", "/tmp/worktree", "/tmp/worktree"],
113 +] as const)(
114 + "copies only an existing workspace path with mode %s and worktree %s",
115 + async (envMode, worktreePath, copiedPath) => {
116 + state.worktreePath = worktreePath;
117 + await render({ envMode });
118 + const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
119 + await act(async () => {
120 + container.querySelector('[aria-label="Run context"]')!.dispatchEvent(event);
121 + });
122 + expect(event.defaultPrevented).toBe(copiedPath !== null);
123 + if (copiedPath === null) {
124 + expect(state.showContextMenu).not.toHaveBeenCalled();
125 + expect(state.writeTextToClipboard).not.toHaveBeenCalled();
126 + } else {
127 + await vi.waitFor(() =>
128 + expect(state.writeTextToClipboard).toHaveBeenCalledWith(copiedPath, "workspace path"),
129 + );
130 + }
131 + },
132 +);
apps/web/src/components/BranchToolbar.panel.test.tsx deleted
-138
@@ -1,138 +0,0 @@
1 -// @vitest-environment jsdom
2 -
3 -import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
4 -import { act } from "react";
5 -import { createRoot } from "react-dom/client";
6 -import { expect, it, vi } from "vite-plus/test";
7 -
8 -const state = vi.hoisted(() => ({
9 - worktreePath: "/tmp/worktree" as string | null,
10 - showContextMenu: vi.fn().mockResolvedValue("copy-path"),
11 - writeTextToClipboard: vi.fn().mockResolvedValue(true),
12 -}));
13 -
14 -vi.mock("../localApi", () => ({
15 - readLocalApi: () => ({ contextMenu: { show: state.showContextMenu } }),
16 -}));
17 -vi.mock("../hooks/useCopyToClipboard", () => ({
18 - writeTextToClipboard: state.writeTextToClipboard,
19 -}));
20 -vi.mock("./BranchToolbarBranchSelector", () => ({ BranchToolbarBranchSelector: () => null }));
21 -vi.mock("../composerDraftStore", () => ({
22 - useComposerDraftStore: (select: (store: unknown) => unknown) =>
23 - select({ getDraftThreadByRef: () => null, setDraftThreadContext: vi.fn() }),
24 -}));
25 -vi.mock("../state/entities", () => ({
26 - useQuietThreadShell: () => ({
27 - environmentId: "local",
28 - projectId: "project",
29 - worktreePath: state.worktreePath,
30 - }),
31 - useProject: () => ({ workspaceRoot: "/tmp/project" }),
32 - useThreadShellsForProjectRefs: () => [],
33 -}));
34 -
35 -import { BranchToolbar } from "./BranchToolbar";
36 -
37 -it("keeps machine choices usable when the combined row's workspace is locked", async () => {
38 - vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
39 - const container = document.createElement("div");
40 - document.body.append(container);
41 - const root = createRoot(container);
42 - const onEnvironmentChange = vi.fn();
43 - try {
44 - await act(async () => {
45 - root.render(
46 - <BranchToolbar
47 - layout="panel"
48 - panelSection="workspace"
49 - environmentId={EnvironmentId.make("local")}
50 - threadId={ThreadId.make("thread")}
51 - showGitControls
52 - envMode="local"
53 - envLocked={false}
54 - startFromOrigin={false}
55 - onStartFromOriginChange={vi.fn()}
56 - onEnvModeChange={vi.fn()}
57 - onEnvironmentChange={onEnvironmentChange}
58 - availableEnvironments={["local", "remote"].map((id) => ({
59 - environmentId: EnvironmentId.make(id),
60 - projectId: ProjectId.make("project"),
61 - label: id,
62 - isPrimary: id === "local",
63 - machine: "server",
64 - }))}
65 - />,
66 - );
67 - });
68 - const trigger = container.querySelector("button")!;
69 - expect(trigger.textContent).toBe("local");
70 - expect(container.querySelectorAll("button")).toHaveLength(1);
71 - await act(async () => {
72 - trigger.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, ctrlKey: true }));
73 - });
74 - expect(document.querySelector('[role="menu"]')).toBeNull();
75 - await act(async () => trigger.click());
76 - const items = [...document.querySelectorAll<HTMLElement>('[role="menuitemradio"]')];
77 - expect(
78 - items.find((item) => item.textContent === "New worktree")?.getAttribute("aria-disabled"),
79 - ).toBe("true");
80 - await act(async () => items.find((item) => item.textContent === "remote")!.click());
81 - expect(onEnvironmentChange).toHaveBeenCalledWith("remote");
82 - } finally {
83 - await act(async () => root.unmount());
84 - container.remove();
85 - vi.unstubAllGlobals();
86 - }
87 -});
88 -
89 -it.each([
90 - ["local", null, "/tmp/project"],
91 - ["worktree", null, null],
92 - ["worktree", "/tmp/worktree", "/tmp/worktree"],
93 -] as const)(
94 - "copies only an existing workspace path with mode %s and worktree %s",
95 - async (envMode, worktreePath, copiedPath) => {
96 - vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
97 - state.worktreePath = worktreePath;
98 - state.showContextMenu.mockClear();
99 - state.writeTextToClipboard.mockClear();
100 - const container = document.createElement("div");
101 - document.body.append(container);
102 - const root = createRoot(container);
103 - try {
104 - await act(async () => {
105 - root.render(
106 - <BranchToolbar
107 - layout="panel"
108 - panelSection="workspace"
109 - environmentId={EnvironmentId.make("local")}
110 - threadId={ThreadId.make("thread")}
111 - showGitControls
112 - envMode={envMode}
113 - envLocked={false}
114 - startFromOrigin={false}
115 - onStartFromOriginChange={vi.fn()}
116 - onEnvModeChange={vi.fn()}
117 - />,
118 - );
119 - });
120 - const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
121 - await act(async () => {
122 - container.querySelector('[aria-label="Run context"]')!.dispatchEvent(event);
123 - });
124 - expect(event.defaultPrevented).toBe(copiedPath !== null);
125 - if (copiedPath === null) {
126 - expect(state.showContextMenu).not.toHaveBeenCalled();
127 - expect(state.writeTextToClipboard).not.toHaveBeenCalled();
128 - } else {
129 - expect(state.writeTextToClipboard).toHaveBeenCalledWith(copiedPath, "workspace path");
130 - }
131 - } finally {
132 - await act(async () => root.unmount());
133 - container.remove();
134 - state.worktreePath = "/tmp/worktree";
135 - vi.unstubAllGlobals();
136 - }
137 - },
138 -);
apps/web/src/components/GitActionsControl.browser.test.tsx new
+382
@@ -0,0 +1,382 @@
1 +import {
2 + AuthOrchestrationOperateScope,
3 + AuthSourceControlWriteScope,
4 + EnvironmentId,
5 + ThreadId,
6 +} from "@t3tools/contracts";
7 +import * as Cause from "effect/Cause";
8 +import { AsyncResult } from "effect/reactivity";
9 +import { act, memo } from "react";
10 +import { createRoot, type Root } from "react-dom/client";
11 +import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
12 +import { page, userEvent } from "vite-plus/test/browser";
13 +
14 +import "~/index.css";
15 +
16 +type Branched = { readonly branch: string };
17 +type GitActionInput = { featureBranch?: boolean; threadId?: string; action: string };
18 +type Toast = { actionProps?: { onClick: () => void } };
19 +
20 +const state = vi.hoisted(() => ({
21 + scopes: new Set<string>(),
22 + primaryScopes: new Set<string>(),
23 + shell: null as Branched | null,
24 + detail: null as Branched | null,
25 + draft: null as (Branched & { worktreePath: null; envMode: "local" }) | null,
26 + branch: "main",
27 + isDefaultRef: false,
28 + actions: [] as { scope: { cwd: string | null }; input: GitActionInput }[],
29 + metadataRequests: [] as { environmentId: string; branch: string }[],
30 + toasts: [] as Toast[],
31 + afterGitAction: undefined as (() => void) | undefined,
32 +}));
33 +
34 +vi.mock(import("~/state/session"), async (original) => {
35 + const hasScope = (environmentId: unknown, scope: string) =>
36 + (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope);
37 + return {
38 + ...(await original()),
39 + useEnvironmentScope: hasScope as never,
40 + readEnvironmentScope: hasScope as never,
41 + };
42 +});
43 +vi.mock(import("~/state/entities"), async (original) => ({
44 + ...(await original()),
45 + useQuietThreadShell: ((ref: { threadId: string } | null) =>
46 + ref === null || state.shell === null ? null : { ...state.shell, id: ref.threadId }) as never,
47 + useThreadProjection: ((ref: unknown) =>
48 + ref === null || state.detail === null
49 + ? null
50 + : { projection: { thread: state.detail } }) as never,
51 +}));
52 +vi.mock(import("~/state/query"), async (original) => ({
53 + ...(await original()),
54 + // Serves both the VCS status and the source-control discovery queries.
55 + useEnvironmentQuery: (() => ({
56 + data: {
57 + sourceControlProviders: [],
58 + isRepo: true,
59 + refName: state.branch,
60 + isDefaultRef: state.isDefaultRef,
61 + hasPrimaryRemote: true,
62 + hasWorkingTreeChanges: true,
63 + workingTree: {
64 + files: [{ path: "file.ts", insertions: 1, deletions: 0 }],
65 + insertions: 1,
66 + deletions: 0,
67 + },
68 + hasUpstream: true,
69 + aheadCount: 0,
70 + behindCount: 0,
71 + pr: null,
72 + },
73 + error: null,
74 + })) as never,
75 +}));
76 +vi.mock(import("~/state/use-atom-command"), async (original) => ({
77 + ...(await original()),
78 + // The only command whose result matters here is the thread's branch metadata update.
79 + useAtomCommand: ((_command: unknown, options: unknown) =>
80 + options === "thread branch metadata update"
81 + ? async ({ environmentId, input }: { environmentId: string; input: { branch: string } }) => {
82 + state.metadataRequests.push({ environmentId, branch: input.branch });
83 + if (!state.scopes.has(AuthOrchestrationOperateScope))
84 + return AsyncResult.failure(Cause.fail(new Error("Task denied")));
85 + if (state.shell) state.shell = { branch: input.branch };
86 + if (state.detail) state.detail = { branch: input.branch };
87 + return AsyncResult.success(undefined);
88 + }
89 + : async () => AsyncResult.success(undefined)) as never,
90 +}));
91 +vi.mock(import("~/lib/sourceControlActions"), async (original) => ({
92 + ...(await original()),
93 + useSourceControlActionRunning: () => false,
94 + useGitStackedAction: ((scope: { cwd: string | null }) => ({
95 + run: async (input: GitActionInput) => {
96 + state.actions.push({ scope, input });
97 + if (input.featureBranch) state.branch = "feature";
98 + state.afterGitAction?.();
99 + return {
100 + _tag: "Success",
101 + value: {
102 + branch: input.featureBranch
103 + ? { status: "created", name: "feature" }
104 + : { status: "skipped_not_requested" },
105 + toast: {
106 + title: "Committed",
107 + description: "Committed",
108 + cta: {
109 + kind: "run_action",
110 + label: "Push & create PR",
111 + action: { kind: "commit_push_pr" },
112 + },
113 + },
114 + },
115 + };
116 + },
117 + })) as never,
118 +}));
119 +vi.mock(import("@tanstack/react-router"), async (original) => ({
120 + ...(await original()),
121 + useNavigate: (() => async () => {}) as never,
122 +}));
123 +vi.mock(import("~/components/ui/toast"), async (original) => {
124 + const actual = await original();
125 + return {
126 + ...actual,
127 + toastManager: {
128 + ...actual.toastManager,
129 + add: ((toast: Toast) => {
130 + state.toasts.push(toast);
131 + return "toast";
132 + }) as never,
133 + },
134 + };
135 +});
136 +
137 +import { useComposerDraftStore } from "~/composerDraftStore";
138 +import GitActionsControl from "./GitActionsControl";
139 +
140 +// ThreadDetailsPanel keeps this component mounted behind React.memo when threads change.
141 +const MemoGitActionsControl = memo(GitActionsControl);
142 +
143 +let root: Root;
144 +let container: HTMLDivElement;
145 +
146 +function render(thread = "thread", cwd = "/repo") {
147 + return act(async () =>
148 + root.render(
149 + <MemoGitActionsControl
150 + gitCwd={cwd}
151 + activeThreadRef={{
152 + environmentId: EnvironmentId.make("environment"),
153 + threadId: ThreadId.make(thread),
154 + }}
155 + />,
156 + ),
157 + );
158 +}
159 +
160 +const button = (name: string | RegExp) =>
161 + page.getByRole("button", { name, exact: typeof name === "string" });
162 +const commits = () => state.actions.length;
163 +
164 +async function openCommitDialog() {
165 + await userEvent.click(button("Git action options"));
166 + await userEvent.click(page.getByRole("menuitem", { name: "Commit" }));
167 + await expect.element(page.getByRole("dialog", { name: "Commit changes" })).toBeVisible();
168 +}
169 +
170 +beforeEach(() => {
171 + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
172 + state.scopes = new Set([AuthSourceControlWriteScope]);
173 + state.primaryScopes = new Set([AuthSourceControlWriteScope, AuthOrchestrationOperateScope]);
174 + state.shell = { branch: "main" };
175 + state.detail = null;
176 + state.draft = null;
177 + state.branch = "main";
178 + state.isDefaultRef = false;
179 + state.actions = [];
180 + state.metadataRequests = [];
181 + state.toasts = [];
182 + state.afterGitAction = undefined;
183 + useComposerDraftStore.setState({
184 + getDraftSession: () => state.draft as never,
185 + getDraftThreadByRef: () => state.draft as never,
186 + setDraftThreadContext: (_target, input) => {
187 + if (state.draft && input.branch) state.draft = { ...state.draft, branch: input.branch };
188 + },
189 + });
190 + container = document.createElement("div");
191 + document.body.append(container);
192 + root = createRoot(container);
193 +});
194 +
195 +afterEach(async () => {
196 + await act(async () => root.unmount());
197 + container.remove();
198 + vi.unstubAllGlobals();
199 + await vi.waitFor(() => expect(document.querySelector('[role="dialog"]')).toBeNull());
200 +});
201 +
202 +describe("Git actions while thread details load", () => {
203 + it("does not offer a feature branch for a server thread without task permission", async () => {
204 + await render();
205 + await openCommitDialog();
206 +
207 + // The primary environment's task grant must not leak into this thread's environment.
208 + await expect.element(button("Commit on new branch")).toBeDisabled();
209 + expect(commits()).toBe(0);
210 + });
211 +
212 + it("checks the task grant again when the feature-branch commit runs", async () => {
213 + state.scopes.add(AuthOrchestrationOperateScope);
214 + await render();
215 + await openCommitDialog();
216 + state.scopes.delete(AuthOrchestrationOperateScope);
217 +
218 + await userEvent.click(button("Commit on new branch"));
219 +
220 + expect(commits()).toBe(0);
221 + expect(state.branch).toBe("main");
222 + expect(state.shell?.branch).toBe("main");
223 + });
224 +
225 + it("commits and synchronizes the server thread before details finish loading", async () => {
226 + state.primaryScopes.clear();
227 + state.scopes.add(AuthOrchestrationOperateScope);
228 + await render();
229 + await openCommitDialog();
230 + await userEvent.click(button("Commit on new branch"));
231 +
232 + await vi.waitFor(() => expect(state.shell?.branch).toBe("feature"));
233 + expect(commits()).toBe(1);
234 + expect(state.actions[0]?.input).toMatchObject({ action: "commit", featureBranch: true });
235 + expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
236 + });
237 +
238 + it("synchronizes archived thread detail after its shell disappears", async () => {
239 + state.scopes.add(AuthOrchestrationOperateScope);
240 + state.detail = { branch: "main" };
241 + await render();
242 + state.shell = null;
243 + await render();
244 + await openCommitDialog();
245 + await userEvent.click(button("Commit on new branch"));
246 +
247 + await vi.waitFor(() => expect(state.detail?.branch).toBe("feature"));
248 + expect(commits()).toBe(1);
249 + expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
250 + });
251 +
252 + it("requires task permission before changing an archived thread's branch", async () => {
253 + state.shell = null;
254 + state.detail = { branch: "main" };
255 + await render();
256 + await openCommitDialog();
257 +
258 + await expect.element(button("Commit on new branch")).toBeDisabled();
259 + expect(state.metadataRequests).toEqual([]);
260 + });
261 +
262 + it("uses the current shell branch when cached detail names the new branch", async () => {
263 + state.scopes.add(AuthOrchestrationOperateScope);
264 + state.detail = { branch: "feature" };
265 + await render();
266 + await openCommitDialog();
267 + await userEvent.click(button("Commit on new branch"));
268 +
269 + await vi.waitFor(() => expect(state.shell?.branch).toBe("feature"));
270 + expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
271 + });
272 +
273 + it.each([
274 + [AuthOrchestrationOperateScope, false],
275 + [AuthSourceControlWriteScope, true],
276 + ] as const)(
277 + "uses the fresh task grant after Git finishes, revoking %s",
278 + async (revokedScope, syncsThread) => {
279 + state.scopes.add(AuthOrchestrationOperateScope);
280 + state.afterGitAction = () => state.scopes.delete(revokedScope);
281 + await render();
282 + await openCommitDialog();
283 + await userEvent.click(button("Commit on new branch"));
284 +
285 + await vi.waitFor(() => expect(state.branch).toBe("feature"));
286 + expect(commits()).toBe(1);
287 + expect(state.shell?.branch).toBe(syncsThread ? "feature" : "main");
288 + expect(state.metadataRequests).toHaveLength(syncsThread ? 1 : 0);
289 + },
290 + );
291 +
292 + it("keeps ordinary commits available while details load", async () => {
293 + await render();
294 + await openCommitDialog();
295 + await userEvent.click(button("Commit"));
296 +
297 + await vi.waitFor(() => expect(commits()).toBe(1));
298 + expect(state.actions[0]?.input).not.toHaveProperty("featureBranch");
299 + expect(state.branch).toBe("main");
300 + });
301 +
302 + it("keeps feature-branch commits available for a local draft", async () => {
303 + state.shell = null;
304 + state.draft = { branch: "main", worktreePath: null, envMode: "local" };
305 + await render();
306 + await openCommitDialog();
307 + await userEvent.click(button("Commit on new branch"));
308 +
309 + await vi.waitFor(() => expect(state.draft?.branch).toBe("feature"));
310 + expect(commits()).toBe(1);
311 + expect(state.metadataRequests).toEqual([]);
312 + });
313 +});
314 +
315 +describe("Default branch prompt", () => {
316 + beforeEach(() => {
317 + state.isDefaultRef = true;
318 + state.scopes.add(AuthOrchestrationOperateScope);
319 + });
320 +
321 + it("moves the commit to a feature branch when asked", async () => {
322 + await render();
323 + await userEvent.click(button(/^Commit & push/));
324 + await expect
325 + .element(page.getByRole("dialog", { name: "Commit & push to default ref?" }))
326 + .toBeVisible();
327 + expect(commits()).toBe(0);
328 +
329 + await userEvent.click(button("Check out feature branch & continue"));
330 +
331 + await vi.waitFor(() => expect(state.shell?.branch).toBe("feature"));
332 + expect(state.actions[0]?.input).toMatchObject({ action: "commit_push", featureBranch: true });
333 + });
334 +
335 + it("checks the task grant again when the feature branch is chosen", async () => {
336 + await render();
337 + await userEvent.click(button(/^Commit & push/));
338 + await expect
339 + .element(page.getByRole("dialog", { name: "Commit & push to default ref?" }))
340 + .toBeVisible();
341 + state.scopes.delete(AuthOrchestrationOperateScope);
342 +
343 + await userEvent.click(button("Check out feature branch & continue"));
344 +
345 + expect(commits()).toBe(0);
346 + expect(state.shell?.branch).toBe("main");
347 + });
348 +});
349 +
350 +describe("Git action targets across thread navigation", () => {
351 + const quickAction = () => button(/^Commit, push & /);
352 +
353 + it("runs a retained PR toast in the thread that produced it", async () => {
354 + await render("first", "/first");
355 + await userEvent.click(quickAction());
356 + await vi.waitFor(() => expect(state.toasts.some((toast) => toast.actionProps)).toBe(true));
357 + const toast = state.toasts.find((toast) => toast.actionProps)!;
358 +
359 + await render("second", "/second");
360 + await act(async () => toast.actionProps!.onClick());
361 +
362 + expect(state.actions.at(-1)).toMatchObject({
363 + scope: { cwd: "/first" },
364 + input: { threadId: "first", action: "commit_push_pr" },
365 + });
366 + });
367 +
368 + it("runs the memoized button in the current thread after navigation", async () => {
369 + for (const [thread, cwd] of [
370 + ["first", "/first"],
371 + ["second", "/second"],
372 + ["first", "/first"],
373 + ] as const) {
374 + await render(thread, cwd);
375 + await userEvent.click(quickAction());
376 + await vi.waitFor(() =>
377 + expect(state.actions.at(-1)).toMatchObject({ scope: { cwd }, input: { threadId: thread } }),
378 + );
379 + }
380 + expect(commits()).toBe(3);
381 + });
382 +});
apps/web/src/components/GitActionsControl.lifecycle.test.ts deleted
-234
@@ -1,234 +0,0 @@
1 -// @vitest-environment jsdom
2 -import { AuthSourceControlWriteScope, EnvironmentId, ThreadId } from "@t3tools/contracts";
3 -import { AsyncResult } from "effect/reactivity";
4 -import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
5 -
6 -const state = vi.hoisted(() => ({
7 - actions: [] as {
8 - scope: { environmentId: string | null; cwd: string | null };
9 - input: { threadId?: string; action: string };
10 - }[],
11 - toasts: [] as { type?: string; description?: string; actionProps?: { onClick: () => void } }[],
12 - scopes: new Set<string>(),
13 - primaryScopes: new Set<string>(),
14 -}));
15 -
16 -vi.mock("@effect/atom-react", () => ({
17 - useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
18 -}));
19 -vi.mock("~/state/entities", () => ({
20 - useThreadProjection: () => null,
21 - useQuietThreadShell: (ref: { threadId: string }) => ({ branch: "main", id: ref.threadId }),
22 -}));
23 -vi.mock("~/state/session", () => ({
24 - useEnvironmentScope: (environmentId: unknown, scope: string) =>
25 - (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
26 - readEnvironmentScope: (environmentId: unknown, scope: string) =>
27 - (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
28 -}));
29 -vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
30 -vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
31 -vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
32 -vi.mock("~/state/vcs", () => ({
33 - vcsEnvironment: { status: () => null },
34 - vcsActionManager: { stateAtom: () => "vcs-state" },
35 -}));
36 -vi.mock("~/state/threads", () => ({
37 - threadEnvironment: { updateMetadata: async () => AsyncResult.success(undefined) },
38 -}));
39 -vi.mock("~/state/query", () => ({
40 - useEnvironmentQuery: () => ({
41 - data: {
42 - sourceControlProviders: [],
43 - isRepo: true,
44 - refName: "main",
45 - isDefaultRef: false,
46 - hasPrimaryRemote: true,
47 - hasWorkingTreeChanges: true,
48 - workingTree: {
49 - files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
50 - },
51 - },
52 - error: null,
53 - }),
54 -}));
55 -vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
56 -vi.mock("~/composerDraftStore", () => ({
57 - useComposerDraftStore: (
58 - select: (store: {
59 - getDraftSession: () => null;
60 - getDraftThreadByRef: () => null;
61 - setDraftThreadContext: () => void;
62 - }) => unknown,
63 - ) =>
64 - select({
65 - getDraftSession: () => null,
66 - getDraftThreadByRef: () => null,
67 - setDraftThreadContext: () => {},
68 - }),
69 -}));
70 -vi.mock("~/lib/sourceControlActions", () => ({
71 - useSourceControlActionRunning: () => false,
72 - useVcsInitAction: () => ({}),
73 - useVcsPullAction: () => ({}),
74 - useSourceControlPublishRepositoryAction: () => ({}),
75 - useGitStackedAction: (scope: { environmentId: string | null; cwd: string | null }) => ({
76 - run: async (input: { featureBranch?: boolean; threadId?: string; action: string }) => {
77 - state.actions.push({ scope, input });
78 - return {
79 - _tag: "Success",
80 - value: {
81 - branch: { status: "skipped_not_requested" },
82 - toast: {
83 - title: "Committed",
84 - description: "Committed",
85 - cta: {
86 - kind: "run_action",
87 - label: "Push & create PR",
88 - action: { kind: "commit_push_pr" },
89 - },
90 - },
91 - },
92 - };
93 - },
94 - }),
95 -}));
96 -vi.mock("~/lib/utils", () => ({ cn: () => "", randomUUID: () => "action" }));
97 -vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => () => {} }));
98 -vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => () => {} }));
99 -vi.mock("~/lib/openPullRequestLink", () => ({ useOpenPrLink: () => () => {} }));
100 -vi.mock("~/components/ui/toast", () => ({
101 - stackedThreadToast: (input: unknown) => input,
102 - toastManager: {
103 - add: (input: {
104 - type?: string;
105 - description?: string;
106 - actionProps?: { onClick: () => void };
107 - }) => {
108 - state.toasts.push(input);
109 - return "toast";
110 - },
111 - update: () => {},
112 - close: () => {},
113 - },
114 -}));
115 -vi.mock("~/components/ui/dialog", () => ({
116 - Dialog: "Dialog",
117 - DialogDescription: "DialogDescription",
118 - DialogFooter: "DialogFooter",
119 - DialogHeader: "DialogHeader",
120 - DialogPanel: "DialogPanel",
121 - DialogPopup: "DialogPopup",
122 - DialogTitle: "DialogTitle",
123 -}));
124 -vi.mock("~/components/ui/group", () => ({ Group: "Group", GroupSeparator: "GroupSeparator" }));
125 -vi.mock("~/components/ui/menu", () => ({
126 - Menu: "Menu",
127 - MenuItem: "MenuItem",
128 - MenuItemLabel: "MenuItemLabel",
129 - MenuPopup: "MenuPopup",
130 - MenuTrigger: "MenuTrigger",
131 -}));
132 -vi.mock("~/components/ui/popover", () => ({
133 - Popover: "Popover",
134 - PopoverPopup: "PopoverPopup",
135 - PopoverTrigger: "PopoverTrigger",
136 -}));
137 -vi.mock("~/components/ui/tooltip", () => ({
138 - Tooltip: "Tooltip",
139 - TooltipPopup: "TooltipPopup",
140 - TooltipTrigger: "TooltipTrigger",
141 -}));
142 -vi.mock("~/components/ui/button", () => ({ Button: "button" }));
143 -vi.mock("~/components/ui/checkbox", () => ({ Checkbox: "Checkbox" }));
144 -vi.mock("~/components/ui/input", () => ({ Input: "Input" }));
145 -vi.mock("~/components/ui/radio-group", () => ({ RadioGroup: "RadioGroup" }));
146 -vi.mock("~/components/ui/scroll-area", () => ({ ScrollArea: "ScrollArea" }));
147 -vi.mock("~/components/ui/spinner", () => ({ Spinner: "Spinner" }));
148 -vi.mock("~/components/ui/textarea", () => ({ Textarea: "Textarea" }));
149 -vi.mock("~/components/ui/toggle", () => ({ toggleVariants: () => "" }));
150 -vi.mock("./AnimatedHeight", () => ({ AnimatedHeight: "AnimatedHeight" }));
151 -
152 -import GitActionsControl from "./GitActionsControl";
153 -
154 -import { createElement, memo } from "react";
155 -import { act, create } from "react-test-renderer";
156 -
157 -vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
158 -
159 -const renderers: ReturnType<typeof create>[] = [];
160 -// ThreadDetailsPanel keeps this component mounted behind React.memo when threads change.
161 -const MemoGitActionsControl = memo(GitActionsControl);
162 -const props = (thread: string, cwd: string) => ({
163 - gitCwd: cwd,
164 - activeThreadRef: {
165 - environmentId: EnvironmentId.make("environment"),
166 - threadId: ThreadId.make(thread),
167 - },
168 -});
169 -
170 -async function renderActions(thread: string, cwd: string) {
171 - let renderer!: ReturnType<typeof create>;
172 - await act(async () => {
173 - renderer = create(createElement(MemoGitActionsControl, props(thread, cwd)));
174 - });
175 - renderers.push(renderer);
176 - return renderer;
177 -}
178 -
179 -async function clickQuickAction(renderer: ReturnType<typeof create>) {
180 - const button = renderer.root
181 - .findAllByType("button")
182 - .find((button) => button.props.onClick && !button.props.disabled);
183 - expect(button).toBeDefined();
184 - await act(async () => {
185 - button!.props.onClick({});
186 - });
187 -}
188 -
189 -beforeEach(() => {
190 - state.scopes = new Set([AuthSourceControlWriteScope]);
191 - state.primaryScopes = new Set([AuthSourceControlWriteScope]);
192 - state.actions = [];
193 - state.toasts = [];
194 -});
195 -
196 -afterEach(async () => {
197 - await act(async () => {
198 - for (const renderer of renderers.splice(0)) renderer.unmount();
199 - });
200 -});
201 -
202 -describe("Git action targets across thread navigation", () => {
203 - it("runs a retained PR toast in the thread that produced it", async () => {
204 - const renderer = await renderActions("first", "/first");
205 - await clickQuickAction(renderer);
206 - const toast = state.toasts.find((toast) => toast.actionProps)!;
207 - expect(toast).toBeDefined();
208 - await act(async () => {
209 - renderer.update(createElement(MemoGitActionsControl, props("second", "/second")));
210 - });
211 - await act(async () => {
212 - toast.actionProps!.onClick();
213 - });
214 - expect(state.actions.at(-1)).toMatchObject({
215 - scope: { cwd: "/first" },
216 - input: { threadId: "first", action: "commit_push_pr" },
217 - });
218 - });
219 -
220 - it("runs the memoized panel button in the current thread after navigation", async () => {
221 - const renderer = await renderActions("first", "/first");
222 - for (const [thread, cwd] of [
223 - ["first", "/first"],
224 - ["second", "/second"],
225 - ["first", "/first"],
226 - ] as const) {
227 - await act(async () => {
228 - renderer.update(createElement(MemoGitActionsControl, props(thread, cwd)));
229 - });
230 - await clickQuickAction(renderer);
231 - expect(state.actions.at(-1)).toMatchObject({ scope: { cwd }, input: { threadId: thread } });
232 - }
233 - });
234 -});
apps/web/src/components/GitActionsControl.test.ts deleted
-337
@@ -1,337 +0,0 @@
1 -// @vitest-environment jsdom
2 -import {
3 - AuthOrchestrationOperateScope,
4 - AuthSourceControlWriteScope,
5 - EnvironmentId,
6 - ThreadId,
7 -} from "@t3tools/contracts";
8 -import * as Cause from "effect/Cause";
9 -import { AsyncResult } from "effect/reactivity";
10 -import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
11 -
12 -const state = vi.hoisted(() => ({
13 - scopes: new Set<string>(),
14 - primaryScopes: new Set<string>(),
15 - shell: { branch: "main" } as { branch: string } | null,
16 - detail: null as { branch: string } | null,
17 - draft: null as { branch: string; worktreePath: null; envMode: "local" } | null,
18 - branch: "main",
19 - commits: 0,
20 - metadataRequests: [] as { environmentId: string; branch: string }[],
21 - afterGitAction: undefined as (() => void) | undefined,
22 -}));
23 -
24 -vi.mock("@effect/atom-react", () => ({
25 - useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
26 -}));
27 -vi.mock("~/state/entities", () => ({
28 - useThreadProjection: (ref: unknown) =>
29 - ref === null || state.detail === null ? null : { projection: { thread: state.detail } },
30 - useQuietThreadShell: () => state.shell,
31 -}));
32 -vi.mock("~/state/session", () => ({
33 - useEnvironmentScope: (environmentId: unknown, scope: string) =>
34 - (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
35 - readEnvironmentScope: (environmentId: unknown, scope: string) =>
36 - (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
37 -}));
38 -vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
39 -vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
40 -vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
41 -vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
42 -vi.mock("~/state/vcs", () => ({
43 - vcsEnvironment: { status: () => null },
44 - vcsActionManager: { stateAtom: () => "vcs-state" },
45 -}));
46 -vi.mock("~/state/threads", () => ({
47 - threadEnvironment: {
48 - updateMetadata: async ({
49 - environmentId,
50 - input,
51 - }: {
52 - environmentId: string;
53 - input: { branch: string };
54 - }) => {
55 - state.metadataRequests.push({ environmentId, branch: input.branch });
56 - if (!state.scopes.has(AuthOrchestrationOperateScope))
57 - return AsyncResult.failure(Cause.fail(new Error("Task denied")));
58 - if (state.shell) state.shell.branch = input.branch;
59 - if (state.detail) state.detail.branch = input.branch;
60 - return AsyncResult.success(undefined);
61 - },
62 - },
63 -}));
64 -vi.mock("~/state/query", () => ({
65 - useEnvironmentQuery: () => ({
66 - data: {
67 - sourceControlProviders: [],
68 - isRepo: true,
69 - refName: state.branch,
70 - isDefaultRef: false,
71 - hasPrimaryRemote: true,
72 - hasWorkingTreeChanges: true,
73 - workingTree: {
74 - files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
75 - },
76 - },
77 - error: null,
78 - }),
79 -}));
80 -vi.mock("~/composerDraftStore", () => ({
81 - useComposerDraftStore: (
82 - select: (store: {
83 - getDraftSession: () => typeof state.draft;
84 - getDraftThreadByRef: () => typeof state.draft;
85 - setDraftThreadContext: (_target: unknown, input: { branch: string }) => void;
86 - }) => unknown,
87 - ) =>
88 - select({
89 - getDraftSession: () => state.draft,
90 - getDraftThreadByRef: () => state.draft,
91 - setDraftThreadContext: (_target, input) => {
92 - if (state.draft) state.draft.branch = input.branch;
93 - },
94 - }),
95 -}));
96 -vi.mock("~/lib/sourceControlActions", () => ({
97 - useSourceControlActionRunning: () => false,
98 - useVcsInitAction: () => ({}),
99 - useVcsPullAction: () => ({}),
100 - useSourceControlPublishRepositoryAction: () => ({}),
101 - useGitStackedAction: () => ({
102 - run: async ({ featureBranch }: { featureBranch?: boolean }) => {
103 - state.commits += 1;
104 - if (featureBranch) state.branch = "feature";
105 - state.afterGitAction?.();
106 - return {
107 - _tag: "Success",
108 - value: {
109 - branch: featureBranch
110 - ? { status: "created", name: "feature" }
111 - : { status: "skipped_not_requested" },
112 - toast: { title: "Committed", description: "Committed", cta: { kind: "none" } },
113 - },
114 - };
115 - },
116 - }),
117 -}));
118 -vi.mock("~/lib/utils", () => ({ cn: () => "", randomUUID: () => "action" }));
119 -vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => () => {} }));
120 -vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => () => {} }));
121 -vi.mock("~/lib/openPullRequestLink", () => ({ useOpenPrLink: () => () => {} }));
122 -vi.mock("~/components/ui/toast", () => ({
123 - stackedThreadToast: (input: unknown) => input,
124 - toastManager: { add: () => "toast", update: () => {}, close: () => {} },
125 -}));
126 -vi.mock("~/components/ui/dialog", () => ({
127 - Dialog: "Dialog",
128 - DialogDescription: "DialogDescription",
129 - DialogFooter: "DialogFooter",
130 - DialogHeader: "DialogHeader",
131 - DialogPanel: "DialogPanel",
132 - DialogPopup: "DialogPopup",
133 - DialogTitle: "DialogTitle",
134 -}));
135 -vi.mock("~/components/ui/group", () => ({ Group: "Group", GroupSeparator: "GroupSeparator" }));
136 -vi.mock("~/components/ui/menu", () => ({
137 - Menu: "Menu",
138 - MenuItem: "MenuItem",
139 - MenuItemLabel: "MenuItemLabel",
140 - MenuPopup: "MenuPopup",
141 - MenuTrigger: "MenuTrigger",
142 -}));
143 -vi.mock("~/components/ui/popover", () => ({
144 - Popover: "Popover",
145 - PopoverPopup: "PopoverPopup",
146 - PopoverTrigger: "PopoverTrigger",
147 -}));
148 -vi.mock("~/components/ui/tooltip", () => ({
149 - Tooltip: "Tooltip",
150 - TooltipPopup: "TooltipPopup",
151 - TooltipTrigger: "TooltipTrigger",
152 -}));
153 -vi.mock("~/components/ui/button", () => ({ Button: "Button" }));
154 -vi.mock("~/components/ui/checkbox", () => ({ Checkbox: "Checkbox" }));
155 -vi.mock("~/components/ui/input", () => ({ Input: "Input" }));
156 -vi.mock("~/components/ui/radio-group", () => ({ RadioGroup: "RadioGroup" }));
157 -vi.mock("~/components/ui/scroll-area", () => ({ ScrollArea: "ScrollArea" }));
158 -vi.mock("~/components/ui/spinner", () => ({ Spinner: "Spinner" }));
159 -vi.mock("~/components/ui/textarea", () => ({ Textarea: "Textarea" }));
160 -vi.mock("~/components/ui/toggle", () => ({ toggleVariants: () => "" }));
161 -vi.mock("./AnimatedHeight", () => ({ AnimatedHeight: "AnimatedHeight" }));
162 -
163 -import GitActionsControl from "./GitActionsControl";
164 -
165 -import { createElement } from "react";
166 -import { act, create, type ReactTestRenderer } from "react-test-renderer";
167 -
168 -vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
169 -
170 -let renderer: ReactTestRenderer | null = null;
171 -
172 -// Opens the commit dialog and returns its buttons' handlers from this render, so a test can
173 -// change grants afterwards and still click what the user saw.
174 -async function renderActions() {
175 - const element = createElement(GitActionsControl, {
176 - gitCwd: "/repo",
177 - activeThreadRef: {
178 - environmentId: EnvironmentId.make("environment"),
179 - threadId: ThreadId.make("thread"),
180 - },
181 - });
182 - await act(async () => {
183 - if (renderer) renderer.update(element);
184 - else renderer = create(element);
185 - });
186 - const root = renderer!.root;
187 - const commitMenuItem = root.find(
188 - (node) => String(node.type) === "MenuItemLabel" && node.props.children === "Commit",
189 - ).parent!;
190 - await act(async () => {
191 - commitMenuItem.props.onClick();
192 - });
193 - const buttonHandler = (label: string): (() => void) =>
194 - root.find((node) => String(node.type) === "Button" && node.props.children === label).props
195 - .onClick;
196 - const commit = buttonHandler("Commit");
197 - const commitOnNewBranch = buttonHandler("Commit on new branch");
198 - return async ({ featureBranch }: { action: "commit"; featureBranch?: boolean }) => {
199 - await act(async () => {
200 - (featureBranch ? commitOnNewBranch : commit)();
201 - });
202 - };
203 -}
204 -
205 -afterEach(async () => {
206 - await act(async () => {
207 - renderer?.unmount();
208 - });
209 - renderer = null;
210 -});
211 -
212 -describe("Git actions while thread details load", () => {
213 - beforeEach(() => {
214 - state.scopes = new Set([AuthSourceControlWriteScope]);
215 - state.primaryScopes = new Set([AuthSourceControlWriteScope, AuthOrchestrationOperateScope]);
216 - state.shell = { branch: "main" };
217 - state.detail = null;
218 - state.draft = null;
219 - state.branch = "main";
220 - state.commits = 0;
221 - state.metadataRequests = [];
222 - state.afterGitAction = undefined;
223 - });
224 -
225 - it("does not create a feature branch for a server thread without task permission", async () => {
226 - await (
227 - await renderActions()
228 - )({ action: "commit", featureBranch: true });
229 -
230 - expect(state.branch).toBe("main");
231 - expect(state.commits).toBe(0);
232 - expect(state.shell?.branch).toBe("main");
233 - });
234 -
235 - it("commits and synchronizes the server thread before details finish loading", async () => {
236 - state.primaryScopes.clear();
237 - state.scopes.add(AuthOrchestrationOperateScope);
238 - await (
239 - await renderActions()
240 - )({ action: "commit", featureBranch: true });
241 -
242 - expect(state.branch).toBe("feature");
243 - expect(state.commits).toBe(1);
244 - expect(state.shell?.branch).toBe("feature");
245 - expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
246 - });
247 -
248 - it("synchronizes archived thread detail after its shell disappears", async () => {
249 - state.scopes.add(AuthOrchestrationOperateScope);
250 - state.detail = { branch: "main" };
251 - await renderActions();
252 - state.shell = null;
253 -
254 - await (
255 - await renderActions()
256 - )({ action: "commit", featureBranch: true });
257 -
258 - expect(state.commits).toBe(1);
259 - expect(state.branch).toBe("feature");
260 - expect(state.detail.branch).toBe("feature");
261 - expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
262 - });
263 -
264 - it("requires task permission before changing an archived thread's branch", async () => {
265 - state.shell = null;
266 - state.detail = { branch: "main" };
267 -
268 - await (
269 - await renderActions()
270 - )({ action: "commit", featureBranch: true });
271 -
272 - expect(state.commits).toBe(0);
273 - expect(state.detail.branch).toBe("main");
274 - expect(state.metadataRequests).toEqual([]);
275 - });
276 -
277 - it("uses the current shell branch when cached detail names the new branch", async () => {
278 - state.scopes.add(AuthOrchestrationOperateScope);
279 - state.detail = { branch: "feature" };
280 -
281 - await (
282 - await renderActions()
283 - )({ action: "commit", featureBranch: true });
284 -
285 - expect(state.commits).toBe(1);
286 - expect(state.shell?.branch).toBe("feature");
287 - expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
288 - });
289 -
290 - it("synchronizes a retained callback after the thread grant is gained", async () => {
291 - const run = await renderActions();
292 - state.scopes.add(AuthOrchestrationOperateScope);
293 - await run({ action: "commit", featureBranch: true });
294 - expect(state.commits).toBe(1);
295 - expect(state.shell?.branch).toBe("feature");
296 - expect(state.metadataRequests).toHaveLength(1);
297 - });
298 -
299 - it.each([
300 - [AuthOrchestrationOperateScope, false],
301 - [AuthSourceControlWriteScope, true],
302 - ] as const)(
303 - "uses the fresh task grant after Git finishes, revoking %s",
304 - async (revokedScope, syncsThread) => {
305 - state.scopes.add(AuthOrchestrationOperateScope);
306 - state.afterGitAction = () => state.scopes.delete(revokedScope);
307 - await (
308 - await renderActions()
309 - )({ action: "commit", featureBranch: true });
310 - expect(state.commits).toBe(1);
311 - expect(state.branch).toBe("feature");
312 - expect(state.shell?.branch).toBe(syncsThread ? "feature" : "main");
313 - expect(state.metadataRequests).toHaveLength(syncsThread ? 1 : 0);
314 - },
315 - );
316 -
317 - it("keeps ordinary commits available while details load", async () => {
318 - await (
319 - await renderActions()
320 - )({ action: "commit" });
321 -
322 - expect(state.commits).toBe(1);
323 - expect(state.branch).toBe("main");
324 - });
325 -
326 - it("keeps feature-branch commits available for a local draft", async () => {
327 - state.shell = null;
328 - state.draft = { branch: "main", worktreePath: null, envMode: "local" };
329 - await (
330 - await renderActions()
331 - )({ action: "commit", featureBranch: true });
332 -
333 - expect(state.commits).toBe(1);
334 - expect(state.draft.branch).toBe("feature");
335 - expect(state.metadataRequests).toEqual([]);
336 - });
337 -});
apps/web/src/components/chat/WorkLog.browser.test.tsx
+1 -1
@@ -3,7 +3,7 @@ import { createRoot, type Root } from "react-dom/client";
3 import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
4 import { WorkLogDetails } from "./WorkLog";
5
6 -// jsdom has no layout, so the scroller's geometry is simulated: a 384px
6 +// The scroller's geometry is simulated so the test controls it: a 384px
7 // viewport over content whose height the test grows like a streamed trace.
8 const VIEWPORT = 384;
9 let contentHeight = 0;
apps/web/src/composer-list-split.browser.test.ts
+1 -1
@@ -19,7 +19,7 @@ import {
19 } from "./composer-rich-text-doc";
20
21 // ProseMirror's DOM observer can flush on a timer after a test ends, which
22 -// throws once jsdom is torn down, so every editor is destroyed after its test.
22 +// throws once its DOM is gone, so every editor is destroyed after its test.
23 const editors: Editor[] = [];
24 afterEach(() => {
25 for (const editor of editors.splice(0)) editor.destroy();
apps/web/src/terminal/ghostty/surface.test.ts
+1 -1
@@ -1370,7 +1370,7 @@ describe("terminal font resolution", () => {
1370 });
1371
1372 it("ignores proportional families the cell grid cannot lay out", () => {
1373 - // jsdom has no canvas metrics, so the probe answers "monospace" and the
1373 + // Node has no canvas, so the probe answers "monospace" and the
1374 // family is kept; the guard is exercised in the browser instead.
1375 const stack = terminalFontFamily("Helvetica Neue");
1376 expect(stack.endsWith("monospace")).toBe(true);
docs/internals/performance-regressions.md
+1 -1
@@ -117,4 +117,4 @@ continuous traffic during an outage.
117
118 Focused coverage: `ProjectionSettlement.test.ts`, `ThreadSettlementService.test.ts`,
119 `runtimeLayer.test.ts`, `AgentAwarenessRelay.test.ts`, `GitVcsDriverCore.test.ts`,
120 -`ThreadStatusIndicators.subscriptions.test.tsx`, and `desktopLocal.test.ts`.
120 +`ThreadStatusIndicators.subscriptions.browser.test.tsx`, and `desktopLocal.test.ts`.
docs/operations/development.md
+4
@@ -106,6 +106,10 @@ vp lint <files>
106 vp run --filter <package> typecheck
107 ```
108
109 +In `apps/web`, a test that renders React or touches the DOM is named `*.browser.test.{ts,tsx}`
110 +and runs in headless Chromium with the React Compiler on, like the app. There is no jsdom; other
111 +`*.test.ts` files run in Node.
112 +
113 TypeScript workspaces typecheck with tsc-rs, which has Effect diagnostics built in.
114 Keep `typescript`, `@effect/tsgo`, and the `effect-tsgo patch` prepare step: editors
115 still use them for Effect quick fixes and refactors. Keep `@effect/tsgo` on the
knip.jsonc
-2
@@ -64,8 +64,6 @@
64 "ignoreDependencies": ["playwright-core", "electron-builder"],
65 },
66 "apps/web": {
67 - // Vitest loads this through the per-file @vitest-environment directive.
68 - "ignoreDependencies": ["jsdom"],
67 // Worktree setup (scripts/setup-worktree.ts) runs this directly.
68 "entry": ["scripts/warm-dep-cache.ts"],
69 // UI component modules are copied and adapted as cohesive sets. Keep their
pnpm-lock.yaml
-20
@@ -974,9 +974,6 @@ importers:
974 '@types/react-dom':
975 specifier: ~19.2.3
976 version: 19.2.3(@types/react@19.3.0)
977 - '@types/react-test-renderer':
978 - specifier: 19.1.0
979 - version: 19.1.0
977 '@types/use-sync-external-store':
978 specifier: ^0.0.6
979 version: 0.0.6
@@ -992,18 +989,12 @@ importers:
989 compression:
990 specifier: ^1.8.2
991 version: 1.8.2
995 - jsdom:
996 - specifier: ^30.0.1
997 - version: 30.1.0(@noble/hashes@1.8.0)
992 oxc-transform-react:
993 specifier: ~0.152.0
994 version: 0.152.0
995 playwright:
996 specifier: 1.60.0
997 version: 1.60.0
1004 - react-test-renderer:
1005 - specifier: 19.2.6
1006 - version: 19.2.6(react@19.2.6)
998 tailwindcss:
999 specifier: 4.3.3
1000 version: 4.3.3
@@ -11223,11 +11214,6 @@ packages:
11214 resolution: {integrity: sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==}
11215 engines: {node: '>=0.10.0'}
11216
11226 - react-test-renderer@19.2.6:
11227 - resolution: {integrity: sha512-GbS6V23YduFTPiWJ5xICbKEjRcqx1Z90js/V5miqhz7qp/d6xSe9Dd6NjSQODFRdzdsqRMPW82E/sFpPRbY5Mw==}
11228 - peerDependencies:
11229 - react: ^19.2.6
11230 -
11217 react@19.2.6:
11218 resolution: {integrity: sha512-sfWGGfavi0xr8Pg0sVsyHMAOziVYKgPLNrS7ig+ivMNb3wbCBw3KxtflsGBAwD3gYQlE/AEZsTLgToRrSCjb0Q==}
11219 engines: {node: '>=0.10.0'}
@@ -22747,12 +22733,6 @@ snapshots:
22733
22734 react-refresh@0.14.2: {}
22735
22750 - react-test-renderer@19.2.6(react@19.2.6):
22751 - dependencies:
22752 - react: 19.2.6
22753 - react-is: 19.2.7
22754 - scheduler: 0.27.0
22755 -
22736 react@19.2.6: {}
22737
22738 react@19.3.0: {}