workspaceShellRemoteMobileLayout.test.ts 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import type { V4ChatPaneProps } from "@/v4/V4ChatPane.js";
  5. import { V4_PRIMARY_PANE_ID } from "@/v4/paneLayoutStore.js";
  6. import { useWorkbenchGroupStore } from "@/v4/workbenchGroupStore.js";
  7. vi.mock("@/app-shell/AnimatedSidePanePanel.js", () => ({
  8. AnimatedSidePanePanel: ({
  9. isVisible,
  10. mobileOverlay,
  11. mobileStacked,
  12. }: {
  13. isVisible?: boolean;
  14. mobileOverlay?: boolean;
  15. mobileStacked?: boolean;
  16. }) =>
  17. createElement("div", {
  18. "data-mobile-overlay": mobileOverlay ? "true" : "false",
  19. "data-mobile-stacked": mobileStacked ? "true" : "false",
  20. "data-panel-visible": isVisible ? "true" : "false",
  21. "data-testid": "side-pane-panel",
  22. }),
  23. }));
  24. vi.mock("@/app-shell/AnimatedTerminalPanel.js", () => ({
  25. AnimatedTerminalPanel: () => createElement("div", { "data-testid": "terminal-panel" }),
  26. }));
  27. vi.mock("@/app-shell/useAnimatedResizablePanel.js", () => ({
  28. useAnimatedResizablePanel: ({ open }: { open: boolean }) => ({
  29. isVisible: open,
  30. panelElementRef: { current: null },
  31. panelRef: { current: null },
  32. }),
  33. }));
  34. vi.mock("@/settings/AutomationsSection.js", () => ({
  35. AUTOMATIONS_TOAST_ANCHOR_ID: "automations-main-toast-anchor",
  36. AutomationsSection: () => createElement("div", { "data-testid": "automations-section" }),
  37. }));
  38. vi.mock("@/settings/PluginStorePage.js", () => ({
  39. PluginStorePage: () => createElement("div", { "data-testid": "plugin-store-page" }),
  40. }));
  41. const capturedChatPaneProps: V4ChatPaneProps[] = [];
  42. vi.mock("@/v4/V4ChatPane.js", () => ({
  43. V4ChatPane: (props: V4ChatPaneProps) => {
  44. capturedChatPaneProps.push(props);
  45. return createElement("div", { "data-testid": "v4-chat-pane" });
  46. },
  47. }));
  48. // M5⑤:桌面主区改由分屏宿主承载(props 形状与 V4ChatPane 相同的超集),
  49. // 布局测试同样打桩——分屏行为在 v4PaneLayoutStore 单测与 v4-split e2e 覆盖。
  50. vi.mock("@/v4/V4WorkspaceChatArea.js", () => ({
  51. V4WorkspaceChatArea: (props: V4ChatPaneProps) => {
  52. capturedChatPaneProps.push(props);
  53. return createElement("div", { "data-testid": "v4-chat-pane" });
  54. },
  55. }));
  56. vi.mock("@/BotsDialog.js", () => ({
  57. BotsDialog: () => createElement("div", { "data-testid": "bots-dialog" }),
  58. }));
  59. vi.mock("@/components/ui/resizable.js", () => ({
  60. ResizableHandle: ({ className }: { className?: string }) =>
  61. createElement("div", {
  62. className,
  63. "data-testid": "resizable-handle",
  64. }),
  65. ResizablePanel: ({
  66. children,
  67. className,
  68. "data-state": dataState,
  69. disabled,
  70. id,
  71. minSize,
  72. }: {
  73. children: ReactNode;
  74. className?: string;
  75. "data-state"?: string;
  76. disabled?: boolean;
  77. id: string;
  78. minSize?: string;
  79. }) =>
  80. createElement(
  81. "section",
  82. {
  83. className,
  84. "data-disabled": disabled ? "true" : "false",
  85. "data-min-size": minSize,
  86. "data-panel-id": id,
  87. "data-state": dataState,
  88. },
  89. children,
  90. ),
  91. ResizablePanelGroup: ({
  92. children,
  93. className,
  94. layoutId,
  95. panelIds,
  96. style,
  97. }: {
  98. children: ReactNode;
  99. className?: string;
  100. layoutId: string;
  101. panelIds?: string[];
  102. style?: Record<string, string>;
  103. }) =>
  104. createElement(
  105. "div",
  106. {
  107. className,
  108. "data-layout-id": layoutId,
  109. "data-panel-ids": panelIds?.join(","),
  110. style,
  111. },
  112. children,
  113. ),
  114. }));
  115. vi.mock("@/components/ui/dropdown-menu.js", () => ({
  116. DropdownMenu: ({ children }: { children: ReactNode }) =>
  117. createElement("div", { "data-testid": "dropdown-menu" }, children),
  118. DropdownMenuContent: ({ children }: { children: ReactNode }) =>
  119. createElement("div", { "data-testid": "dropdown-menu-content" }, children),
  120. DropdownMenuItem: ({ children }: { children: ReactNode }) =>
  121. createElement("button", { "data-testid": "dropdown-menu-item" }, children),
  122. DropdownMenuTrigger: ({ children }: { children: ReactNode }) => children,
  123. }));
  124. vi.mock("@/ControlHintTooltip.js", () => ({
  125. ControlHintTooltip: ({ children }: { children: ReactNode }) => children,
  126. }));
  127. vi.mock("@/DesktopTopOverlay.js", () => ({
  128. DesktopTopOverlay: () => createElement("div", { "data-testid": "desktop-top-overlay" }),
  129. }));
  130. vi.mock("@/DesktopWindowFrame.js", () => ({
  131. DesktopWindowFrame: ({ children }: { children: ReactNode }) =>
  132. createElement("div", { "data-testid": "desktop-window-frame" }, children),
  133. }));
  134. vi.mock("@/i18n/IntlProvider.js", () => ({
  135. useZCodeIntl: () => ({
  136. intl: {
  137. formatMessage: ({ id }: { id: string }) => id,
  138. },
  139. }),
  140. }));
  141. vi.mock("@/feedback/feedbackStore.js", () => ({
  142. useFeedbackStore: (
  143. selector: (state: { openFeatureRequest: () => void; openSubmit: () => void }) => unknown,
  144. ) =>
  145. selector({
  146. openFeatureRequest: vi.fn(),
  147. openSubmit: vi.fn(),
  148. }),
  149. }));
  150. vi.mock("@/hooks/usePlatform.js", async (importOriginal) => ({
  151. // 布局 SSR 没有 PlatformProvider;保留可选读取的真实空边界,避免整模块 mock 漏掉新增 hook。
  152. ...(await importOriginal<typeof import("@/hooks/usePlatform.js")>()),
  153. usePlatform: () => ({
  154. openCommunity: vi.fn(async () => {}),
  155. openExternal: vi.fn(),
  156. }),
  157. // DirectoryOwner 的角标同步走 optional 平台;布局测试无 Provider,返回 null 即跳过。
  158. useOptionalPlatform: () => null,
  159. }));
  160. vi.mock("@/hooks/useWorkspaceServices.js", () => ({
  161. useBaseWorkspaceServices: () => ({}),
  162. // 布局断言不启动远端挂回;保留 services resolver 的本地 ready 合同。
  163. useWorkspaceServicesResolution: () => ({ services: {}, connectionKind: "local-ready" }),
  164. }));
  165. vi.mock("@/store/TabStoreProvider.js", () => ({
  166. // 项目树(useProjectTree / useProjectTaskNavigation)直接订阅 tab store;
  167. // 这里给出最小状态,避免真实侧栏在窄屏分支挂载时缺少 useTabStore。
  168. useTabStore: (select: (state: any) => unknown) =>
  169. select({ tabs: [], activeWorkspaceIdentity: undefined }),
  170. useTabStoreApi: () => ({
  171. getState: () => ({
  172. activateTabByPath: vi.fn(() => true),
  173. addTab: vi.fn(),
  174. }),
  175. }),
  176. }));
  177. vi.mock("@/WorkspaceHeader.js", () => ({
  178. WorkspaceHeader: ({ variant }: { variant?: string }) =>
  179. createElement("header", {
  180. "data-testid": "workspace-header",
  181. "data-workspace-header-variant": variant,
  182. }),
  183. }));
  184. vi.mock("@/WindowsCaptionMenuButton.js", () => ({
  185. WindowsCaptionMenuButton: ({ triggerPresentation }: { triggerPresentation?: string }) =>
  186. createElement("button", {
  187. "data-testid": "windows-caption-menu",
  188. "data-trigger-presentation": triggerPresentation ?? "header",
  189. }),
  190. }));
  191. vi.mock("@/WebRemoteControlMobileShell.js", () => ({
  192. WebRemoteControlMobileShell: ({
  193. children,
  194. isMobileViewport = true,
  195. chatContent,
  196. renderTaskHome,
  197. chatOverlay,
  198. isSidePaneOpen,
  199. renderChatHeader,
  200. sidePaneContent,
  201. }: {
  202. children?: ReactNode;
  203. isMobileViewport?: boolean;
  204. chatContent?: ReactNode;
  205. renderTaskHome?: (options: {
  206. navigateToChat(): void;
  207. setSwitching(switching: boolean): void;
  208. }) => ReactNode;
  209. chatOverlay?: ReactNode;
  210. isSidePaneOpen?: boolean;
  211. renderChatHeader?: () => ReactNode;
  212. sidePaneContent?: ReactNode;
  213. }) =>
  214. !isMobileViewport
  215. ? children
  216. : createElement(
  217. "div",
  218. {
  219. "data-mobile-side-pane-open": isSidePaneOpen ? "true" : "false",
  220. "data-testid": "web-remote-mobile-shell",
  221. },
  222. renderChatHeader?.(),
  223. renderTaskHome?.({ navigateToChat: vi.fn(), setSwitching: vi.fn() }),
  224. createElement("div", { "data-testid": "mobile-chat-content" }, chatContent),
  225. chatOverlay
  226. ? createElement("div", { "data-testid": "mobile-chat-overlay-prop" }, chatOverlay)
  227. : null,
  228. sidePaneContent
  229. ? createElement("div", { "data-testid": "mobile-side-pane-overlay" }, sidePaneContent)
  230. : null,
  231. ),
  232. }));
  233. const capturedWorkspaceSidebarProps = vi.hoisted(() => ({
  234. props: [] as Array<{
  235. workspaceIdentity?: string;
  236. workspaceRemoteSessionId?: string;
  237. onSelectTask: (
  238. targetWorkspacePath: string,
  239. taskId: string,
  240. targetWorkspaceIdentity?: string,
  241. ) => void;
  242. }>,
  243. }));
  244. vi.mock("@/WorkspaceSidebar.js", () => ({
  245. WorkspaceSidebar: (props: (typeof capturedWorkspaceSidebarProps.props)[number]) => {
  246. capturedWorkspaceSidebarProps.props.push(props);
  247. return createElement("aside", { "data-testid": "workspace-sidebar" });
  248. },
  249. }));
  250. function createWorkspaceShellProps() {
  251. return {
  252. activeGitSourceId: "unstaged" as const,
  253. activeSessionId: null,
  254. activeTaskChangeSummary: null,
  255. activeTaskId: null,
  256. activeTaskProvider: null,
  257. activeTaskTitle: "",
  258. activeTraceId: null,
  259. allowOpenWorkspace: false,
  260. allowRemoteWorkspace: false,
  261. appLogoUrl: "",
  262. browserNavigationRequest: null,
  263. browserRestoreUrls: {},
  264. canGoBack: false,
  265. canGoForward: false,
  266. canTaskNavBack: false,
  267. canTaskNavForward: false,
  268. gitState: {
  269. datasets: {
  270. staged: { sections: [] },
  271. unstaged: { sections: [] },
  272. },
  273. summary: {
  274. isGitAvailable: false,
  275. isRepository: false,
  276. },
  277. },
  278. goBackShortcutLabel: "",
  279. goForwardShortcutLabel: "",
  280. handleActivateSidePaneTab: vi.fn(),
  281. handleBrowserNavigationRequestHandled: vi.fn(),
  282. handleBrowserPageMetadataChange: vi.fn(),
  283. handleBrowserUrlChange: vi.fn(),
  284. handleCloseCodeViewer: vi.fn(),
  285. handleCloseGit: vi.fn(),
  286. handleOpenBrowserTab: vi.fn(),
  287. handleOpenBrowserUrl: vi.fn(),
  288. handleOpenCodeViewer: vi.fn(),
  289. handleRefreshGit: vi.fn(),
  290. handleReloadSession: vi.fn(async () => {}),
  291. handleReorderSidePaneTab: vi.fn(),
  292. handleOpenAutomations: vi.fn(),
  293. handleSelectTask: vi.fn(),
  294. handleStartDraftInWorkspace: vi.fn(),
  295. handleTaskNavBack: vi.fn(),
  296. handleTaskNavForward: vi.fn(),
  297. handleToggleBrowser: vi.fn(),
  298. handleToggleGit: vi.fn(),
  299. handleToggleSidePane: vi.fn(),
  300. handleToggleSidebar: vi.fn(),
  301. handleToggleTerminal: vi.fn(),
  302. onOpenAutomationConsumed: vi.fn(),
  303. onWorkspaceMainViewChange: vi.fn(),
  304. openAutomationId: null,
  305. workspaceMainView: "chat" as const,
  306. headerGitChangeSummary: null,
  307. isBrowserOpen: false,
  308. isDesktop: false,
  309. isGitOpen: false,
  310. isMacDesktop: false,
  311. isMacFullscreen: false,
  312. isSidePaneOpen: false,
  313. isWorkspaceVisible: true,
  314. isSidebarVisible: true,
  315. isTerminalOpen: false,
  316. isWindowsDesktop: false,
  317. newTaskShortcutLabel: "",
  318. onCancelRemoteProject: vi.fn(async () => {}),
  319. onConnectRemote: vi.fn(async () => ""),
  320. onCreateTask: vi.fn(),
  321. onLogin: vi.fn(),
  322. onLogout: vi.fn(),
  323. onOpenWorkspace: vi.fn(),
  324. onReconnectRemoteWorkspace: vi.fn(async () => {}),
  325. onSelectRemoteProject: vi.fn(async () => {}),
  326. platform: {},
  327. projectName: "project",
  328. providerConfigFile: {
  329. exists: false,
  330. loading: false,
  331. path: null,
  332. },
  333. reconnectingRemoteWorkspaceKeys: [],
  334. reloadSessionDisabled: false,
  335. reloadSessionPending: false,
  336. remoteWorkspaceErrorByWorkspaceKey: {},
  337. remoteWorkspaceSessions: [],
  338. resolvedActiveTaskMeta: null,
  339. services: {},
  340. setGitSelectedSourceId: vi.fn(),
  341. setIsTerminalOpen: vi.fn(),
  342. shellPanelIds: ["sidebar", "content"],
  343. sidePaneState: null,
  344. sidebarContainerRef: { current: null },
  345. taskNativeSessionLogFile: {
  346. exists: false,
  347. loading: false,
  348. path: null,
  349. provider: null,
  350. },
  351. taskSessionFile: {
  352. path: null,
  353. },
  354. testMessages: null,
  355. theme: "light" as const,
  356. toggleSidebarShortcutLabel: "",
  357. toggleSidePaneShortcutLabel: "",
  358. updateReadyVersion: null,
  359. user: null,
  360. webRemoteControlWorkspaceSwitcher: undefined,
  361. workspaceAbsPath: "/tmp/project",
  362. workspaceRemoteSessionId: undefined,
  363. workspaceShellZCodeState: {
  364. activeTaskId: null,
  365. modelSwitchPending: false,
  366. modelSwitchStage: null,
  367. optimisticTaskListByTaskId: {},
  368. selectedProvider: "codex",
  369. taskError: null,
  370. taskStatus: "notReady",
  371. workspaceInit: {
  372. attempts: 0,
  373. error: null,
  374. status: "idle",
  375. },
  376. },
  377. workspaceTabs: [],
  378. };
  379. }
  380. async function renderWorkspaceShell(
  381. overrides: Partial<ReturnType<typeof createWorkspaceShellProps>> = {},
  382. ) {
  383. const { WorkspaceShellLayout } = await import("@/app-shell/WorkspaceShellLayout.js");
  384. return renderToStaticMarkup(
  385. createElement(WorkspaceShellLayout, {
  386. ...createWorkspaceShellProps(),
  387. ...overrides,
  388. } as Parameters<typeof WorkspaceShellLayout>[0]),
  389. );
  390. }
  391. describe("WorkspaceShellLayout Web remote control mobile layout", () => {
  392. it.each([
  393. { mobile: false, sidePaneOpen: false, workspaceVisible: true, expected: true },
  394. { mobile: false, sidePaneOpen: true, workspaceVisible: true, expected: false },
  395. { mobile: false, sidePaneOpen: false, workspaceVisible: false, expected: false },
  396. { mobile: true, sidePaneOpen: false, workspaceVisible: true, expected: true },
  397. { mobile: true, sidePaneOpen: true, workspaceVisible: true, expected: false },
  398. { mobile: true, sidePaneOpen: false, workspaceVisible: false, expected: false },
  399. ])(
  400. "limits default Esc stop to the visible main chat without a side pane: %j",
  401. async (scenario) => {
  402. capturedChatPaneProps.length = 0;
  403. vi.stubGlobal("window", {
  404. innerHeight: 800,
  405. matchMedia: vi.fn(() => ({
  406. addEventListener: vi.fn(),
  407. addListener: vi.fn(),
  408. matches: scenario.mobile,
  409. removeEventListener: vi.fn(),
  410. removeListener: vi.fn(),
  411. })),
  412. sessionStorage: { getItem: vi.fn(() => null), removeItem: vi.fn(), setItem: vi.fn() },
  413. });
  414. try {
  415. await renderWorkspaceShell({
  416. isSidePaneOpen: scenario.sidePaneOpen,
  417. isWorkspaceVisible: scenario.workspaceVisible,
  418. webRemoteControlWorkspaceSwitcher: scenario.mobile
  419. ? {
  420. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  421. switchWorkspace: vi.fn(async () => {}),
  422. }
  423. : undefined,
  424. });
  425. expect(capturedChatPaneProps).toHaveLength(1);
  426. expect(capturedChatPaneProps[0]?.allowEscapeStopOutsidePane).toBe(scenario.expected);
  427. } finally {
  428. vi.unstubAllGlobals();
  429. }
  430. },
  431. );
  432. // Bugfix: 这些断言只覆盖远控导航纯计算逻辑,直接导入小模块,避免全量并发单测时拉起整页组件。
  433. it("resolves draggable navigation heights and collapse thresholds", async () => {
  434. const {
  435. getDefaultWebRemoteNavigationHeightPx,
  436. resolveWebRemoteNavigationDragState,
  437. resolveWebRemoteNavigationToggleState,
  438. } = await import("@/app-shell/webRemoteNavigationLayout.js");
  439. expect(getDefaultWebRemoteNavigationHeightPx(800)).toBe(352);
  440. expect(getDefaultWebRemoteNavigationHeightPx(600)).toBe(252);
  441. expect(
  442. resolveWebRemoteNavigationDragState({
  443. heightPx: 18,
  444. viewportHeight: 800,
  445. }),
  446. ).toEqual({ heightPx: 0, isCollapsed: true });
  447. expect(
  448. resolveWebRemoteNavigationDragState({
  449. heightPx: 320,
  450. viewportHeight: 800,
  451. }),
  452. ).toEqual({ heightPx: 320, isCollapsed: false });
  453. expect(
  454. resolveWebRemoteNavigationDragState({
  455. heightPx: 720,
  456. viewportHeight: 800,
  457. }),
  458. ).toEqual({ heightPx: 584, isCollapsed: false });
  459. expect(
  460. resolveWebRemoteNavigationToggleState({
  461. currentHeightPx: 280,
  462. isCollapsed: false,
  463. viewportHeight: 800,
  464. }),
  465. ).toEqual({ heightPx: 0, isCollapsed: true });
  466. expect(
  467. resolveWebRemoteNavigationToggleState({
  468. currentHeightPx: 0,
  469. isCollapsed: true,
  470. viewportHeight: 800,
  471. }),
  472. ).toEqual({ heightPx: 352, isCollapsed: false });
  473. });
  474. it("keeps sidebar panel ids stable while still marking collapsed mobile layout", async () => {
  475. const { getActiveWorkspaceShellPanelIds, shouldRenderWebRemoteNavigationPanel } =
  476. await import("@/app-shell/webRemoteNavigationLayout.js");
  477. expect(
  478. shouldRenderWebRemoteNavigationPanel({
  479. isCollapsed: true,
  480. isMobileViewport: true,
  481. isWebRemoteControlShell: true,
  482. }),
  483. ).toBe(false);
  484. expect(
  485. shouldRenderWebRemoteNavigationPanel({
  486. isCollapsed: true,
  487. isMobileViewport: false,
  488. isWebRemoteControlShell: true,
  489. }),
  490. ).toBe(true);
  491. expect(
  492. shouldRenderWebRemoteNavigationPanel({
  493. isCollapsed: true,
  494. isMobileViewport: true,
  495. isWebRemoteControlShell: false,
  496. }),
  497. ).toBe(true);
  498. expect(getActiveWorkspaceShellPanelIds(["sidebar", "content"], false)).toEqual([
  499. "sidebar",
  500. "content",
  501. ]);
  502. expect(getActiveWorkspaceShellPanelIds(["sidebar", "content"], true)).toEqual([
  503. "sidebar",
  504. "content",
  505. ]);
  506. });
  507. // Bugfix: 该断言需要 SSR 整个 WorkspaceShellLayout,renderWorkspaceShell 内的动态 import
  508. // 会一次性 transform 整张页面模块图,成本全记在本文件第一个整页用例上(实测冷启动 5s 量级)。
  509. // 纯计算逻辑已拆到 webRemoteNavigationLayout。这里曾写死 `}, 15_000)`,但 vitest.config.ts
  510. // 全局 testTimeout 已是 30s,per-test 参数是覆盖而非取大,局部值反而把预算砍到 15s 并在
  511. // 全量并发时被打穿;故删除局部值,回落到全局 30s。
  512. it("keeps the hidden sidebar mounted without an outer resizable panel target", async () => {
  513. const html = await renderWorkspaceShell({ isSidebarVisible: false });
  514. expect(html).toContain('id="sidebar"');
  515. expect(html).toContain("--workspace-sidebar-panel-width:0px");
  516. expect(html).not.toContain('data-panel-id="sidebar"');
  517. expect(html).not.toContain('data-layout-id="workspace-shell-layout"');
  518. });
  519. it("keeps the desktop Browser Guest host mounted and collapsed on the Automations main view", async () => {
  520. const html = await renderWorkspaceShell({
  521. isDesktop: true,
  522. isSidePaneOpen: true,
  523. sidePaneState: {
  524. activeTabId: "browser-use:iab-tab:automation",
  525. tabs: [
  526. {
  527. id: "browser-use:iab-tab:automation",
  528. sessionId: "automation-session",
  529. tabId: "iab-tab:automation",
  530. type: "browser-use",
  531. workspaceKey: "/tmp/project",
  532. },
  533. ],
  534. } as never,
  535. workspaceMainView: "automations",
  536. });
  537. expect(html).toContain('id="automations-main-toast-anchor"');
  538. expect(html).toContain('data-layout-id="workspace-body-layout"');
  539. expect(html).toContain('data-panel-id="conversation-column"');
  540. expect(html.match(/data-testid="side-pane-panel"/gu)).toHaveLength(1);
  541. expect(html).toContain('data-panel-visible="false"');
  542. const chatHtml = await renderWorkspaceShell({
  543. isDesktop: true,
  544. isSidePaneOpen: true,
  545. workspaceMainView: "chat",
  546. });
  547. expect(chatHtml.match(/data-testid="side-pane-panel"/gu)).toHaveLength(1);
  548. expect(chatHtml).toContain('data-panel-visible="true"');
  549. });
  550. it.each([true, false])(
  551. "hides retained side panes with an inactive workspace (desktop=%s)",
  552. async (isDesktop) => {
  553. const html = await renderWorkspaceShell({
  554. isDesktop,
  555. isSidePaneOpen: true,
  556. isWorkspaceVisible: false,
  557. workspaceMainView: "chat",
  558. });
  559. expect(html).toContain('data-panel-visible="false"');
  560. expect(html).not.toContain('data-panel-visible="true"');
  561. },
  562. );
  563. it("hides the retained side pane on the plugin marketplace main page", async () => {
  564. const html = await renderWorkspaceShell({
  565. isDesktop: true,
  566. isSidePaneOpen: true,
  567. workspaceMainView: "plugin-store",
  568. });
  569. expect(html).toContain('data-panel-visible="false"');
  570. expect(html).not.toContain('data-panel-visible="true"');
  571. });
  572. it("adds mobile stacking classes only for Web remote control mode", async () => {
  573. const html = await renderWorkspaceShell({
  574. webRemoteControlWorkspaceSwitcher: {
  575. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  576. switchWorkspace: vi.fn(async () => {}),
  577. },
  578. });
  579. expect(html).not.toContain("max-md:data-[state=collapsed]");
  580. expect(html).not.toContain('data-layout-id="workspace-shell-layout"');
  581. expect(html).not.toContain('data-web-remote-navigation-toggle="true"');
  582. expect(html).toContain('data-web-remote-navigation-resize-handle="true"');
  583. expect(html).toContain("--web-remote-navigation-height:352px");
  584. expect(html).toContain('aria-controls="web-remote-control-navigation-panel"');
  585. expect(html).toContain("webRemoteControl.collapseNavigation");
  586. expect(html).not.toContain("webRemoteControl.navigationPanel");
  587. expect(html).not.toContain("max-md:!h-10");
  588. expect(html).toContain('data-mobile-stacked="true"');
  589. });
  590. it("keeps remote sidebar selection out of hidden workbench group context", async () => {
  591. capturedWorkspaceSidebarProps.props = [];
  592. useWorkbenchGroupStore.getState().configureClientMode("desktop-continuous");
  593. useWorkbenchGroupStore.getState().resetWorkbenchGroups();
  594. useWorkbenchGroupStore.getState().splitSessionIntoGroup(
  595. V4_PRIMARY_PANE_ID,
  596. "right",
  597. {
  598. workspaceScope: { workspacePath: "/workspace-b" },
  599. sessionId: "secondary-session",
  600. },
  601. {
  602. workspaceScope: { workspacePath: "/tmp/project" },
  603. sessionId: "main-session",
  604. },
  605. );
  606. const groupId = useWorkbenchGroupStore.getState().activeGroupId;
  607. const handleSelectTask = vi.fn();
  608. await renderWorkspaceShell({
  609. activeTaskId: "main-session",
  610. handleSelectTask,
  611. webRemoteControlWorkspaceSwitcher: {
  612. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  613. switchWorkspace: vi.fn(async () => {}),
  614. },
  615. });
  616. const onSelectTask = capturedWorkspaceSidebarProps.props.at(-1)?.onSelectTask;
  617. expect(onSelectTask).toBeTypeOf("function");
  618. onSelectTask?.("/tmp/project", "main-session");
  619. expect(handleSelectTask).toHaveBeenCalledWith("/tmp/project", "main-session", undefined);
  620. expect(useWorkbenchGroupStore.getState().groups[groupId!]?.focusedPaneId).toBe("pane-1");
  621. useWorkbenchGroupStore.getState().resetWorkbenchGroups();
  622. });
  623. it("renders the dedicated mobile task shell on Web remote control mobile viewports", async () => {
  624. vi.stubGlobal("window", {
  625. innerHeight: 800,
  626. matchMedia: vi.fn(() => ({
  627. addEventListener: vi.fn(),
  628. addListener: vi.fn(),
  629. matches: true,
  630. removeEventListener: vi.fn(),
  631. removeListener: vi.fn(),
  632. })),
  633. sessionStorage: {
  634. getItem: vi.fn(() => null),
  635. removeItem: vi.fn(),
  636. setItem: vi.fn(),
  637. },
  638. });
  639. const html = await renderWorkspaceShell({
  640. webRemoteControlWorkspaceSwitcher: {
  641. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  642. switchWorkspace: vi.fn(async () => {}),
  643. },
  644. });
  645. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  646. expect(html).toContain('data-testid="workspace-sidebar"');
  647. vi.unstubAllGlobals();
  648. });
  649. it("passes workspace identity to mobile V4ChatPane for remote workspaces", async () => {
  650. capturedChatPaneProps.length = 0;
  651. vi.stubGlobal("window", {
  652. innerHeight: 800,
  653. matchMedia: vi.fn(() => ({
  654. addEventListener: vi.fn(),
  655. addListener: vi.fn(),
  656. matches: true,
  657. removeEventListener: vi.fn(),
  658. removeListener: vi.fn(),
  659. })),
  660. sessionStorage: {
  661. getItem: vi.fn(() => null),
  662. removeItem: vi.fn(),
  663. setItem: vi.fn(),
  664. },
  665. });
  666. const workspaceIdentity = "remote:ssh:dev:22:root:/root";
  667. await renderWorkspaceShell({
  668. webRemoteControlWorkspaceSwitcher: {
  669. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  670. switchWorkspace: vi.fn(async () => {}),
  671. },
  672. workspaceIdentity,
  673. workspaceRemoteSessionId: "remote-session-1",
  674. });
  675. expect(capturedChatPaneProps[0]?.workspaceIdentity).toBe(workspaceIdentity);
  676. vi.unstubAllGlobals();
  677. });
  678. it("exposes plan-detail opening from the mobile remote chat", async () => {
  679. capturedChatPaneProps.length = 0;
  680. const handleOpenPlanDetail = vi.fn();
  681. vi.stubGlobal("window", {
  682. innerHeight: 800,
  683. matchMedia: vi.fn(() => ({
  684. addEventListener: vi.fn(),
  685. addListener: vi.fn(),
  686. matches: true,
  687. removeEventListener: vi.fn(),
  688. removeListener: vi.fn(),
  689. })),
  690. sessionStorage: {
  691. getItem: vi.fn(() => null),
  692. removeItem: vi.fn(),
  693. setItem: vi.fn(),
  694. },
  695. });
  696. await renderWorkspaceShell({
  697. activeTaskId: "task-with-plan",
  698. handleOpenPlanDetail,
  699. initialWebRemoteControlMobileNavigationIntent: "chat",
  700. webRemoteControlWorkspaceSwitcher: {
  701. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  702. switchWorkspace: vi.fn(async () => {}),
  703. },
  704. });
  705. expect(capturedChatPaneProps[0]?.onOpenPlanDetail).toBe(handleOpenPlanDetail);
  706. vi.unstubAllGlobals();
  707. });
  708. it("passes side pane content as a right-side overlay into the dedicated mobile chat shell", async () => {
  709. vi.stubGlobal("window", {
  710. innerHeight: 800,
  711. matchMedia: vi.fn(() => ({
  712. addEventListener: vi.fn(),
  713. addListener: vi.fn(),
  714. matches: true,
  715. removeEventListener: vi.fn(),
  716. removeListener: vi.fn(),
  717. })),
  718. sessionStorage: {
  719. getItem: vi.fn(() => null),
  720. removeItem: vi.fn(),
  721. setItem: vi.fn(),
  722. },
  723. });
  724. const html = await renderWorkspaceShell({
  725. isSidePaneOpen: true,
  726. sidePaneState: {
  727. activeTabId: "git",
  728. tabs: [{ id: "git", type: "git" }],
  729. },
  730. webRemoteControlWorkspaceSwitcher: {
  731. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  732. switchWorkspace: vi.fn(async () => {}),
  733. },
  734. });
  735. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  736. expect(html).toContain('data-mobile-side-pane-open="true"');
  737. expect(html).toContain('data-testid="mobile-side-pane-overlay"');
  738. expect(html).toContain('data-testid="side-pane-panel"');
  739. expect(html).toContain('data-mobile-overlay="true"');
  740. expect(html).toContain('data-panel-visible="true"');
  741. const hiddenHtml = await renderWorkspaceShell({
  742. isWorkspaceVisible: false,
  743. isSidePaneOpen: true,
  744. webRemoteControlWorkspaceSwitcher: {
  745. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  746. switchWorkspace: vi.fn(async () => {}),
  747. },
  748. });
  749. expect(hiddenHtml).toContain('data-mobile-overlay="true"');
  750. expect(hiddenHtml).toContain('data-panel-visible="false"');
  751. expect(hiddenHtml).not.toContain('data-panel-visible="true"');
  752. vi.unstubAllGlobals();
  753. });
  754. it("routes mobile task find through the shell overlay instead of chat content", async () => {
  755. vi.stubGlobal("window", {
  756. innerHeight: 800,
  757. matchMedia: vi.fn(() => ({
  758. addEventListener: vi.fn(),
  759. addListener: vi.fn(),
  760. matches: true,
  761. removeEventListener: vi.fn(),
  762. removeListener: vi.fn(),
  763. })),
  764. sessionStorage: {
  765. getItem: vi.fn(() => null),
  766. removeItem: vi.fn(),
  767. setItem: vi.fn(),
  768. },
  769. });
  770. const html = await renderWorkspaceShell({
  771. initialWebRemoteControlMobileNavigationIntent: "chat",
  772. isSidePaneOpen: true,
  773. taskFindDialogProps: {
  774. open: true,
  775. placement: "chat",
  776. focusRequestId: 1,
  777. conversationMatchCount: 1,
  778. conversationMatchIndex: 0,
  779. fileChangeMatchCount: 1,
  780. fileChangeMatchIndex: 0,
  781. onOpenChange: vi.fn(),
  782. onConversationFindChange: vi.fn(),
  783. onConversationFindNavigate: vi.fn(),
  784. onFileChangeFindChange: vi.fn(),
  785. onFileChangeFindNavigate: vi.fn(),
  786. onOpenFileChanges: vi.fn(),
  787. },
  788. webRemoteControlWorkspaceSwitcher: {
  789. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  790. switchWorkspace: vi.fn(async () => {}),
  791. },
  792. });
  793. const chatContentStart = html.indexOf('data-testid="mobile-chat-content"');
  794. const chatOverlayStart = html.indexOf('data-testid="mobile-chat-overlay-prop"');
  795. expect(chatOverlayStart).toBeGreaterThan(chatContentStart);
  796. expect(html.slice(chatContentStart, chatOverlayStart)).not.toContain(
  797. 'placeholder="quickPick.find.placeholder.conversation"',
  798. );
  799. expect(html.slice(chatOverlayStart)).toContain(
  800. 'placeholder="quickPick.find.placeholder.conversation"',
  801. );
  802. vi.unstubAllGlobals();
  803. });
  804. it("keeps mobile stacking disabled for the default shell", async () => {
  805. const html = await renderWorkspaceShell();
  806. expect(html).toContain('data-mobile-stacked="false"');
  807. });
  808. it("renders the draft workspace header while a new task draft is active", async () => {
  809. const html = await renderWorkspaceShell({
  810. activeTaskId: null,
  811. isDesktop: true,
  812. workspaceShellZCodeState: {
  813. ...createWorkspaceShellProps().workspaceShellZCodeState,
  814. activeTaskId: null,
  815. },
  816. });
  817. expect(html).toContain('data-testid="workspace-header"');
  818. expect(html).toContain('data-workspace-header-variant="draft"');
  819. expect(html).toContain("<header");
  820. expect(html).not.toContain('data-testid="new-task-draft-drag-region"');
  821. expect(html).not.toContain("absolute inset-x-0 top-0 z-10 h-10 [app-region:drag]");
  822. });
  823. it("does not render the draft drag region on web", async () => {
  824. const html = await renderWorkspaceShell({
  825. activeTaskId: null,
  826. isDesktop: false,
  827. workspaceShellZCodeState: {
  828. ...createWorkspaceShellProps().workspaceShellZCodeState,
  829. activeTaskId: null,
  830. },
  831. });
  832. expect(html).not.toContain('data-testid="new-task-draft-drag-region"');
  833. expect(html).not.toContain('data-testid="terminal-toggle"');
  834. });
  835. it("uses the draft workspace header within Windows chrome", async () => {
  836. const html = await renderWorkspaceShell({
  837. activeTaskId: null,
  838. isDesktop: true,
  839. isMacDesktop: false,
  840. isWindowsDesktop: true,
  841. workspaceShellZCodeState: {
  842. ...createWorkspaceShellProps().workspaceShellZCodeState,
  843. activeTaskId: null,
  844. },
  845. });
  846. expect(html).toContain('data-workspace-header-variant="draft"');
  847. expect(html).not.toContain('data-testid="linux-window-controls"');
  848. });
  849. it("uses the draft workspace header within Linux chrome", async () => {
  850. const html = await renderWorkspaceShell({
  851. activeTaskId: null,
  852. isDesktop: true,
  853. isMacDesktop: false,
  854. isWindowsDesktop: false,
  855. workspaceShellZCodeState: {
  856. ...createWorkspaceShellProps().workspaceShellZCodeState,
  857. activeTaskId: null,
  858. },
  859. });
  860. expect(html).toContain('data-workspace-header-variant="draft"');
  861. expect(html).not.toContain('data-testid="linux-window-controls"');
  862. expect(html).toContain("rounded-xl");
  863. });
  864. it("renders the workspace header again after the draft is promoted to a task", async () => {
  865. const html = await renderWorkspaceShell({
  866. activeTaskId: "task-1",
  867. activeTaskTitle: "Task 1",
  868. workspaceShellZCodeState: {
  869. ...createWorkspaceShellProps().workspaceShellZCodeState,
  870. activeTaskId: "task-1",
  871. },
  872. });
  873. expect(html).toContain('data-testid="workspace-header"');
  874. expect(html).toContain('data-workspace-header-variant="task"');
  875. expect(html).not.toContain('data-testid="new-task-draft-drag-region"');
  876. });
  877. it("does not inject the workspace header into mobile remote chat while a new task draft is active", async () => {
  878. vi.stubGlobal("window", {
  879. innerHeight: 800,
  880. matchMedia: vi.fn(() => ({
  881. addEventListener: vi.fn(),
  882. addListener: vi.fn(),
  883. matches: true,
  884. removeEventListener: vi.fn(),
  885. removeListener: vi.fn(),
  886. })),
  887. sessionStorage: {
  888. getItem: vi.fn(() => null),
  889. removeItem: vi.fn(),
  890. setItem: vi.fn(),
  891. },
  892. });
  893. const html = await renderWorkspaceShell({
  894. activeTaskId: null,
  895. initialWebRemoteControlMobileNavigationIntent: "chat",
  896. webRemoteControlWorkspaceSwitcher: {
  897. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  898. switchWorkspace: vi.fn(async () => {}),
  899. },
  900. workspaceShellZCodeState: {
  901. ...createWorkspaceShellProps().workspaceShellZCodeState,
  902. activeTaskId: null,
  903. },
  904. });
  905. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  906. expect(html).not.toContain('data-testid="workspace-header"');
  907. vi.unstubAllGlobals();
  908. });
  909. });
  910. it("places the workspace header inside the independent conversation frame", async () => {
  911. const html = await renderWorkspaceShell({ isDesktop: true, isMacDesktop: true });
  912. expect(html).toContain('data-workspace-conversation-frame="true"');
  913. expect(html.indexOf('data-panel-id="conversation-column"')).toBeLessThan(
  914. html.indexOf('data-testid="workspace-header"'),
  915. );
  916. expect(html.indexOf('data-workspace-conversation-frame="true"')).toBeLessThan(
  917. html.indexOf('data-testid="workspace-header"'),
  918. );
  919. });
  920. it("项目侧栏保留当前远端 identity 与 attachment,不按相同 cwd 合并", async () => {
  921. capturedWorkspaceSidebarProps.props = [];
  922. await renderWorkspaceShell({
  923. workspaceAbsPath: "/same",
  924. workspaceIdentity: "remote:server:one:/same",
  925. workspaceRemoteSessionId: "attachment-one",
  926. });
  927. await renderWorkspaceShell({
  928. workspaceAbsPath: "/same",
  929. workspaceIdentity: "remote:server:two:/same",
  930. workspaceRemoteSessionId: "attachment-two",
  931. });
  932. expect(
  933. capturedWorkspaceSidebarProps.props.map((props) => [
  934. props.workspaceIdentity,
  935. props.workspaceRemoteSessionId,
  936. ]),
  937. ).toEqual([
  938. ["remote:server:one:/same", "attachment-one"],
  939. ["remote:server:two:/same", "attachment-two"],
  940. ]);
  941. });
  942. it("mounts the same project sidebar in the real narrow mobile branch", async () => {
  943. vi.stubGlobal("window", {
  944. innerHeight: 844,
  945. innerWidth: 390,
  946. matchMedia: vi.fn(() => ({
  947. matches: true,
  948. addEventListener: vi.fn(),
  949. removeEventListener: vi.fn(),
  950. addListener: vi.fn(),
  951. removeListener: vi.fn(),
  952. })),
  953. sessionStorage: { getItem: vi.fn(() => null), removeItem: vi.fn(), setItem: vi.fn() },
  954. });
  955. try {
  956. const html = await renderWorkspaceShell({
  957. webRemoteControlWorkspaceSwitcher: {
  958. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  959. switchWorkspace: vi.fn(async () => {}),
  960. },
  961. });
  962. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  963. expect(html).toContain('data-testid="workspace-sidebar"');
  964. } finally {
  965. vi.unstubAllGlobals();
  966. }
  967. });