mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 15:26:25 +00:00
* feat(process): add a non-executing dry run to capture_process_scenario Preparation prompts asked an agent to prepare a scenario without running it but could only suggest the tool that launches the target. Add dry_run: true so the CLI and MCP resolve the executable, working directory, observation paths and admission checks, then return planned Evidence under the rea.process-scenario-plan predicate. Planned Evidence is not capture Evidence and comparison tools refuse it as a capture. The preparation prompt now suggests the dry-run call, and the scenario identity commitments exclude the operation-only field. Fixes #8398 * fix(process): redact planned sensitive input and share admission Address review findings on the dry-run contract: - Redact sensitive input events in planned Evidence and preserve only their byte length. - Recheck cancellation after the last awaited admission step. - Run the sensitive-matcher and filesystem-root admission checks that a capture performs before launch. - Assert the prompt advertises the dry_run field without freezing explanatory wording. * test(process): hold the final admission step for cancellation Add a preparation host seam so the regression can cancel while the last filesystem admission call is pending, then assert the returned AnalysisCancelledError retains the caller's reason. * refactor(process): remove the unused plan alias Keep the plan schema as the single exported contract and satisfy the unused-export check. * fix(process): report admission-time aborts as planning cancellation `prepareProcessScenarioPlan` returned the admission error verbatim, so an abort that landed while `admitFilesystemObservationRoots` awaited its `lstat` surfaced as a cancelled `ProcessCaptureError` with `operation: process_capture` even though no process ran. Convert that result through the same `cancelled()` projection the neighbouring checks use, and pin it with a test. * fix(contracts): keep the process result invariants on the dry-run union The output schema for `capture_process_scenario` became a union of the capture and plan shapes, and the union no longer carried the description that advertised the cross-field invariants to MCP clients — the boundary test reads `normalized_result.description`. Attach a description to the union that names both variants and keeps the capture invariants verbatim. * test(process): exercise the post-admission cancellation check The previous regression aborted immediately after starting preparation and released the held admission afterwards. Preparation awaits runtime path resolution first, so that abort was always observed by the pre-admission check; deleting the post-admission "if (aborted()) return cancelled();" still left the test green. Signal from the admitRoots seam when admission is actually entered, abort only after that point, then let admission resolve ok. Preparation now has to reach the check between a successful admission and the ok result, and the assertion pins both the AnalysisCancelledError tag and the caller's reason as its cause. Verified red-green: removing only the post-admission check fails this test (expected true to be false at prepared.ok) while the other two pass, and restoring it passes all three. * test(process): gate the admission seam on acknowledgement Race the admission acknowledgement against planning's own settlement and a bounded deadline, and release and join planning in `finally`, so a planning result that arrives before admission fails the test instead of stalling it until the suite timeout. * fix(contracts): hold plans to the scenario refinements and redact inputs `processScenarioPlanSchema` described the resolved dry-run response but dropped every cross-field check the input contract applies, so a plan could advertise out-of-order events, an event past `timeout_ms`, or a terminal beyond the renderer cell budget while claiming it had been validated. Extract those checks into `scenarioRefinements` and refine the plan's scenario with them. The plan's input event also carried `sensitive` and an optional `input_bytes`, which accepted a sensitive event that still shipped its data. Model the public and sensitive forms as separate exact variants: public input forbids `input_bytes`, sensitive input requires an empty `data` plus its byte length. --------- Co-authored-by: 2SinceJuly <202121119+2SinceJuly@users.noreply.github.com>
175 lines
5.9 KiB
TypeScript
175 lines
5.9 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import {
|
|
createProcessCaptureEvidence,
|
|
createProcessScenarioPlanEvidence,
|
|
} from "../../../src/application/process/ProcessEvidence.js";
|
|
import {
|
|
createRunManifest,
|
|
observeLaunchedExecutable,
|
|
observeSelectedExecutable,
|
|
} from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
|
import {
|
|
accountFullyObservedProcessCapture,
|
|
emptyUnverifiedProcessCapture,
|
|
} from "../../../src/domain/process/processCapture.fixture.js";
|
|
import { compareProcessCaptures } from "../../../src/domain/process/processComparison.js";
|
|
import { parseProcessCapture } from "../../../src/domain/process/processCaptureParsing.js";
|
|
import {
|
|
digestProcessCommitment,
|
|
processScenarioPlanSchema,
|
|
processScenarioSchema,
|
|
processComparisonContract,
|
|
processScenarioCommitment,
|
|
} from "../../../src/domain/process/processScenario.js";
|
|
|
|
const captureEvidenceForSensitiveInput = (data: string) => {
|
|
const scenario = processScenarioSchema.parse({
|
|
executable: "/bin/echo",
|
|
working_directory: "/tmp",
|
|
events: [{ type: "input", at_ms: 0, data, sensitive: true }],
|
|
});
|
|
const base = emptyUnverifiedProcessCapture();
|
|
const executableSha256 = "0".repeat(64);
|
|
const scenarioProjection = processScenarioCommitment(
|
|
scenario,
|
|
executableSha256,
|
|
);
|
|
const comparisonContract = processComparisonContract(scenario);
|
|
const capture = parseProcessCapture({
|
|
...base,
|
|
normalization: scenario.normalization,
|
|
residual_unknowns: [
|
|
{
|
|
scope: "interaction",
|
|
reason:
|
|
"Sensitive scripted input values are redacted from process capture Evidence.",
|
|
},
|
|
{
|
|
scope: "environment",
|
|
reason: "Inherited host environment variables are not recorded.",
|
|
},
|
|
],
|
|
manifest: {
|
|
...base.manifest,
|
|
scenario: scenarioProjection,
|
|
comparison_contract: comparisonContract,
|
|
full_scenario_sha256: digestProcessCommitment(scenarioProjection),
|
|
comparison_contract_sha256: digestProcessCommitment(comparisonContract),
|
|
executable_sha256: executableSha256,
|
|
normalization_sha256: digestProcessCommitment(scenario.normalization),
|
|
},
|
|
});
|
|
return createProcessCaptureEvidence(scenario, capture);
|
|
};
|
|
|
|
const captureEvidenceForEnvironmentSecret = async (value: string) => {
|
|
const scenario = processScenarioSchema.parse({
|
|
executable: "/bin/echo",
|
|
working_directory: "/tmp",
|
|
environment: { API_TOKEN: value },
|
|
events: [{ type: "input", at_ms: 0, data: value }],
|
|
});
|
|
const selectedExecutable = await observeSelectedExecutable(
|
|
scenario.executable,
|
|
);
|
|
const executableIdentity = observeLaunchedExecutable(
|
|
scenario.executable,
|
|
selectedExecutable,
|
|
);
|
|
const manifest = await createRunManifest(
|
|
scenario,
|
|
new Date(0),
|
|
new Date(1),
|
|
executableIdentity,
|
|
);
|
|
const base = emptyUnverifiedProcessCapture();
|
|
const scenarioManifest = {
|
|
...manifest,
|
|
normalization_sha256: digestProcessCommitment(scenario.normalization),
|
|
};
|
|
const capture = parseProcessCapture(
|
|
accountFullyObservedProcessCapture({
|
|
...base,
|
|
normalization: scenario.normalization,
|
|
frames: [{ sequence: 0, at_ms: 0, data: "observed-output" }],
|
|
residual_unknowns: [
|
|
{
|
|
scope: "environment",
|
|
reason: "Inherited host environment variables are not recorded.",
|
|
},
|
|
],
|
|
manifest: scenarioManifest,
|
|
}),
|
|
);
|
|
return createProcessCaptureEvidence(scenario, capture);
|
|
};
|
|
|
|
it("does not persist sensitive scripted input in process capture Evidence", () => {
|
|
const secret = "top-secret-input";
|
|
const evidence = captureEvidenceForSensitiveInput(secret);
|
|
const serialized = JSON.stringify(evidence);
|
|
const manifest = evidence.normalized_result;
|
|
|
|
expect(JSON.stringify(manifest)).not.toContain(secret);
|
|
expect(JSON.stringify(evidence.parameters)).not.toContain(secret);
|
|
expect(serialized).not.toContain(secret);
|
|
});
|
|
|
|
it("does not persist sensitive scripted input in planned Evidence", () => {
|
|
const secret = "top-secret-planned-input";
|
|
const scenario = processScenarioSchema.parse({
|
|
executable: "/bin/echo",
|
|
working_directory: "/tmp",
|
|
events: [{ type: "input", at_ms: 0, data: secret, sensitive: true }],
|
|
});
|
|
const evidence = createProcessScenarioPlanEvidence(scenario, "darwin");
|
|
|
|
expect(JSON.stringify(evidence)).not.toContain(secret);
|
|
const plan = processScenarioPlanSchema.parse(evidence.normalized_result);
|
|
expect(plan.scenario.events[0]).toMatchObject({
|
|
type: "input",
|
|
data: "",
|
|
sensitive: true,
|
|
input_bytes: Buffer.byteLength(secret),
|
|
});
|
|
});
|
|
|
|
it("does not treat captures with different redacted inputs as equivalent", () => {
|
|
const left = captureEvidenceForSensitiveInput("secret-left");
|
|
const right = captureEvidenceForSensitiveInput("secret-right");
|
|
|
|
expect(
|
|
compareProcessCaptures(
|
|
parseProcessCapture(left.normalized_result),
|
|
parseProcessCapture(right.normalized_result),
|
|
),
|
|
).toMatchObject({ status: "unknown", interaction: "unknown" });
|
|
});
|
|
|
|
it("preserves selected local environment and input values", async () => {
|
|
const left = await captureEvidenceForEnvironmentSecret("secret-left");
|
|
const right = await captureEvidenceForEnvironmentSecret("secret-right");
|
|
const leftCapture = parseProcessCapture(left.normalized_result);
|
|
const rightCapture = parseProcessCapture(right.normalized_result);
|
|
|
|
expect(leftCapture.manifest.scenario).toMatchObject({
|
|
environment: { API_TOKEN: "secret-left" },
|
|
});
|
|
expect(leftCapture.manifest.scenario).not.toHaveProperty("PATH");
|
|
expect(leftCapture.manifest.comparison_contract_sha256).not.toBe(
|
|
rightCapture.manifest.comparison_contract_sha256,
|
|
);
|
|
|
|
const changedOutput = parseProcessCapture(
|
|
accountFullyObservedProcessCapture({
|
|
...leftCapture,
|
|
frames: [{ sequence: 0, at_ms: 0, data: "different-output" }],
|
|
}),
|
|
);
|
|
expect(compareProcessCaptures(leftCapture, changedOutput)).toMatchObject({
|
|
status: "changed",
|
|
terminal: "changed",
|
|
});
|
|
});
|