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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. import { selectTaskOrganizeMode } from "#e2e/helpers/workspace-agent-warmup";
  2. import { releaseControlledReplay } from "#e2e/helpers/controlled-replay";
  3. import { prepareSourceServerUpdateArchive } from "#e2e/helpers/source-server-update-fixture";
  4. import {
  5. disconnectDuringNextSourceUpdate,
  6. readUpdateDisconnectEvidence,
  7. restoreUpdateDisconnectProbe,
  8. updateAndRemoveNonCurrentProfile,
  9. } from "#e2e/helpers/source-server-update-disconnect";
  10. import {
  11. disconnectRemoteSource,
  12. requestRemoteProjectConnection,
  13. } from "#e2e/helpers/remote-project-actions";
  14. import { execFile } from "node:child_process";
  15. import { mkdir, writeFile } from "node:fs/promises";
  16. import { resolve } from "node:path";
  17. import { promisify } from "node:util";
  18. import { parseRemoteWorkspaceIdentity } from "@zcode/shared";
  19. import {
  20. TID_TASK_SETTINGS_BUTTON,
  21. TID_SETTINGS_BACK_BUTTON,
  22. TID_SETTINGS_SECTION_NAV,
  23. testId,
  24. } from "@zcode/shared/test-ids";
  25. import {
  26. clearAppData,
  27. clickTestIdByDom,
  28. readSettings,
  29. waitForDefaultWorkspaceReady,
  30. } from "#e2e/helpers/desktop-app";
  31. import {
  32. connectSSHWorkspaceAndSendFirstTurn,
  33. prepareSSHLifecycle,
  34. readRemoteCoreIdentity,
  35. readTaskRowInProject,
  36. sendSSHFollowTurn,
  37. type SSHLifecycleProvider,
  38. type SSHLifecycleTask,
  39. } from "#e2e/helpers/ssh-remote-lifecycle";
  40. import {
  41. readHostProcesses,
  42. connectSSHWorkspace,
  43. readSSHRuntimeConfig,
  44. waitForRemoteTab,
  45. type SSHConnectionConfig,
  46. } from "#e2e/helpers/ssh-remote-p0";
  47. import {
  48. sendV4Prompt,
  49. waitForV4Pane,
  50. waitForV4TimelineContaining,
  51. } from "#e2e/helpers/v4-conversation";
  52. const CASE_MARKER = "E2E_R3_SERVER_UPDATE";
  53. const artifactDir = resolve(
  54. process.env.ZCODE_E2E_ARTIFACT_DIR ?? ".e2e-artifacts/r3-server-update",
  55. );
  56. const run = promisify(execFile);
  57. const updateScenario = process.env.R3_SERVER_UPDATE_CASE ?? "cancel";
  58. /** 上传/解压期间容器 sshd 在 x64 模拟下会拒绝或拖慢新握手;只读探针改走 docker exec,不经 sshd。 */
  59. async function dockerSh(
  60. command: string,
  61. ): Promise<{ code: number | null; stdout: string; stderr: string }> {
  62. const container = process.env.ZCODE_E2E_SSH_CONTAINER?.trim();
  63. if (!container) throw new Error(`${CASE_MARKER}: 缺少 ZCODE_E2E_SSH_CONTAINER`);
  64. try {
  65. const result = await run("docker", ["exec", "-u", "dev", container, "bash", "-lc", command], {
  66. maxBuffer: 1 << 22,
  67. timeout: 30_000,
  68. });
  69. return { code: 0, stdout: result.stdout, stderr: result.stderr };
  70. } catch (error) {
  71. const failure = error as { code?: number; stdout?: string; stderr?: string };
  72. return {
  73. code: failure.code ?? 1,
  74. stdout: failure.stdout ?? "",
  75. stderr: failure.stderr ?? String(error),
  76. };
  77. }
  78. }
  79. async function readRemoteCurrentSha(_config: SSHConnectionConfig): Promise<string> {
  80. const result = await dockerSh(
  81. 'grep -o \'"archiveSha256": *"[0-9a-f]*"\' "$HOME/.zcode/server/current.json" | grep -o "[0-9a-f]\\{64\\}"',
  82. );
  83. return result.stdout.trim();
  84. }
  85. async function readRemoteCoreIdentityViaDocker(): Promise<{
  86. pid: number;
  87. supervisorPid: number;
  88. state: string;
  89. generation: number;
  90. startTicks: number;
  91. }> {
  92. const result = await dockerSh(
  93. 'S="$HOME/.zcode/server/run/status.json"; cat "$S"; echo; P=$(sed -nE \'s/.*"pid": *([0-9]+).*/\\1/p\' "$S" | head -n1); echo "__STAT__ $(awk \'{print $4" "$22}\' /proc/$P/stat)"',
  94. );
  95. const statusText = result.stdout.slice(0, result.stdout.indexOf("__STAT__"));
  96. const status = JSON.parse(statusText) as { pid: number; generation: number; state: string };
  97. const stat = /__STAT__ (\d+) (\d+)/u.exec(result.stdout);
  98. if (!stat) throw new Error(`${CASE_MARKER}: 读取远端 Core 身份失败: ${result.stderr}`);
  99. return {
  100. pid: status.pid,
  101. supervisorPid: Number.parseInt(stat[1]!, 10),
  102. state: status.state,
  103. generation: status.generation,
  104. startTicks: Number.parseInt(stat[2]!, 10),
  105. };
  106. }
  107. /** 远端解压 75MB 期间(x64 模拟)sshd 握手可能超时;轮询中把探针失败当作"尚未就绪"而不是用例失败。 */
  108. async function readRemoteCurrentShaOrNull(config: SSHConnectionConfig): Promise<string | null> {
  109. try {
  110. return await readRemoteCurrentSha(config);
  111. } catch {
  112. return null;
  113. }
  114. }
  115. async function readRemoteRuntimeReleaseDirs(_config: SSHConnectionConfig): Promise<string[]> {
  116. const result = await dockerSh(
  117. 'for d in /proc/[0-9]*; do c=$(tr "\\0" " " < "$d/cmdline" 2>/dev/null) || continue; case "$c" in *releases/*) echo "$c" | grep -oE "releases/[^/ ]+" | head -n1;; esac; done | sort | uniq -c',
  118. );
  119. return result.stdout.trim().split("\n").filter(Boolean);
  120. }
  121. describe(`${CASE_MARKER}: 同版本异 SHA 更新在 running task 下被守卫,显式强制后换代`, () => {
  122. let provider: SSHLifecycleProvider | null = null;
  123. const facts: Record<string, unknown> = { scenario: updateScenario, timeline: [] as string[] };
  124. const mark = async (label: string) => {
  125. (facts.timeline as string[]).push(`${new Date().toISOString()} ${label}`);
  126. await mkdir(artifactDir, { recursive: true });
  127. await writeFile(resolve(artifactDir, "server-update.json"), JSON.stringify(facts, null, 2));
  128. };
  129. after(async () => {
  130. await mkdir(artifactDir, { recursive: true });
  131. if (updateScenario === "remove-sibling") {
  132. facts.finalEvidence = await readUpdateDisconnectEvidence().catch(() => null);
  133. facts.finalUi = await browser.execute(() => document.body?.innerText ?? "");
  134. await browser.saveScreenshot(resolve(artifactDir, "source-update.png"));
  135. }
  136. await restoreUpdateDisconnectProbe();
  137. await writeFile(resolve(artifactDir, "server-update.json"), JSON.stringify(facts, null, 2));
  138. await provider?.tunnel.close().catch(() => undefined);
  139. provider = null;
  140. await browser.electron.restoreAllMocks();
  141. await clearAppData();
  142. });
  143. it("R3A-UPG-03/04 同版本异 SHA 刷新在 running task 下被守卫且保持可用;任务收口后重连原子切换到新 release", async function () {
  144. this.timeout(35 * 60_000);
  145. if (!["cancel", "force", "disconnect", "remove-sibling"].includes(updateScenario))
  146. throw new Error("未知更新场景");
  147. if (updateScenario === "remove-sibling") await waitForDefaultWorkspaceReady(30_000);
  148. if (updateScenario === "remove-sibling") {
  149. const config = readSSHRuntimeConfig(CASE_MARKER);
  150. if (!["localhost", "127.0.0.1"].includes(config.host))
  151. throw new Error(`${CASE_MARKER}: 多线路回归要求本机隔离 SSH 容器`);
  152. const tabA = await connectSSHWorkspace({
  153. caseMarker: CASE_MARKER,
  154. config,
  155. workspacePath: config.workspacePaths[0],
  156. });
  157. const sourceId = parseRemoteWorkspaceIdentity(tabA.workspaceIdentity!)?.sourceServerId;
  158. const ownerProfileId = (await readSettings()).connectionProfiles?.find(
  159. (profile) => profile.sourceServerId === sourceId,
  160. )?.profileId;
  161. await connectSSHWorkspace({
  162. caseMarker: CASE_MARKER,
  163. config: { ...config, host: config.host === "localhost" ? "127.0.0.1" : "localhost" },
  164. workspacePath: config.workspacePaths[1],
  165. });
  166. const shaBefore = await readRemoteCurrentSha(config);
  167. facts.before = { tabA, sha: shaBefore };
  168. const repack = await prepareSourceServerUpdateArchive(shaBefore, CASE_MARKER);
  169. expect(repack.newSha).not.toBe(shaBefore);
  170. facts.repack = repack;
  171. const siblingId = (await readSettings()).connectionProfiles?.find(
  172. (profile) => profile.sourceServerId === sourceId && profile.profileId !== ownerProfileId,
  173. )?.profileId;
  174. if (!sourceId || !ownerProfileId || !siblingId)
  175. throw new Error(`${CASE_MARKER}: 没有建立同一 Source 的两条真实线路`);
  176. await updateAndRemoveNonCurrentProfile(sourceId, ownerProfileId, {
  177. profileId: siblingId,
  178. profileDisplayName: "Update route B",
  179. sshAuthMethod: "password",
  180. target: {
  181. kind: "ssh",
  182. host: config.host === "localhost" ? "127.0.0.1" : "localhost",
  183. port: config.port,
  184. username: config.username,
  185. password: config.password,
  186. },
  187. });
  188. await clickTestIdByDom(TID_TASK_SETTINGS_BUTTON);
  189. await clickTestIdByDom(testId(TID_SETTINGS_SECTION_NAV, "remoteDevices"));
  190. await browser.waitUntil(
  191. async () => {
  192. const evidence = await readUpdateDisconnectEvidence();
  193. if (evidence.savedProfile) expect(evidence.savedProfile.header[0]).toBe(201);
  194. if (evidence.update && !evidence.sent)
  195. throw new Error(`${CASE_MARKER}: 更新在取消前结束: ${JSON.stringify(evidence.update)}`);
  196. return Boolean(
  197. evidence.cancellation &&
  198. evidence.update &&
  199. evidence.states.some(
  200. (state) => state.profileId === ownerProfileId && state.state === "online",
  201. ),
  202. );
  203. },
  204. { timeout: 240_000, timeoutMsg: `${CASE_MARKER}: 删除更新线路后原线路没有恢复` },
  205. );
  206. const evidence = await readUpdateDisconnectEvidence();
  207. facts.removeUpdatingSibling = { ownerProfileId, siblingId, ...evidence };
  208. expect(evidence.cancellation?.header[0]).toBe(201);
  209. expect(evidence.update?.header[0]).toBe(202);
  210. expect(evidence.update?.body.name).toBe("SourceServerProfileRemovedError");
  211. expect(
  212. evidence.states.some(
  213. (state) => state.profileId === ownerProfileId && state.state === "retrying",
  214. ),
  215. ).toBe(true);
  216. expect(
  217. (await readSettings()).connectionProfiles?.some(
  218. (profile) => profile.profileId === siblingId,
  219. ),
  220. ).toBe(false);
  221. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON);
  222. const recovered = await waitForRemoteTab({
  223. caseMarker: CASE_MARKER,
  224. expectedIdentity: tabA.workspaceIdentity!,
  225. expectedPath: config.workspacePaths[0],
  226. requireActive: false,
  227. });
  228. expect(recovered.remoteSessionId).not.toBe(tabA.remoteSessionId);
  229. facts.recovered = recovered;
  230. await mark("R3-REMOTE-08F-original-owner-recovered-after-sibling-removal");
  231. return;
  232. }
  233. const prepared = await prepareSSHLifecycle(CASE_MARKER, {
  234. apiType: "anthropic-messages",
  235. tunnelUsername: "tunnel",
  236. });
  237. provider = prepared.provider;
  238. const [workspaceA] = prepared.config.workspacePaths;
  239. const taskA = await connectSSHWorkspaceAndSendFirstTurn({
  240. caseMarker: CASE_MARKER,
  241. config: prepared.config,
  242. label: "A",
  243. provider,
  244. workspacePath: workspaceA,
  245. });
  246. const shaBefore = await readRemoteCurrentSha(prepared.config);
  247. const core0 = await readRemoteCoreIdentity(prepared.config, CASE_MARKER);
  248. facts.before = {
  249. sha: shaBefore,
  250. core: core0,
  251. runtimeReleases: await readRemoteRuntimeReleaseDirs(prepared.config),
  252. };
  253. const repack = await prepareSourceServerUpdateArchive(shaBefore, CASE_MARKER);
  254. expect(repack.newSha).not.toBe(shaBefore);
  255. facts.repack = repack;
  256. if (updateScenario === "disconnect") {
  257. const sourceId = parseRemoteWorkspaceIdentity(taskA.identity)?.sourceServerId;
  258. if (!sourceId) throw new Error(`${CASE_MARKER}: 缺少已握手 Source 身份`);
  259. await disconnectRemoteSource(sourceId, CASE_MARKER);
  260. await disconnectDuringNextSourceUpdate(sourceId);
  261. await requestRemoteProjectConnection(taskA.identity, CASE_MARKER);
  262. await browser.waitUntil(
  263. async () => {
  264. if ((await readUpdateDisconnectEvidence()).sent) return true;
  265. await browser.execute(() => {
  266. const button = Array.from(
  267. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  268. ).find(
  269. (item) =>
  270. /^(更新远端|Update server|立即更新|Update now)$/iu.test(item.innerText.trim()) &&
  271. !item.disabled,
  272. );
  273. button?.click();
  274. });
  275. return false;
  276. },
  277. { timeout: 180_000, timeoutMsg: `${CASE_MARKER}: 未进入真实更新并发断开场景` },
  278. );
  279. await browser.waitUntil(
  280. async () => {
  281. const evidence = await readUpdateDisconnectEvidence();
  282. return Boolean(evidence.cancellation && evidence.update);
  283. },
  284. { timeout: 180_000, timeoutMsg: `${CASE_MARKER}: 断开或更新操作没有收口` },
  285. );
  286. const evidence = await readUpdateDisconnectEvidence();
  287. facts.disconnectDuringUpdate = evidence;
  288. expect(evidence.cancellation?.header[0]).toBe(201);
  289. expect(
  290. evidence.cancellation?.body.states.find(
  291. (state: { sourceServerId?: string }) => state.sourceServerId === sourceId,
  292. )?.state,
  293. ).toBe("offline");
  294. expect(evidence.update?.header[0]).toBe(202);
  295. expect(evidence.update?.body.code).toBe("remote-connection-canceled");
  296. expect(evidence.states.at(-1)?.state).toBe("offline");
  297. expect(evidence.states.some((state) => state.state === "online")).toBe(false);
  298. await mark("R3-REMOTE-08E-update-canceled-without-republish");
  299. return;
  300. }
  301. // 受控回放保持任务运行,只有确认守卫并取消强制更新后才释放。
  302. await sendV4Prompt(`${CASE_MARKER}_SLOW 慢慢回答`);
  303. await waitForV4TimelineContaining("R3_UPDATE_STREAMING", 60_000);
  304. await waitForV4Pane(
  305. (s) => s.canStop && s.sessionId === taskA.taskId,
  306. "A 没有进入 running",
  307. 45_000,
  308. );
  309. const sourceId = parseRemoteWorkspaceIdentity(taskA.identity)?.sourceServerId;
  310. // 同版本异 SHA 属开发态内容寻址判定:连接时判定“需要更新”后,走与生产态相同的 needs-upgrade → updateSource 链路。
  311. // 普通路径:running 中断开再重连 → 向导自动发起 force:false 更新 → running-task guard → 向导弹出“强制更新”确认;
  312. // 用户取消后远端保持原 release、任务继续,向导错误面板保留“立即更新”入口(R3A-B-06 修正前该状态只有普通连接失败)。
  313. await selectTaskOrganizeMode(["项目", "Project"]);
  314. await disconnectRemoteSource(sourceId!, CASE_MARKER, { workspaceIdentities: [taskA.identity] });
  315. await requestRemoteProjectConnection(taskA.identity, CASE_MARKER);
  316. const FORCE_UPDATE_TITLE = /强制更新此设备|Force update this device/iu;
  317. // guard:向导内自动 force:false 更新被拒绝后,弹出共享的“强制更新”确认(与生产态 needs-upgrade 完全相同的入口)。
  318. let guardText = "";
  319. const forceConfirmVisible = () =>
  320. browser.execute(() =>
  321. Array.from(
  322. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  323. ).some(
  324. (button) =>
  325. button.getClientRects().length &&
  326. /^(强制更新|Force update)$/iu.test(button.innerText.trim()),
  327. ),
  328. );
  329. // running-tasks 是 Server 根命令;多加 server 会误走旧 CLI,使守卫取证失真。
  330. facts.runningTasksBeforeUpdate = (
  331. await dockerSh('"$HOME/.zcode/server/bin/zcode" running-tasks --json')
  332. ).stdout;
  333. // 手动原项目连接应自动尝试一次受保护更新;直接等待 running-task 守卫,不能补点更新掩盖交接缺失。
  334. await browser
  335. .waitUntil(
  336. async () => {
  337. guardText = await browser.execute(() => document.body?.innerText ?? "");
  338. return FORCE_UPDATE_TITLE.test(guardText) && (await forceConfirmVisible());
  339. },
  340. {
  341. timeout: 180_000,
  342. interval: 1000,
  343. timeoutMsg: `${CASE_MARKER}: 重连没有经 running-task guard 弹出强制更新确认`,
  344. },
  345. )
  346. .catch(async (error) => {
  347. facts.guardFailure = {
  348. body: await browser.execute(() => document.body.innerText.slice(-3500)),
  349. currentSha: await readRemoteCurrentShaOrNull(prepared.config),
  350. runningTasks: (await dockerSh('"$HOME/.zcode/server/bin/zcode" running-tasks --json'))
  351. .stdout,
  352. core: await readRemoteCoreIdentityViaDocker().catch(() => null),
  353. };
  354. throw error;
  355. });
  356. const remoteShaDuringGuard = await readRemoteCurrentSha(prepared.config);
  357. const coreAfterGuard = await readRemoteCoreIdentityViaDocker();
  358. expect(remoteShaDuringGuard).toBe(shaBefore);
  359. expect(coreAfterGuard.pid).toBe(core0.pid);
  360. await mark("guard-observed");
  361. expect(guardText).toContain(workspaceA);
  362. let updateActionConfirmed = false;
  363. if (updateScenario === "force") {
  364. // 守卫已经证明回合仍运行;只有此处真实确认才允许强制中断并更新。
  365. updateActionConfirmed = await browser.execute(() => {
  366. const button = Array.from(
  367. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  368. ).find(
  369. (item) => /^(强制更新|Force update)$/iu.test(item.innerText.trim()) && !item.disabled,
  370. );
  371. button?.click();
  372. return Boolean(button);
  373. });
  374. expect(updateActionConfirmed).toBe(true);
  375. facts.guard = { forceConfirmedWhileRunning: true, listedWorkspace: workspaceA };
  376. } else {
  377. const cancelled = await browser.execute(() => {
  378. const dialog = document.querySelector<HTMLElement>('[data-testid="ssh-dialog"]');
  379. const button = Array.from(dialog?.querySelectorAll<HTMLButtonElement>("button") ?? []).find(
  380. (item) =>
  381. /^(取消连接|Cancel connection)$/iu.test(item.innerText.trim()) && !item.disabled,
  382. );
  383. button?.click();
  384. return Boolean(button);
  385. });
  386. expect(cancelled).toBe(true);
  387. // 当前合同取消整个连接流程并给出“重试”,旧 case 要求过时的“立即更新”错误面板。
  388. await browser.waitUntil(
  389. async () => /已取消|Cancelled/iu.test(await $('[data-testid="ssh-dialog"]').getText()),
  390. { timeout: 30_000 },
  391. );
  392. expect(await readRemoteCurrentSha(prepared.config)).toBe(shaBefore);
  393. const runningAfterCancel = await dockerSh(
  394. '"$HOME/.zcode/server/bin/zcode" running-tasks --json',
  395. );
  396. expect(runningAfterCancel.code).toBe(0);
  397. expect(JSON.parse(runningAfterCancel.stdout).length).toBeGreaterThan(0);
  398. facts.guard = {
  399. forceConfirmCancelled: true,
  400. remoteShaUnchanged: true,
  401. coreUnchanged: true,
  402. listedWorkspace: workspaceA,
  403. };
  404. await releaseControlledReplay("r3-update-slow-turn");
  405. await browser.waitUntil(
  406. async () => {
  407. const result = await dockerSh('"$HOME/.zcode/server/bin/zcode" running-tasks --json');
  408. return result.code === 0 && JSON.parse(result.stdout).length === 0;
  409. },
  410. { timeout: 120_000, timeoutMsg: `${CASE_MARKER}: 释放回合后运行任务未收口` },
  411. );
  412. await browser.waitUntil(
  413. () =>
  414. browser.execute(() => {
  415. const button = Array.from(
  416. document.querySelectorAll<HTMLButtonElement>('[data-testid="ssh-dialog"] button'),
  417. ).find((item) => /^(重试|Retry)$/iu.test(item.innerText.trim()) && !item.disabled);
  418. button?.click();
  419. return Boolean(button);
  420. }),
  421. { timeout: 15_000, timeoutMsg: `${CASE_MARKER}: 取消后没有重试入口` },
  422. );
  423. // 当前重试会自动发起受保护更新;不能在更新已成功后等待一个不会再次出现的按钮。
  424. updateActionConfirmed = true;
  425. }
  426. await mark("guard-recorded");
  427. await browser.waitUntil(
  428. async () => (await readRemoteCurrentShaOrNull(prepared.config)) === repack.newSha,
  429. {
  430. timeout: 600_000,
  431. interval: 2000,
  432. timeoutMsg: `${CASE_MARKER}: 确认更新后 current.json 没有切换到新 SHA`,
  433. },
  434. );
  435. expect(updateActionConfirmed).toBe(true);
  436. facts.updatePath =
  437. updateScenario === "force" ? "confirmed-force-update" : "cancel-retry-auto-update";
  438. await mark("sha-switched");
  439. let core1: {
  440. pid: number;
  441. supervisorPid: number;
  442. state: string;
  443. generation: number;
  444. startTicks: number;
  445. } = core0;
  446. await browser.waitUntil(
  447. async () => {
  448. try {
  449. core1 = await readRemoteCoreIdentityViaDocker();
  450. } catch {
  451. return false;
  452. }
  453. return core1.state === "ready" && core1.pid !== core0.pid;
  454. },
  455. {
  456. timeout: 180_000,
  457. interval: 2000,
  458. timeoutMsg: `${CASE_MARKER}: 新 release 的 Core 没有 ready`,
  459. },
  460. );
  461. const reconnected = await waitForRemoteTab({
  462. caseMarker: CASE_MARKER,
  463. expectedIdentity: taskA.identity,
  464. expectedPath: workspaceA,
  465. requireActive: false,
  466. timeoutMs: 180_000,
  467. });
  468. expect(reconnected.remoteSessionId).not.toBe(taskA.remoteSessionId);
  469. const releaseDirs = await readRemoteRuntimeReleaseDirs(prepared.config);
  470. const remoteMarker = await dockerSh(
  471. 'ls "$HOME"/.zcode/server/releases/*/runtime/E2E_R3_UPGRADE_MARKER.txt 2>/dev/null | wc -l; grep -o \'"releaseId": *"[^"]*"\' "$HOME/.zcode/server/current.json"; ls "$HOME/.zcode/server/releases"',
  472. );
  473. facts.after = {
  474. sha: repack.newSha,
  475. core: core1,
  476. runtimeReleases: releaseDirs,
  477. marker: remoteMarker.stdout.trim(),
  478. };
  479. expect(remoteMarker.stdout).toContain(repack.newSha.slice(0, 12));
  480. const distinctReleases = releaseDirs
  481. .map((line) => line.trim().split(/\s+/u)[1])
  482. .filter(
  483. (value): value is string =>
  484. typeof value === "string" && value.length > 0 && !value.endsWith("*)"),
  485. );
  486. expect(new Set(distinctReleases).size).toBe(1);
  487. expect(distinctReleases[0]).toContain(repack.newSha.slice(0, 12));
  488. expect(await readHostProcesses()).toEqual(prepared.initialHosts);
  489. const resumed: SSHLifecycleTask = { ...taskA, remoteSessionId: reconnected.remoteSessionId! };
  490. await readTaskRowInProject(resumed, CASE_MARKER);
  491. await sendSSHFollowTurn(resumed, CASE_MARKER);
  492. });
  493. });