conversation-session-r3-update-inflight.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. import { mkdir, writeFile } from "node:fs/promises";
  2. import { resolve } from "node:path";
  3. import { parseRemoteWorkspaceIdentity, type SourceServerManagementSnapshot } from "@zcode/shared";
  4. import { clearAppData, readSettings, waitForDefaultWorkspaceReady } from "#e2e/helpers/desktop-app";
  5. import {
  6. disconnectRemoteSource,
  7. openRemoteDevicesSettings,
  8. requestRemoteProjectConnection,
  9. } from "#e2e/helpers/remote-project-actions";
  10. import {
  11. execInRemoteContainer,
  12. readRemoteDockerContainer,
  13. } from "#e2e/helpers/remote-docker-target";
  14. import { prepareSourceServerUpdateArchive } from "#e2e/helpers/source-server-update-fixture";
  15. import {
  16. callSourceManagement,
  17. connectDuringNextSourceUpdate,
  18. holdConfirmIdentityChange,
  19. installSourceManagementRpc,
  20. readHeldConfirmIdentityChangeCount,
  21. readSourceManagementCall,
  22. readUpdateInflightEvidence,
  23. releaseConfirmIdentityChange,
  24. restoreSourceManagementRpc,
  25. restoreUpdateInflightProbe,
  26. startSourceManagementCall,
  27. waitForSourceManagementRpcReady,
  28. } from "#e2e/helpers/source-server-update-inflight";
  29. import {
  30. connectSSHWorkspace,
  31. readSSHRuntimeConfig,
  32. waitForRemoteTab,
  33. } from "#e2e/helpers/ssh-remote-p0";
  34. const CASE_MARKER = "E2E_R3_UPDATE_INFLIGHT";
  35. const artifactDir = resolve(
  36. process.env.ZCODE_E2E_ARTIFACT_DIR ?? ".e2e-artifacts/r3-update-inflight",
  37. );
  38. async function readRemoteCurrentSha(container: string): Promise<string> {
  39. const { stdout } = await execInRemoteContainer(container, [
  40. "sh",
  41. "-c",
  42. 'cat "$HOME/.zcode/server/current.json"',
  43. ]);
  44. return /"archiveSha256":\s*"([0-9a-f]{64})"/u.exec(stdout)?.[1] ?? "";
  45. }
  46. async function readRemoteCurrentShaOrNull(container: string): Promise<string | null> {
  47. // 远端安装切换 current.json 的瞬间可能读到中间态;轮询里按“尚未完成”处理。
  48. return readRemoteCurrentSha(container).catch(() => null);
  49. }
  50. async function readWizardButtons() {
  51. return browser.execute(() =>
  52. Array.from(
  53. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  54. ).map((button) => ({ text: button.innerText.trim(), disabled: button.disabled })),
  55. );
  56. }
  57. /** 展开设置页中目标设备行,返回其后台连接卡片文本;没有卡片时返回 null。 */
  58. async function readDeviceBackgroundCard(sourceServerId: string): Promise<string | null> {
  59. return browser.execute((id) => {
  60. const row = document.querySelector(`[data-source-server-card="${id}"]`);
  61. row?.querySelector<HTMLElement>('[data-source-server-toggle][aria-expanded="false"]')?.click();
  62. return (
  63. row?.querySelector<HTMLElement>('[data-testid="remote-connection-minimized"]')?.innerText ??
  64. null
  65. );
  66. }, sourceServerId);
  67. }
  68. /** 页面上任何位置的后台连接卡片文本;关闭撤销意图后应为空。 */
  69. async function readAllBackgroundCards(): Promise<string[]> {
  70. return browser.execute(() =>
  71. Array.from(
  72. document.querySelectorAll<HTMLElement>('[data-testid="remote-connection-minimized"]'),
  73. ).map((card) => card.innerText),
  74. );
  75. }
  76. /** 向导全文(含 sr-only 副题),用于判断等待点是否被说成连接失败。 */
  77. async function readDialogText(): Promise<string> {
  78. return browser.execute(
  79. () => document.querySelector('[data-testid="ssh-dialog"]')?.textContent ?? "",
  80. );
  81. }
  82. /** 连接屏把标题区收成 sr-only,副题仍是对话框的 aria 描述;按 aria-describedby 读取。 */
  83. async function readDialogDescription(): Promise<string | null> {
  84. return browser.execute(() => {
  85. const dialog = document.querySelector('[data-testid="ssh-dialog"]')?.closest('[role="dialog"]');
  86. const id = dialog?.getAttribute("aria-describedby");
  87. return id ? (document.getElementById(id)?.textContent ?? null) : null;
  88. });
  89. }
  90. async function clickEnabledDialogButton(pattern: RegExp): Promise<boolean> {
  91. return browser.execute(
  92. (source, flags) => {
  93. const matcher = new RegExp(source, flags);
  94. const button = Array.from(
  95. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  96. ).find((item) => matcher.test(item.innerText.trim()) && !item.disabled);
  97. button?.click();
  98. return Boolean(button);
  99. },
  100. pattern.source,
  101. pattern.flags,
  102. );
  103. }
  104. async function readStates(): Promise<SourceServerManagementSnapshot["states"]> {
  105. return (await callSourceManagement<SourceServerManagementSnapshot>("getSnapshot")).states;
  106. }
  107. /** 项目菜单「连接」偶发一次点击无 RPC(R3-UPDATE-INFLIGHT-01 已记录);20 秒无向导时补点一次。 */
  108. async function openProjectConnectionWizard(identity: string): Promise<number> {
  109. let clicks = 1;
  110. let lastClickAt = Date.now();
  111. await requestRemoteProjectConnection(identity, CASE_MARKER);
  112. await browser.waitUntil(
  113. async () => {
  114. if (await $('[data-testid="ssh-dialog"]').isExisting()) return true;
  115. if (Date.now() - lastClickAt > 20_000) {
  116. clicks += 1;
  117. await requestRemoteProjectConnection(identity, CASE_MARKER);
  118. lastClickAt = Date.now();
  119. }
  120. return false;
  121. },
  122. { timeout: 120_000, interval: 500, timeoutMsg: `${CASE_MARKER}: 原项目连接没有打开向导` },
  123. );
  124. return clicks;
  125. }
  126. interface InflightContext {
  127. container: string;
  128. identity: string;
  129. sourceServerId: string;
  130. profileId: string;
  131. workspacePath: string;
  132. remoteSessionId: string;
  133. }
  134. describe(`${CASE_MARKER}: 更新进行中的连接不覆盖更新,向导保留原意图`, () => {
  135. const facts: Record<string, unknown> = { timeline: [] as string[] };
  136. let context: InflightContext | undefined;
  137. const requireContext = () => {
  138. if (!context) throw new Error(`${CASE_MARKER}: 前一个用例没有完成,缺少设备与项目上下文`);
  139. return context;
  140. };
  141. const mark = async (label: string) => {
  142. (facts.timeline as string[]).push(`${new Date().toISOString()} ${label}`);
  143. await mkdir(artifactDir, { recursive: true });
  144. await writeFile(resolve(artifactDir, "update-inflight.json"), JSON.stringify(facts, null, 2));
  145. };
  146. after(async () => {
  147. facts.finalEvidence = await readUpdateInflightEvidence().catch(() => null);
  148. await restoreSourceManagementRpc().catch(() => undefined);
  149. await restoreUpdateInflightProbe().catch(() => undefined);
  150. await mkdir(artifactDir, { recursive: true });
  151. await browser.saveScreenshot(resolve(artifactDir, "update-inflight-final.png")).catch(() => {});
  152. await writeFile(resolve(artifactDir, "update-inflight.json"), JSON.stringify(facts, null, 2));
  153. await clearAppData();
  154. });
  155. it("R3-UPDATE-INFLIGHT-01/02 更新中另一入口连接被拒;返回配置禁用,关闭等同收起,更新后继续原项目", async function () {
  156. this.timeout(20 * 60_000);
  157. await waitForDefaultWorkspaceReady(30_000);
  158. const config = readSSHRuntimeConfig(CASE_MARKER);
  159. const container = readRemoteDockerContainer(CASE_MARKER);
  160. const [workspacePath] = config.workspacePaths;
  161. const tab = await connectSSHWorkspace({ caseMarker: CASE_MARKER, config, workspacePath });
  162. const identity = tab.workspaceIdentity;
  163. const sourceServerId = identity
  164. ? parseRemoteWorkspaceIdentity(identity)?.sourceServerId
  165. : undefined;
  166. const profileId = (await readSettings()).connectionProfiles?.find(
  167. (profile) => profile.sourceServerId === sourceServerId,
  168. )?.profileId;
  169. if (!identity || !sourceServerId || !profileId)
  170. throw new Error(`${CASE_MARKER}: 首连后缺少 Source 身份或线路`);
  171. const shaBefore = await readRemoteCurrentSha(container);
  172. // 同版本异 SHA:开发态内容寻址判定需要更新,走与生产版本不兼容相同的向导自动更新链。
  173. const repack = await prepareSourceServerUpdateArchive(shaBefore, CASE_MARKER);
  174. expect(repack.newSha).not.toBe(shaBefore);
  175. facts.before = { tab, profileId, sha: shaBefore, repack };
  176. await disconnectRemoteSource(sourceServerId, CASE_MARKER, { workspaceIdentities: [identity] });
  177. await connectDuringNextSourceUpdate({
  178. sourceServerId,
  179. profileId,
  180. target: {
  181. kind: "ssh",
  182. host: config.host,
  183. port: config.port,
  184. username: config.username,
  185. password: config.password,
  186. assetInstallMode: "local-download-upload",
  187. },
  188. });
  189. await requestRemoteProjectConnection(identity, CASE_MARKER);
  190. // 第二次实跑观察到:项目菜单「连接」点击后没有任何 RPC(原因未查明,与本用例无关)。
  191. // 20 秒内没有打开向导时按用户行为再点一次,并记录次数,不把它算作本用例的通过条件。
  192. let projectConnectClicks = 1;
  193. let lastProjectConnectAt = Date.now();
  194. await browser.waitUntil(
  195. async () => {
  196. if ((await readUpdateInflightEvidence()).updatingSeen) return true;
  197. if (
  198. Date.now() - lastProjectConnectAt > 20_000 &&
  199. !(await $('[data-testid="ssh-dialog"]').isExisting())
  200. ) {
  201. projectConnectClicks += 1;
  202. await requestRemoteProjectConnection(identity, CASE_MARKER);
  203. lastProjectConnectAt = Date.now();
  204. }
  205. return false;
  206. },
  207. {
  208. timeout: 180_000,
  209. interval: 200,
  210. timeoutMsg: `${CASE_MARKER}: 原项目连接没有触发向导自动更新`,
  211. },
  212. );
  213. facts.projectConnectClicks = projectConnectClicks;
  214. await mark("update-started");
  215. // R3-UPDATE-INFLIGHT-02:更新在途时返回配置不可用,关闭只收起。
  216. const buttonsDuringUpdate = await readWizardButtons();
  217. facts.buttonsDuringUpdate = buttonsDuringUpdate;
  218. const back = buttonsDuringUpdate.find((button) =>
  219. /^(返回配置|Back to configuration)$/u.test(button.text),
  220. );
  221. expect(back).toBeDefined();
  222. expect(back?.disabled).toBe(true);
  223. const closed = await browser.execute(() => {
  224. const button = Array.from(
  225. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  226. ).find((item) => /^(关闭|Close)$/u.test(item.innerText.trim()) && !item.disabled);
  227. button?.click();
  228. return Boolean(button);
  229. });
  230. expect(closed).toBe(true);
  231. await $('[data-testid="ssh-dialog"]').waitForExist({
  232. reverse: true,
  233. timeout: 15_000,
  234. timeoutMsg: `${CASE_MARKER}: 更新中关闭后对话框仍在`,
  235. });
  236. // 后台卡片只在设置页的设备行里展示;卡片存在说明流程被收起而不是被关闭撤销。
  237. await openRemoteDevicesSettings();
  238. await browser.waitUntil(() => readDeviceBackgroundCard(sourceServerId).then(Boolean), {
  239. timeout: 15_000,
  240. timeoutMsg: `${CASE_MARKER}: 更新中关闭没有收起为后台连接`,
  241. });
  242. facts.backgroundCardDuringUpdate = await readDeviceBackgroundCard(sourceServerId);
  243. // 更新进行中的卡片按进行中展示,不能沿用触发更新的“需升级”错误显示连接失败。
  244. expect(facts.backgroundCardDuringUpdate).toMatch(/正在连接|Connecting/u);
  245. expect(facts.backgroundCardDuringUpdate).not.toMatch(/失败|failed/iu);
  246. await mark("closed-as-minimized");
  247. // R3-UPDATE-INFLIGHT-01:并发连接被拒,更新日志未被替换,此时更新尚未完成。
  248. await browser.waitUntil(
  249. async () => Boolean((await readUpdateInflightEvidence()).operationLogs),
  250. {
  251. timeout: 60_000,
  252. timeoutMsg: `${CASE_MARKER}: 并发连接没有返回或日志读取没有完成`,
  253. },
  254. );
  255. const duringUpdate = await readUpdateInflightEvidence();
  256. facts.duringUpdate = {
  257. connectResult: duringUpdate.connectResult,
  258. operationLogs: duringUpdate.operationLogs,
  259. };
  260. expect(duringUpdate.connectResult).toMatchObject({
  261. success: false,
  262. reasonCode: "source-server-update-in-progress",
  263. });
  264. expect(duringUpdate.operationLogs?.length).toBeGreaterThan(0);
  265. expect(duringUpdate.operationLogs?.every((entry) => entry.operation === "update")).toBe(true);
  266. expect(duringUpdate.operationLogs?.some((entry) => entry.phase === "ready")).toBe(false);
  267. await mark("concurrent-connect-rejected");
  268. await browser.waitUntil(
  269. async () => (await readRemoteCurrentShaOrNull(container)) === repack.newSha,
  270. {
  271. timeout: 600_000,
  272. interval: 2000,
  273. timeoutMsg: `${CASE_MARKER}: 更新没有切换到新 release`,
  274. },
  275. );
  276. await mark("sha-switched");
  277. // 收起保留原意图:更新后的连接在后台完成,用户继续时打开原项目。
  278. await browser.waitUntil(
  279. async () => {
  280. const text = await readDeviceBackgroundCard(sourceServerId);
  281. if (!text || !/(连接已完成|Connection complete)/u.test(text)) return false;
  282. return browser.execute((id) => {
  283. const card = document.querySelector<HTMLButtonElement>(
  284. `[data-source-server-card="${id}"] [data-testid="remote-connection-minimized"]`,
  285. );
  286. card?.click();
  287. return Boolean(card);
  288. }, sourceServerId);
  289. },
  290. { timeout: 240_000, interval: 1000, timeoutMsg: `${CASE_MARKER}: 更新后没有后台完成提示` },
  291. );
  292. const reconnected = await waitForRemoteTab({
  293. caseMarker: CASE_MARKER,
  294. expectedIdentity: identity,
  295. expectedPath: workspacePath,
  296. requireActive: false,
  297. timeoutMs: 180_000,
  298. });
  299. expect(reconnected.remoteSessionId).toBeTruthy();
  300. expect(reconnected.remoteSessionId).not.toBe(tab.remoteSessionId);
  301. facts.reconnected = reconnected;
  302. const finalEvidence = await readUpdateInflightEvidence();
  303. const states = finalEvidence.states.filter((state) => state.profileId === profileId);
  304. facts.states = states;
  305. const firstUpdating = states.findIndex((state) => state.state === "updating");
  306. expect(firstUpdating).toBeGreaterThanOrEqual(0);
  307. expect(states.slice(firstUpdating).some((state) => state.state === "needs-upgrade")).toBe(
  308. false,
  309. );
  310. await mark("original-intent-continued");
  311. context = {
  312. container,
  313. identity,
  314. sourceServerId,
  315. profileId,
  316. workspacePath,
  317. remoteSessionId: reconnected.remoteSessionId!,
  318. };
  319. });
  320. it("R3-UPDATE-INFLIGHT-03 其他入口发起的更新进行中,原项目连接显示等待点,收起后卡片不显示失败", async function () {
  321. this.timeout(20 * 60_000);
  322. const current = requireContext();
  323. const { container, identity, sourceServerId, profileId, workspacePath } = current;
  324. const shaBefore = await readRemoteCurrentSha(container);
  325. const repack = await prepareSourceServerUpdateArchive(shaBefore, `${CASE_MARKER}_03`);
  326. expect(repack.newSha).not.toBe(shaBefore);
  327. await installSourceManagementRpc();
  328. await disconnectRemoteSource(sourceServerId, CASE_MARKER, { workspaceIdentities: [identity] });
  329. await waitForSourceManagementRpcReady(CASE_MARKER);
  330. // 模拟设置页「更新」、更新提示或另一窗口发起的更新:它不归向导所有,向导只能等它完成。
  331. const updateKey = await startSourceManagementCall("updateSource", [{ profileId }]);
  332. await browser.waitUntil(
  333. async () =>
  334. (await readStates()).some(
  335. (state) => state.profileId === profileId && state.state === "updating",
  336. ),
  337. { timeout: 60_000, interval: 500, timeoutMsg: `${CASE_MARKER}: 向导以外的更新没有开始` },
  338. );
  339. await mark("03-update-started");
  340. facts.projectConnectClicks03 = await openProjectConnectionWizard(identity);
  341. await browser.waitUntil(
  342. async () =>
  343. /远程设备正在更新远端服务|The remote device is updating its remote service/u.test(
  344. await readDialogText(),
  345. ),
  346. { timeout: 60_000, timeoutMsg: `${CASE_MARKER}: 向导没有显示“远端服务正在更新”等待点` },
  347. );
  348. facts.waitingDialog03 = await readDialogText();
  349. const waitingDescription = await readDialogDescription();
  350. facts.waitingDescription03 = waitingDescription;
  351. const waitingButtons = await readWizardButtons();
  352. facts.waitingButtons03 = waitingButtons;
  353. expect(
  354. waitingButtons.some((button) => /^(重试|Retry)$/u.test(button.text) && !button.disabled),
  355. ).toBe(true);
  356. expect(await clickEnabledDialogButton(/^(在后台继续|Continue in background)$/u)).toBe(true);
  357. await $('[data-testid="ssh-dialog"]').waitForExist({
  358. reverse: true,
  359. timeout: 15_000,
  360. timeoutMsg: `${CASE_MARKER}: 等待点收起后对话框仍在`,
  361. });
  362. await openRemoteDevicesSettings();
  363. await browser.waitUntil(() => readDeviceBackgroundCard(sourceServerId).then(Boolean), {
  364. timeout: 15_000,
  365. timeoutMsg: `${CASE_MARKER}: 等待点收起后没有后台卡片`,
  366. });
  367. const waitingCard = await readDeviceBackgroundCard(sourceServerId);
  368. facts.backgroundCard03 = waitingCard;
  369. await mark("03-minimized-waiting");
  370. // 等待点不是连接失败:副题与连接屏一致显示“正在更新远端服务”,收起后的卡片也不显示失败。
  371. // 两处现象先记录到工件再断言,修复前的证据不会因第一处失败而缺失。
  372. expect(waitingDescription).toMatch(/^(正在更新远端服务|Updating the remote server)$/u);
  373. expect(waitingCard).not.toMatch(/失败|failed/iu);
  374. expect(waitingCard).toMatch(/等待确认或补充信息|Waiting for confirmation or information/u);
  375. await browser.waitUntil(async () => Boolean(await readSourceManagementCall(updateKey)), {
  376. timeout: 600_000,
  377. interval: 2000,
  378. timeoutMsg: `${CASE_MARKER}: 向导以外的更新没有完成`,
  379. });
  380. const updateResult = await readSourceManagementCall(updateKey);
  381. facts.update03 = updateResult?.ok ? "ok" : updateResult;
  382. expect(updateResult?.ok).toBe(true);
  383. expect(await readRemoteCurrentSha(container)).toBe(repack.newSha);
  384. await mark("03-update-finished");
  385. // 更新完成后用户恢复卡片并重试,原项目意图仍由这个向导完成。
  386. const resumed = await browser.execute((id) => {
  387. const card = document.querySelector<HTMLButtonElement>(
  388. `[data-source-server-card="${id}"] [data-testid="remote-connection-minimized"]`,
  389. );
  390. card?.click();
  391. return Boolean(card);
  392. }, sourceServerId);
  393. expect(resumed).toBe(true);
  394. await browser.waitUntil(() => clickEnabledDialogButton(/^(重试|Retry)$/u), {
  395. timeout: 30_000,
  396. timeoutMsg: `${CASE_MARKER}: 恢复后的向导没有可用的重试`,
  397. });
  398. const reconnected = await waitForRemoteTab({
  399. caseMarker: CASE_MARKER,
  400. expectedIdentity: identity,
  401. expectedPath: workspacePath,
  402. requireActive: false,
  403. timeoutMs: 180_000,
  404. });
  405. expect(reconnected.remoteSessionId).toBeTruthy();
  406. expect(reconnected.remoteSessionId).not.toBe(current.remoteSessionId);
  407. current.remoteSessionId = reconnected.remoteSessionId!;
  408. await mark("03-original-intent-continued");
  409. });
  410. it("R3-UPDATE-INFLIGHT-04 确认设备身份进行中关闭向导仍撤销意图,不收起", async function () {
  411. this.timeout(10 * 60_000);
  412. const { container, identity, sourceServerId } = requireContext();
  413. await disconnectRemoteSource(sourceServerId, CASE_MARKER, { workspaceIdentities: [identity] });
  414. // 远端换一个安装身份:停止 daemon 并改写 installationId,下一次握手得到新的 sourceServerId。
  415. const rewrite = await execInRemoteContainer(container, [
  416. "sh",
  417. "-c",
  418. 'set -e; R="$HOME/.zcode/server"; ' +
  419. '"$R/bin/zcode" stop --wait --server-root "$R" --json >/dev/null 2>&1 || true; ' +
  420. "NEW=$(cat /proc/sys/kernel/random/uuid); " +
  421. 'sed -i -E "s/(\\"installationId\\"[[:space:]]*:[[:space:]]*\\")[0-9a-f-]{36}/\\1$NEW/" "$R/install.json"; ' +
  422. 'grep -q "$NEW" "$R/install.json"; echo "$NEW"',
  423. ]);
  424. facts.rewrittenInstallationId04 = rewrite.stdout.trim();
  425. await installSourceManagementRpc();
  426. await holdConfirmIdentityChange();
  427. facts.projectConnectClicks04 = await openProjectConnectionWizard(identity);
  428. await browser.waitUntil(
  429. () => clickEnabledDialogButton(/^(作为新设备使用|Use as a new device)$/u),
  430. { timeout: 120_000, interval: 500, timeoutMsg: `${CASE_MARKER}: 向导没有出现身份确认` },
  431. );
  432. await browser.waitUntil(async () => (await readHeldConfirmIdentityChangeCount()) > 0, {
  433. timeout: 15_000,
  434. timeoutMsg: `${CASE_MARKER}: 身份确认请求没有发出`,
  435. });
  436. // 主按钮换成进行中的“取消连接”说明 React 已按确认中重新渲染;此后点关闭才测到真实的确认中状态。
  437. await browser.waitUntil(
  438. async () =>
  439. !(await readWizardButtons()).some((button) =>
  440. /^(作为新设备使用|Use as a new device)$/u.test(button.text),
  441. ),
  442. { timeout: 15_000, timeoutMsg: `${CASE_MARKER}: 向导没有进入确认中状态` },
  443. );
  444. facts.buttonsDuringIdentityConfirm04 = await readWizardButtons();
  445. expect(await clickEnabledDialogButton(/^(关闭|Close)$/u)).toBe(true);
  446. await $('[data-testid="ssh-dialog"]').waitForExist({
  447. reverse: true,
  448. timeout: 15_000,
  449. timeoutMsg: `${CASE_MARKER}: 确认身份中关闭后对话框仍在`,
  450. });
  451. await openRemoteDevicesSettings();
  452. // 第一次调用只负责展开设备行;展开后的进度块在下一次渲染才出现。
  453. await readDeviceBackgroundCard(sourceServerId);
  454. await browser.pause(1000);
  455. facts.cardsAfterClose04 = await readAllBackgroundCards();
  456. expect(facts.cardsAfterClose04).toEqual([]);
  457. await mark("04-closed-during-identity-confirm");
  458. // 放行迟到的确认:Host 照常把线路改绑到新设备并上线,向导不能借此恢复已撤销的意图。
  459. await releaseConfirmIdentityChange();
  460. await browser.waitUntil(
  461. async () =>
  462. (await readStates()).some(
  463. (state) =>
  464. state.state === "online" &&
  465. state.sourceServerId !== undefined &&
  466. state.sourceServerId !== sourceServerId,
  467. ),
  468. { timeout: 120_000, interval: 1000, timeoutMsg: `${CASE_MARKER}: 迟到的身份确认没有完成` },
  469. );
  470. await mark("04-identity-confirm-settled");
  471. await browser.pause(8000);
  472. facts.cardsAfterConfirm04 = await readAllBackgroundCards();
  473. expect(facts.cardsAfterConfirm04).toEqual([]);
  474. expect(await $('[data-testid="ssh-dialog"]').isExisting()).toBe(false);
  475. await mark("04-intent-stayed-cancelled");
  476. });
  477. });