From 954bcd6082035c6a323a8700caa2119a8ea2e71f Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Thu, 19 Nov 2026 03:58:21 +0800 Subject: [PATCH] fix(verify): preserve Linux descendant records with multiline names (#11949) * fix(verify): preserve Linux descendant records with multiline names * fix(verify): load the stat parser without changing stderr --------- Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> --- scripts/lib/verifier-run.mjs | 25 +++++++++++++++++------- tests/process-global/verifierRun.test.ts | 24 +++++++++++++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/scripts/lib/verifier-run.mjs b/scripts/lib/verifier-run.mjs index ddf44cdf5c..99019b12ca 100644 --- a/scripts/lib/verifier-run.mjs +++ b/scripts/lib/verifier-run.mjs @@ -193,7 +193,15 @@ const processSnapshot = async () => { return posixProcessSnapshot(); }; +/** @type {Promise | undefined} */ +let linuxStatParser; + const linuxProcessSnapshot = async () => { + // The pinned Node can strip this leaf module without a transform or loader. + linuxStatParser ??= import( + new URL("../../src/process/LinuxProcessStat.ts", import.meta.url).href + ); + const { parseLinuxProcessStat } = await linuxStatParser; const entries = await readdir("/proc", { withFileTypes: true }); /** @type {ProcessMember[]} */ const members = []; @@ -201,13 +209,16 @@ const linuxProcessSnapshot = async () => { if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue; try { const stat = await readFile(`/proc/${entry.name}/stat`, "utf8"); - const match = /^\d+ \(.*\) (\S) (\d+) (\d+) /u.exec(stat); - if (match === null || match[1] === "Z") continue; - members.push({ - pid: Number(entry.name), - parentPid: Number(match[2]), - processGroupId: Number(match[3]), - }); + const parsed = parseLinuxProcessStat(stat); + if ( + parsed === undefined || + parsed.pid !== Number(entry.name) || + parsed.lifecycle === "zombie" || + parsed.lifecycle === "dead" + ) + continue; + const { pid, parentPid, processGroupId } = parsed; + members.push({ pid, parentPid, processGroupId }); } catch { // Processes can exit while /proc is being sampled. } diff --git a/tests/process-global/verifierRun.test.ts b/tests/process-global/verifierRun.test.ts index 10cb80f649..3f8c042454 100644 --- a/tests/process-global/verifierRun.test.ts +++ b/tests/process-global/verifierRun.test.ts @@ -49,13 +49,18 @@ describe("verifier run identity", { concurrent: false }, () => { } }); - it.runIf(process.platform !== "win32")( - "reports token-verified live descendants", - async () => { + it + .runIf(process.platform !== "win32") + .each([ + undefined, + ...(process.platform === "linux" ? ["fixture\nworker"] : []), + ])( + "reports token-verified live descendants with display name %j", + async (displayName) => { const previousRunId = process.env.REA_PROCESS_RUN_ID; delete process.env.REA_PROCESS_RUN_ID; const run = createVerifierRun(); - const child = spawnReadyChild(process.env); + const child = spawnReadyChild(process.env, displayName); try { await childReady(child); const completed = await completeVerifierRun(run); @@ -106,10 +111,17 @@ describe("verifier run identity", { concurrent: false }, () => { ); }); -const spawnReadyChild = (env: NodeJS.ProcessEnv): ChildProcess => +const spawnReadyChild = ( + env: NodeJS.ProcessEnv, + displayName?: string, +): ChildProcess => spawn( process.execPath, - ["-e", "process.stdout.write('ready'); setInterval(() => {}, 1000)"], + [ + "-e", + `if (process.argv[1] !== undefined) process.title = process.argv[1]; process.stdout.write("ready"); setInterval(() => {}, 1000)`, + ...(displayName === undefined ? [] : [displayName]), + ], { env, stdio: ["ignore", "pipe", "ignore"] }, );