mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +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
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
|
import { ArtifactReaderFailure } from "./ArtifactReader.js";
|
|
import type { SafeOutputTree } from "./SafeOutputTree.js";
|
|
import {
|
|
outputDirectoryAdmissionRefusal,
|
|
SafeOutputTreeDestinationRefusal,
|
|
} from "./SafeOutputTreeAdmission.js";
|
|
import { SafeOutputTreeCreationFailure } from "./SafeOutputTreeCreationFailure.js";
|
|
|
|
// Only the failure's type matters here; no tree method is called.
|
|
const acquiredTree = {} as SafeOutputTree;
|
|
const refuse = (cause: unknown) =>
|
|
outputDirectoryAdmissionRefusal(
|
|
"export_web_scripts",
|
|
"output_directory",
|
|
cause,
|
|
);
|
|
|
|
describe("output directory admission refusal", () => {
|
|
it.each([
|
|
[
|
|
"a refusal before acquisition",
|
|
new SafeOutputTreeDestinationRefusal(
|
|
"Extraction output root already exists",
|
|
),
|
|
],
|
|
[
|
|
"a refusal of an acquired non-empty root",
|
|
new SafeOutputTreeCreationFailure(
|
|
new SafeOutputTreeDestinationRefusal("Output directory is not empty"),
|
|
acquiredTree,
|
|
),
|
|
],
|
|
])("blames the selected directory for %s", (_name, cause) => {
|
|
const refused = refuse(cause);
|
|
|
|
expect(refused).toBeInstanceOf(AnalysisInputError);
|
|
expect(refused).toMatchObject({
|
|
operation: "export_web_scripts",
|
|
// A schema-valid path the filesystem refused: name the fix, not the schema.
|
|
conformsToInputContract: true,
|
|
remediationAction: expect.stringContaining(
|
|
"Choose a different destination path",
|
|
),
|
|
issues: [
|
|
{
|
|
path: ["output_directory"],
|
|
reason: "invalid_value",
|
|
message: cause.message,
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
"an acquired-tree setup failure",
|
|
new SafeOutputTreeCreationFailure(
|
|
new ArtifactReaderFailure(
|
|
"path",
|
|
"Cannot restrict output root to 0700",
|
|
),
|
|
acquiredTree,
|
|
),
|
|
],
|
|
[
|
|
"a path failure that is not a destination refusal",
|
|
new ArtifactReaderFailure("path", "Output file path changed"),
|
|
],
|
|
[
|
|
"a refusal whose cleanup is unresolved",
|
|
new ArtifactReaderFailure(
|
|
"path",
|
|
"Extraction output root already exists",
|
|
{
|
|
cause: new SafeOutputTreeDestinationRefusal(
|
|
"Extraction output root already exists",
|
|
),
|
|
cleanup: { reason: "rollback failed", resources: ["/out"] },
|
|
},
|
|
),
|
|
],
|
|
])("keeps artifact semantics for %s", (_name, cause) => {
|
|
expect(refuse(cause)).toBe(cause);
|
|
});
|
|
});
|