e2eProcessCleanup.test.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it, vi } from "vitest";
  3. import {
  4. buildE2ERunIdArg,
  5. buildWindowsTaskkillArgs,
  6. collectProcessTreeByRootPids,
  7. collectE2EProcessTreePids,
  8. collectWindowsE2EProcessTreePids,
  9. createWindowsE2EHomeMarkerArg,
  10. listE2EProcessTreePids,
  11. listSystemProcesses,
  12. } from "./e2e/helpers/e2e-process-cleanup.js";
  13. const CURRENT_HOME = "C:\\e2e\\shards\\current";
  14. const CURRENT_HOME_MARKER = createWindowsE2EHomeMarkerArg(CURRENT_HOME);
  15. function toProcessJson(rows: Array<{ command: unknown; parentPid: unknown; pid: unknown }>) {
  16. return JSON.stringify(
  17. rows.map((row) => ({
  18. CommandLine: row.command,
  19. ParentProcessId: row.parentPid,
  20. ProcessId: row.pid,
  21. })),
  22. );
  23. }
  24. describe("desktop e2e process cleanup", () => {
  25. it("combines one worker process tree into a single taskkill invocation", () => {
  26. expect(buildWindowsTaskkillArgs([12, 11, 12, 10])).toEqual([
  27. "/PID",
  28. "12",
  29. "/PID",
  30. "11",
  31. "/PID",
  32. "10",
  33. "/T",
  34. "/F",
  35. ]);
  36. });
  37. it("passes both run and HOME identity markers through Electron appArgs", () => {
  38. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  39. expect(CURRENT_HOME_MARKER).toBe(`--zcode-e2e-home=${CURRENT_HOME}`);
  40. expect(wdioSource).toMatch(
  41. /appArgs:\s*\[[\s\S]*?buildE2ERunIdArg\(E2E_RUN_ID\)[\s\S]*?createWindowsE2EHomeMarkerArg\(E2E_HOME_DIR\)[\s\S]*?\]/u,
  42. );
  43. });
  44. it("stages and launches an immutable app output under the current run cache", () => {
  45. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  46. // Bugfix: dev watcher 会清空共享 out;Electron 必须从 runId 隔离副本启动。
  47. expect(wdioSource).toMatch(/const E2E_APP_OUTPUT_DIR = resolve\(E2E_RUN_CACHE_DIR, "app"\)/u);
  48. expect(wdioSource).toMatch(
  49. /await stageE2EAppOutput\(DESKTOP_BUILD_OUTPUT_DIR, E2E_APP_OUTPUT_DIR\)/u,
  50. );
  51. expect(wdioSource).toMatch(/`--app=\$\{E2E_APP_ENTRY_POINT\}`/u);
  52. expect(wdioSource).not.toMatch(/`--app=\$\{DESKTOP_BUILD_ENTRY_POINT\}`/u);
  53. });
  54. it("lets ChromeDriver close the renderer before Electron app.quit", () => {
  55. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  56. const mainSource = readFileSync(new URL("../src/main/index.ts", import.meta.url), "utf8");
  57. expect(wdioSource).toMatch(/appWindow\.once\("closed", requestQuitAfterDriverClose\)/u);
  58. expect(wdioSource).toMatch(/async after[\s\S]*?await armCurrentElectronAppQuit\("after"\)/u);
  59. expect(wdioSource).not.toMatch(/async after[\s\S]*?await quitCurrentElectronApp\("after"\)/u);
  60. expect(mainSource).toMatch(/win\.once\("closed", exitAfterLastWindowClosed\)/u);
  61. expect(mainSource).toMatch(
  62. /const exitAfterLastWindowClosed[\s\S]*?exitPreparedApp\("all-windows-closed-after-preparation"\)/u,
  63. );
  64. expect(mainSource).toMatch(
  65. /process\.env\.ZCODE_E2E_RUN_ID\?\.trim\(\)[\s\S]*?spawn\("taskkill"[\s\S]*?spawn\("kill", \["-9", String\(process\.pid\)\]/u,
  66. );
  67. });
  68. it("waits for each window Host once and keeps update install on the strict policy", () => {
  69. const mainSource = readFileSync(new URL("../src/main/index.ts", import.meta.url), "utf8");
  70. // R1 后 remote session 是窗口 Host 内资源;manager 只清理请求关联,真正的连接释放由
  71. // windowHostProcessMap 中唯一 Host 的 shutdown barrier 完成。
  72. expect(mainSource).toMatch(
  73. /async function prepareAppQuit[\s\S]*?remoteSessionManager\.disposeAllAndWaitForAppShutdown\(reason\)/u,
  74. );
  75. expect(mainSource).toMatch(
  76. /async function prepareAppQuit[\s\S]*?stopRemoteUsageArmsPeriodicSampling\(\)[\s\S]*?remoteSessionManager\.disposeAllAndWaitForAppShutdown\(reason\)/u,
  77. );
  78. expect(mainSource).toMatch(
  79. /async function prepareAppQuit[\s\S]*?stopDesktopResourceTelemetry\(\{ flushPendingWindows: true \}\)/u,
  80. );
  81. // 修复原因:更新安装现在复用唯一的 prepareAppQuit 屏障并显式选择严格预算;旧断言要求
  82. // Windows 专项资源扫描再次等待 Remote Host,已经与“只执行一次 Host 屏障”的事实冲突。
  83. expect(mainSource).toMatch(
  84. /prepareAppQuit\("auto-update quitAndInstall", "update-install"\)[\s\S]*?prepareWindowsProcessesForUpdateInstall\(\)/u,
  85. );
  86. expect(mainSource).toMatch(
  87. /async function prepareAppQuit[\s\S]*?selectAppShutdownPolicy[\s\S]*?if \(hasPreparedAppQuit\)[\s\S]*?if \(appQuitPreparationInFlight\)/u,
  88. );
  89. expect(mainSource).toMatch(
  90. /createRemoteWorkspaceSessionManager\(\{[\s\S]*?windowHostProcessMap[\s\S]*?const hostProcesses = \[[\s\S]*?windowHostProcessMap\.values\(\)[\s\S]*?disposeHostProcessAndWait\([\s\S]*?activeAppShutdownPolicy\.forceKillDelayMs[\s\S]*?activeAppShutdownPolicy\.waitTimeoutMs/u,
  91. );
  92. expect(mainSource).not.toMatch(/resolveRemoteHostShutdownPolicy/u);
  93. expect(mainSource).toMatch(
  94. /const cronSchedulerToDispose = cronScheduler[\s\S]*?appQuitPreparationInFlight = Promise\.all\(\[[\s\S]*?cronSchedulerToDispose\?\.dispose\(\)[\s\S]*?remoteSessionManager\.disposeAllAndWaitForAppShutdown/u,
  95. );
  96. // Bug 原因:退出屏障结束后窗口 close 还会启动异步设置写入,app.exit 可能留下锁。
  97. // 窗口尺寸只在 resize/maximize/unmaximize 阶段保存,退出屏障不得新建该写入。
  98. expect(mainSource).not.toMatch(
  99. /appQuitPreparationInFlight = Promise\.all\(\[[\s\S]*?desktopWindowSizePersistence\?\.flush\(\)/u,
  100. );
  101. // /event/report 的内存内投递必须与 Host/Cron 清理并行进入同一个退出屏障,且等待有界。
  102. expect(mainSource).toMatch(
  103. /appQuitPreparationInFlight = Promise\.all\(\[[\s\S]*?appTelemetryCore\.flushPendingReports\(\{ timeoutMs: 2_000 \}\)/u,
  104. );
  105. // Bug 根因:Browser tab 已改为进程内 stateless residency,完整退出不再恢复 tab。
  106. // 退出屏障只等待真实的 Host/Cron owner;继续要求 recovery idle 会让测试绑定已删除的恢复链路。
  107. expect(mainSource).not.toMatch(/browserGuestManager\.whenRecoveryIdle\(\)/u);
  108. expect(mainSource).toMatch(
  109. /async function prepareAppQuit[\s\S]*?browserScreenshotSurfaceCoordinator\.dispose\(\)/u,
  110. );
  111. });
  112. it("forces the Host to exit after its parent IPC disconnects", () => {
  113. const hostSource = readFileSync(new URL("../src/host/index.ts", import.meta.url), "utf8");
  114. expect(hostSource).toMatch(
  115. /process\.once\("disconnect"[\s\S]*?disposeHostResources\("disconnect"\)\.finally\(\(\) => process\.exit\(1\)\)/u,
  116. );
  117. });
  118. it("Host waits for the remote stdio close handshake", () => {
  119. const hostSource = readFileSync(new URL("../src/host/index.ts", import.meta.url), "utf8");
  120. expect(hostSource).toMatch(
  121. /async function disposeHostRemoteConnection[\s\S]*?connection\.dispose\(\)[\s\S]*?name: "remote-registry-dispose"[\s\S]*?timeoutMs: 6_000/u,
  122. );
  123. expect(hostSource).toContain('name: "source-server-manager-dispose"');
  124. });
  125. it("collects only the current run root and its child process tree", () => {
  126. const sharedEntryPoint = "/repo/packages/desktop/out/main/index.js";
  127. const processes = [
  128. {
  129. command: `Electron --app=${sharedEntryPoint} --no-sandbox ${buildE2ERunIdArg("run-a")}`,
  130. pid: 10,
  131. ppid: 1,
  132. },
  133. { command: "node host-process", pid: 11, ppid: 10 },
  134. { command: "node zcode-agent", pid: 12, ppid: 11 },
  135. {
  136. command: `Electron --app=${sharedEntryPoint} --no-sandbox ${buildE2ERunIdArg("run-b")}`,
  137. pid: 20,
  138. ppid: 1,
  139. },
  140. { command: "node other-host-process", pid: 21, ppid: 20 },
  141. ];
  142. expect(
  143. collectE2EProcessTreePids(processes, {
  144. currentPid: 999,
  145. homeDir: "/tmp/zcode-e2e-run-a",
  146. runId: "run-a",
  147. }),
  148. ).toEqual([12, 11, 10]);
  149. });
  150. it("collects an explicitly anchored Electron main tree without command markers", () => {
  151. const processes = [
  152. { command: "Electron", pid: 10, ppid: 1 },
  153. { command: "Electron Helper (Renderer)", pid: 11, ppid: 10 },
  154. { command: "node host-process", pid: 12, ppid: 10 },
  155. { command: "node zcode-agent", pid: 13, ppid: 12 },
  156. ];
  157. expect(
  158. collectE2EProcessTreePids(processes, {
  159. currentPid: 999,
  160. homeDir: "/tmp/zcode-e2e-run-a",
  161. rootPids: [10],
  162. runId: "run-a",
  163. }),
  164. ).toEqual([13, 12, 11, 10]);
  165. });
  166. it("recovers markerless ChromeDriver and Electron ancestors from a marked renderer", () => {
  167. const currentHome = "/tmp/zcode-e2e-run-a";
  168. const processes = [
  169. { command: "node wdio.conf.ts", pid: 9, ppid: 1 },
  170. { command: "chromedriver --port=55089", pid: 10, ppid: 9 },
  171. { command: "ZCode E2E", pid: 11, ppid: 10 },
  172. {
  173. command: `Electron Helper (Renderer) --user-data-dir=/repo/.e2e-cache/run-a/chromium-profiles/0-51 --config=${currentHome}/.zcode/config.json`,
  174. pid: 12,
  175. ppid: 11,
  176. },
  177. { command: "node host-process", pid: 13, ppid: 11 },
  178. {
  179. command: "Electron Helper --user-data-dir=/repo/.e2e-cache/run-b/chromium-profiles/0-4",
  180. pid: 22,
  181. ppid: 21,
  182. },
  183. { command: "ZCode E2E", pid: 21, ppid: 20 },
  184. ];
  185. expect(
  186. collectE2EProcessTreePids(processes, {
  187. currentPid: 9,
  188. homeDir: currentHome,
  189. runId: "run-a",
  190. }),
  191. ).toEqual([13, 12, 11, 10]);
  192. });
  193. it("keeps ChromeDriver out of the per-session reload exit barrier", () => {
  194. const currentHome = "/tmp/zcode-e2e-run-a";
  195. const processes = [
  196. { command: "node wdio.conf.ts", pid: 9, ppid: 1 },
  197. { command: "chromedriver --port=55089", pid: 10, ppid: 9 },
  198. { command: "ZCode E2E", pid: 11, ppid: 10 },
  199. {
  200. command: `Electron Helper (Renderer) --config=${currentHome}/.zcode/config.json`,
  201. pid: 12,
  202. ppid: 11,
  203. },
  204. { command: "node host-process", pid: 13, ppid: 11 },
  205. ];
  206. expect(
  207. collectE2EProcessTreePids(processes, {
  208. currentPid: 9,
  209. homeDir: currentHome,
  210. includeChromeDriverAncestors: false,
  211. runId: "run-a",
  212. }),
  213. ).toEqual([13, 12, 11]);
  214. });
  215. it("recovers the complete renamed Electron tree from only its run-owned Chromium profile", () => {
  216. const chromiumProfileRootDir = "/repo/.e2e-cache/run-a/chromium-profiles";
  217. const processes = [
  218. { command: "node wdio.conf.ts", pid: 9, ppid: 1 },
  219. { command: "chromedriver --port=55089", pid: 10, ppid: 9 },
  220. { command: "ZCode E2E", pid: 11, ppid: 10 },
  221. {
  222. command: `Electron Helper --type=gpu-process --user-data-dir=${chromiumProfileRootDir}/0-2`,
  223. pid: 12,
  224. ppid: 11,
  225. },
  226. { command: "Electron Helper", pid: 13, ppid: 11 },
  227. { command: "node zcode-agent", pid: 14, ppid: 13 },
  228. {
  229. command: "chrome_crashpad_handler --database=/tmp/zcode-e2e-run-a/.zcode/crash",
  230. pid: 15,
  231. ppid: 1,
  232. },
  233. { command: "chromedriver --port=55090", pid: 20, ppid: 9 },
  234. { command: "ZCode E2E", pid: 21, ppid: 20 },
  235. {
  236. command:
  237. "Electron Helper --user-data-dir=/repo/.e2e-cache/run-a-other/chromium-profiles/0-2",
  238. pid: 22,
  239. ppid: 21,
  240. },
  241. {
  242. command: `Electron Helper --user-data-dir=${chromiumProfileRootDir}-other/0-2`,
  243. pid: 30,
  244. ppid: 1,
  245. },
  246. ];
  247. const identity = {
  248. chromiumProfileRootDir,
  249. currentPid: 9,
  250. homeDir: "/tmp/zcode-e2e-run-a",
  251. runId: "run-a",
  252. };
  253. expect(collectE2EProcessTreePids(processes, identity)).toEqual([15, 14, 13, 12, 11, 10]);
  254. expect(
  255. collectE2EProcessTreePids(processes, {
  256. ...identity,
  257. includeChromeDriverAncestors: false,
  258. }),
  259. ).toEqual([15, 14, 13, 12, 11]);
  260. });
  261. it("matches quoted Windows Chromium profile paths without matching neighboring directories", () => {
  262. const processes = [
  263. {
  264. command: 'electron.exe --user-data-dir="C:\\E2E Cache\\run-a\\chromium-profiles\\0-2"',
  265. pid: 10,
  266. ppid: 1,
  267. },
  268. {
  269. command:
  270. 'electron.exe --user-data-dir="C:\\E2E Cache\\run-a\\chromium-profiles-other\\0-2"',
  271. pid: 20,
  272. ppid: 1,
  273. },
  274. ];
  275. expect(
  276. collectE2EProcessTreePids(processes, {
  277. chromiumProfileRootDir: "c:/e2e cache/run-a/chromium-profiles/",
  278. currentPid: 999,
  279. homeDir: "",
  280. }),
  281. ).toEqual([10]);
  282. });
  283. it("uses the entire current run profile root for worker cleanup", () => {
  284. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  285. expect(wdioSource).toMatch(
  286. /listE2EProcessTreePids\(\{\s*chromiumProfileRootDir: E2E_CHROMIUM_USER_DATA_ROOT_DIR,/u,
  287. );
  288. });
  289. it("does not climb from an E2E driver into an unrelated terminal process tree", () => {
  290. const processes = [
  291. { command: "Terminal.app", pid: 5, ppid: 1 },
  292. { command: "zsh", pid: 6, ppid: 5 },
  293. { command: "node old-wdio-worker.js", pid: 7, ppid: 6 },
  294. { command: "chromedriver --port=55089", pid: 10, ppid: 7 },
  295. { command: "ZCode E2E", pid: 11, ppid: 10 },
  296. {
  297. command:
  298. "Electron Helper --user-data-dir=/repo/.e2e-cache/run-a/chromium-profiles/0-51 --config=/tmp/zcode-e2e-run-a/.zcode/config.json",
  299. pid: 12,
  300. ppid: 11,
  301. },
  302. ];
  303. expect(
  304. collectE2EProcessTreePids(processes, {
  305. currentPid: 99,
  306. homeDir: "/tmp/zcode-e2e-run-a",
  307. runId: "run-a",
  308. }),
  309. ).toEqual([12, 11, 10]);
  310. });
  311. it("uses the shared run identity scanner for POSIX process trees", () => {
  312. const runCommand = vi.fn(() =>
  313. [
  314. `10 1 Electron ${buildE2ERunIdArg("run-a")}`,
  315. "11 10 node host-process",
  316. "12 11 node zcode-agent",
  317. ].join("\n"),
  318. );
  319. expect(
  320. listE2EProcessTreePids(
  321. { currentPid: 999, homeDir: "/tmp/zcode-e2e-run-a", runId: "run-a" },
  322. { platform: "linux", runCommand },
  323. ),
  324. ).toEqual([12, 11, 10]);
  325. expect(runCommand).toHaveBeenCalledWith("ps", ["-axo", "pid=,ppid=,command="]);
  326. });
  327. it("lists and scopes a read-only system process snapshot by explicit roots", async () => {
  328. const runCommand = vi.fn(async () =>
  329. [
  330. "10 1 ZCode E2E",
  331. "11 10 zcode-host-local-1",
  332. "12 11 zcode-cli",
  333. "13 12 zcode-browser-use-mcp",
  334. "20 1 unrelated",
  335. ].join("\n"),
  336. );
  337. const processes = await listSystemProcesses({
  338. platform: "linux",
  339. runCommand,
  340. });
  341. expect(collectProcessTreeByRootPids(processes, [10])).toEqual([
  342. { command: "ZCode E2E", pid: 10, ppid: 1 },
  343. { command: "zcode-host-local-1", pid: 11, ppid: 10 },
  344. { command: "zcode-cli", pid: 12, ppid: 11 },
  345. { command: "zcode-browser-use-mcp", pid: 13, ppid: 12 },
  346. ]);
  347. });
  348. it("uses the shared PowerShell fallback for Windows process trees", () => {
  349. const runCommand = vi
  350. .fn<(command: string, args: string[]) => string>()
  351. .mockImplementationOnce(() => {
  352. throw new Error("Windows PowerShell unavailable");
  353. })
  354. .mockReturnValueOnce(
  355. toProcessJson([
  356. {
  357. command: `electron.exe ${CURRENT_HOME_MARKER}`,
  358. parentPid: 1,
  359. pid: 101,
  360. },
  361. { command: "node.exe host-process", parentPid: 101, pid: 102 },
  362. ]),
  363. );
  364. expect(
  365. listE2EProcessTreePids(
  366. { currentPid: 999, homeDir: CURRENT_HOME },
  367. { platform: "win32", runCommand },
  368. ),
  369. ).toEqual([102, 101]);
  370. expect(runCommand.mock.calls.map(([command]) => command)).toEqual(["powershell.exe", "pwsh"]);
  371. });
  372. it("does not treat shared app title or build paths as cleanup identity", () => {
  373. const sharedEntryPoint = "/repo/packages/desktop/out/main/index.js";
  374. const sharedMainDir = "/repo/packages/desktop/out/main";
  375. const processes = [
  376. {
  377. command: `Electron "ZCode E2E" --app=${sharedEntryPoint} --inspect=${sharedMainDir}`,
  378. pid: 10,
  379. ppid: 1,
  380. },
  381. { command: "node host-process", pid: 11, ppid: 10 },
  382. ];
  383. expect(
  384. collectE2EProcessTreePids(processes, {
  385. currentPid: 999,
  386. homeDir: "/tmp/zcode-e2e-run-a",
  387. runId: "run-a",
  388. }),
  389. ).toEqual([]);
  390. });
  391. it("matches the current HOME with Windows and slash-normalized paths", () => {
  392. const output = toProcessJson([
  393. {
  394. command: `electron.exe ${CURRENT_HOME_MARKER}`,
  395. parentPid: 1,
  396. pid: 101,
  397. },
  398. {
  399. command: "node.exe --config=C:/e2e/shards/current/.zcode/cli/config.json",
  400. parentPid: 101,
  401. pid: 102,
  402. },
  403. ]);
  404. expect(
  405. collectWindowsE2EProcessTreePids(output, {
  406. currentPid: 999,
  407. homeDir: CURRENT_HOME,
  408. }),
  409. ).toEqual([102, 101]);
  410. });
  411. it("does not select another shard with the same app entry point or a HOME prefix", () => {
  412. const sharedApp = "C:\\repo\\packages\\desktop\\out\\main\\index.js";
  413. const output = toProcessJson([
  414. {
  415. command: `electron.exe --app=${sharedApp} --name="ZCode E2E" ${CURRENT_HOME_MARKER}`,
  416. parentPid: 1,
  417. pid: 201,
  418. },
  419. {
  420. command: `electron.exe --app=${sharedApp} --name="ZCode E2E" ${createWindowsE2EHomeMarkerArg("C:\\e2e\\shards\\other")}`,
  421. parentPid: 1,
  422. pid: 202,
  423. },
  424. {
  425. command: `electron.exe --app=${sharedApp} --name="ZCode E2E" ${createWindowsE2EHomeMarkerArg(`${CURRENT_HOME}-copy`)}`,
  426. parentPid: 1,
  427. pid: 203,
  428. },
  429. ]);
  430. expect(
  431. collectWindowsE2EProcessTreePids(output, {
  432. currentPid: 999,
  433. homeDir: CURRENT_HOME,
  434. }),
  435. ).toEqual([201]);
  436. });
  437. it("excludes the current process, its ancestors, and WDIO controllers", () => {
  438. const processes = [
  439. { command: `node parent ${CURRENT_HOME_MARKER}`, pid: 400, ppid: 1 },
  440. { command: `node runner ${CURRENT_HOME_MARKER}`, pid: 401, ppid: 400 },
  441. { command: `node @wdio/cli ${CURRENT_HOME_MARKER}`, pid: 402, ppid: 1 },
  442. {
  443. command: `node wdio.conf.ts ${CURRENT_HOME_MARKER}`,
  444. pid: 403,
  445. ppid: 1,
  446. },
  447. { command: "node controller-child", pid: 404, ppid: 402 },
  448. ];
  449. expect(
  450. collectE2EProcessTreePids(processes, {
  451. currentPid: 401,
  452. homeDir: CURRENT_HOME,
  453. }),
  454. ).toEqual([]);
  455. });
  456. it("matches run id arguments with command boundaries", () => {
  457. const processes = [
  458. {
  459. command: `Electron ${buildE2ERunIdArg("run-1-extra")}`,
  460. pid: 10,
  461. ppid: 1,
  462. },
  463. { command: `Electron ${buildE2ERunIdArg("run-1")}`, pid: 20, ppid: 1 },
  464. ];
  465. expect(
  466. collectE2EProcessTreePids(processes, {
  467. currentPid: 999,
  468. homeDir: "/tmp/zcode-e2e-run-1",
  469. runId: "run-1",
  470. }),
  471. ).toEqual([20]);
  472. });
  473. it.each(["", "not-json", "null", "{}"])(
  474. "treats malformed or empty Windows process JSON as no matches: %j",
  475. (output) => {
  476. expect(
  477. collectWindowsE2EProcessTreePids(output, {
  478. currentPid: 999,
  479. homeDir: CURRENT_HOME,
  480. }),
  481. ).toEqual([]);
  482. },
  483. );
  484. });