conversation-session-remote-sidebar-pending.test.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { execFile } from "node:child_process";
  2. import { mkdir } from "node:fs/promises";
  3. import { resolve } from "node:path";
  4. import { promisify } from "node:util";
  5. import { ServiceChannels, parseRemoteWorkspaceIdentity } from "@zcode/shared";
  6. import { clearAppData, readSettings } from "#e2e/helpers/desktop-app";
  7. import { waitForRemoteDeviceLocated } from "#e2e/helpers/remote-project-actions";
  8. import {
  9. callHandoffHost,
  10. installHandoffRpcProbe,
  11. restoreHandoffProbes,
  12. } from "#e2e/helpers/remote-project-handoff-probe";
  13. import { prepareSourceServerUpdateArchive } from "#e2e/helpers/source-server-update-fixture";
  14. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  15. import { selectTaskOrganizeMode } from "#e2e/helpers/workspace-agent-warmup";
  16. import {
  17. connectSSHWorkspace,
  18. prepareSSHConnectionPage,
  19. readSSHRuntimeConfig,
  20. } from "#e2e/helpers/ssh-remote-p0";
  21. const CASE_MARKER = "E2E_REMOTE_SIDEBAR_PENDING";
  22. const artifactDir = resolve(
  23. process.env.ZCODE_E2E_ARTIFACT_DIR ?? ".e2e-artifacts/remote-sidebar-pending",
  24. );
  25. const run = promisify(execFile);
  26. /** 只读远端当前 release;走 docker exec,不占用被测 SSH 连接。 */
  27. async function setAppearance(locale: "zh-CN" | "en-US", theme: "light" | "dark") {
  28. await browser.execute(
  29. (lang, appearance) => {
  30. const actions = (
  31. window as Window & {
  32. __testActions?: {
  33. setLocale(value: "zh-CN" | "en-US"): void;
  34. setTheme(value: string): void;
  35. };
  36. }
  37. ).__testActions;
  38. if (!actions) throw new Error("Missing appearance actions");
  39. actions.setLocale(lang);
  40. actions.setTheme(appearance);
  41. },
  42. locale,
  43. theme,
  44. );
  45. await browser.executeAsync((done) =>
  46. requestAnimationFrame(() => requestAnimationFrame(() => done())),
  47. );
  48. }
  49. async function readRemoteCurrentSha(): Promise<string> {
  50. const container = process.env.ZCODE_E2E_SSH_CONTAINER?.trim();
  51. if (!container) throw new Error(`${CASE_MARKER}: 缺少 ZCODE_E2E_SSH_CONTAINER`);
  52. const { stdout } = await run(
  53. "docker",
  54. [
  55. "exec",
  56. "-u",
  57. process.env.ZCODE_E2E_SSH_USERNAME?.trim() || "dev",
  58. container,
  59. "bash",
  60. "-lc",
  61. 'grep -o \'"archiveSha256": *"[0-9a-f]*"\' "$HOME/.zcode/server/current.json" | grep -o "[0-9a-f]\\{64\\}"',
  62. ],
  63. { timeout: 30_000 },
  64. );
  65. return stdout.trim();
  66. }
  67. describe(`${CASE_MARKER}: 待处理设备在项目行与详情显示具体原因`, () => {
  68. afterEach(async () => {
  69. await browser.saveScreenshot(resolve(artifactDir, "last-state.png"));
  70. });
  71. after(async () => {
  72. await restoreHandoffProbes();
  73. await browser.electron.restoreAllMocks();
  74. await clearAppData();
  75. });
  76. it("RDUX-SIDEBAR-PENDING needs-upgrade 显示“需要更新”,详情入口定位设置页设备卡且不自动更新", async function () {
  77. this.timeout(15 * 60_000);
  78. await mkdir(artifactDir, { recursive: true });
  79. const config = readSSHRuntimeConfig(CASE_MARKER);
  80. await prepareSSHConnectionPage(CASE_MARKER);
  81. await prepareV4ConversationE2E({ skipProvider: true });
  82. const tab = await connectSSHWorkspace({
  83. caseMarker: CASE_MARKER,
  84. config,
  85. workspacePath: config.workspacePaths[0]!,
  86. });
  87. const identity = tab.workspaceIdentity!;
  88. const sourceId = parseRemoteWorkspaceIdentity(identity)?.sourceServerId;
  89. if (!sourceId) throw new Error(`${CASE_MARKER}: 远程项目缺少 Source 身份`);
  90. const profileId = (await readSettings()).connectionProfiles?.find(
  91. (profile) => profile.sourceServerId === sourceId,
  92. )?.profileId;
  93. if (!profileId) throw new Error(`${CASE_MARKER}: 找不到设备线路`);
  94. // 重打包本轮 release,使远端已安装 SHA 与桌面端期望不一致,复现启动重连停在 needs-upgrade。
  95. const shaBefore = await readRemoteCurrentSha();
  96. const repack = await prepareSourceServerUpdateArchive(shaBefore, CASE_MARKER);
  97. expect(repack.newSha).not.toBe(shaBefore);
  98. await installHandoffRpcProbe();
  99. await callHandoffHost(ServiceChannels.SourceServerManagement, "disconnectSource", [sourceId]);
  100. // 直接走 Host 连接,不经过向导;向导会自动发起更新,无法观察停留在待处理的设备。
  101. await callHandoffHost(ServiceChannels.SourceServerManagement, "connectProfile", [
  102. profileId,
  103. ]).catch(() => undefined);
  104. await selectTaskOrganizeMode(["项目", "Project"]);
  105. const row = $(`[data-project-workspace-identity=${JSON.stringify(identity)}]`);
  106. const status = row.$('[data-testid="project-status-label"]');
  107. await browser.waitUntil(
  108. async () =>
  109. (await status.isExisting()) && /^(需要更新|Update required)$/u.test(await status.getText()),
  110. { timeout: 60_000, timeoutMsg: `${CASE_MARKER}: 项目行没有显示“需要更新”` },
  111. );
  112. expect(await status.getAttribute("class")).toContain("text-warning-surface-foreground");
  113. expect(await row.$('[data-remote-state-icon="cloud-alert"]').isExisting()).toBe(true);
  114. // Host 投影曾丢掉 upgradeTarget,桌面端过旧时详情入口误显示“更新远端”;这里锁住投影带出该字段。
  115. const directory = await callHandoffHost<{ hosts: { id: string; upgradeTarget?: string }[] }>(
  116. ServiceChannels.RemoteProjects,
  117. "readDirectory",
  118. );
  119. expect(
  120. directory.hosts.find((host) => host.id === `remote:server:${sourceId}`)?.upgradeTarget,
  121. ).toBe("server");
  122. const details = $('[data-testid="remote-identity-details"]');
  123. for (const locale of ["zh-CN", "en-US"] as const) {
  124. for (const theme of ["light", "dark"] as const) {
  125. await setAppearance(locale, theme);
  126. // 状态是行内关键信息,窄侧栏里也必须完整显示,由项目名和设备名让出空间。
  127. expect(
  128. await browser.execute(
  129. (el) => el.scrollWidth <= el.clientWidth,
  130. await status.getElement(),
  131. ),
  132. ).toBe(true);
  133. const outside = await browser.execute(() => ({ x: innerWidth - 24, y: 24 }));
  134. await browser.action("pointer").move(outside).perform();
  135. await details.waitForDisplayed({ reverse: true });
  136. await row.$('[data-testid="virtual-project-toggle"]').moveTo();
  137. await details.waitForDisplayed();
  138. await browser.saveScreenshot(resolve(artifactDir, `pending-${locale}-${theme}.png`));
  139. }
  140. }
  141. await setAppearance("zh-CN", "dark");
  142. const outside = await browser.execute(() => ({ x: innerWidth - 24, y: 24 }));
  143. await browser.action("pointer").move(outside).perform();
  144. await details.waitForDisplayed({ reverse: true });
  145. await row.$('[data-testid="virtual-project-toggle"]').moveTo();
  146. await details.waitForDisplayed();
  147. const detailsText = await details.getText();
  148. expect(detailsText).toMatch(/需要更新|Update required/u);
  149. expect(detailsText).not.toMatch(/需要处理|Needs attention/u);
  150. const buttons = await details.$$("button");
  151. expect(buttons).toHaveLength(1);
  152. const entry = details.$('[data-testid="remote-identity-device-settings"]');
  153. expect(await entry.getText()).toMatch(/更新远端|Update remote device/u);
  154. await browser.saveScreenshot(resolve(artifactDir, "pending-details.png"));
  155. await entry.click();
  156. await details.waitForDisplayed({ reverse: true });
  157. const card = $(`[data-source-server-card="${sourceId}"]`);
  158. await card.waitForDisplayed({ timeout: 15_000 });
  159. // RDUX-13:定位后只展开目标设备行,焦点在设备名按钮上并持续高亮。
  160. await waitForRemoteDeviceLocated(sourceId, CASE_MARKER);
  161. expect(await card.getText()).toMatch(/更新远端|Update remote device/u);
  162. await browser.saveScreenshot(resolve(artifactDir, "device-settings.png"));
  163. // 入口只负责定位,不能替用户执行更新。
  164. expect(await readRemoteCurrentSha()).toBe(shaBefore);
  165. });
  166. });