refactor(process): separate capture implementation from analyst workflows (#988)
* refactor(process): separate capture implementation from analyst workflows * fix(ci): generate source catalog before shard tests
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { emptyUnverifiedProcessCapture } from "../../../src/domain/process/processCapture.fixture.js";
|
||||
import { parseProcessCapture } from "../../../src/domain/process/processCapture.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/process/processScenario.js";
|
||||
import { createProcessCaptureEvidence } from "../../../src/application/process/ProcessEvidence.js";
|
||||
import { observeSettlement } from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
||||
|
||||
it("stamps process Evidence from the capture manifest host", () => {
|
||||
const scenario = parseProcessScenario({
|
||||
executable: process.execPath,
|
||||
working_directory: process.cwd(),
|
||||
events: [],
|
||||
});
|
||||
const base = emptyUnverifiedProcessCapture();
|
||||
const capture = parseProcessCapture({
|
||||
...base,
|
||||
manifest: {
|
||||
...base.manifest,
|
||||
platform: "linux",
|
||||
architecture: "arm64",
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
createProcessCaptureEvidence(scenario, capture).environment,
|
||||
).toMatchObject({
|
||||
id: "linux-arm64",
|
||||
platform: "linux",
|
||||
architecture: "arm64",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the selected host platform for process settlement behavior", async () => {
|
||||
const events: string[] = [];
|
||||
const result = await observeSettlement(
|
||||
"run",
|
||||
[],
|
||||
0,
|
||||
(event) => events.push(event),
|
||||
"win32",
|
||||
);
|
||||
|
||||
expect(result).toEqual({ state: "unverifiable", elapsed_ms: 0 });
|
||||
expect(events).toEqual(["lifecycle"]);
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { createProcessCaptureEvidence } from "../../../src/application/process/ProcessEvidence.js";
|
||||
import { createRunManifest } from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
||||
import { emptyUnverifiedProcessCapture } from "../../../src/domain/process/processCapture.fixture.js";
|
||||
import {
|
||||
compareProcessCaptures,
|
||||
parseProcessCapture,
|
||||
} from "../../../src/domain/process/processCapture.js";
|
||||
import {
|
||||
digestProcessCommitment,
|
||||
parseProcessScenario,
|
||||
processComparisonContract,
|
||||
processScenarioCommitment,
|
||||
} from "../../../src/domain/process/processScenario.js";
|
||||
|
||||
const captureEvidenceForSensitiveInput = (data: string) => {
|
||||
const scenario = parseProcessScenario({
|
||||
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 = parseProcessScenario({
|
||||
executable: "/bin/echo",
|
||||
working_directory: "/tmp",
|
||||
environment: { API_TOKEN: value },
|
||||
events: [{ type: "input", at_ms: 0, data: value }],
|
||||
});
|
||||
const base = emptyUnverifiedProcessCapture();
|
||||
const manifest = await createRunManifest(scenario, new Date(0), new Date(1));
|
||||
const scenarioManifest = {
|
||||
...manifest,
|
||||
normalization_sha256: digestProcessCommitment(scenario.normalization),
|
||||
};
|
||||
const capture = parseProcessCapture({
|
||||
...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 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 serialized = JSON.stringify(left);
|
||||
const leftCapture = parseProcessCapture(left.normalized_result);
|
||||
const rightCapture = parseProcessCapture(right.normalized_result);
|
||||
|
||||
expect(serialized).toContain("secret-left");
|
||||
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({
|
||||
...leftCapture,
|
||||
frames: [{ sequence: 0, at_ms: 0, data: "different-output" }],
|
||||
});
|
||||
expect(compareProcessCaptures(leftCapture, changedOutput)).toMatchObject({
|
||||
status: "changed",
|
||||
terminal: "changed",
|
||||
});
|
||||
});
|
||||
@@ -23,7 +23,7 @@ it.skipIf(process.platform === "win32")(
|
||||
);
|
||||
const snapshotModule = fileURLToPath(
|
||||
new URL(
|
||||
"../../../dist/application/FilesystemSnapshot.js",
|
||||
"../../../dist/process/capture/FilesystemSnapshot.js",
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
processCaptureProbeFailureReason,
|
||||
processCaptureOwnershipUnavailableReason,
|
||||
probeProcessCaptureCapability,
|
||||
} from "../../../src/application/ProcessCaptureCapability.js";
|
||||
} from "../../../src/process/capture/ProcessCaptureCapability.js";
|
||||
|
||||
describe("process capture capability diagnostics", () => {
|
||||
it("distinguishes missing native modules from runtime ABI mismatches", () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { it } from "vitest";
|
||||
|
||||
import { probeProcessCaptureCapability } from "../../../src/application/ProcessCaptureCapability.js";
|
||||
import { probeProcessCaptureCapability } from "../../../src/process/capture/ProcessCaptureCapability.js";
|
||||
|
||||
/**
|
||||
* Process-capture tests need real native PTY authority. Probing once at module
|
||||
|
||||
@@ -7,9 +7,9 @@ import { expect } from "vitest";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { itWithCaptureCapability } from "./processCaptureCapability.js";
|
||||
|
||||
import { captureProcessScenario } from "../../../src/application/ProcessHarness.js";
|
||||
import { snapshotRoots } from "../../../src/application/FilesystemSnapshot.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/processCapture.js";
|
||||
import { captureProcessScenario } from "../../../src/process/capture/ProcessHarness.js";
|
||||
import { snapshotRoots } from "../../../src/process/capture/FilesystemSnapshot.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/process/processCapture.js";
|
||||
|
||||
const processFixture = fileURLToPath(
|
||||
new URL("../../fixtures/processFidelity.mjs", import.meta.url),
|
||||
|
||||
@@ -4,13 +4,13 @@ import { fileURLToPath } from "node:url";
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { captureProcessScenario } from "../../../src/application/ProcessHarness.js";
|
||||
import { createProcessCaptureEvidence } from "../../../src/application/ProcessEvidence.js";
|
||||
import { captureProcessScenario } from "../../../src/process/capture/ProcessHarness.js";
|
||||
import { createProcessCaptureEvidence } from "../../../src/application/process/ProcessEvidence.js";
|
||||
import {
|
||||
digestProcessCommitment,
|
||||
parseProcessCapture,
|
||||
parseProcessScenario,
|
||||
} from "../../../src/domain/processCapture.js";
|
||||
} from "../../../src/domain/process/processCapture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { itWithCaptureCapability } from "./processCaptureCapability.js";
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
captureProcessScenario,
|
||||
probeProcessCaptureCapability,
|
||||
} from "../../../src/application/ProcessHarness.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/processCapture.js";
|
||||
} from "../../../src/process/capture/ProcessHarness.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/process/processCapture.js";
|
||||
|
||||
it("captures one command's terminal output, selected files, and owned cleanup", async () => {
|
||||
const root = await createTestTempDirectory("rea-process-capture-");
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { parseProcessScenario } from "../../../src/domain/processScenario.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/process/processScenario.js";
|
||||
import {
|
||||
createRunManifest,
|
||||
observeSettlement,
|
||||
} from "../../../src/application/ProcessCaptureLifecycle.js";
|
||||
} from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
||||
|
||||
it("uses one selected host identity for manifest and settlement", async () => {
|
||||
const scenario = parseProcessScenario({
|
||||
|
||||
Reference in New Issue
Block a user