mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
a68cfd7db0
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.
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import type { ProcessOwnershipHost } from "./ProcessOwnership.js";
|
|
import { readProcessRunId } from "./ProcessOwnership.js";
|
|
|
|
it.each([undefined, "selected-token", ""])(
|
|
"reads only the process environment's own run token %j",
|
|
async (selected) => {
|
|
const environment: Record<string, string> = Object.create({
|
|
REA_PROCESS_RUN_ID: "inherited-token",
|
|
});
|
|
if (selected !== undefined) environment.REA_PROCESS_RUN_ID = selected;
|
|
const host: ProcessOwnershipHost = {
|
|
listProcesses: async () => [],
|
|
environment: async () => environment,
|
|
signalGroup: () => undefined,
|
|
};
|
|
expect(await readProcessRunId(42, host)).toBe(selected);
|
|
},
|
|
);
|
|
|
|
it("passes cancellation through run-token reads", async () => {
|
|
const controller = new AbortController();
|
|
const cancellation = new Error("cancelled");
|
|
const host: ProcessOwnershipHost = {
|
|
listProcesses: async () => [],
|
|
environment: async (_pid, signal) => {
|
|
if (signal === undefined) throw new Error("run-token signal was omitted");
|
|
return await new Promise<Readonly<Record<string, string>>>(
|
|
(_resolve, reject) => {
|
|
signal.addEventListener("abort", () => reject(signal.reason), {
|
|
once: true,
|
|
});
|
|
},
|
|
);
|
|
},
|
|
signalGroup: () => undefined,
|
|
};
|
|
|
|
const reading = readProcessRunId(42, host, controller.signal);
|
|
controller.abort(cancellation);
|
|
|
|
await expect(reading).rejects.toBe(cancellation);
|
|
});
|