mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 22:11:12 +00:00
* fix(artifacts): refuse an unusable extract_artifact output_root before scanning extract_artifact checked output_root only when it created the output tree, after scanning the whole archive and preparing its reader. A destination that already existed was refused there, and the refusal carried the archive's complete inventory as its partial observation: 1.7 MB of error text for a 2,000-entry ZIP. The read-only SafeOutputTree.checkDestination admission, which firmware and environment-bundle extraction already use, now runs before the archive is read. SafeOutputTree.create still rechecks and acquires the destination exclusively, so a destination that changes after the early check is still refused there. Refs #15326 * fix(artifacts)!: report a refused extract_artifact output_root as caller input A destination refusal on extract_artifact is now an input error on output_root, as firmware, UEFI, script and bundle export report theirs. Every destination refusal conforms to the input contract and names the fix instead of pointing at the schema. BREAKING CHANGE: extract_artifact reports a refused output_root as invalid_request with an issue at output_root (CLI: outputRoot) instead of artifact_operation_failed with reason path. Destination refusals of extract_firmware, UEFI extraction, export_web_scripts, export_environment_bundle, environment-export/build and desktop build exports no longer carry recovery.kind inspect_input_contract; read remediation.action and details.issues instead. Refs #15326 * test(artifacts): expect the caller-input refusal for a refused extract_artifact output_root The provider extraction boundary tests still asserted ArtifactOperationError reason path, the shape this change replaces; they now expect AnalysisInputError with an issue at output_root. * test(artifacts): prove extract_artifact refuses the destination before reading the source
106 lines
4.0 KiB
TypeScript
106 lines
4.0 KiB
TypeScript
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { writeEnvironmentServeFiles } from "../../fixtures/environmentServe.js";
|
|
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
cliTest.for(["environment-export", "environment-build"] as const)(
|
|
"%s attributes non-directory parents to the selected destination",
|
|
async (command, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-bundle-parent-");
|
|
const files = await writeEnvironmentServeFiles(root);
|
|
const occupied = join(root, "parentfile");
|
|
await writeFile(occupied, "keep\n");
|
|
const before = await stat(occupied);
|
|
const entries = await readdir(root);
|
|
const call = await cli.sharedMcpCall?.();
|
|
if (call === undefined) throw new Error("Expected stdio MCP session");
|
|
for (const directory of [
|
|
join(occupied, "bundle"),
|
|
join(occupied, "missing", "bundle"),
|
|
]) {
|
|
const arguments_ =
|
|
command === "environment-export"
|
|
? [command, files.manifestPath, "--evidence", files.capturePath]
|
|
: [command, files.capturePath];
|
|
const result = await cli.run({
|
|
arguments: [...arguments_, directory, "--json"],
|
|
});
|
|
expect(result.exitCode, result.stderr).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
code: "invalid_request",
|
|
category: "invalid_input",
|
|
details: {
|
|
issues: [{ path: ["directory"], reason: "invalid_value" }],
|
|
},
|
|
// A schema-valid path the filesystem refused: the fix is named,
|
|
// not the input schema.
|
|
remediation: {
|
|
action: expect.stringContaining(
|
|
"Choose a different destination path",
|
|
),
|
|
},
|
|
});
|
|
const mcp = await call("export_environment_bundle", {
|
|
source: { kind: "evidence-file", path: files.capturePath },
|
|
output_directory: directory,
|
|
});
|
|
expect(mcp.isError).toBe(true);
|
|
expect(parseMcpToolError(mcp).error).toMatchObject({
|
|
code: "invalid_request",
|
|
category: "invalid_input",
|
|
details: {
|
|
issues: [{ path: ["output_directory"], reason: "invalid_value" }],
|
|
},
|
|
// A schema-valid path the filesystem refused: the fix is named,
|
|
// not the input schema.
|
|
remediation: {
|
|
action: expect.stringContaining(
|
|
"Choose a different destination path",
|
|
),
|
|
},
|
|
});
|
|
expect(await readFile(occupied, "utf8")).toBe("keep\n");
|
|
const after = await stat(occupied);
|
|
expect({ dev: after.dev, ino: after.ino }).toEqual({
|
|
dev: before.dev,
|
|
ino: before.ino,
|
|
});
|
|
expect(await readdir(root)).toEqual(entries);
|
|
}
|
|
},
|
|
);
|
|
|
|
cliTest.for(["environment-export", "environment-build"] as const)(
|
|
"%s still creates missing parents and accepts an empty destination",
|
|
async (command, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-bundle-parent-control-");
|
|
const files = await writeEnvironmentServeFiles(root);
|
|
const empty = join(root, "empty");
|
|
await mkdir(empty);
|
|
for (const directory of [
|
|
join(root, "missing", "nested", "bundle"),
|
|
empty,
|
|
]) {
|
|
const arguments_ =
|
|
command === "environment-export"
|
|
? [command, files.manifestPath, "--evidence", files.capturePath]
|
|
: [command, files.capturePath];
|
|
const result = await cli.run({
|
|
arguments: [...arguments_, directory, "--json"],
|
|
});
|
|
expect(result.exitCode, result.stderr).toBe(0);
|
|
expect(result.json).toMatchObject({
|
|
status: command === "environment-export" ? "exported" : "built",
|
|
});
|
|
expect(
|
|
(
|
|
await readFile(join(directory, "envs/grafana-example/evidence.json"))
|
|
).equals(await readFile(files.capturePath)),
|
|
).toBe(true);
|
|
}
|
|
},
|
|
);
|