Skip to content

Fix branch tuple identity mismatches - #1207

Merged
sferik merged 5 commits into
simplecov-ruby:mainfrom
kettle-dev:kettle-dev/branch-identity-repro
Jun 21, 2026
Merged

sferik merged 5 commits into
simplecov-ruby:mainfrom
kettle-dev:kettle-dev/branch-identity-repro

Conversation

@pboling

@pboling pboling commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix branch tuple identity mismatches that can duplicate equivalent branches when static branch extraction, runtime branch coverage, and serialized resultsets are combined.

This PR:

  • emits :unless static branch tuples for Prism::UnlessNode, matching Ruby Coverage
  • emits static :\"&.\" branch tuples for safe-navigation calls, matching Ruby Coverage
  • merges branch resultset tuples by branch type and source location instead of by the local sequential id
  • restores serialized tuple keys through the existing Ruby data parser before comparing branch identity
  • adds focused regression specs and a changelog entry

Closes #1206.

Validation

  • bundle exec rubocop passes.
  • Focused specs: bundle exec rspec spec/static_coverage_extractor_spec.rb spec/combine/branches_combiner_spec.rb reports 29 examples, 0 failures, 2 pending; the command exits 2 because SimpleCov's own dogfood coverage gate requires 100% whole-project coverage on partial spec runs.
  • bundle exec rake passed RuboCop and the full RSpec suite with 1124 examples, 0 failures, 2 pending and 100% dogfood line/branch/method coverage, then local Cucumber entered a long retry/failure loop before completion in my environment.

Environment

  • SimpleCov: 1.0.0.rc3
  • Ruby: ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]

Copilot AI review requested due to automatic review settings June 20, 2026 23:55

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.

Pull request overview

This PR fixes branch-coverage tuple identity mismatches that could cause equivalent branches to be duplicated (inflating totals) when combining static branch extraction, runtime branch coverage, and serialized resultsets.

Changes:

  • Update static Prism extraction to emit :unless for Prism::UnlessNode and emit safe-navigation branches as :"&.", aligning tuple types with Ruby Coverage.
  • Update branch result merging to merge by (type, source range) (ignoring the local sequential id) and to normalize serialized tuple keys via SourceFile::RubyDataParser before comparison.
  • Add focused regression specs plus a changelog entry describing the bugfix.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
spec/static_coverage_extractor_spec.rb Updates/extends specs to assert tuple types for unless and safe navigation match Coverage expectations.
spec/combine/branches_combiner_spec.rb Adds regression tests ensuring equivalent branches merge correctly even when ids differ or keys are serialized strings.
lib/simplecov/static_coverage_extractor/visitor.rb Emits :unless tuples for UnlessNode and adds safe-navigation branch emission for Prism call nodes.
lib/simplecov/combine/branches_combiner.rb Changes merge strategy to use tuple identity based on type + source range, normalizing serialized tuple strings via RubyDataParser.
CHANGELOG.md Documents the bugfix in the unreleased main section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@sferik
sferik merged commit 9b5123c into simplecov-ruby:main Jun 21, 2026
10 checks passed
sferik added a commit that referenced this pull request Jun 21, 2026
The visitor now emits :unless for unless nodes (#1207), so the comment's
claim that it "reports :if for unless and ternary" was no longer true.
Reword to explain the conservative start_line-only matching without citing
a specific, now-inaccurate type mismatch.
@pboling
pboling deleted the kettle-dev/branch-identity-repro branch June 21, 2026 13:33
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.

Static branch extraction can duplicate equivalent branches after resultset serialization

3 participants