Simplify and harden investigation workflows

This commit is contained in:
morluto
2026-07-12 21:45:26 +00:00
parent fbe8ec1f13
commit 293cea7723
35 changed files with 531 additions and 1041 deletions
+25 -5
View File
@@ -1,4 +1,5 @@
import { access, mkdtemp, readdir } from "node:fs/promises";
import { createHash } from "node:crypto";
import { access, mkdtemp, readFile, readdir } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Readable } from "node:stream";
@@ -16,19 +17,19 @@ const LIMITS = {
maxPathBytes: 256,
} as const;
describe("safe artifact output transaction", () => {
describe("safe artifact output tree", () => {
it("removes only its owned tree after digest failure and proves absence", async () => {
const parent = await mkdtemp(join(tmpdir(), "rea-safe-output-"));
const output = join(parent, "published");
const transaction = await SafeOutputTree.create(output, LIMITS);
const tree = await SafeOutputTree.create(output, LIMITS);
await expect(
transaction.write(
tree.write(
"nested/file.txt",
Readable.from(Buffer.from("unexpected")),
"0".repeat(64),
),
).rejects.toThrow(/disagrees/u);
expect(await transaction.rollback()).toMatchObject({
expect(await tree.rollback()).toMatchObject({
attempted: true,
verified: true,
residualPaths: [],
@@ -36,4 +37,23 @@ describe("safe artifact output transaction", () => {
await expect(access(output)).rejects.toThrow();
expect(await readdir(parent)).toEqual([]);
});
it("publishes files while building and preserves them after sealing", async () => {
const parent = await mkdtemp(join(tmpdir(), "rea-safe-output-"));
const output = join(parent, "published");
const tree = await SafeOutputTree.create(output, LIMITS);
const bytes = Buffer.from("visible before seal");
const digest = createHash("sha256").update(bytes).digest("hex");
await tree.write("file.txt", Readable.from(bytes), digest);
expect(await readFile(join(output, "file.txt"), "utf8")).toBe(
"visible before seal",
);
await tree.commit();
expect(await tree.rollback()).toMatchObject({ attempted: false });
expect(await readFile(join(output, "file.txt"), "utf8")).toBe(
"visible before seal",
);
});
});