Skip to content

Keep branch and method data the resultsets carried - #1256

Merged
sferik merged 1 commit into
mainfrom
merge-preserves-measured-criteria
Aug 8, 2026
Merged

sferik merged 1 commit into
mainfrom
merge-preserves-measured-criteria

Conversation

@sferik

@sferik sferik commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

A merge runs on behalf of the processes that produced the resultsets, and does not necessarily share their configuration. simplecov merge only requires the library, so it never runs SimpleCov.start and measures nothing at all. A SimpleCov.collate block need not repeat enable_coverage :branch either.

Such a process dropped the branch table from every file that appeared in more than one resultset, while passing through untouched the table of any file that appeared in only one:

merging process branch_coverage? false
  sample.rb        keys=["lines"]              branches GONE
  resultset1.rb    keys=["lines", "branches"]  branches kept

So the merged output was both lossy and internally inconsistent, and merge_and_store wrote that state back to disk for the next collate to read.

A criterion is in play when the merging process measures it or when the data carries a table for it, and it stays in play once any absorbed side has carried one. Nothing a producer measured is lost, and a process that does measure a criterion still always gets a table, even an empty one, which is what lets SourceFile tell "no branches in this file" apart from "branch coverage was off".

That second half is why this is a union rather than a swap. Deciding purely from the data looks cleaner, and I tried it first, but it drops the guarantee that an enabled criterion always yields a table. spec/combine/results_combiner_spec.rb pins that guarantee for a reason, and removing it would hand SourceFile a nil where it expects a hash.

This predates the accumulator. FilesCombiner gated on the same configuration before #1254 replaced it, so the behavior goes back well beyond the merge rewrite.

@sferik
sferik requested a balanced review from Copilot August 8, 2026 01:17

This comment was marked as resolved.

@sferik
sferik force-pushed the merge-preserves-measured-criteria branch from e422117 to 16e05c4 Compare August 8, 2026 01:53
@sferik
sferik requested a balanced review from Copilot August 8, 2026 01:58

This comment was marked as resolved.

A merge runs on behalf of the processes that produced the resultsets and
does not necessarily share their configuration. `simplecov merge` only
requires the library, so it never runs SimpleCov.start and measures
nothing, and a SimpleCov.collate block need not repeat enable_coverage
:branch. Such a process dropped the branch table from every file that
appeared in more than one resultset, while passing through untouched the
table of any file that appeared in only one:

  merging process branch_coverage? false
    sample.rb      keys=["lines"]              branches GONE
    resultset1.rb  keys=["lines", "branches"]  branches kept

So the merged output was both lossy and internally inconsistent, and
merge_and_store wrote that state back to disk for the next collate to
read.

A criterion is now in play when the merging process measures it or when
tuples that survive reconciliation carried it. Nothing measured is lost,
and a process that does measure a criterion still always gets a table,
even an empty one, which is what lets SourceFile tell "no branches in
this file" apart from "branch coverage was off".

Which tuples survive needs two things said. A simulated side's
synthesized tuples are dropped when the other side ran, and the criterion
goes with them: keeping an empty table there would claim the file has no
branches when the truth is that nobody measured them in the run that
executed it. The side that ran therefore decides which criteria the file
carries, not only their tuples, which is also what keeps the answer
independent of which side is absorbed first.

And a side is only judged when it can be. Absent lines do not mean a side
never ran: a branch-only or method-only run omits them even for the files
it loaded, so judging on their absence discarded the real branch counts
such a run had measured. Unknown now means union, which is already what
happened when neither side carried lines. never_executed_files guards the
same conflation for the same reason.

This predates the accumulator. FilesCombiner gated on the same
configuration before it, so the behaviour goes back well beyond the merge
rewrite.
@sferik
sferik force-pushed the merge-preserves-measured-criteria branch from 16e05c4 to 5ecb8bc Compare August 8, 2026 02:07
@sferik
sferik requested a balanced review from Copilot August 8, 2026 02:15

This comment was marked as resolved.

@sferik
sferik merged commit 5afe987 into main Aug 8, 2026
21 checks passed
@sferik
sferik deleted the merge-preserves-measured-criteria branch August 12, 2026 19:51
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.

2 participants