test(process): budget integration cleanup scenarios
This commit is contained in:
+138
-124
@@ -37,6 +37,7 @@ const processFixture = fileURLToPath(
|
|||||||
new URL("./fixtures/processFidelity.mjs", import.meta.url),
|
new URL("./fixtures/processFidelity.mjs", import.meta.url),
|
||||||
);
|
);
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
|
const PROCESS_CAPTURE_INTEGRATION_TIMEOUT_MS = 20_000;
|
||||||
|
|
||||||
const emptyCapture = (): ProcessCapture => {
|
const emptyCapture = (): ProcessCapture => {
|
||||||
const normalization = {
|
const normalization = {
|
||||||
@@ -839,95 +840,103 @@ describe("process capture adapter", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders terminal state, records shim invocations, and captures literal checkpoints", async () => {
|
it(
|
||||||
const root = await mkdtemp(join(tmpdir(), "rea-v3-test-"));
|
"renders terminal state, records shim invocations, and captures literal checkpoints",
|
||||||
const script = join(root, "scenario.mjs");
|
async () => {
|
||||||
await writeFile(
|
const root = await mkdtemp(join(tmpdir(), "rea-v3-test-"));
|
||||||
script,
|
const script = join(root, "scenario.mjs");
|
||||||
[
|
await writeFile(
|
||||||
'import { spawnSync } from "node:child_process";',
|
script,
|
||||||
'const result = spawnSync("codex", ["--version"], { encoding: "utf8" });',
|
[
|
||||||
'const node = spawnSync("node", ["--version"], { encoding: "utf8" });',
|
'import { spawnSync } from "node:child_process";',
|
||||||
"process.stdout.write(`probe:${result.stdout}`);",
|
'const result = spawnSync("codex", ["--version"], { encoding: "utf8" });',
|
||||||
"process.stdout.write(`runtime:${node.stdout}`);",
|
'const node = spawnSync("node", ["--version"], { encoding: "utf8" });',
|
||||||
].join("\n"),
|
"process.stdout.write(`probe:${result.stdout}`);",
|
||||||
);
|
"process.stdout.write(`runtime:${node.stdout}`);",
|
||||||
try {
|
].join("\n"),
|
||||||
const capability = await probeProcessCaptureCapability();
|
|
||||||
if (!capability.available) return;
|
|
||||||
const result = await captureProcessScenario(
|
|
||||||
parseProcessScenario({
|
|
||||||
approved: true,
|
|
||||||
executable: process.execPath,
|
|
||||||
arguments: [script],
|
|
||||||
working_directory: root,
|
|
||||||
filesystem_roots: [root],
|
|
||||||
checkpoints: [
|
|
||||||
{
|
|
||||||
name: "probe_seen",
|
|
||||||
trigger: { type: "terminal_literal", value: "probe:codex 1.2.3" },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
command_shims: [
|
|
||||||
{
|
|
||||||
name: "codex",
|
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
arguments: ["--version"],
|
|
||||||
outputs: [
|
|
||||||
{ at_ms: 0, stream: "stdout", data: "codex 1.2.3\n" },
|
|
||||||
],
|
|
||||||
termination: { type: "exit", code: 0 },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "node",
|
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
arguments: ["--version"],
|
|
||||||
outputs: [
|
|
||||||
{ at_ms: 0, stream: "stdout", data: "node 9.8.7\n" },
|
|
||||||
],
|
|
||||||
termination: { type: "exit", code: 0 },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
enabled: true,
|
|
||||||
executableRoots: [dirname(process.execPath)],
|
|
||||||
workingRoots: [root],
|
|
||||||
allowedEnvironment: [],
|
|
||||||
allowExternalNetwork: true,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
expect(result.ok).toBe(true);
|
try {
|
||||||
if (!result.ok) throw result.error;
|
const capability = await probeProcessCaptureCapability();
|
||||||
expect(result.value.schema_version).toBe(4);
|
if (!capability.available) return;
|
||||||
expect(result.value.rendered_frames.at(-1)?.lines.join("\n")).toContain(
|
const result = await captureProcessScenario(
|
||||||
"probe:codex 1.2.3",
|
parseProcessScenario({
|
||||||
);
|
approved: true,
|
||||||
expect(result.value.shim_events).toEqual([
|
executable: process.execPath,
|
||||||
expect.objectContaining({
|
arguments: [script],
|
||||||
command: "codex",
|
working_directory: root,
|
||||||
arguments: ["--version"],
|
filesystem_roots: [root],
|
||||||
outcome: "matched",
|
checkpoints: [
|
||||||
}),
|
{
|
||||||
expect.objectContaining({
|
name: "probe_seen",
|
||||||
command: "node",
|
trigger: {
|
||||||
arguments: ["--version"],
|
type: "terminal_literal",
|
||||||
outcome: "matched",
|
value: "probe:codex 1.2.3",
|
||||||
}),
|
},
|
||||||
]);
|
},
|
||||||
expect(
|
],
|
||||||
result.value.filesystem_checkpoints.map(({ name }) => name),
|
command_shims: [
|
||||||
).toEqual(["before", "probe_seen", "after_settlement"]);
|
{
|
||||||
} finally {
|
name: "codex",
|
||||||
await rm(root, { recursive: true, force: true });
|
routes: [
|
||||||
}
|
{
|
||||||
});
|
arguments: ["--version"],
|
||||||
|
outputs: [
|
||||||
|
{ at_ms: 0, stream: "stdout", data: "codex 1.2.3\n" },
|
||||||
|
],
|
||||||
|
termination: { type: "exit", code: 0 },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "node",
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
arguments: ["--version"],
|
||||||
|
outputs: [
|
||||||
|
{ at_ms: 0, stream: "stdout", data: "node 9.8.7\n" },
|
||||||
|
],
|
||||||
|
termination: { type: "exit", code: 0 },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
timeout_ms: 5_000,
|
||||||
|
idle_timeout_ms: 5_000,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
enabled: true,
|
||||||
|
executableRoots: [dirname(process.execPath)],
|
||||||
|
workingRoots: [root],
|
||||||
|
allowedEnvironment: [],
|
||||||
|
allowExternalNetwork: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!result.ok) throw result.error;
|
||||||
|
expect(result.value.schema_version).toBe(4);
|
||||||
|
expect(result.value.rendered_frames.at(-1)?.lines.join("\n")).toContain(
|
||||||
|
"probe:codex 1.2.3",
|
||||||
|
);
|
||||||
|
expect(result.value.shim_events).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
command: "codex",
|
||||||
|
arguments: ["--version"],
|
||||||
|
outcome: "matched",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
command: "node",
|
||||||
|
arguments: ["--version"],
|
||||||
|
outcome: "matched",
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
expect(
|
||||||
|
result.value.filesystem_checkpoints.map(({ name }) => name),
|
||||||
|
).toEqual(["before", "probe_seen", "after_settlement"]);
|
||||||
|
} finally {
|
||||||
|
await rm(root, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PROCESS_CAPTURE_INTEGRATION_TIMEOUT_MS,
|
||||||
|
);
|
||||||
|
|
||||||
it("does not follow or disclose symlink targets outside declared roots", async () => {
|
it("does not follow or disclose symlink targets outside declared roots", async () => {
|
||||||
const root = await mkdtemp(join(tmpdir(), "rea-symlink-test-"));
|
const root = await mkdtemp(join(tmpdir(), "rea-symlink-test-"));
|
||||||
@@ -1108,40 +1117,45 @@ describe("process capture adapter", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("samples and cleans a source-owned child and grandchild process tree", async () => {
|
it(
|
||||||
const capability = await probeProcessCaptureCapability();
|
"samples and cleans a source-owned child and grandchild process tree",
|
||||||
if (!capability.available) return;
|
async () => {
|
||||||
const result = await captureProcessScenario(
|
const capability = await probeProcessCaptureCapability();
|
||||||
parseProcessScenario({
|
if (!capability.available) return;
|
||||||
approved: true,
|
const result = await captureProcessScenario(
|
||||||
executable: process.execPath,
|
parseProcessScenario({
|
||||||
arguments: [processFixture, "tree"],
|
approved: true,
|
||||||
working_directory: dirname(processFixture),
|
executable: process.execPath,
|
||||||
timeout_ms: 2_000,
|
arguments: [processFixture, "tree"],
|
||||||
idle_timeout_ms: 2_000,
|
working_directory: dirname(processFixture),
|
||||||
}),
|
timeout_ms: 2_000,
|
||||||
{
|
idle_timeout_ms: 2_000,
|
||||||
enabled: true,
|
}),
|
||||||
executableRoots: [dirname(process.execPath)],
|
{
|
||||||
workingRoots: [dirname(processFixture)],
|
enabled: true,
|
||||||
allowedEnvironment: [],
|
executableRoots: [dirname(process.execPath)],
|
||||||
allowExternalNetwork: true,
|
workingRoots: [dirname(processFixture)],
|
||||||
},
|
allowedEnvironment: [],
|
||||||
);
|
allowExternalNetwork: true,
|
||||||
expect(result.ok).toBe(true);
|
},
|
||||||
if (!result.ok) throw result.error;
|
);
|
||||||
const commands = result.value.process_samples.map(({ command }) => command);
|
if (!result.ok) throw result.error;
|
||||||
expect(commands.some((command) => command.includes("tree-child"))).toBe(
|
const commands = result.value.process_samples.map(
|
||||||
true,
|
({ command }) => command,
|
||||||
);
|
);
|
||||||
expect(
|
expect(commands.some((command) => command.includes("tree-child"))).toBe(
|
||||||
commands.some((command) => command.includes("tree-grandchild")),
|
true,
|
||||||
).toBe(true);
|
);
|
||||||
expect(JSON.stringify(result.value.process_samples)).not.toContain(
|
expect(
|
||||||
dirname(processFixture),
|
commands.some((command) => command.includes("tree-grandchild")),
|
||||||
);
|
).toBe(true);
|
||||||
const { stdout } = await execFileAsync("ps", ["-axo", "command="]);
|
expect(JSON.stringify(result.value.process_samples)).not.toContain(
|
||||||
expect(stdout).not.toContain(`${processFixture} tree-child`);
|
dirname(processFixture),
|
||||||
expect(stdout).not.toContain(`${processFixture} tree-grandchild`);
|
);
|
||||||
});
|
const { stdout } = await execFileAsync("ps", ["-axo", "command="]);
|
||||||
|
expect(stdout).not.toContain(`${processFixture} tree-child`);
|
||||||
|
expect(stdout).not.toContain(`${processFixture} tree-grandchild`);
|
||||||
|
},
|
||||||
|
PROCESS_CAPTURE_INTEGRATION_TIMEOUT_MS,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user