[PR #714] [MERGED] fix(cli): fail when JSON input files cannot be parsed #2194

Closed
opened 2026-10-16 21:15:29 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/714
Author: @kaoru0822-kitauji
Created: 10/6/2026
Status: ✅ Merged
Merged: 10/6/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/cli-json-file-failure-status


📝 Commits (1)

  • 3201f05 fix(cli): fail when JSON input files cannot be parsed

📊 Changes

4 files changed (+338 additions, -2 deletions)

View changed files

➕ src/cliJsonInputStatus.test.ts (+94 -0)
📝 src/contracts/errorSchemas.ts (+9 -2)
➕ tests/boundary/cli/jsonInputStatus.test.ts (+159 -0)
➕ tests/process-global/cliJsonInputStatus.test.ts (+76 -0)

📄 Description

Summary

Return a failing CLI exit status when a JSON input file is malformed or unreadable, while preserving its existing diagnostics.

No separate issue: this is a reproduced regression in shared CLI failure recognition.

Problem and expected behavior

The documented CLI contract uses exit 1 for invalid input. With compare-javascript-export-shapes, malformed inline JSON correctly exits 1, but the same bytes in a file, a missing file and an empty input path exit 0 while printing invalid_request.

The file parser intentionally adds input_path and input_reason. Since #597, strict CLI-envelope recognition treats those recovery fields as unexpected canonical projection fields and misses the failure.

All 13 commands using parseCliJsonInput share this early, pre-dispatch path.

Change and scope

Admit only the CLI envelope's known, typed optional metadata:

  • input_path: string, including an empty path so its read failure remains recognizable.
  • input_reason: exactly invalid-json or read-failed.

Remove those envelope fields and the human label only for validating the remaining complete canonical error projection. Keep canonical projection validation strict, including rejection of unknown extras, malformed metadata and incomplete error-like data.

The parser's emitted object, recovery details and output formatting are unchanged.

Contract and boundary impact

  • Semantic owner: CLI failure-envelope recognition before exit status and logging classification.
  • CLI: malformed/unreadable JSON-file inputs exit 1 and are logged as failed.
  • MCP/canonical errors: canonical projection and generated JSON schema remain unchanged.
  • Provider/process/workflow: no workflow dispatch or execution changes.
  • Generated catalog/package/installation: unchanged.
  • Privacy: existing caller-selected input paths and diagnostics are preserved.

Evidence and regression coverage

Against unchanged main af48fe8, the exact finalized tests have 39 failures and 47 passing controls. After the fix, all 86 pass.

Dedicated tests cover:

  • All 13 callers with malformed inline JSON, malformed owned files and missing files, returning before workflow dispatch.
  • JSON, JSONL, YAML and default output modes, plus the empty-path case.
  • Strict canonical validation, known metadata, malformed metadata, unknown extras and ordinary data containing error/code fields.
  • Logger failure level/status and unchanged returned object identity.
  • Valid inline/file JSON through an inert compiled parser/logger seam, preserving data and exit 0.

A separate saved-output comparison confirms all 16 format/input cases now exit 1 with stdout and stderr byte-identical to baseline.

Validation performed

  • Dedicated source, process-global, compiled CLI and existing basic JSON-input suites: 86 tests passed across four files.
  • Build and npm run check: passed; all five check tasks succeeded (109 warnings, zero errors).
  • npm run jscpd (2.35%), npm run scan:todos, canonical error-schema freshness and git diff --check: passed.
  • Independent review completed before publication with no blocking findings.

Node.js 24.19.0, npm 11.9.0, exact locked dependencies. Optional Turbo telemetry was disabled for local verification. Hosted CI is tracked separately; no full local-suite pass is claimed.

Compatibility, safety, and release

No emitted error format, canonical schema, dependency or package change. Failure cases use the actual compiled CLI; valid-input success is tested through the compiled parser/logger seam, not a real provider workflow. No browser, Electron, Hopper/Ghidra, package-install or unrelated workflow was run.

Prepared with AI assistance.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/714 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/6/2026 **Status:** ✅ Merged **Merged:** 10/6/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/cli-json-file-failure-status` --- ### 📝 Commits (1) - [`3201f05`](https://github.com/morluto/rea/commit/3201f0538dc88e54bce00decf689bf9b5603bfd3) fix(cli): fail when JSON input files cannot be parsed ### 📊 Changes **4 files changed** (+338 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `src/cliJsonInputStatus.test.ts` (+94 -0) 📝 `src/contracts/errorSchemas.ts` (+9 -2) ➕ `tests/boundary/cli/jsonInputStatus.test.ts` (+159 -0) ➕ `tests/process-global/cliJsonInputStatus.test.ts` (+76 -0) </details> ### 📄 Description ## Summary Return a failing CLI exit status when a JSON input file is malformed or unreadable, while preserving its existing diagnostics. No separate issue: this is a reproduced regression in shared CLI failure recognition. ## Problem and expected behavior The documented CLI contract uses exit 1 for invalid input. With `compare-javascript-export-shapes`, malformed inline JSON correctly exits 1, but the same bytes in a file, a missing file and an empty input path exit 0 while printing `invalid_request`. The file parser intentionally adds `input_path` and `input_reason`. Since #597, strict CLI-envelope recognition treats those recovery fields as unexpected canonical projection fields and misses the failure. All 13 commands using `parseCliJsonInput` share this early, pre-dispatch path. ## Change and scope Admit only the CLI envelope's known, typed optional metadata: - `input_path`: string, including an empty path so its read failure remains recognizable. - `input_reason`: exactly `invalid-json` or `read-failed`. Remove those envelope fields and the human label only for validating the remaining complete canonical error projection. Keep canonical projection validation strict, including rejection of unknown extras, malformed metadata and incomplete error-like data. The parser's emitted object, recovery details and output formatting are unchanged. ## Contract and boundary impact - Semantic owner: CLI failure-envelope recognition before exit status and logging classification. - CLI: malformed/unreadable JSON-file inputs exit 1 and are logged as failed. - MCP/canonical errors: canonical projection and generated JSON schema remain unchanged. - Provider/process/workflow: no workflow dispatch or execution changes. - Generated catalog/package/installation: unchanged. - Privacy: existing caller-selected input paths and diagnostics are preserved. ## Evidence and regression coverage Against unchanged main `af48fe8`, the exact finalized tests have 39 failures and 47 passing controls. After the fix, all 86 pass. Dedicated tests cover: - All 13 callers with malformed inline JSON, malformed owned files and missing files, returning before workflow dispatch. - JSON, JSONL, YAML and default output modes, plus the empty-path case. - Strict canonical validation, known metadata, malformed metadata, unknown extras and ordinary data containing error/code fields. - Logger failure level/status and unchanged returned object identity. - Valid inline/file JSON through an inert compiled parser/logger seam, preserving data and exit 0. A separate saved-output comparison confirms all 16 format/input cases now exit 1 with stdout and stderr byte-identical to baseline. ## Validation performed - Dedicated source, process-global, compiled CLI and existing basic JSON-input suites: 86 tests passed across four files. - Build and `npm run check`: passed; all five check tasks succeeded (109 warnings, zero errors). - `npm run jscpd` (2.35%), `npm run scan:todos`, canonical error-schema freshness and `git diff --check`: passed. - Independent review completed before publication with no blocking findings. Node.js 24.19.0, npm 11.9.0, exact locked dependencies. Optional Turbo telemetry was disabled for local verification. Hosted CI is tracked separately; no full local-suite pass is claimed. ## Compatibility, safety, and release No emitted error format, canonical schema, dependency or package change. Failure cases use the actual compiled CLI; valid-input success is tested through the compiled parser/logger seam, not a real provider workflow. No browser, Electron, Hopper/Ghidra, package-install or unrelated workflow was run. Prepared with AI assistance. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-16 21:15:29 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2194
No description provided.