chore: integrate main for process progress verification
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
parseProcessScenario,
|
||||
} from "../../../src/domain/process/processScenario.js";
|
||||
import { parseProcessCapture } from "../../../src/domain/process/processCaptureParsing.js";
|
||||
import { compareProcessCaptures } from "../../../src/domain/process/processComparison.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { itWithCaptureCapability } from "./processCaptureCapability.js";
|
||||
|
||||
@@ -64,7 +65,11 @@ itWithCaptureCapability(
|
||||
).toBe(true);
|
||||
expect(capture.manifest.comparison_contract).toMatchObject({
|
||||
port_normalization_version: "contextual-endpoints-v2",
|
||||
rendered_line_format: "trailing-spaces-trimmed-v1",
|
||||
});
|
||||
expect(capture.manifest.comparison_contract).not.toHaveProperty(
|
||||
"pattern_normalization_version",
|
||||
);
|
||||
expect(capture.exit).toMatchObject({ code: 0, reason: "exited" });
|
||||
expect(capture.cleanup).toMatchObject({
|
||||
owned_process_group: "verified",
|
||||
@@ -73,6 +78,67 @@ itWithCaptureCapability(
|
||||
},
|
||||
);
|
||||
|
||||
itWithCaptureCapability.each([
|
||||
{ pattern: "AB", replacement: "$&$&", expected: "$&$&" },
|
||||
{
|
||||
pattern: "AB",
|
||||
replacement: "$$ $` $' $1",
|
||||
expected: "$$ $` $' $1",
|
||||
},
|
||||
{ pattern: "", replacement: "-", expected: "-A-B-" },
|
||||
])(
|
||||
"preserves literal replacement $replacement and rejects legacy comparison semantics",
|
||||
async ({ pattern, replacement, expected }) => {
|
||||
const root = await createTestTempDirectory("rea-process-literal-");
|
||||
const scenario = parseProcessScenario({
|
||||
executable: process.execPath,
|
||||
arguments: ["-e", 'process.stdout.write("AB")'],
|
||||
working_directory: root,
|
||||
normalization: {
|
||||
paths: false,
|
||||
pids: false,
|
||||
ports: false,
|
||||
patterns: [{ pattern, replacement }],
|
||||
},
|
||||
settle_ms: 100,
|
||||
});
|
||||
const result = await captureProcessScenario(scenario);
|
||||
if (!result.ok) throw result.error;
|
||||
const capture = parseProcessCapture(
|
||||
createProcessCaptureEvidence(scenario, result.value).normalized_result,
|
||||
);
|
||||
expect(capture.frames.map(({ data }) => data).join("")).toBe(expected);
|
||||
expect(
|
||||
capture.frames.map(({ raw_data, data }) => raw_data ?? data).join(""),
|
||||
).toBe("AB");
|
||||
expect(capture.cleanup).toMatchObject({
|
||||
owned_process_group: "verified",
|
||||
temporary_root: "removed",
|
||||
});
|
||||
expect(compareProcessCaptures(capture, capture).terminal).toBe("unchanged");
|
||||
const legacyContract = { ...capture.manifest.comparison_contract };
|
||||
delete legacyContract.pattern_normalization_version;
|
||||
const legacy = parseProcessCapture({
|
||||
...capture,
|
||||
manifest: {
|
||||
...capture.manifest,
|
||||
comparison_contract: legacyContract,
|
||||
comparison_contract_sha256: digestProcessCommitment(legacyContract),
|
||||
},
|
||||
});
|
||||
expect(() => compareProcessCaptures(legacy, capture)).toThrow(
|
||||
expect.objectContaining({
|
||||
issues: [
|
||||
expect.objectContaining({
|
||||
expected: ["pattern_normalization_version"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
},
|
||||
20_000,
|
||||
);
|
||||
|
||||
itWithLinuxCaptureCapability.each([false, true])(
|
||||
"honors pids=%s in owned Linux capture samples and committed Evidence",
|
||||
async (pids) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
@@ -7,6 +8,7 @@ import { expect, it, onTestFinished } from "vitest";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { compareProcessCaptures } from "../../../src/domain/process/processComparison.js";
|
||||
import { parseProcessCapture } from "../../../src/domain/process/processCaptureParsing.js";
|
||||
import { parseProcessScenario } from "../../../src/domain/process/processScenario.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
@@ -58,6 +60,108 @@ const captureViaMcp = async (scenario: Record<string, unknown>) => {
|
||||
return evidence;
|
||||
};
|
||||
|
||||
itWithCaptureCapability.each(["cli", "mcp"] as const)(
|
||||
"hashes the documented complete report despite omitted terminal output through %s",
|
||||
async (adapter) => {
|
||||
const document = await readFile("docs/process-capture.md", "utf8");
|
||||
const example = document
|
||||
.split("## Hash a report independently of terminal output")[1]
|
||||
?.match(/```json\n([\s\S]*?)\n```/u)?.[1];
|
||||
if (example === undefined)
|
||||
throw new Error("Missing report capture example");
|
||||
const scenario = parseProcessScenario(JSON.parse(example));
|
||||
const root = await createTestTempDirectory("rea-full-report-adapter-");
|
||||
const evidence = await (adapter === "cli" ? captureViaCli : captureViaMcp)({
|
||||
...scenario,
|
||||
executable: process.execPath,
|
||||
working_directory: root,
|
||||
filesystem_observation_paths: [join(root, "reports")],
|
||||
});
|
||||
const capture = parseProcessCapture(evidence.normalized_result);
|
||||
const bytes = await readFile(join(root, "reports", "final.json"));
|
||||
expect(JSON.parse(bytes.toString())).toEqual({
|
||||
status: "complete",
|
||||
data: "X".repeat(131072),
|
||||
});
|
||||
expect(bytes.length).toBeGreaterThan(scenario.limits.output_bytes);
|
||||
expect(capture.files_after).toContainEqual(
|
||||
expect.objectContaining({
|
||||
path: "root_0:final.json",
|
||||
size: bytes.length,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
}),
|
||||
);
|
||||
expect(capture.truncation_details.filesystem_after).toMatchObject({
|
||||
enumeration_truncated: false,
|
||||
hash_budget_bytes: scenario.limits.file_bytes,
|
||||
hashed_bytes: bytes.length,
|
||||
hash_omissions: [],
|
||||
});
|
||||
expect(capture.truncation_details.raw_terminal.retained_bytes).toBeLessThan(
|
||||
capture.truncation_details.raw_terminal.observed_bytes,
|
||||
);
|
||||
},
|
||||
20_000,
|
||||
);
|
||||
|
||||
itWithCaptureCapability.each(["cli", "mcp"] as const)(
|
||||
"accounts for exact cumulative hash budgets independently at each %s checkpoint",
|
||||
async (adapter) => {
|
||||
const runCapture = adapter === "cli" ? captureViaCli : captureViaMcp;
|
||||
for (const shortfall of [0, 1]) {
|
||||
const root = await createTestTempDirectory("rea-report-cumulative-");
|
||||
const periodic = Buffer.from('{"status":"running"}');
|
||||
const final = Buffer.from('{"status":"complete"}');
|
||||
await writeFile(join(root, "periodic.json"), periodic);
|
||||
const budget = periodic.length + final.length - shortfall;
|
||||
const evidence = await runCapture({
|
||||
executable: process.execPath,
|
||||
arguments: [
|
||||
"-e",
|
||||
"require('node:fs').writeFileSync('final.json','{\"status\":\"complete\"}')",
|
||||
],
|
||||
working_directory: root,
|
||||
filesystem_observation_paths: [root],
|
||||
limits: { output_bytes: 1, file_bytes: budget },
|
||||
});
|
||||
const capture = parseProcessCapture(evidence.normalized_result);
|
||||
expect(capture.truncation_details.filesystem_before).toMatchObject({
|
||||
hashed_bytes: periodic.length,
|
||||
hash_omissions: [],
|
||||
});
|
||||
expect(capture.files_after).toContainEqual(
|
||||
expect.objectContaining({
|
||||
path: "root_0:final.json",
|
||||
sha256: createHash("sha256").update(final).digest("hex"),
|
||||
}),
|
||||
);
|
||||
expect(capture.truncation_details.filesystem_after).toMatchObject({
|
||||
enumeration_truncated: false,
|
||||
hashed_bytes: final.length + (shortfall === 0 ? periodic.length : 0),
|
||||
hash_omissions:
|
||||
shortfall === 0
|
||||
? []
|
||||
: [
|
||||
{
|
||||
path: "root_0:periodic.json",
|
||||
reason: "file_bytes_budget",
|
||||
remaining_budget_bytes: periodic.length - 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(
|
||||
capture.files_after.find(({ path }) => path === "root_0:periodic.json")
|
||||
?.sha256,
|
||||
).toBe(
|
||||
shortfall === 0
|
||||
? createHash("sha256").update(periodic).digest("hex")
|
||||
: null,
|
||||
);
|
||||
}
|
||||
},
|
||||
20_000,
|
||||
);
|
||||
|
||||
itWithCaptureCapability.each(["cli", "mcp"] as const)(
|
||||
"reports unknown absence instead of deletion in truncated %s capture Evidence",
|
||||
async (adapter) => {
|
||||
|
||||
Reference in New Issue
Block a user