* fix(web): refuse an existing script-export destination as invalid input export_web_scripts refused an existing output directory or link correctly, but reported it as artifact_operation_failed / execution_failure with no field issue or recovery. SafeOutputTree.create raises that refusal as a path failure before any output tree exists, and the export mapper wrapped it as an artifact failure. Attribute pre-admission path refusals to output_directory as an AnalysisInputError, as environment export already does for its directory. Both now share one helper owned beside SafeOutputTree; failures after the tree is admitted keep their artifact semantics. Fixes #6029 * fix(artifacts): type SafeOutputTree destination refusals Admission conversion treated any cleanup-free path failure raised before admission as a refusal of the selected directory, so an acquired-tree setup failure, such as being unable to restrict a created root to 0700, blamed valid output_directory or directory input. SafeOutputTree.create now raises SafeOutputTreeDestinationRefusal for the refusals of the selection itself: a relative or reserved root, an existing root, and an accepted existing root that is not an empty directory. The shared conversion accepts only that type, directly or wrapped by SafeOutputTreeCreationFailure, so script and environment export no longer track admission separately.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 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",
|
|
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);
|
|
});
|
|
});
|