mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
80 lines
2.8 KiB
TypeScript
80 lines
2.8 KiB
TypeScript
import { readFile, symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { createSingleEntryZip } from "../../fixtures/zipNames.js";
|
|
import { parseEvidence } from "../../../src/domain/evidence.js";
|
|
|
|
cliTest.skipIf(process.platform === "win32")(
|
|
"retains the selected archive alias independently of its canonical subject",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-artifact-selected-alias-");
|
|
const target = join(root, "program.zip");
|
|
const alias = "selected-alias.zip";
|
|
await writeFile(target, await createSingleEntryZip("payload.txt"));
|
|
await symlink(target, join(root, alias));
|
|
const selected = await cli.run({
|
|
arguments: ["inspect-artifact", alias, "--json"],
|
|
cwd: root,
|
|
});
|
|
const control = await cli.run({
|
|
arguments: ["inspect-artifact", target, "--json"],
|
|
cwd: root,
|
|
});
|
|
expect(selected.exitCode).toBe(0);
|
|
expect(control.exitCode).toBe(0);
|
|
const observed = parseEvidence(selected.json);
|
|
const direct = parseEvidence(control.json);
|
|
expect(observed.parameters).toMatchObject({ input_path: alias });
|
|
expect(observed.subject).toEqual(direct.subject);
|
|
expect(observed.normalized_result).toEqual(direct.normalized_result);
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"offers a fresh destination after protected inspection publication collides, preserving the existing bundle",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory(
|
|
"rea-artifact-collision-guidance-",
|
|
);
|
|
const archive = join(root, "program.zip");
|
|
const output = join(root, "evidence.json");
|
|
await writeFile(archive, await createSingleEntryZip("payload.txt"));
|
|
const args = [
|
|
"inspect-artifact",
|
|
archive,
|
|
"--detail",
|
|
"summary",
|
|
"--evidence_output",
|
|
output,
|
|
"--json",
|
|
];
|
|
const initial = await cli.run({ arguments: args });
|
|
expect(initial.exitCode).toBe(0);
|
|
const before = await readFile(output);
|
|
const collision = await cli.run({ arguments: args });
|
|
expect(collision.exitCode).not.toBe(0);
|
|
expect(collision.json).toMatchObject({
|
|
code: "invalid_request",
|
|
message: "Evidence file already exists. Choose another output path.",
|
|
remediation: {
|
|
action: "Evidence file already exists. Choose another output path.",
|
|
},
|
|
});
|
|
expect(await readFile(output)).toEqual(before);
|
|
const next = await cli.run({
|
|
arguments: [
|
|
"inspect-artifact",
|
|
archive,
|
|
"--detail",
|
|
"summary",
|
|
"--evidence_output",
|
|
join(root, "next.json"),
|
|
"--json",
|
|
],
|
|
});
|
|
expect(next.exitCode).toBe(0);
|
|
},
|
|
);
|