Skip to content

Feat: added CLI Friendly output format and json - #29

Merged
shossain786 merged 2 commits into
seleniumboot:mainfrom
PUSHPAK-JAISWAL:feat/ci-friendly
Oct 1, 2026
Merged

shossain786 merged 2 commits into
seleniumboot:mainfrom
PUSHPAK-JAISWAL:feat/ci-friendly

Conversation

@PUSHPAK-JAISWAL

@PUSHPAK-JAISWAL PUSHPAK-JAISWAL commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Enables CI/CD pipelines and automated tooling to consume analysis reports and enforce minimum migration confidence thresholds:

  • --format <text|json>: Adds support for machine-readable JSON output (--format json) for tooling and dashboards, with text remaining the default.
  • --fail-under <percent>: Adds a threshold check (0–100) that exits with code 1 if the estimated migration confidence score is strictly below the threshold. The report (text or JSON) is always emitted prior to exiting so that build logs remain actionable.
  • Deterministic Exit Codes:
    • 0: Success (analysis succeeded and confidence meets --fail-under if set).
    • 1: Threshold failure (confidence strictly below --fail-under).
    • 2: Invocation / CLI usage error (unknown options, missing arguments, invalid threshold, missing/non-existent directory).
  • Documentation: Documents CLI options, exit codes, example JSON, and a formal JSON Schema (Draft 2020-12) in README.md.

Type of change

  • New rule (MIG-xxx)
  • Bug fix
  • Documentation
  • Internal refactor / test coverage
  • New feature (CLI tooling & CI support)

Checklist

  • mvn test passes
  • New behaviour is covered by a test
  • Nothing here modifies the user's original project (read-only by default)
  • Rules are AST-based and deterministic, not AI-generated transformations
  • Any new mapping was checked against the Selenium Boot docs first
  • If a new rule was added, the table in README.md was updated

Notes for reviewers

  • Zero new dependencies: Built a dedicated JsonRenderer to keep the project lightweight and avoid adding Jackson / external libraries to the shaded JAR.
  • Cross-platform path normalization: Relative file paths (unparsableFiles and findings[].file) normalize backslashes to / so JSON outputs are deterministic across Windows and Linux.
  • Test coverage:
    • ReportJsonTest.java: Validates JSON structure, empty reports, finding details, escaping of quotes/newlines/control characters.
    • CliTest.java: Covers in-memory execution and actual OS subprocess execution (ProcessBuilder) verifying exit codes 0, 1, 2, argument order permutations, and edge-case validation.

closes #9

@shossain786

Copy link
Copy Markdown
Contributor

Thanks for this, reviewed the code. Two things to fix before merge:

  1. Exit code 1 means two different things. Right now, if analysis crashes (e.g. can't read a file), it exits with code 1 — same code as "quality gate failed". In CI this would look like a real gate failure instead of a crash. Can we use a different exit code for real errors?

  2. JSON schema says line is always ≥ 1, but code can output line: 0. This happens when a node's position isn't found. If a CI tool validates against your schema, it'll reject a valid report.

Smaller nit: the byRule counting logic in JsonRenderer is copy-pasted from Report.render() — worth pulling into one shared method so they don't drift apart.

@PUSHPAK-JAISWAL

Copy link
Copy Markdown
Contributor Author

@shossain786 on it

@PUSHPAK-JAISWAL

Copy link
Copy Markdown
Contributor Author

@shossain786 i made some changes those are :-
Introduced Exit Code 3 for Runtime Errors
Added ruleCounts(): Extracted the byRule aggregation into public Map<String, Long> ruleCounts().
Refactored render(): Updated render() to consume ruleCounts() instead of computing the map inline.
Deduplicated byRule: Replaced the duplicated counting logic with report.ruleCounts().
Removed Unused Import: Removed java.util.TreeMap.
Updated Exit Codes Table: Documented exit code 3 as runtime/I/O error.
Fixed JSON Schema: Changed "line" from "minimum": 1 to "minimum": 0 and clarified that 0 denotes an unavailable AST position.
Added unit test rendersLineZeroWhenPositionUnavailable() verifying line: 0 serializes properly.
Added unit test ruleCountsProvidesSharedAggregation() verifying shared rule-counting behavior.
Added in-memory test returnsExitCodeThreeOnRuntimeError verifying exit code 3 on I/O failure.
Added a subprocess test in processExitCodes verifying OS exit code 3.

@shossain786

Copy link
Copy Markdown
Contributor

Both fixes look right — exit code 3 cleanly separates runtime errors from quality-gate failures now, and the schema/line:0 handling checks out. Ran the full suite locally too (55/55 green) plus a manual smoke test of --format json --fail-under. Thanks for the thorough follow-through on the review, merging this.

@shossain786
shossain786 merged commit 7784bc3 into seleniumboot:main Oct 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI-friendly output: --format json and exit codes

2 participants