From 536c54ca1fb362f3fee9d8df8bb14296ce53517c Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:23:05 +0800 Subject: [PATCH] feat(process): name whether a process input file failed to read or to parse (#11008) --- src/application/process/ProcessCli.ts | 11 +++++++++- .../filesystem/processCliFileInput.test.ts | 22 +++++++++++++------ .../filesystem/sourcePathFailures.test.ts | 9 +++++++- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/application/process/ProcessCli.ts b/src/application/process/ProcessCli.ts index da4a0e7775..02722f1859 100644 --- a/src/application/process/ProcessCli.ts +++ b/src/application/process/ProcessCli.ts @@ -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 => ({ diff --git a/tests/boundary/filesystem/processCliFileInput.test.ts b/tests/boundary/filesystem/processCliFileInput.test.ts index 5f01ea0630..6c69bad712 100644 --- a/tests/boundary/filesystem/processCliFileInput.test.ts +++ b/tests/boundary/filesystem/processCliFileInput.test.ts @@ -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( diff --git a/tests/boundary/filesystem/sourcePathFailures.test.ts b/tests/boundary/filesystem/sourcePathFailures.test.ts index 8c5795ecfd..9af60369e5 100644 --- a/tests/boundary/filesystem/sourcePathFailures.test.ts +++ b/tests/boundary/filesystem/sourcePathFailures.test.ts @@ -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" }, + }), + ], + }, }); }, );