mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
feat(process): name whether a process input file failed to read or to parse (#11008)
This commit is contained in:
1 parent
e0249db65c
commit
536c54ca1f
3 files changed
+33
-9
No files matched your search
@@ -5,6 +5,7 @@ import { analysisErrorWithCancellation } from "../../domain/analysisErrorCancell
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
type AnalysisInputIssue,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
||||
import type { AnalysisErrorProjection } from "../../domain/analysisErrorProjection.js";
|
||||
@@ -344,6 +345,8 @@ const readJson = async (
|
||||
: `Process input file could not be read: ${path} (${detail}). Check the reported filesystem constraint and retry.`,
|
||||
["input_file"],
|
||||
"invalid_value",
|
||||
// Read and parse failures share one issue reason; name which one occurred.
|
||||
{ file_reason: loaded.error.reason },
|
||||
);
|
||||
};
|
||||
|
||||
@@ -352,9 +355,15 @@ const processInputFailure = (
|
||||
userMessage: string,
|
||||
path: readonly (string | number)[],
|
||||
reason: "invalid_value" | "missing_argument",
|
||||
observed?: AnalysisInputIssue["observed"],
|
||||
): AnalysisInputError =>
|
||||
new AnalysisInputError(operation, { userMessage }, [
|
||||
{ path, reason, message: userMessage },
|
||||
{
|
||||
path,
|
||||
reason,
|
||||
message: userMessage,
|
||||
...(observed === undefined ? {} : { observed }),
|
||||
},
|
||||
]);
|
||||
|
||||
const cliAnalysisError = (error: AnalysisError): ProcessCliErrorOutput => ({
|
||||
|
||||
@@ -283,6 +283,13 @@ it("keeps a physical read primary when its cause is also the abort reason", asyn
|
||||
}
|
||||
});
|
||||
|
||||
/** The process CLI's input-file refusal, naming whether reading or parsing failed. */
|
||||
const inputFileIssue = (fileReason: string) => ({
|
||||
path: ["input_file"],
|
||||
reason: "invalid_value",
|
||||
observed: { file_reason: fileReason },
|
||||
});
|
||||
|
||||
describe("process CLI input diagnostics", () => {
|
||||
it("keeps physical file I/O failures in the execution-error projection", async () => {
|
||||
const path = "/selected/scenario.json";
|
||||
@@ -344,8 +351,9 @@ describe("process CLI input diagnostics", () => {
|
||||
{
|
||||
path: ["input_file"],
|
||||
reason: "invalid_value",
|
||||
observed: { file_reason: "missing" },
|
||||
message: expect.stringContaining(
|
||||
`Process input file could not be read: ${join(root, "missing.json")} (ENOENT`,
|
||||
`${join(root, "missing.json")} (ENOENT`,
|
||||
),
|
||||
},
|
||||
],
|
||||
@@ -360,16 +368,14 @@ describe("process CLI input diagnostics", () => {
|
||||
error: "Process command failed",
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
message: expect.stringContaining(
|
||||
`Process input file is not valid UTF-8 JSON: ${malformed}`,
|
||||
),
|
||||
message: expect.stringContaining(malformed),
|
||||
retryable: false,
|
||||
recovery: {
|
||||
kind: "inspect_input_contract",
|
||||
operation: "capture_process_scenario",
|
||||
},
|
||||
details: {
|
||||
issues: [{ path: ["input_file"], reason: "invalid_value" }],
|
||||
issues: [inputFileIssue("invalid-json")],
|
||||
},
|
||||
});
|
||||
expect(analysisCliErrorEnvelopeSchema.safeParse(invalidJson).success).toBe(
|
||||
@@ -382,7 +388,9 @@ describe("process CLI input diagnostics", () => {
|
||||
category: "invalid_input",
|
||||
retryable: false,
|
||||
message: expect.stringContaining(invalidUtf8),
|
||||
details: { issues: [{ path: ["input_file"], reason: "invalid_value" }] },
|
||||
details: {
|
||||
issues: [inputFileIssue("invalid-json")],
|
||||
},
|
||||
});
|
||||
expect(
|
||||
analysisCliErrorEnvelopeSchema.safeParse(invalidUtf8Json).success,
|
||||
@@ -399,7 +407,7 @@ describe("process CLI input diagnostics", () => {
|
||||
retryable: false,
|
||||
details: {
|
||||
operation: "compare_process_captures",
|
||||
issues: [{ path: ["input_file"], reason: "invalid_value" }],
|
||||
issues: [inputFileIssue("missing")],
|
||||
},
|
||||
});
|
||||
expect(
|
||||
|
||||
@@ -49,7 +49,14 @@ it.skipIf(process.platform === "win32")(
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
message: expect.stringContaining("ELOOP"),
|
||||
details: { issues: [expect.objectContaining({ path: ["input_file"] })] },
|
||||
details: {
|
||||
issues: [
|
||||
expect.objectContaining({
|
||||
path: ["input_file"],
|
||||
observed: { file_reason: "symlink-traversal" },
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user