Skip to content

Add --fail-on-low-coverage flag to exit non-zero on under-covered files - #12

Merged
cesarjr merged 1 commit into
mainfrom
fail-on-low-coverage
Jun 5, 2026
Merged

Add --fail-on-low-coverage flag to exit non-zero on under-covered files#12
cesarjr merged 1 commit into
mainfrom
fail-on-low-coverage

Conversation

@cesarjr

@cesarjr cesarjr commented Jun 5, 2026

Copy link
Copy Markdown
Member

Closes #11

Summary

  • Add a boolean --fail-on-low-coverage CLI flag. When set, couve writes the report and then exits 1 if any reported file is below the green threshold (rated 🔴 or 🟡, < 66.66%).
  • The report is written before exiting, so the offending files stay visible in the report and in any PR comment built from it.
  • The offending files are printed to stderr, e.g. couve: coverage below 66.66% in app/foo.rb, app/bar.rb.
  • Extract the 33.33 / 66.66 magic numbers into RED_THRESHOLD / GREEN_THRESHOLD constants (shared by percentage_bar_color and percentage_indicator).
  • Add public Couve::Parser#low_coverage? and #low_coverage_files. Since the constructor already narrows the source files to the reported set, these automatically respect --changed-files scope — a green or empty changed-file set passes the build.

How to test

  • bundle exec rspec — 35 examples, 0 failures.
  • bin/rubocop — no offenses.
  • Fail case: couve spec/fixtures/codeclimate.json report.md --fail-on-low-coverage exits 1 (the fixture's people_resolver.rb is at 60%) and prints the offending file to stderr, while still writing report.md.
  • Pass case: scope to a green file and confirm exit 0: echo app/javascript/routes.jsx | couve spec/fixtures/codeclimate.json report.md --changed-files - --fail-on-low-coverage.

Notes

  • Reuses the existing fixed threshold band; no new or configurable threshold.
  • No version bump or CHANGELOG entry in this PR (intentionally deferred to the release).
  • Follow-up (separate repo): wire the flag into facil123's .semaphore/semaphore.yml Coverage block so it posts the comment first, then fails.

🤖 Generated with Claude Code

Add a boolean --fail-on-low-coverage CLI flag. When set, couve writes the
report and then exits 1 if any reported file is below the green threshold
(rated red or yellow, < 66.66%), printing the offending files to stderr.

Extract the 33.33 / 66.66 magic numbers into RED_THRESHOLD / GREEN_THRESHOLD
constants and add public Parser#low_coverage? / #low_coverage_files, which
respect the existing --changed-files scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cesarjr
cesarjr merged commit 6b7f643 into main Jun 5, 2026
2 checks passed
@cesarjr
cesarjr deleted the fail-on-low-coverage branch June 5, 2026 13:11
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.

Add --fail-on-low-coverage flag to exit non-zero when a reported file is below the green threshold

1 participant