conversation-session-ssh-remote-project-conversation-scope.test.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. TID_COMPOSER_PROJECT_DETACH,
  3. TID_COMPOSER_WORK_OUTSIDE_PROJECT,
  4. TID_COMPOSER_WORKSPACE_TRIGGER,
  5. } from "@zcode/shared/test-ids";
  6. import { clearAppData, clickTestIdByWebDriver, readSettings } from "#e2e/helpers/desktop-app";
  7. import {
  8. connectSSHWorkspace,
  9. openSSHSourceDirectory,
  10. readHostProcesses,
  11. readRemoteTabSnapshot,
  12. readSSHRuntimeConfig,
  13. selectSSHRemoteDirectory,
  14. waitForRemoteTab,
  15. waitForSSHDirectoryStep,
  16. } from "#e2e/helpers/ssh-remote-p0";
  17. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  18. const CASE_MARKER = "E2E_SSH_REMOTE_PROJECT_CONVERSATION_SCOPE";
  19. describe(`${CASE_MARKER}: 远程项目隔离与无项目入口停用`, () => {
  20. after(async () => {
  21. await browser.electron.restoreAllMocks();
  22. await clearAppData();
  23. });
  24. it("CWP13/CWP15→RPN-03/07 项目 A/B 使用独立 session,远程项目不能退出到无项目聊天", async function () {
  25. this.timeout(10 * 60_000);
  26. const config = readSSHRuntimeConfig(CASE_MARKER);
  27. await prepareV4ConversationE2E({ skipProvider: true });
  28. const hosts = await readHostProcesses();
  29. const [pathA, pathB] = config.workspacePaths;
  30. const a = await connectSSHWorkspace({ config, caseMarker: CASE_MARKER, workspacePath: pathA });
  31. await openSSHSourceDirectory(config, CASE_MARKER);
  32. await waitForSSHDirectoryStep(CASE_MARKER);
  33. await selectSSHRemoteDirectory(pathB, CASE_MARKER);
  34. const b = await waitForRemoteTab({ caseMarker: CASE_MARKER, expectedPath: pathB });
  35. expect(b.workspaceIdentity).not.toBe(a.workspaceIdentity);
  36. expect(b.remoteSessionId).not.toBe(a.remoteSessionId);
  37. // 项目创建已打开所属 Source 的草稿;全局新建会改为本地未分类任务。
  38. expect((await readRemoteTabSnapshot()).activeWorkspaceIdentity).toBe(b.workspaceIdentity);
  39. // Radix trigger 依赖 pointerdown;DOM click 不会打开菜单,空菜单不能证明负向入口不存在。
  40. await clickTestIdByWebDriver(TID_COMPOSER_WORKSPACE_TRIGGER, { timeout: 15_000 });
  41. const trigger = $(`[data-testid="${TID_COMPOSER_WORKSPACE_TRIGGER}"]`);
  42. await browser.waitUntil(async () => (await trigger.getAttribute("aria-expanded")) === "true", {
  43. timeout: 15_000,
  44. timeoutMsg: `${CASE_MARKER}: 项目菜单没有展开`,
  45. });
  46. const menuId = await trigger.getAttribute("aria-controls");
  47. expect(menuId).toBeTruthy();
  48. await $(`[id="${menuId}"]`).waitForDisplayed({ timeout: 15_000 });
  49. const items = await browser.execute(
  50. (id) =>
  51. Array.from(
  52. document
  53. .getElementById(id)
  54. ?.querySelectorAll<HTMLElement>(
  55. '[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]',
  56. ) ?? [],
  57. )
  58. .filter((item) => item.getClientRects().length)
  59. .map((item) => ({
  60. text: item.innerText.trim(),
  61. checked: item.getAttribute("aria-checked") === "true",
  62. })),
  63. menuId!,
  64. );
  65. expect(items.length).toBeGreaterThan(0);
  66. expect(items.some((item) => item.checked && item.text.includes(pathB.split("/").at(-1)!))).toBe(
  67. true,
  68. );
  69. expect(
  70. items.some((item) => /不在项目中工作|Work outside (?:a )?project/iu.test(item.text)),
  71. ).toBe(false);
  72. expect(await $(`[data-testid="${TID_COMPOSER_WORK_OUTSIDE_PROJECT}"]`).isExisting()).toBe(
  73. false,
  74. );
  75. expect(await $(`[data-testid="${TID_COMPOSER_PROJECT_DETACH}"]`).isExisting()).toBe(false);
  76. await browser.keys("Escape");
  77. expect((await readRemoteTabSnapshot()).activeWorkspaceIdentity).toBe(b.workspaceIdentity);
  78. const remote =
  79. (await readSettings()).lastWorkspaceSession?.filter((entry) => entry.kind === "remote") ?? [];
  80. expect(remote.map((entry) => entry.workspacePath).sort()).toEqual([pathA, pathB].sort());
  81. expect(remote.some((entry) => entry.workspacePurpose === "conversation")).toBe(false);
  82. expect(await readHostProcesses()).toEqual(hosts);
  83. });
  84. });