Skip to content

Commit 5afb4d0

Browse files
Merge branch 'main' into fix/preview-snapshot-backdrop-filter
2 parents aaea59f + d5b7095 commit 5afb4d0

28 files changed

Lines changed: 871 additions & 930 deletions

‎apps/web/package.json‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,13 @@
8484
"@types/mdast": "^4.0.4",
8585
"@types/react": "~19.3.0",
8686
"@types/react-dom": "~19.2.3",
87-
"@types/react-test-renderer": "19.1.0",
8887
"@types/use-sync-external-store": "^0.0.6",
8988
"@vercel/config": "^0.3.0",
9089
"@vitejs/plugin-react": "^6.1.2",
9190
"@vitest/browser-playwright": "5.0.1",
9291
"compression": "^1.8.2",
93-
"jsdom": "^30.0.1",
9492
"oxc-transform-react": "~0.152.0",
9593
"playwright": "1.60.0",
96-
"react-test-renderer": "19.2.6",
9794
"tailwindcss": "^4.0.0",
9895
"unified": "catalog:",
9996
"vite": "catalog:",

‎apps/web/src/browserFaviconStore.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { scopeProjectRef } from "@t3tools/client-runtime/environment";
22
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
33
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
44

5-
vi.mock("~/state/entities", () => ({ useThreadShell: () => null }));
5+
vi.mock("~/state/entities", () => ({ useQuietThreadShell: () => null }));
66
vi.mock("~/state/session", () => ({ usePreparedConnection: () => ({ _tag: "None" }) }));
77

88
import {

‎apps/web/src/browserFaviconStore.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { create } from "zustand";
99
import { createJSONStorage, persist } from "zustand/middleware";
1010

1111
import { normalizeHostname } from "~/browser/browserTargetResolver";
12-
import { useThreadShell } from "~/state/entities";
12+
import { useQuietThreadShell } from "~/state/entities";
1313
import { usePreparedConnection } from "~/state/session";
1414

1515
import {
@@ -196,7 +196,7 @@ export function registerFaviconProjectForThread(
196196
}
197197

198198
export function useFaviconProjectRefForThread(threadRef: ScopedThreadRef): ScopedProjectRef | null {
199-
const shell = useThreadShell(threadRef);
199+
const shell = useQuietThreadShell(threadRef);
200200
const shellProjectId = shell?.projectId ?? null;
201201
const environmentId = threadRef.environmentId;
202202
const shellProjectRef = shellProjectId ? scopeProjectRef(environmentId, shellProjectId) : null;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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‎

Lines changed: 0 additions & 138 deletions
This file was deleted.

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525

2626
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
2727
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
28-
import { useProject, useThreadShell, useThreadShellsForProjectRefs } from "../state/entities";
28+
import { useProject, useQuietThreadShell, useThreadShellsForProjectRefs } from "../state/entities";
2929
import {
3030
type EnvMode,
3131
type EnvironmentOption,
@@ -587,7 +587,7 @@ export const BranchToolbar = memo(function BranchToolbar({
587587
const draftThread = useComposerDraftStore((store) =>
588588
draftId ? store.getDraftSession(draftId) : store.getDraftThreadByRef(threadRef),
589589
);
590-
const serverThread = useThreadShell(threadRef);
590+
const serverThread = useQuietThreadShell(threadRef);
591591
const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
592592
const activeProjectRef = serverThread
593593
? scopeProjectRef(serverThread.environmentId, serverThread.projectId)

‎apps/web/src/components/BranchToolbarBranchSelector.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
3333
import { readLocalApi } from "../localApi";
3434
import { useOpenPrLink } from "../lib/openPullRequestLink";
3535
import { usePaginatedBranches } from "../state/queries";
36-
import { useProject, useThreadShell } from "../state/entities";
36+
import { useProject, useQuietThreadShell } from "../state/entities";
3737
import { useEnvironmentQuery } from "../state/query";
3838
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
3939
import { threadEnvironment } from "../state/threads";
@@ -130,7 +130,7 @@ export function BranchToolbarBranchSelector({
130130
reportFailure: false,
131131
});
132132
const threadRef = scopeThreadRef(environmentId, threadId);
133-
const serverThread = useThreadShell(threadRef);
133+
const serverThread = useQuietThreadShell(threadRef);
134134
const serverSession = serverThread?.runtime ?? null;
135135
const draftThread = useComposerDraftStore((store) =>
136136
draftId ? store.getDraftSession(draftId) : store.getDraftThreadByRef(threadRef),

0 commit comments

Comments
 (0)