test(process): cover argv rewrites in native ownership inspection

This commit is contained in:
morluto
2026-10-09 04:12:49 +08:00
parent 9a70fb482c
commit 09d7b9bab5
2 changed files with 44 additions and 11 deletions
+8
View File
@@ -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:
@@ -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<ReturnType<typeof startNodeChild>>[] = [];
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?.();
}
}
},
);