From 09d7b9bab53ae968502fd6e19df694cca8cab817 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 9 Oct 2026 04:06:02 +0800 Subject: [PATCH] test(process): cover argv rewrites in native ownership inspection --- docs/process-capture.md | 8 ++++ .../darwinProcessRunTokenReader.test.ts | 47 ++++++++++++++----- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/docs/process-capture.md b/docs/process-capture.md index 20195bdc4..2b4438139 100644 --- a/docs/process-capture.md +++ b/docs/process-capture.md @@ -108,6 +108,14 @@ and process residual unknowns. Successful cleanup verifies the owned group; it does not attribute those unrelated processes. Related or otherwise unexplained unreadable processes still prevent successful cleanup. +On macOS, changing a Node process's `process.title` can make its run token +unreadable. Node documents that [setting the title overwrites argv memory](https://nodejs.org/download/release/v24.18.0/docs/api/process.html#processtitle). +With the pinned toolchain, a live child retained a readable start identity +while its token became unavailable after this change; npm changes its title +as well. A newly started unreadable process can prevent verified cleanup even +after the selected command exits. REA preserves this uncertainty and leaves +that process untouched. + ## Compare two captures Compare saved capture Evidence with: diff --git a/tests/boundary/process/darwinProcessRunTokenReader.test.ts b/tests/boundary/process/darwinProcessRunTokenReader.test.ts index 0c41c0ffd..81fbf9997 100644 --- a/tests/boundary/process/darwinProcessRunTokenReader.test.ts +++ b/tests/boundary/process/darwinProcessRunTokenReader.test.ts @@ -614,18 +614,36 @@ it.skipIf(!onDarwin)( ); it.skipIf(!onDarwin)( - "reads only the exact ownership key from live process environments", + "reads exact ownership keys and preserves unknowns after process title changes", async () => { const host = createSystemProcessOwnershipHost("darwin"); - const decoy = await startNodeChild({ - DECOY: "words REA_PROCESS_RUN_ID=synthetic-decoy", - }); - const owned = await startNodeChild({ - REA_PROCESS_RUN_ID: "synthetic-owned", - }); + const children: Awaited>[] = []; try { + const decoy = await startNodeChild({ + DECOY: "words REA_PROCESS_RUN_ID=synthetic-decoy", + }); + children.push(decoy); + const owned = await startNodeChild({ + REA_PROCESS_RUN_ID: "synthetic-owned", + }); + children.push(owned); + const titleMutated = await startNodeChild( + { REA_PROCESS_RUN_ID: "synthetic-title-mutated" }, + process.execPath, + ["-e", 'process.title = "npm run check"; setInterval(() => {}, 1_000)'], + ); + children.push(titleMutated); + await expect + .poll(async () => { + const process = (await host.listProcesses()).find( + ({ pid }) => pid === titleMutated.pid, + ); + return process?.command ?? ""; + }) + .toMatch(/^npm run check/u); + const processes = await host.listProcesses(); - const entries = [decoy, owned].map(({ pid }) => { + const entries = [decoy, owned, titleMutated].map(({ pid }) => { const entry = processes.find((process) => process.pid === pid); if (entry === undefined) throw new Error("test child is absent from process table"); @@ -641,12 +659,19 @@ it.skipIf(!onDarwin)( state: "readable", runId: "synthetic-owned", }); + expect(observations?.get(titleMutated.pid)).toMatchObject({ + state: "unavailable", + reason: expect.stringMatching(/\S/u), + }); expect(identities?.get(decoy.pid)?.state).toBe("readable"); expect(identities?.get(owned.pid)?.state).toBe("readable"); + expect(identities?.get(titleMutated.pid)?.state).toBe("readable"); } finally { - await stopNodeChild(decoy.child); - await stopNodeChild(owned.child); - await host.close?.(); + try { + await Promise.all(children.map(({ child }) => stopNodeChild(child))); + } finally { + await host.close?.(); + } } }, );