Skip to content

Record branch coverage from the minitest runs too - #417

Merged
exoego merged 1 commit into
masterfrom
fix/minitest-branch-coverage
Aug 5, 2026
Merged

Record branch coverage from the minitest runs too#417
exoego merged 1 commit into
masterfrom
fix/minitest-branch-coverage

Conversation

@exoego

@exoego exoego commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Answering "are we even running minitest?" — yes, six spawned runs (three Rails, three Roda). But they were contributing line coverage and no branch coverage at all: 0 of the 27 library files they load carried branch data.

Cause

.simplecov_spawn.rb asked for branch coverage inside the SimpleCov.start block, which sits below SimpleCov.at_fork.call. That lambda calls SimpleCov.start itself, and once Coverage is running its mode is fixed, so the request arrived too late.

The rspec runs were unaffected: they go through scripts/rspec_with_simplecov, which starts SimpleCov with branches on before .simplecov_spawn is loaded. Only the runs spawned as plain ruby -r./.simplecov_spawn — the minitest ones — hit it.

Configuring before at_fork fixes it. 23 of 27 files now carry branch data; the other 4 have no branches at all.

Effect

master this PR
branches measured 446 456
branches covered 426 437
lines with an uncovered branch 20 19

Ten branches became visible. Most were already exercised — including the require 'rspec/openapi/minitest_hooks' that was being reported as never taken while minitest was plainly running through it, which is what makes this worth fixing beyond the number.

It also surfaced two branches in minitest_hooks.rb that nothing exercised, so a minitest run now covers them: it resolves path from a proc, and it appends a record the schema builder cannot handle so the after_run reporter has something to report. The rspec side already had the equivalent in rspec_hook_error_spec.

Note the headline percentage barely moves, because the denominator grew along with the numerator. The point is that the measurement is now honest about a sixth of the suite.

Verified

  • 15 spec files, 0 failures; every committed document regenerates byte for byte.
  • Rubocop reports the same 4 pre-existing offenses as master.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling when recorded requests cannot be converted into an OpenAPI document.
    • Error messages now identify how many requests could not be processed and include the underlying type-detection issue.
  • Tests

    • Added coverage for Rails and Minitest hook failures.
    • Added validation for branch coverage in forked test runs.

The six spawned minitest runs were contributing line coverage and no branch
coverage at all: 0 of the 27 library files they load carried branch data.

SimpleCov.at_fork's lambda calls SimpleCov.start itself, and once Coverage is
running its mode is fixed, so the `enable_coverage :branch` in the start block
below it arrived too late. The rspec runs were unaffected because they go
through scripts/rspec_with_simplecov, which starts SimpleCov with branches on
before .simplecov_spawn is loaded. Configuring before at_fork fixes it: 23 of
27 files now carry branch data, the rest having no branches at all.

That makes 10 more branches visible. Most were already covered, and it also
surfaced two in minitest_hooks that nothing exercised, so a minitest run now
covers them: it resolves `path` from a proc, and it appends a record the
schema builder cannot handle so the after_run reporter has something to
report. The rspec side already had the equivalent.

  branches measured   446 -> 456
  branches covered    426 -> 437
  partials             20 -> 19
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 82862539-c3bd-452f-98f5-89279f68d3e3

📥 Commits

Reviewing files that changed from the base of the PR and between 847c643 and 9f363f5.

📒 Files selected for processing (3)
  • .simplecov_spawn.rb
  • spec/integration_tests/rails_hook_error_test.rb
  • spec/minitest/hook_error_spec.rb

📝 Walkthrough

Walkthrough

The change moves SimpleCov branch coverage configuration before fork initialization. It adds Rails/Minitest coverage for recorder hook errors caused by an unbuildable response body.

Changes

Coverage and hook error validation

Layer / File(s) Summary
SimpleCov fork setup
.simplecov_spawn.rb
Branch coverage and path filters are configured before SimpleCov.at_fork.
Recorder hook error flow
spec/integration_tests/rails_hook_error_test.rb, spec/minitest/hook_error_spec.rb
The integration fixture creates an unbuildable recorded response. The spec verifies the failed request count and type-detection error text.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling branch coverage recording for minitest runs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/minitest-branch-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.32%. Comparing base (847c643) to head (9f363f5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #417      +/-   ##
==========================================
+ Coverage   98.23%   98.32%   +0.09%     
==========================================
  Files          27       27              
  Lines        1076     1076              
  Branches      209      214       +5     
==========================================
+ Hits         1057     1058       +1     
+ Partials       19       18       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@exoego
exoego merged commit 3f90bf4 into master Aug 5, 2026
19 checks passed
@exoego
exoego deleted the fix/minitest-branch-coverage branch August 5, 2026 04:42
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.

1 participant