Skip to content
TypeScript

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

Julius Marminged5b7095a0971
diff --git a/apps/web/package.json b/apps/web/package.json
index ccd3ce96e9d..15a202c071b 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -84,16 +84,13 @@
"@types/mdast": "^4.0.4",
"@types/react": "~19.3.0",
"@types/react-dom": "~19.2.3",
- "@types/react-test-renderer": "19.1.0",
"@types/use-sync-external-store": "^0.0.6",
"@vercel/config": "^0.3.0",
"@vitejs/plugin-react": "^6.1.2",
"@vitest/browser-playwright": "5.0.1",
"compression": "^1.8.2",
- "jsdom": "^30.0.1",
"oxc-transform-react": "~0.152.0",
"playwright": "1.60.0",
- "react-test-renderer": "19.2.6",
"tailwindcss": "^4.0.0",
"unified": "catalog:",
"vite": "catalog:",
diff --git a/apps/web/src/components/BranchToolbar.panel.browser.test.tsx b/apps/web/src/components/BranchToolbar.panel.browser.test.tsx
new file mode 100644
index 00000000000..d551a854c26
--- /dev/null
+++ b/apps/web/src/components/BranchToolbar.panel.browser.test.tsx
@@ -0,0 +1,132 @@
+import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
+import { act, type ComponentProps } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
+import { page, userEvent } from "vite-plus/test/browser";
+
+import "~/index.css";
+
+const state = vi.hoisted(() => ({
+ worktreePath: "/tmp/worktree" as string | null,
+ showContextMenu: vi.fn(),
+ writeTextToClipboard: vi.fn(),
+}));
+
+vi.mock(import("../localApi"), async (original) => ({
+ ...(await original()),
+ readLocalApi: (() => ({ contextMenu: { show: state.showContextMenu } })) as never,
+}));
+vi.mock(import("../hooks/useCopyToClipboard"), async (original) => ({
+ ...(await original()),
+ writeTextToClipboard: state.writeTextToClipboard,
+}));
+vi.mock(import("./BranchToolbarBranchSelector"), async (original) => ({
+ ...(await original()),
+ BranchToolbarBranchSelector: (() => null) as never,
+}));
+vi.mock(import("../state/entities"), async (original) => ({
+ ...(await original()),
+ useQuietThreadShell: (() => ({
+ environmentId: "local",
+ projectId: "project",
+ worktreePath: state.worktreePath,
+ })) as never,
+ useProject: (() => ({ workspaceRoot: "/tmp/project" })) as never,
+ useThreadShellsForProjectRefs: () => [],
+}));
+
+import { BranchToolbar } from "./BranchToolbar";
+
+let root: Root;
+let container: HTMLDivElement;
+
+beforeEach(() => {
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ state.worktreePath = "/tmp/worktree";
+ state.showContextMenu.mockReset().mockResolvedValue("copy-path");
+ state.writeTextToClipboard.mockReset().mockResolvedValue(true);
+ container = document.createElement("div");
+ document.body.append(container);
+ root = createRoot(container);
+});
+
+afterEach(async () => {
+ await act(async () => root.unmount());
+ container.remove();
+ vi.unstubAllGlobals();
+});
+
+function render(props: Partial<ComponentProps<typeof BranchToolbar>>) {
+ return act(async () =>
+ root.render(
+ <BranchToolbar
+ layout="panel"
+ panelSection="workspace"
+ environmentId={EnvironmentId.make("local")}
+ threadId={ThreadId.make("thread")}
+ showGitControls
+ envMode="local"
+ envLocked={false}
+ startFromOrigin={false}
+ onStartFromOriginChange={vi.fn()}
+ onEnvModeChange={vi.fn()}
+ {...props}
+ />,
+ ),
+ );
+}
+
+it("keeps machine choices usable when the combined row's workspace is locked", async () => {
+ const onEnvironmentChange = vi.fn();
+ await render({
+ onEnvironmentChange,
+ availableEnvironments: ["local", "remote"].map((id) => ({
+ environmentId: EnvironmentId.make(id),
+ projectId: ProjectId.make("project"),
+ label: id,
+ isPrimary: id === "local",
+ machine: "server",
+ })),
+ });
+ const trigger = container.querySelector("button")!;
+ expect(trigger.textContent).toBe("local");
+ expect(container.querySelectorAll("button")).toHaveLength(1);
+
+ // A ctrl-click is a macOS secondary click; it must not open the menu.
+ await act(async () => {
+ trigger.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, ctrlKey: true }));
+ });
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+
+ await userEvent.click(trigger);
+ await expect
+ .element(page.getByRole("menuitemradio", { name: "New worktree" }))
+ .toHaveAttribute("aria-disabled", "true");
+ await userEvent.click(page.getByRole("menuitemradio", { name: "remote" }));
+ expect(onEnvironmentChange).toHaveBeenCalledWith("remote");
+});
+
+it.each([
+ ["local", null, "/tmp/project"],
+ ["worktree", null, null],
+ ["worktree", "/tmp/worktree", "/tmp/worktree"],
+] as const)(
+ "copies only an existing workspace path with mode %s and worktree %s",
+ async (envMode, worktreePath, copiedPath) => {
+ state.worktreePath = worktreePath;
+ await render({ envMode });
+ const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
+ await act(async () => {
+ container.querySelector('[aria-label="Run context"]')!.dispatchEvent(event);
+ });
+ expect(event.defaultPrevented).toBe(copiedPath !== null);
+ if (copiedPath === null) {
+ expect(state.showContextMenu).not.toHaveBeenCalled();
+ expect(state.writeTextToClipboard).not.toHaveBeenCalled();
+ } else {
+ await vi.waitFor(() =>
+ expect(state.writeTextToClipboard).toHaveBeenCalledWith(copiedPath, "workspace path"),
+ );
+ }
+ },
+);
diff --git a/apps/web/src/components/BranchToolbar.panel.test.tsx b/apps/web/src/components/BranchToolbar.panel.test.tsx
deleted file mode 100644
index 6b73fdc615e..00000000000
--- a/apps/web/src/components/BranchToolbar.panel.test.tsx
+++ /dev/null
@@ -1,138 +0,0 @@
-// @vitest-environment jsdom
-
-import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
-import { act } from "react";
-import { createRoot } from "react-dom/client";
-import { expect, it, vi } from "vite-plus/test";
-
-const state = vi.hoisted(() => ({
- worktreePath: "/tmp/worktree" as string | null,
- showContextMenu: vi.fn().mockResolvedValue("copy-path"),
- writeTextToClipboard: vi.fn().mockResolvedValue(true),
-}));
-
-vi.mock("../localApi", () => ({
- readLocalApi: () => ({ contextMenu: { show: state.showContextMenu } }),
-}));
-vi.mock("../hooks/useCopyToClipboard", () => ({
- writeTextToClipboard: state.writeTextToClipboard,
-}));
-vi.mock("./BranchToolbarBranchSelector", () => ({ BranchToolbarBranchSelector: () => null }));
-vi.mock("../composerDraftStore", () => ({
- useComposerDraftStore: (select: (store: unknown) => unknown) =>
- select({ getDraftThreadByRef: () => null, setDraftThreadContext: vi.fn() }),
-}));
-vi.mock("../state/entities", () => ({
- useQuietThreadShell: () => ({
- environmentId: "local",
- projectId: "project",
- worktreePath: state.worktreePath,
- }),
- useProject: () => ({ workspaceRoot: "/tmp/project" }),
- useThreadShellsForProjectRefs: () => [],
-}));
-
-import { BranchToolbar } from "./BranchToolbar";
-
-it("keeps machine choices usable when the combined row's workspace is locked", async () => {
- vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
- const container = document.createElement("div");
- document.body.append(container);
- const root = createRoot(container);
- const onEnvironmentChange = vi.fn();
- try {
- await act(async () => {
- root.render(
- <BranchToolbar
- layout="panel"
- panelSection="workspace"
- environmentId={EnvironmentId.make("local")}
- threadId={ThreadId.make("thread")}
- showGitControls
- envMode="local"
- envLocked={false}
- startFromOrigin={false}
- onStartFromOriginChange={vi.fn()}
- onEnvModeChange={vi.fn()}
- onEnvironmentChange={onEnvironmentChange}
- availableEnvironments={["local", "remote"].map((id) => ({
- environmentId: EnvironmentId.make(id),
- projectId: ProjectId.make("project"),
- label: id,
- isPrimary: id === "local",
- machine: "server",
- }))}
- />,
- );
- });
- const trigger = container.querySelector("button")!;
- expect(trigger.textContent).toBe("local");
- expect(container.querySelectorAll("button")).toHaveLength(1);
- await act(async () => {
- trigger.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, ctrlKey: true }));
- });
- expect(document.querySelector('[role="menu"]')).toBeNull();
- await act(async () => trigger.click());
- const items = [...document.querySelectorAll<HTMLElement>('[role="menuitemradio"]')];
- expect(
- items.find((item) => item.textContent === "New worktree")?.getAttribute("aria-disabled"),
- ).toBe("true");
- await act(async () => items.find((item) => item.textContent === "remote")!.click());
- expect(onEnvironmentChange).toHaveBeenCalledWith("remote");
- } finally {
- await act(async () => root.unmount());
- container.remove();
- vi.unstubAllGlobals();
- }
-});
-
-it.each([
- ["local", null, "/tmp/project"],
- ["worktree", null, null],
- ["worktree", "/tmp/worktree", "/tmp/worktree"],
-] as const)(
- "copies only an existing workspace path with mode %s and worktree %s",
- async (envMode, worktreePath, copiedPath) => {
- vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
- state.worktreePath = worktreePath;
- state.showContextMenu.mockClear();
- state.writeTextToClipboard.mockClear();
- const container = document.createElement("div");
- document.body.append(container);
- const root = createRoot(container);
- try {
- await act(async () => {
- root.render(
- <BranchToolbar
- layout="panel"
- panelSection="workspace"
- environmentId={EnvironmentId.make("local")}
- threadId={ThreadId.make("thread")}
- showGitControls
- envMode={envMode}
- envLocked={false}
- startFromOrigin={false}
- onStartFromOriginChange={vi.fn()}
- onEnvModeChange={vi.fn()}
- />,
- );
- });
- const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
- await act(async () => {
- container.querySelector('[aria-label="Run context"]')!.dispatchEvent(event);
- });
- expect(event.defaultPrevented).toBe(copiedPath !== null);
- if (copiedPath === null) {
- expect(state.showContextMenu).not.toHaveBeenCalled();
- expect(state.writeTextToClipboard).not.toHaveBeenCalled();
- } else {
- expect(state.writeTextToClipboard).toHaveBeenCalledWith(copiedPath, "workspace path");
- }
- } finally {
- await act(async () => root.unmount());
- container.remove();
- state.worktreePath = "/tmp/worktree";
- vi.unstubAllGlobals();
- }
- },
-);
diff --git a/apps/web/src/components/GitActionsControl.browser.test.tsx b/apps/web/src/components/GitActionsControl.browser.test.tsx
new file mode 100644
index 00000000000..e4641b21700
--- /dev/null
+++ b/apps/web/src/components/GitActionsControl.browser.test.tsx
@@ -0,0 +1,382 @@
+import {
+ AuthOrchestrationOperateScope,
+ AuthSourceControlWriteScope,
+ EnvironmentId,
+ ThreadId,
+} from "@t3tools/contracts";
+import * as Cause from "effect/Cause";
+import { AsyncResult } from "effect/reactivity";
+import { act, memo } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
+import { page, userEvent } from "vite-plus/test/browser";
+
+import "~/index.css";
+
+type Branched = { readonly branch: string };
+type GitActionInput = { featureBranch?: boolean; threadId?: string; action: string };
+type Toast = { actionProps?: { onClick: () => void } };
+
+const state = vi.hoisted(() => ({
+ scopes: new Set<string>(),
+ primaryScopes: new Set<string>(),
+ shell: null as Branched | null,
+ detail: null as Branched | null,
+ draft: null as (Branched & { worktreePath: null; envMode: "local" }) | null,
+ branch: "main",
+ isDefaultRef: false,
+ actions: [] as { scope: { cwd: string | null }; input: GitActionInput }[],
+ metadataRequests: [] as { environmentId: string; branch: string }[],
+ toasts: [] as Toast[],
+ afterGitAction: undefined as (() => void) | undefined,
+}));
+
+vi.mock(import("~/state/session"), async (original) => {
+ const hasScope = (environmentId: unknown, scope: string) =>
+ (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope);
+ return {
+ ...(await original()),
+ useEnvironmentScope: hasScope as never,
+ readEnvironmentScope: hasScope as never,
+ };
+});
+vi.mock(import("~/state/entities"), async (original) => ({
+ ...(await original()),
+ useQuietThreadShell: ((ref: { threadId: string } | null) =>
+ ref === null || state.shell === null ? null : { ...state.shell, id: ref.threadId }) as never,
+ useThreadProjection: ((ref: unknown) =>
+ ref === null || state.detail === null
+ ? null
+ : { projection: { thread: state.detail } }) as never,
+}));
+vi.mock(import("~/state/query"), async (original) => ({
+ ...(await original()),
+ // Serves both the VCS status and the source-control discovery queries.
+ useEnvironmentQuery: (() => ({
+ data: {
+ sourceControlProviders: [],
+ isRepo: true,
+ refName: state.branch,
+ isDefaultRef: state.isDefaultRef,
+ hasPrimaryRemote: true,
+ hasWorkingTreeChanges: true,
+ workingTree: {
+ files: [{ path: "file.ts", insertions: 1, deletions: 0 }],
+ insertions: 1,
+ deletions: 0,
+ },
+ hasUpstream: true,
+ aheadCount: 0,
+ behindCount: 0,
+ pr: null,
+ },
+ error: null,
+ })) as never,
+}));
+vi.mock(import("~/state/use-atom-command"), async (original) => ({
+ ...(await original()),
+ // The only command whose result matters here is the thread's branch metadata update.
+ useAtomCommand: ((_command: unknown, options: unknown) =>
+ options === "thread branch metadata update"
+ ? async ({ environmentId, input }: { environmentId: string; input: { branch: string } }) => {
+ state.metadataRequests.push({ environmentId, branch: input.branch });
+ if (!state.scopes.has(AuthOrchestrationOperateScope))
+ return AsyncResult.failure(Cause.fail(new Error("Task denied")));
+ if (state.shell) state.shell = { branch: input.branch };
+ if (state.detail) state.detail = { branch: input.branch };
+ return AsyncResult.success(undefined);
+ }
+ : async () => AsyncResult.success(undefined)) as never,
+}));
+vi.mock(import("~/lib/sourceControlActions"), async (original) => ({
+ ...(await original()),
+ useSourceControlActionRunning: () => false,
+ useGitStackedAction: ((scope: { cwd: string | null }) => ({
+ run: async (input: GitActionInput) => {
+ state.actions.push({ scope, input });
+ if (input.featureBranch) state.branch = "feature";
+ state.afterGitAction?.();
+ return {
+ _tag: "Success",
+ value: {
+ branch: input.featureBranch
+ ? { status: "created", name: "feature" }
+ : { status: "skipped_not_requested" },
+ toast: {
+ title: "Committed",
+ description: "Committed",
+ cta: {
+ kind: "run_action",
+ label: "Push & create PR",
+ action: { kind: "commit_push_pr" },
+ },
+ },
+ },
+ };
+ },
+ })) as never,
+}));
+vi.mock(import("@tanstack/react-router"), async (original) => ({
+ ...(await original()),
+ useNavigate: (() => async () => {}) as never,
+}));
+vi.mock(import("~/components/ui/toast"), async (original) => {
+ const actual = await original();
+ return {
+ ...actual,
+ toastManager: {
+ ...actual.toastManager,
+ add: ((toast: Toast) => {
+ state.toasts.push(toast);
+ return "toast";
+ }) as never,
+ },
+ };
+});
+
+import { useComposerDraftStore } from "~/composerDraftStore";
+import GitActionsControl from "./GitActionsControl";
+
+// ThreadDetailsPanel keeps this component mounted behind React.memo when threads change.
+const MemoGitActionsControl = memo(GitActionsControl);
+
+let root: Root;
+let container: HTMLDivElement;
+
+function render(thread = "thread", cwd = "/repo") {
+ return act(async () =>
+ root.render(
+ <MemoGitActionsControl
+ gitCwd={cwd}
+ activeThreadRef={{
+ environmentId: EnvironmentId.make("environment"),
+ threadId: ThreadId.make(thread),
+ }}
+ />,
+ ),
+ );
+}
+
+const button = (name: string | RegExp) =>
+ page.getByRole("button", { name, exact: typeof name === "string" });
+const commits = () => state.actions.length;
+
+async function openCommitDialog() {
+ await userEvent.click(button("Git action options"));
+ await userEvent.click(page.getByRole("menuitem", { name: "Commit" }));
+ await expect.element(page.getByRole("dialog", { name: "Commit changes" })).toBeVisible();
+}
+
+beforeEach(() => {
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ state.scopes = new Set([AuthSourceControlWriteScope]);
+ state.primaryScopes = new Set([AuthSourceControlWriteScope, AuthOrchestrationOperateScope]);
+ state.shell = { branch: "main" };
+ state.detail = null;
+ state.draft = null;
+ state.branch = "main";
+ state.isDefaultRef = false;
+ state.actions = [];
+ state.metadataRequests = [];
+ state.toasts = [];
+ state.afterGitAction = undefined;
+ useComposerDraftStore.setState({
+ getDraftSession: () => state.draft as never,
+ getDraftThreadByRef: () => state.draft as never,
+ setDraftThreadContext: (_target, input) => {
+ if (state.draft && input.branch) state.draft = { ...state.draft, branch: input.branch };
+ },
+ });
+ container = document.createElement("div");
+ document.body.append(container);
+ root = createRoot(container);
+});
+
+afterEach(async () => {
+ await act(async () => root.unmount());
+ container.remove();
+ vi.unstubAllGlobals();
+ await vi.waitFor(() => expect(document.querySelector('[role="dialog"]')).toBeNull());
+});
+
+describe("Git actions while thread details load", () => {
+ it("does not offer a feature branch for a server thread without task permission", async () => {
+ await render();
+ await openCommitDialog();
+
+ // The primary environment's task grant must not leak into this thread's environment.
+ await expect.element(button("Commit on new branch")).toBeDisabled();
+ expect(commits()).toBe(0);
+ });
+
+ it("checks the task grant again when the feature-branch commit runs", async () => {
+ state.scopes.add(AuthOrchestrationOperateScope);
+ await render();
+ await openCommitDialog();
+ state.scopes.delete(AuthOrchestrationOperateScope);
+
+ await userEvent.click(button("Commit on new branch"));
+
+ expect(commits()).toBe(0);
+ expect(state.branch).toBe("main");
+ expect(state.shell?.branch).toBe("main");
+ });
+
+ it("commits and synchronizes the server thread before details finish loading", async () => {
+ state.primaryScopes.clear();
+ state.scopes.add(AuthOrchestrationOperateScope);
+ await render();
+ await openCommitDialog();
+ await userEvent.click(button("Commit on new branch"));
+
+ await vi.waitFor(() => expect(state.shell?.branch).toBe("feature"));
+ expect(commits()).toBe(1);
+ expect(state.actions[0]?.input).toMatchObject({ action: "commit", featureBranch: true });
+ expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
+ });
+
+ it("synchronizes archived thread detail after its shell disappears", async () => {
+ state.scopes.add(AuthOrchestrationOperateScope);
+ state.detail = { branch: "main" };
+ await render();
+ state.shell = null;
+ await render();
+ await openCommitDialog();
+ await userEvent.click(button("Commit on new branch"));
+
+ await vi.waitFor(() => expect(state.detail?.branch).toBe("feature"));
+ expect(commits()).toBe(1);
+ expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
+ });
+
+ it("requires task permission before changing an archived thread's branch", async () => {
+ state.shell = null;
+ state.detail = { branch: "main" };
+ await render();
+ await openCommitDialog();
+
+ await expect.element(button("Commit on new branch")).toBeDisabled();
+ expect(state.metadataRequests).toEqual([]);
+ });
+
+ it("uses the current shell branch when cached detail names the new branch", async () => {
+ state.scopes.add(AuthOrchestrationOperateScope);
+ state.detail = { branch: "feature" };
+ await render();
+ await openCommitDialog();
+ await userEvent.click(button("Commit on new branch"));
+
+ await vi.waitFor(() => expect(state.shell?.branch).toBe("feature"));
+ expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
+ });
+
+ it.each([
+ [AuthOrchestrationOperateScope, false],
+ [AuthSourceControlWriteScope, true],
+ ] as const)(
+ "uses the fresh task grant after Git finishes, revoking %s",
+ async (revokedScope, syncsThread) => {
+ state.scopes.add(AuthOrchestrationOperateScope);
+ state.afterGitAction = () => state.scopes.delete(revokedScope);
+ await render();
+ await openCommitDialog();
+ await userEvent.click(button("Commit on new branch"));
+
+ await vi.waitFor(() => expect(state.branch).toBe("feature"));
+ expect(commits()).toBe(1);
+ expect(state.shell?.branch).toBe(syncsThread ? "feature" : "main");
+ expect(state.metadataRequests).toHaveLength(syncsThread ? 1 : 0);
+ },
+ );
+
+ it("keeps ordinary commits available while details load", async () => {
+ await render();
+ await openCommitDialog();
+ await userEvent.click(button("Commit"));
+
+ await vi.waitFor(() => expect(commits()).toBe(1));
+ expect(state.actions[0]?.input).not.toHaveProperty("featureBranch");
+ expect(state.branch).toBe("main");
+ });
+
+ it("keeps feature-branch commits available for a local draft", async () => {
+ state.shell = null;
+ state.draft = { branch: "main", worktreePath: null, envMode: "local" };
+ await render();
+ await openCommitDialog();
+ await userEvent.click(button("Commit on new branch"));
+
+ await vi.waitFor(() => expect(state.draft?.branch).toBe("feature"));
+ expect(commits()).toBe(1);
+ expect(state.metadataRequests).toEqual([]);
+ });
+});
+
+describe("Default branch prompt", () => {
+ beforeEach(() => {
+ state.isDefaultRef = true;
+ state.scopes.add(AuthOrchestrationOperateScope);
+ });
+
+ it("moves the commit to a feature branch when asked", async () => {
+ await render();
+ await userEvent.click(button(/^Commit & push/));
+ await expect
+ .element(page.getByRole("dialog", { name: "Commit & push to default ref?" }))
+ .toBeVisible();
+ expect(commits()).toBe(0);
+
+ await userEvent.click(button("Check out feature branch & continue"));
+
+ await vi.waitFor(() => expect(state.shell?.branch).toBe("feature"));
+ expect(state.actions[0]?.input).toMatchObject({ action: "commit_push", featureBranch: true });
+ });
+
+ it("checks the task grant again when the feature branch is chosen", async () => {
+ await render();
+ await userEvent.click(button(/^Commit & push/));
+ await expect
+ .element(page.getByRole("dialog", { name: "Commit & push to default ref?" }))
+ .toBeVisible();
+ state.scopes.delete(AuthOrchestrationOperateScope);
+
+ await userEvent.click(button("Check out feature branch & continue"));
+
+ expect(commits()).toBe(0);
+ expect(state.shell?.branch).toBe("main");
+ });
+});
+
+describe("Git action targets across thread navigation", () => {
+ const quickAction = () => button(/^Commit, push & /);
+
+ it("runs a retained PR toast in the thread that produced it", async () => {
+ await render("first", "/first");
+ await userEvent.click(quickAction());
+ await vi.waitFor(() => expect(state.toasts.some((toast) => toast.actionProps)).toBe(true));
+ const toast = state.toasts.find((toast) => toast.actionProps)!;
+
+ await render("second", "/second");
+ await act(async () => toast.actionProps!.onClick());
+
+ expect(state.actions.at(-1)).toMatchObject({
+ scope: { cwd: "/first" },
+ input: { threadId: "first", action: "commit_push_pr" },
+ });
+ });
+
+ it("runs the memoized button in the current thread after navigation", async () => {
+ for (const [thread, cwd] of [
+ ["first", "/first"],
+ ["second", "/second"],
+ ["first", "/first"],
+ ] as const) {
+ await render(thread, cwd);
+ await userEvent.click(quickAction());
+ await vi.waitFor(() =>
+ expect(state.actions.at(-1)).toMatchObject({ scope: { cwd }, input: { threadId: thread } }),
+ );
+ }
+ expect(commits()).toBe(3);
+ });
+});
diff --git a/apps/web/src/components/GitActionsControl.lifecycle.test.ts b/apps/web/src/components/GitActionsControl.lifecycle.test.ts
deleted file mode 100644
index 1c8b014bb2c..00000000000
--- a/apps/web/src/components/GitActionsControl.lifecycle.test.ts
+++ /dev/null
@@ -1,234 +0,0 @@
-// @vitest-environment jsdom
-import { AuthSourceControlWriteScope, EnvironmentId, ThreadId } from "@t3tools/contracts";
-import { AsyncResult } from "effect/reactivity";
-import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
-
-const state = vi.hoisted(() => ({
- actions: [] as {
- scope: { environmentId: string | null; cwd: string | null };
- input: { threadId?: string; action: string };
- }[],
- toasts: [] as { type?: string; description?: string; actionProps?: { onClick: () => void } }[],
- scopes: new Set<string>(),
- primaryScopes: new Set<string>(),
-}));
-
-vi.mock("@effect/atom-react", () => ({
- useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
-}));
-vi.mock("~/state/entities", () => ({
- useThreadProjection: () => null,
- useQuietThreadShell: (ref: { threadId: string }) => ({ branch: "main", id: ref.threadId }),
-}));
-vi.mock("~/state/session", () => ({
- useEnvironmentScope: (environmentId: unknown, scope: string) =>
- (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
- readEnvironmentScope: (environmentId: unknown, scope: string) =>
- (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
-}));
-vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
-vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
-vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
-vi.mock("~/state/vcs", () => ({
- vcsEnvironment: { status: () => null },
- vcsActionManager: { stateAtom: () => "vcs-state" },
-}));
-vi.mock("~/state/threads", () => ({
- threadEnvironment: { updateMetadata: async () => AsyncResult.success(undefined) },
-}));
-vi.mock("~/state/query", () => ({
- useEnvironmentQuery: () => ({
- data: {
- sourceControlProviders: [],
- isRepo: true,
- refName: "main",
- isDefaultRef: false,
- hasPrimaryRemote: true,
- hasWorkingTreeChanges: true,
- workingTree: {
- files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
- },
- },
- error: null,
- }),
-}));
-vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
-vi.mock("~/composerDraftStore", () => ({
- useComposerDraftStore: (
- select: (store: {
- getDraftSession: () => null;
- getDraftThreadByRef: () => null;
- setDraftThreadContext: () => void;
- }) => unknown,
- ) =>
- select({
- getDraftSession: () => null,
- getDraftThreadByRef: () => null,
- setDraftThreadContext: () => {},
- }),
-}));
-vi.mock("~/lib/sourceControlActions", () => ({
- useSourceControlActionRunning: () => false,
- useVcsInitAction: () => ({}),
- useVcsPullAction: () => ({}),
- useSourceControlPublishRepositoryAction: () => ({}),
- useGitStackedAction: (scope: { environmentId: string | null; cwd: string | null }) => ({
- run: async (input: { featureBranch?: boolean; threadId?: string; action: string }) => {
- state.actions.push({ scope, input });
- return {
- _tag: "Success",
- value: {
- branch: { status: "skipped_not_requested" },
- toast: {
- title: "Committed",
- description: "Committed",
- cta: {
- kind: "run_action",
- label: "Push & create PR",
- action: { kind: "commit_push_pr" },
- },
- },
- },
- };
- },
- }),
-}));
-vi.mock("~/lib/utils", () => ({ cn: () => "", randomUUID: () => "action" }));
-vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => () => {} }));
-vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => () => {} }));
-vi.mock("~/lib/openPullRequestLink", () => ({ useOpenPrLink: () => () => {} }));
-vi.mock("~/components/ui/toast", () => ({
- stackedThreadToast: (input: unknown) => input,
- toastManager: {
- add: (input: {
- type?: string;
- description?: string;
- actionProps?: { onClick: () => void };
- }) => {
- state.toasts.push(input);
- return "toast";
- },
- update: () => {},
- close: () => {},
- },
-}));
-vi.mock("~/components/ui/dialog", () => ({
- Dialog: "Dialog",
- DialogDescription: "DialogDescription",
- DialogFooter: "DialogFooter",
- DialogHeader: "DialogHeader",
- DialogPanel: "DialogPanel",
- DialogPopup: "DialogPopup",
- DialogTitle: "DialogTitle",
-}));
-vi.mock("~/components/ui/group", () => ({ Group: "Group", GroupSeparator: "GroupSeparator" }));
-vi.mock("~/components/ui/menu", () => ({
- Menu: "Menu",
- MenuItem: "MenuItem",
- MenuItemLabel: "MenuItemLabel",
- MenuPopup: "MenuPopup",
- MenuTrigger: "MenuTrigger",
-}));
-vi.mock("~/components/ui/popover", () => ({
- Popover: "Popover",
- PopoverPopup: "PopoverPopup",
- PopoverTrigger: "PopoverTrigger",
-}));
-vi.mock("~/components/ui/tooltip", () => ({
- Tooltip: "Tooltip",
- TooltipPopup: "TooltipPopup",
- TooltipTrigger: "TooltipTrigger",
-}));
-vi.mock("~/components/ui/button", () => ({ Button: "button" }));
-vi.mock("~/components/ui/checkbox", () => ({ Checkbox: "Checkbox" }));
-vi.mock("~/components/ui/input", () => ({ Input: "Input" }));
-vi.mock("~/components/ui/radio-group", () => ({ RadioGroup: "RadioGroup" }));
-vi.mock("~/components/ui/scroll-area", () => ({ ScrollArea: "ScrollArea" }));
-vi.mock("~/components/ui/spinner", () => ({ Spinner: "Spinner" }));
-vi.mock("~/components/ui/textarea", () => ({ Textarea: "Textarea" }));
-vi.mock("~/components/ui/toggle", () => ({ toggleVariants: () => "" }));
-vi.mock("./AnimatedHeight", () => ({ AnimatedHeight: "AnimatedHeight" }));
-
-import GitActionsControl from "./GitActionsControl";
-
-import { createElement, memo } from "react";
-import { act, create } from "react-test-renderer";
-
-vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
-
-const renderers: ReturnType<typeof create>[] = [];
-// ThreadDetailsPanel keeps this component mounted behind React.memo when threads change.
-const MemoGitActionsControl = memo(GitActionsControl);
-const props = (thread: string, cwd: string) => ({
- gitCwd: cwd,
- activeThreadRef: {
- environmentId: EnvironmentId.make("environment"),
- threadId: ThreadId.make(thread),
- },
-});
-
-async function renderActions(thread: string, cwd: string) {
- let renderer!: ReturnType<typeof create>;
- await act(async () => {
- renderer = create(createElement(MemoGitActionsControl, props(thread, cwd)));
- });
- renderers.push(renderer);
- return renderer;
-}
-
-async function clickQuickAction(renderer: ReturnType<typeof create>) {
- const button = renderer.root
- .findAllByType("button")
- .find((button) => button.props.onClick && !button.props.disabled);
- expect(button).toBeDefined();
- await act(async () => {
- button!.props.onClick({});
- });
-}
-
-beforeEach(() => {
- state.scopes = new Set([AuthSourceControlWriteScope]);
- state.primaryScopes = new Set([AuthSourceControlWriteScope]);
- state.actions = [];
- state.toasts = [];
-});
-
-afterEach(async () => {
- await act(async () => {
- for (const renderer of renderers.splice(0)) renderer.unmount();
- });
-});
-
-describe("Git action targets across thread navigation", () => {
- it("runs a retained PR toast in the thread that produced it", async () => {
- const renderer = await renderActions("first", "/first");
- await clickQuickAction(renderer);
- const toast = state.toasts.find((toast) => toast.actionProps)!;
- expect(toast).toBeDefined();
- await act(async () => {
- renderer.update(createElement(MemoGitActionsControl, props("second", "/second")));
- });
- await act(async () => {
- toast.actionProps!.onClick();
- });
- expect(state.actions.at(-1)).toMatchObject({
- scope: { cwd: "/first" },
- input: { threadId: "first", action: "commit_push_pr" },
- });
- });
-
- it("runs the memoized panel button in the current thread after navigation", async () => {
- const renderer = await renderActions("first", "/first");
- for (const [thread, cwd] of [
- ["first", "/first"],
- ["second", "/second"],
- ["first", "/first"],
- ] as const) {
- await act(async () => {
- renderer.update(createElement(MemoGitActionsControl, props(thread, cwd)));
- });
- await clickQuickAction(renderer);
- expect(state.actions.at(-1)).toMatchObject({ scope: { cwd }, input: { threadId: thread } });
- }
- });
-});
diff --git a/apps/web/src/components/GitActionsControl.test.ts b/apps/web/src/components/GitActionsControl.test.ts
deleted file mode 100644
index 964a4d45096..00000000000
--- a/apps/web/src/components/GitActionsControl.test.ts
+++ /dev/null
@@ -1,337 +0,0 @@
-// @vitest-environment jsdom
-import {
- AuthOrchestrationOperateScope,
- AuthSourceControlWriteScope,
- EnvironmentId,
- ThreadId,
-} from "@t3tools/contracts";
-import * as Cause from "effect/Cause";
-import { AsyncResult } from "effect/reactivity";
-import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
-
-const state = vi.hoisted(() => ({
- scopes: new Set<string>(),
- primaryScopes: new Set<string>(),
- shell: { branch: "main" } as { branch: string } | null,
- detail: null as { branch: string } | null,
- draft: null as { branch: string; worktreePath: null; envMode: "local" } | null,
- branch: "main",
- commits: 0,
- metadataRequests: [] as { environmentId: string; branch: string }[],
- afterGitAction: undefined as (() => void) | undefined,
-}));
-
-vi.mock("@effect/atom-react", () => ({
- useAtomValue: (atom: unknown) => (atom === "vcs-state" ? { isRunning: false } : null),
-}));
-vi.mock("~/state/entities", () => ({
- useThreadProjection: (ref: unknown) =>
- ref === null || state.detail === null ? null : { projection: { thread: state.detail } },
- useQuietThreadShell: () => state.shell,
-}));
-vi.mock("~/state/session", () => ({
- useEnvironmentScope: (environmentId: unknown, scope: string) =>
- (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
- readEnvironmentScope: (environmentId: unknown, scope: string) =>
- (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
-}));
-vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
-vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
-vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
-vi.mock("@tanstack/react-router", () => ({ useNavigate: () => () => {} }));
-vi.mock("~/state/vcs", () => ({
- vcsEnvironment: { status: () => null },
- vcsActionManager: { stateAtom: () => "vcs-state" },
-}));
-vi.mock("~/state/threads", () => ({
- threadEnvironment: {
- updateMetadata: async ({
- environmentId,
- input,
- }: {
- environmentId: string;
- input: { branch: string };
- }) => {
- state.metadataRequests.push({ environmentId, branch: input.branch });
- if (!state.scopes.has(AuthOrchestrationOperateScope))
- return AsyncResult.failure(Cause.fail(new Error("Task denied")));
- if (state.shell) state.shell.branch = input.branch;
- if (state.detail) state.detail.branch = input.branch;
- return AsyncResult.success(undefined);
- },
- },
-}));
-vi.mock("~/state/query", () => ({
- useEnvironmentQuery: () => ({
- data: {
- sourceControlProviders: [],
- isRepo: true,
- refName: state.branch,
- isDefaultRef: false,
- hasPrimaryRemote: true,
- hasWorkingTreeChanges: true,
- workingTree: {
- files: [{ path: "file.ts", status: "modified", insertions: 1, deletions: 0 }],
- },
- },
- error: null,
- }),
-}));
-vi.mock("~/composerDraftStore", () => ({
- useComposerDraftStore: (
- select: (store: {
- getDraftSession: () => typeof state.draft;
- getDraftThreadByRef: () => typeof state.draft;
- setDraftThreadContext: (_target: unknown, input: { branch: string }) => void;
- }) => unknown,
- ) =>
- select({
- getDraftSession: () => state.draft,
- getDraftThreadByRef: () => state.draft,
- setDraftThreadContext: (_target, input) => {
- if (state.draft) state.draft.branch = input.branch;
- },
- }),
-}));
-vi.mock("~/lib/sourceControlActions", () => ({
- useSourceControlActionRunning: () => false,
- useVcsInitAction: () => ({}),
- useVcsPullAction: () => ({}),
- useSourceControlPublishRepositoryAction: () => ({}),
- useGitStackedAction: () => ({
- run: async ({ featureBranch }: { featureBranch?: boolean }) => {
- state.commits += 1;
- if (featureBranch) state.branch = "feature";
- state.afterGitAction?.();
- return {
- _tag: "Success",
- value: {
- branch: featureBranch
- ? { status: "created", name: "feature" }
- : { status: "skipped_not_requested" },
- toast: { title: "Committed", description: "Committed", cta: { kind: "none" } },
- },
- };
- },
- }),
-}));
-vi.mock("~/lib/utils", () => ({ cn: () => "", randomUUID: () => "action" }));
-vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => () => {} }));
-vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => () => {} }));
-vi.mock("~/lib/openPullRequestLink", () => ({ useOpenPrLink: () => () => {} }));
-vi.mock("~/components/ui/toast", () => ({
- stackedThreadToast: (input: unknown) => input,
- toastManager: { add: () => "toast", update: () => {}, close: () => {} },
-}));
-vi.mock("~/components/ui/dialog", () => ({
- Dialog: "Dialog",
- DialogDescription: "DialogDescription",
- DialogFooter: "DialogFooter",
- DialogHeader: "DialogHeader",
- DialogPanel: "DialogPanel",
- DialogPopup: "DialogPopup",
- DialogTitle: "DialogTitle",
-}));
-vi.mock("~/components/ui/group", () => ({ Group: "Group", GroupSeparator: "GroupSeparator" }));
-vi.mock("~/components/ui/menu", () => ({
- Menu: "Menu",
- MenuItem: "MenuItem",
- MenuItemLabel: "MenuItemLabel",
- MenuPopup: "MenuPopup",
- MenuTrigger: "MenuTrigger",
-}));
-vi.mock("~/components/ui/popover", () => ({
- Popover: "Popover",
- PopoverPopup: "PopoverPopup",
- PopoverTrigger: "PopoverTrigger",
-}));
-vi.mock("~/components/ui/tooltip", () => ({
- Tooltip: "Tooltip",
- TooltipPopup: "TooltipPopup",
- TooltipTrigger: "TooltipTrigger",
-}));
-vi.mock("~/components/ui/button", () => ({ Button: "Button" }));
-vi.mock("~/components/ui/checkbox", () => ({ Checkbox: "Checkbox" }));
-vi.mock("~/components/ui/input", () => ({ Input: "Input" }));
-vi.mock("~/components/ui/radio-group", () => ({ RadioGroup: "RadioGroup" }));
-vi.mock("~/components/ui/scroll-area", () => ({ ScrollArea: "ScrollArea" }));
-vi.mock("~/components/ui/spinner", () => ({ Spinner: "Spinner" }));
-vi.mock("~/components/ui/textarea", () => ({ Textarea: "Textarea" }));
-vi.mock("~/components/ui/toggle", () => ({ toggleVariants: () => "" }));
-vi.mock("./AnimatedHeight", () => ({ AnimatedHeight: "AnimatedHeight" }));
-
-import GitActionsControl from "./GitActionsControl";
-
-import { createElement } from "react";
-import { act, create, type ReactTestRenderer } from "react-test-renderer";
-
-vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
-
-let renderer: ReactTestRenderer | null = null;
-
-// Opens the commit dialog and returns its buttons' handlers from this render, so a test can
-// change grants afterwards and still click what the user saw.
-async function renderActions() {
- const element = createElement(GitActionsControl, {
- gitCwd: "/repo",
- activeThreadRef: {
- environmentId: EnvironmentId.make("environment"),
- threadId: ThreadId.make("thread"),
- },
- });
- await act(async () => {
- if (renderer) renderer.update(element);
- else renderer = create(element);
- });
- const root = renderer!.root;
- const commitMenuItem = root.find(
- (node) => String(node.type) === "MenuItemLabel" && node.props.children === "Commit",
- ).parent!;
- await act(async () => {
- commitMenuItem.props.onClick();
- });
- const buttonHandler = (label: string): (() => void) =>
- root.find((node) => String(node.type) === "Button" && node.props.children === label).props
- .onClick;
- const commit = buttonHandler("Commit");
- const commitOnNewBranch = buttonHandler("Commit on new branch");
- return async ({ featureBranch }: { action: "commit"; featureBranch?: boolean }) => {
- await act(async () => {
- (featureBranch ? commitOnNewBranch : commit)();
- });
- };
-}
-
-afterEach(async () => {
- await act(async () => {
- renderer?.unmount();
- });
- renderer = null;
-});
-
-describe("Git actions while thread details load", () => {
- beforeEach(() => {
- state.scopes = new Set([AuthSourceControlWriteScope]);
- state.primaryScopes = new Set([AuthSourceControlWriteScope, AuthOrchestrationOperateScope]);
- state.shell = { branch: "main" };
- state.detail = null;
- state.draft = null;
- state.branch = "main";
- state.commits = 0;
- state.metadataRequests = [];
- state.afterGitAction = undefined;
- });
-
- it("does not create a feature branch for a server thread without task permission", async () => {
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
-
- expect(state.branch).toBe("main");
- expect(state.commits).toBe(0);
- expect(state.shell?.branch).toBe("main");
- });
-
- it("commits and synchronizes the server thread before details finish loading", async () => {
- state.primaryScopes.clear();
- state.scopes.add(AuthOrchestrationOperateScope);
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
-
- expect(state.branch).toBe("feature");
- expect(state.commits).toBe(1);
- expect(state.shell?.branch).toBe("feature");
- expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
- });
-
- it("synchronizes archived thread detail after its shell disappears", async () => {
- state.scopes.add(AuthOrchestrationOperateScope);
- state.detail = { branch: "main" };
- await renderActions();
- state.shell = null;
-
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
-
- expect(state.commits).toBe(1);
- expect(state.branch).toBe("feature");
- expect(state.detail.branch).toBe("feature");
- expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
- });
-
- it("requires task permission before changing an archived thread's branch", async () => {
- state.shell = null;
- state.detail = { branch: "main" };
-
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
-
- expect(state.commits).toBe(0);
- expect(state.detail.branch).toBe("main");
- expect(state.metadataRequests).toEqual([]);
- });
-
- it("uses the current shell branch when cached detail names the new branch", async () => {
- state.scopes.add(AuthOrchestrationOperateScope);
- state.detail = { branch: "feature" };
-
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
-
- expect(state.commits).toBe(1);
- expect(state.shell?.branch).toBe("feature");
- expect(state.metadataRequests).toEqual([{ environmentId: "environment", branch: "feature" }]);
- });
-
- it("synchronizes a retained callback after the thread grant is gained", async () => {
- const run = await renderActions();
- state.scopes.add(AuthOrchestrationOperateScope);
- await run({ action: "commit", featureBranch: true });
- expect(state.commits).toBe(1);
- expect(state.shell?.branch).toBe("feature");
- expect(state.metadataRequests).toHaveLength(1);
- });
-
- it.each([
- [AuthOrchestrationOperateScope, false],
- [AuthSourceControlWriteScope, true],
- ] as const)(
- "uses the fresh task grant after Git finishes, revoking %s",
- async (revokedScope, syncsThread) => {
- state.scopes.add(AuthOrchestrationOperateScope);
- state.afterGitAction = () => state.scopes.delete(revokedScope);
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
- expect(state.commits).toBe(1);
- expect(state.branch).toBe("feature");
- expect(state.shell?.branch).toBe(syncsThread ? "feature" : "main");
- expect(state.metadataRequests).toHaveLength(syncsThread ? 1 : 0);
- },
- );
-
- it("keeps ordinary commits available while details load", async () => {
- await (
- await renderActions()
- )({ action: "commit" });
-
- expect(state.commits).toBe(1);
- expect(state.branch).toBe("main");
- });
-
- it("keeps feature-branch commits available for a local draft", async () => {
- state.shell = null;
- state.draft = { branch: "main", worktreePath: null, envMode: "local" };
- await (
- await renderActions()
- )({ action: "commit", featureBranch: true });
-
- expect(state.commits).toBe(1);
- expect(state.draft.branch).toBe("feature");
- expect(state.metadataRequests).toEqual([]);
- });
-});
diff --git a/apps/web/src/components/chat/WorkLog.browser.test.tsx b/apps/web/src/components/chat/WorkLog.browser.test.tsx
index 1cc82c7b5ff..9ab6c17a067 100644
--- a/apps/web/src/components/chat/WorkLog.browser.test.tsx
+++ b/apps/web/src/components/chat/WorkLog.browser.test.tsx
@@ -3,7 +3,7 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import { WorkLogDetails } from "./WorkLog";
-// jsdom has no layout, so the scroller's geometry is simulated: a 384px
+// The scroller's geometry is simulated so the test controls it: a 384px
// viewport over content whose height the test grows like a streamed trace.
const VIEWPORT = 384;
let contentHeight = 0;
diff --git a/apps/web/src/composer-list-split.browser.test.ts b/apps/web/src/composer-list-split.browser.test.ts
index 7b206dc08d0..ed672464c7c 100644
--- a/apps/web/src/composer-list-split.browser.test.ts
+++ b/apps/web/src/composer-list-split.browser.test.ts
@@ -19,7 +19,7 @@ import {
} from "./composer-rich-text-doc";
// ProseMirror's DOM observer can flush on a timer after a test ends, which
-// throws once jsdom is torn down, so every editor is destroyed after its test.
+// throws once its DOM is gone, so every editor is destroyed after its test.
const editors: Editor[] = [];
afterEach(() => {
for (const editor of editors.splice(0)) editor.destroy();
diff --git a/apps/web/src/terminal/ghostty/surface.test.ts b/apps/web/src/terminal/ghostty/surface.test.ts
index ca7363b815b..c81f9ae1823 100644
--- a/apps/web/src/terminal/ghostty/surface.test.ts
+++ b/apps/web/src/terminal/ghostty/surface.test.ts
@@ -1370,7 +1370,7 @@ describe("terminal font resolution", () => {
});
it("ignores proportional families the cell grid cannot lay out", () => {
- // jsdom has no canvas metrics, so the probe answers "monospace" and the
+ // Node has no canvas, so the probe answers "monospace" and the
// family is kept; the guard is exercised in the browser instead.
const stack = terminalFontFamily("Helvetica Neue");
expect(stack.endsWith("monospace")).toBe(true);
diff --git a/docs/internals/performance-regressions.md b/docs/internals/performance-regressions.md
index ac3d4a29d48..3ac6703ad6a 100644
--- a/docs/internals/performance-regressions.md
+++ b/docs/internals/performance-regressions.md
@@ -117,4 +117,4 @@ continuous traffic during an outage.
Focused coverage: `ProjectionSettlement.test.ts`, `ThreadSettlementService.test.ts`,
`runtimeLayer.test.ts`, `AgentAwarenessRelay.test.ts`, `GitVcsDriverCore.test.ts`,
-`ThreadStatusIndicators.subscriptions.test.tsx`, and `desktopLocal.test.ts`.
+`ThreadStatusIndicators.subscriptions.browser.test.tsx`, and `desktopLocal.test.ts`.
diff --git a/docs/operations/development.md b/docs/operations/development.md
index cc7d569f704..7346612d965 100644
--- a/docs/operations/development.md
+++ b/docs/operations/development.md
@@ -106,6 +106,10 @@ vp lint <files>
vp run --filter <package> typecheck
```
+In `apps/web`, a test that renders React or touches the DOM is named `*.browser.test.{ts,tsx}`
+and runs in headless Chromium with the React Compiler on, like the app. There is no jsdom; other
+`*.test.ts` files run in Node.
+
TypeScript workspaces typecheck with tsc-rs, which has Effect diagnostics built in.
Keep `typescript`, `@effect/tsgo`, and the `effect-tsgo patch` prepare step: editors
still use them for Effect quick fixes and refactors. Keep `@effect/tsgo` on the
diff --git a/knip.jsonc b/knip.jsonc
index 12c661fd083..e0886545f2b 100644
--- a/knip.jsonc
+++ b/knip.jsonc
@@ -64,8 +64,6 @@
"ignoreDependencies": ["playwright-core", "electron-builder"],
},
"apps/web": {
- // Vitest loads this through the per-file @vitest-environment directive.
- "ignoreDependencies": ["jsdom"],
// Worktree setup (scripts/setup-worktree.ts) runs this directly.
"entry": ["scripts/warm-dep-cache.ts"],
// UI component modules are copied and adapted as cohesive sets. Keep their
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f98342d2983..8c6cd98d70c 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -974,9 +974,6 @@ importers:
'@types/react-dom':
specifier: ~19.2.3
version: 19.2.3(@types/[email protected])
- '@types/react-test-renderer':
- specifier: 19.1.0
- version: 19.1.0
'@types/use-sync-external-store':
specifier: ^0.0.6
version: 0.0.6
@@ -992,18 +989,12 @@ importers:
compression:
specifier: ^1.8.2
version: 1.8.2
- jsdom:
- specifier: ^30.0.1
- version: 30.1.0(@noble/[email protected])
oxc-transform-react:
specifier: ~0.152.0
version: 0.152.0
playwright:
specifier: 1.60.0
version: 1.60.0
- react-test-renderer:
- specifier: 19.2.6
- version: 19.2.6([email protected])
tailwindcss:
specifier: 4.3.3
version: 4.3.3
@@ -11223,11 +11214,6 @@ packages:
resolution: {integrity: sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==}
engines: {node: '>=0.10.0'}
- resolution: {integrity: sha512-GbS6V23YduFTPiWJ5xICbKEjRcqx1Z90js/V5miqhz7qp/d6xSe9Dd6NjSQODFRdzdsqRMPW82E/sFpPRbY5Mw==}
- peerDependencies:
- react: ^19.2.6
-
resolution: {integrity: sha512-sfWGGfavi0xr8Pg0sVsyHMAOziVYKgPLNrS7ig+ivMNb3wbCBw3KxtflsGBAwD3gYQlE/AEZsTLgToRrSCjb0Q==}
engines: {node: '>=0.10.0'}
@@ -22747,12 +22733,6 @@ snapshots:
- dependencies:
- react: 19.2.6
- react-is: 19.2.7
- scheduler: 0.27.0
-