Files
rea/tests/boundary/process/processRunTokenEnvironment.test.ts
T
morluto a68cfd7db0 fix(process): require observed environment ownership tokens
Centralize run-token extraction at the environment observation boundary and require an own field. Build decoded OS environment records without host prototypes while retaining source names, empty values and last-assignment precedence.

Reject inherited matching tokens before cleanup signaling, preserve normal owned-group behavior, and verify live Linux process environments alongside native CLI/MCP capture workflows.
2026-10-23 22:13:12 +08:00

44 lines
1.6 KiB
TypeScript

import { once } from "node:events";
import { expect } from "vitest";
import { readProcessRunId } from "../../../src/process/ProcessOwnership.js";
import { createSystemProcessOwnershipHost } from "../../../src/process/ProcessOwnershipObservation.js";
import { readProcessRunTokens } from "../../../src/process/ProcessRunTokenObservations.js";
import { processTest } from "../../support/process/processFixture.js";
processTest.skipIf(process.platform !== "linux").for([
{ name: "absent", runId: undefined },
{ name: "selected", runId: "source-process-token" },
])(
"reads $name run tokens from the live process environment",
async ({ runId }, { processes }) => {
const environment = {
EMPTY: "",
VALUE: "a=b",
["__proto__"]: "source-value",
...(runId === undefined ? {} : { REA_PROCESS_RUN_ID: runId }),
};
const child = processes.spawn(
process.execPath,
["-e", "process.stdin.resume()"],
{ env: environment },
);
await once(child, "spawn");
const host = createSystemProcessOwnershipHost("linux", {});
const row = (await host.listProcesses()).find(
({ pid }) => pid === child.pid,
);
if (row === undefined) throw new Error("Selected child was not observed");
expect(await host.environment(row.pid)).toEqual(environment);
expect(await readProcessRunId(row.pid, host)).toBe(runId);
const observations = [];
for await (const observation of readProcessRunTokens(host, [row]))
observations.push(observation);
expect(observations).toEqual([
{ process: row, observation: { state: "readable", runId } },
]);
child.stdin.end();
},
);