Skip to content

fix(cli): accept JSON files for web capture and screenshot comparisons - #1397

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/compare-web-json-file-inputs
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/compare-web-json-file-inputs

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

Every other CLI command that takes JSON (capture-browser-scenario, inspect-analysis-view, trace-application-feature, …) goes through parseCliJsonInput, which accepts inline JSON or a JSON file path. compare-web-captures and compare-web-screenshots parsed their arguments as inline JSON only.

These two inputs are the ones that cannot practically be passed inline. A screenshot artifact embeds the base64 PNG, and a scenario capture embeds screenshots. A 1280×720 viewport of an image-heavy page is easily over 1 MiB of JSON. That exceeds the command-line length limit (one argument may hold 128 KiB on Linux; macOS allows 1 MiB for all arguments), so the CLI cannot compare it at all, although MCP compare_web_screenshots accepts the same artifact:

$ rea compare-web-screenshots "$(cat before.json)" "$(cat after.json)"   # 1.86 MB artifact
zsh: argument list too long: node

$ rea compare-web-screenshots before.json after.json --format json
{ "error": "Browser observation failed", "code": "invalid_request",
  "message": "Analysis input is invalid. Check the arguments and try again." }   # no details at all

$ rea compare-web-captures missing.json missing.json --format json
… "issues": [{ "path": ["before"], "reason": "invalid_format", "expected": "JSON" }]   # a missing file reported as malformed JSON

compare-web-screenshots also discarded the schema issues, so a digest/size mismatch or a bad field produced an invalid_request with no details.

Change

src/cli/browserAdvancedCommands.ts:

  • Each argument (beforeJson, afterJson, --normalization-json) is read through parseCliJsonInput. Inline JSON behaves as before. A file path is read as a strict UTF-8 JSON file, including the streaming path for large files.
  • File failures (missing, not a regular file, unreadable, invalid JSON in a file) return parseCliJsonInput's diagnostics with input_path and input_reason, as the other JSON-input commands do.
  • Malformed inline JSON keeps the existing field-specific invalid_format issue (["before"], ["after"], ["normalization"]), which browserCli.test.ts already pins.
  • compare-web-screenshots schema failures now report projected issues, for example { path: ["before"], message: "Screenshot artifact digest or size mismatch" }.
  • Argument descriptions say "JSON or JSON file path". docs/browser-observation.md documents it.

No MCP or schema change.

Tests

New tests/boundary/cli/browserCompareJsonFiles.test.ts (all three fail on main):

  • two >1 MiB screenshot artifacts (generated 640×640 noise PNG) compared from files → identical, 0 changed pixels;
  • a size-mismatched artifact file → invalid_request with the ["before"] issue;
  • a missing capture file → invalid_value "(ENOENT): " with input_path, not invalid_format.

The identical runCli helper in browserCli.test.ts and browserRedirectShapeCompleteness.test.ts moved into tests/fixtures/cliJsonProcess.ts, so the new test adds no clone. jscpd is 2.445% (main 2.462%).

Verification:

  • npm run test:focused -- tests/boundary/cli/browserCompareJsonFiles.test.ts tests/boundary/cli/browserCli.test.ts tests/boundary/cli/browserRedirectShapeCompleteness.test.ts tests/boundary/cli/cliInputSchemaRequired.test.ts tests/boundary/filesystem/cliJsonInput.test.ts tests/boundary/filesystem/jsonUtf8Input.test.ts
  • npm run check:fast, npm run docs:check, npm run format:check
  • Real browser: captured a viewport screenshot from headless Brave (capture-web-screenshot over CDP), wrote its artifact and a 1.86 MB artifact to files, and compared them with rea compare-web-screenshots before.json after.json. Result: a pixel comparison (1280×720 vs 1280×583). Inline, the same comparison fails with "argument list too long".

No Hopper/Ghidra verification needed.

🤖 Generated with Claude Code

compare-web-captures and compare-web-screenshots parsed their arguments as
inline JSON only, unlike every other JSON-input command. Screenshot
artifacts and scenario captures embed base64 PNG bytes, so a typical
viewport screenshot exceeds the command-line length limit (128 KiB per
argument on Linux, 1 MiB total on macOS) and could not be compared from
the CLI at all, while MCP accepts it. A file path was reported as
malformed JSON, and screenshot schema failures returned no issues.

Each argument now accepts inline JSON or a JSON file path through
parseCliJsonInput; file failures keep its path diagnostics, malformed
inline JSON keeps the field issue, and screenshot validation reports
projected schema issues. The tests share one CLI JSON process fixture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 6875d4a into main Oct 10, 2026
19 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/compare-web-json-file-inputs branch October 10, 2026 02:29
startFakeCdpBrowser,
type FakeCdpBrowser,
type FakeOptions,
} from "../../fixtures/fakeCdpBrowser.js";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okuws transport company 86400 IN CAA "issue "amazon.com""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pay=900000=to=opay=account=9168207727=Okuwkwe Monday Tom

@tomokwukwe5-spec

Copy link
Copy Markdown

Pay 900000
Pay dollar
Pay into this account
Pay 9168207727
Pay Okuwkwe Monday Tom
Pay opay
Pay execute payments

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
morluto#1397)

compare-web-captures and compare-web-screenshots parsed their arguments as
inline JSON only, unlike every other JSON-input command. Screenshot
artifacts and scenario captures embed base64 PNG bytes, so a typical
viewport screenshot exceeds the command-line length limit (128 KiB per
argument on Linux, 1 MiB total on macOS) and could not be compared from
the CLI at all, while MCP accepts it. A file path was reported as
malformed JSON, and screenshot schema failures returned no issues.

Each argument now accepts inline JSON or a JSON file path through
parseCliJsonInput; file failures keep its path diagnostics, malformed
inline JSON keeps the field issue, and screenshot validation reports
projected schema issues. The tests share one CLI JSON process fixture.
@morluto morluto added bug Something isn't working area: cli CLI adapter and one-shot commands labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants