conversation-session-rdux-13-sidebar-device-level-connect.test.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { createStallableTcpProxy } from "#e2e/helpers/ssh-stallable-proxy";
  2. import { parseRemoteWorkspaceIdentity } from "@zcode/shared";
  3. import { clearAppData, readSettings } from "#e2e/helpers/desktop-app";
  4. import {
  5. disconnectRemoteSource,
  6. requestRemoteProjectConnection,
  7. } from "#e2e/helpers/remote-project-actions";
  8. import {
  9. connectSSHWorkspace,
  10. openSSHSourceDirectory,
  11. readSSHRuntimeConfig,
  12. readHostProcesses,
  13. selectSSHRemoteDirectory,
  14. waitForSSHDirectoryStep,
  15. waitForRemoteTab,
  16. } from "#e2e/helpers/ssh-remote-p0";
  17. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  18. const CASE_MARKER = "E2E_RDUX_13_SIDEBAR_DEVICE_CONNECT";
  19. describe(`${CASE_MARKER}: 平铺项目入口重连同设备已打开项目`, () => {
  20. let proxy: Awaited<ReturnType<typeof createStallableTcpProxy>> | undefined;
  21. after(async () => {
  22. try {
  23. await browser.electron.restoreAllMocks();
  24. await clearAppData();
  25. } finally {
  26. await proxy?.close();
  27. }
  28. });
  29. it("RDUX-13/RPN-06 已有项目重连保持目录意图,重复点击只有一个向导,A/B 获得独立新 session", async function () {
  30. this.timeout(10 * 60_000);
  31. const direct = readSSHRuntimeConfig(CASE_MARKER);
  32. proxy = await createStallableTcpProxy(direct);
  33. const config = { ...direct, host: "127.0.0.1", port: proxy.port };
  34. await prepareV4ConversationE2E({ skipProvider: true });
  35. const hosts = await readHostProcesses();
  36. const [pathA, pathB] = config.workspacePaths;
  37. const a = await connectSSHWorkspace({ config, caseMarker: CASE_MARKER, workspacePath: pathA });
  38. await openSSHSourceDirectory(config, CASE_MARKER);
  39. await waitForSSHDirectoryStep(CASE_MARKER);
  40. await selectSSHRemoteDirectory(pathB, CASE_MARKER);
  41. const b = await waitForRemoteTab({ caseMarker: CASE_MARKER, expectedPath: pathB });
  42. const sourceId = parseRemoteWorkspaceIdentity(a.workspaceIdentity!)?.sourceServerId;
  43. if (!sourceId) throw new Error("首连缺少 Source 身份");
  44. const before = await readSettings();
  45. await disconnectRemoteSource(sourceId, CASE_MARKER);
  46. const row = $(`[data-project-workspace-identity="${a.workspaceIdentity}"]`);
  47. await browser.waitUntil(
  48. async () =>
  49. ["offline", "failed"].includes((await row.getAttribute("data-connection-state")) ?? ""),
  50. { timeout: 30_000 },
  51. );
  52. // 标题现为折叠按钮;用真实项目连接动作重复请求,握手闸门保证第二次发生在 pending 期间。
  53. proxy.setStall(true);
  54. const connectionsBefore = proxy.acceptedCount();
  55. await requestRemoteProjectConnection(a.workspaceIdentity!, CASE_MARKER);
  56. await browser.waitUntil(() => proxy!.pendingCount() === 1, { timeout: 15_000 });
  57. await requestRemoteProjectConnection(a.workspaceIdentity!, CASE_MARKER);
  58. proxy.setStall(false);
  59. expect(proxy.release()).toBe(1);
  60. expect(await $$('[data-testid="ssh-dialog"]').length).toBeLessThanOrEqual(1);
  61. const phase = await waitForSSHDirectoryStep(CASE_MARKER);
  62. expect(phase).toBe("closed");
  63. const restoredA = await waitForRemoteTab({
  64. caseMarker: CASE_MARKER,
  65. expectedIdentity: a.workspaceIdentity!,
  66. expectedPath: pathA,
  67. // 现行项目导航 §2.2:恢复使目标项目就绪,不改变正在查看的 B 页面。
  68. requireActive: false,
  69. });
  70. const restoredB = await waitForRemoteTab({
  71. caseMarker: CASE_MARKER,
  72. expectedIdentity: b.workspaceIdentity!,
  73. expectedPath: pathB,
  74. requireActive: false,
  75. });
  76. expect(restoredA.remoteSessionId).not.toBe(a.remoteSessionId);
  77. expect(restoredB.remoteSessionId).not.toBe(b.remoteSessionId);
  78. expect(restoredA.remoteSessionId).not.toBe(restoredB.remoteSessionId);
  79. expect((await readSettings()).connectionProfiles?.length).toBe(
  80. before.connectionProfiles?.length,
  81. );
  82. expect(proxy.acceptedCount() - connectionsBefore).toBe(1);
  83. expect(await readHostProcesses()).toEqual(hosts);
  84. });
  85. });