Merge pull request #1256 from morluto/fix/evidence-file-selection-code
fix(errors): report caller-selected evidence path failures as invalid input
This commit is contained in:
@@ -119,6 +119,13 @@ export const analysisErrorCategory = (
|
|||||||
return "unavailable";
|
return "unavailable";
|
||||||
if (error instanceof ArtifactOperationError)
|
if (error instanceof ArtifactOperationError)
|
||||||
return artifactErrorCategory(error.reason);
|
return artifactErrorCategory(error.reason);
|
||||||
|
if (
|
||||||
|
error instanceof EvidenceFileError &&
|
||||||
|
(error.reason === "missing" ||
|
||||||
|
error.reason === "not-file" ||
|
||||||
|
error.reason === "exists")
|
||||||
|
)
|
||||||
|
return "invalid_input";
|
||||||
return STATIC_ERROR_CATEGORIES[error._tag] ?? "execution_failure";
|
return STATIC_ERROR_CATEGORIES[error._tag] ?? "execution_failure";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { ArtifactOperationError } from "./artifactOperationError.js";
|
import { ArtifactOperationError } from "./artifactOperationError.js";
|
||||||
import { BinaryTargetError } from "./configurationErrors.js";
|
import { BinaryTargetError } from "./configurationErrors.js";
|
||||||
import { BrowserObservationError } from "./browserObservationError.js";
|
import { BrowserObservationError } from "./browserObservationError.js";
|
||||||
import { EvidenceIntegrityError } from "./evidenceErrors.js";
|
import { EvidenceFileError, EvidenceIntegrityError } from "./evidenceErrors.js";
|
||||||
import {
|
import {
|
||||||
HopperProcessError,
|
HopperProcessError,
|
||||||
HopperRemoteError,
|
HopperRemoteError,
|
||||||
@@ -573,3 +573,32 @@ describe("analysis error projection: operational diagnostics", () => {
|
|||||||
expect(unknown.remediation.action).toContain("provider_operation_health");
|
expect(unknown.remediation.action).toContain("provider_operation_health");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("analysis error projection: evidence files", () => {
|
||||||
|
it.each([
|
||||||
|
["read", "missing", "invalid_request", "invalid_input"],
|
||||||
|
["read", "not-file", "invalid_request", "invalid_input"],
|
||||||
|
["write", "missing", "invalid_request", "invalid_input"],
|
||||||
|
["write", "exists", "invalid_request", "invalid_input"],
|
||||||
|
[
|
||||||
|
"read",
|
||||||
|
"invalid-json",
|
||||||
|
"evidence_integrity_mismatch",
|
||||||
|
"execution_failure",
|
||||||
|
],
|
||||||
|
["read", "io", "execution_failure", "execution_failure"],
|
||||||
|
] as const)(
|
||||||
|
"classifies a %s %s evidence file by who can correct it",
|
||||||
|
(operation, reason, code, category) => {
|
||||||
|
const projected = projectAnalysisError(
|
||||||
|
new EvidenceFileError(operation, reason, { path: "/selected.json" }),
|
||||||
|
);
|
||||||
|
expect(projected).toMatchObject({
|
||||||
|
code,
|
||||||
|
category,
|
||||||
|
details: { operation, reason, path: "/selected.json" },
|
||||||
|
});
|
||||||
|
expect(analysisErrorProjectionSchema.parse(projected)).toEqual(projected);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -144,10 +144,12 @@ const artifactOperationCode = (
|
|||||||
|
|
||||||
const evidenceFileCode = (
|
const evidenceFileCode = (
|
||||||
reason: EvidenceFileError["reason"],
|
reason: EvidenceFileError["reason"],
|
||||||
): AnalysisErrorProjection["code"] =>
|
): AnalysisErrorProjection["code"] => {
|
||||||
reason === "invalid-json"
|
if (reason === "invalid-json") return "evidence_integrity_mismatch";
|
||||||
? "evidence_integrity_mismatch"
|
// A missing, non-file or already-existing path is the caller's selection.
|
||||||
: "execution_failure";
|
if (reason === "io") return "execution_failure";
|
||||||
|
return "invalid_request";
|
||||||
|
};
|
||||||
|
|
||||||
const unknownRegistryCode = (
|
const unknownRegistryCode = (
|
||||||
reason: UnknownRegistryError["reason"],
|
reason: UnknownRegistryError["reason"],
|
||||||
|
|||||||
Reference in New Issue
Block a user