mirror of
https://github.com/morluto/rea.git
synced 2026-11-06 06:46:10 +00:00
* fix(cli): seal in-process Evidence before publishing The CLI rebuilt a plain bundle from records it had already authenticated, so writeEvidenceBundle cloned and authenticated the complete analyzed graph again at the final checkpoint. On a default heap that second copy could exceed available memory after minutes of analysis and discard the whole run. Seal the in-process bundle once so publication can stream the canonical form without the redundant authentication copies. The regression test fails on the previous behavior with resource_constraint under a one-byte heap allowance. Fixes #8411 * fix(cli): preserve the heap check for mutable Evidence Only seal the publication bundle when every record is already immutable. Mutable producer records keep the writer's existing heap check instead of being copied before that check. The regression now covers the safe fallback and lets the shared temporary-directory fixture own cleanup. * test(cli): keep a distinct mutable source in the publication regression Seal the main record and give the mutable source its own evidence ID so the map cannot replace it before the bundle guard runs.
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it, vi } from "vitest";
|
|
|
|
import { publishCliAnalysisEvidence } from "../../src/cli/analysisEvidenceDelivery.js";
|
|
import { createEvidence } from "../../src/domain/evidence.js";
|
|
import { parseEvidenceBundle } from "../../src/domain/evidenceBundle.js";
|
|
import { ok } from "../../src/domain/result.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
|
|
vi.mock("node:v8", () => ({
|
|
getHeapStatistics: () => ({
|
|
total_available_size: 1,
|
|
heap_size_limit: 1,
|
|
}),
|
|
}));
|
|
|
|
it("publishes CLI Evidence without re-authenticating the complete graph", async () => {
|
|
const root = await createTestTempDirectory("rea-cli-evidence-");
|
|
const destination = join(root, "bundle.json");
|
|
const evidence = createEvidence(
|
|
undefined,
|
|
{ id: "fixture", name: "Fixture", version: "1" },
|
|
{
|
|
operation: "fixture",
|
|
parameters: { payload_bytes: 4_000_000 },
|
|
result: { payload: "x".repeat(4_000_000) },
|
|
},
|
|
{ immutable: true },
|
|
);
|
|
|
|
const output = await publishCliAnalysisEvidence(ok(evidence), {
|
|
providerId: "fixture",
|
|
operation: "fixture",
|
|
signal: new AbortController().signal,
|
|
detail: "complete",
|
|
evidenceOutput: destination,
|
|
});
|
|
|
|
expect(output).toMatchObject({ evidence_id: evidence.evidence_id });
|
|
const bundle = parseEvidenceBundle(
|
|
JSON.parse(await readFile(destination, "utf8")),
|
|
);
|
|
expect(bundle.records.map((record) => record.evidence_id)).toContain(
|
|
evidence.evidence_id,
|
|
);
|
|
});
|
|
|
|
it("keeps the writer heap check for mutable source Evidence", async () => {
|
|
const root = await createTestTempDirectory("rea-cli-mutable-evidence-");
|
|
const destination = join(root, "bundle.json");
|
|
const evidence = createEvidence(
|
|
undefined,
|
|
{ id: "fixture", name: "Fixture", version: "1" },
|
|
{
|
|
operation: "fixture",
|
|
parameters: { payload_bytes: 1_000 },
|
|
result: { payload: "x".repeat(1_000) },
|
|
},
|
|
{ immutable: true },
|
|
);
|
|
const source = createEvidence(
|
|
undefined,
|
|
{ id: "fixture", name: "Fixture", version: "1" },
|
|
{
|
|
operation: "source-fixture",
|
|
parameters: { payload_bytes: 1_000 },
|
|
result: { payload: "y".repeat(1_000) },
|
|
},
|
|
);
|
|
const mutableSource = JSON.parse(JSON.stringify(source)) as typeof source;
|
|
|
|
const output = await publishCliAnalysisEvidence(ok(evidence), {
|
|
providerId: "fixture",
|
|
operation: "fixture",
|
|
signal: new AbortController().signal,
|
|
detail: "complete",
|
|
evidenceOutput: destination,
|
|
sourceEvidence: [mutableSource],
|
|
});
|
|
|
|
expect(output).toMatchObject({ code: "resource_constraint" });
|
|
});
|