Skip to content

Exempt baselined files from per-file checks under oneshot_line - #1339

Merged
sferik merged 2 commits into
simplecov-ruby:mainfrom
yamamoto7:fix/oneshot-baseline-exemption
Nov 8, 2026
Merged

sferik merged 2 commits into
simplecov-ruby:mainfrom
yamamoto7:fix/oneshot-baseline-exemption

Conversation

@yamamoto7

Copy link
Copy Markdown
Contributor

With oneshot: true, a file that has an entry in .simplecov_baseline.yml is still held to the per-file minimum and the per-file missed cap. The baseline is meant to exempt it ("Files with an entry are exempt from the per-file minimum (per criterion)", docs/Configuration.md), and without oneshot: true it is.

Reproduction

# run.rb
require "simplecov"
SimpleCov.root __dir__
SimpleCov.command_name "repro"
SimpleCov.start do
  formatter SimpleCov::Formatter::SimpleFormatter
  coverage :line, oneshot: true, primary: true do
    minimum 90, per: :file
  end
end
require_relative "lib/legacy"
Legacy.new.used
# lib/legacy.rb (4 of 5 lines covered, 80%)
class Legacy
  def used
    :used
  end

  def unused
    :unused
  end
end
# .simplecov_baseline.yml
lib/legacy.rb:
  lines:
    percent: 50.0
    missed: 2
no baseline with the baseline above
coverage :line exit 2 exit 0
coverage :line, oneshot: true exit 2 exit 2

With the baseline, the oneshot run still prints:

Oneshot_line coverage by file (80.00%) is below the expected minimum coverage (90.00%) in lib/legacy.rb.
SimpleCov failed with exit 2 due to a coverage related error

Cause

Oneshot results are folded into the :line statistics, and a baseline stores line floors under :line. CoverageViolations.minimum_by_file and .maximum_missed_by_file called baseline.covers? with the configured criterion, :oneshot_line, so no floor was found. Both now map the criterion with SimpleCov.coverage_statistics_key, as the statistics lookups do since #1170.

This affects 1.2.0 through 1.3.2.

Testing

  • Two examples in spec/simple_cov/coverage_violations_spec.rb, one for the minimum and one for the missed cap. Both fail without the change.
  • On Ruby 4.0.5 (macOS): bundle exec rspec (6396 examples, 0 failures), standardrb and rubocop with no offenses, and mutant run 'SimpleCov::CoverageViolations*' (1304 of 1304 mutations killed).

A baseline records line floors under :line, since oneshot_line results
are folded into the :line statistics. minimum_by_file and
maximum_missed_by_file asked the baseline about the criterion as
configured, :oneshot_line, found no floor, and held a baselined file to
the per-file minimum and missed cap it should be exempt from. Look the
floor up under SimpleCov.coverage_statistics_key(criterion), which the
statistics lookups already use since simplecov-ruby#1170.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the change includes targeted regression coverage for both affected exemption paths.

No open issues 🎉

What changed in this PR

This pull request fixes baseline exemptions for per-file coverage thresholds when using oneshot_line. Because oneshot statistics are stored under the line criterion, per-file baseline checks now use the normalized statistics key.

Changes:

  • Normalize oneshot_line to line for per-file minimum and missed-cap checks.
  • Add regression tests for both exemption paths.
  • Document the fix in the changelog.
File Summary
spec/​simple_cov/​coverage_violations_spec.rb Adds regression coverage for oneshot per-file minimum and missed-cap exemptions.
lib/​simplecov/​coverage_violations.rb Uses the normalized statistics key for baseline lookups in per-file checks.
CHANGELOG.md Documents the corrected oneshot baseline behavior.

Review effort: Lite

@sferik sferik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! Thanks for fixing this!

@sferik
sferik merged commit ea151e0 into simplecov-ruby:main Nov 8, 2026
20 checks 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.

3 participants