Skip to content

Fix branch coverage tracking and expand test suite #444

Open
benber86 wants to merge 38 commits intomasterfrom
fix/coverage-refactor
Open

Fix branch coverage tracking and expand test suite #444
benber86 wants to merge 38 commits intomasterfrom
fix/coverage-refactor

Conversation

@benber86
Copy link
Collaborator

@benber86 benber86 commented Mar 2, 2026

What I did

Branch coverage barely worked with conditional statements/loops/multiline statements as described in #327.

How I did it

  • Replaced ast-based coverage trace approximation with bytecode based one
  • Used fuzzer + mutation test based harness to get claude to find, fix and write tests for all edge-cases

How to verify it

python -m pytest tests/unitary/test_coverage

Description for the changelog

Fix branch coverage and expand test suite

Cute Animal Picture

image

benber86 and others added 8 commits March 2, 2026 21:00
The compiler's pc_raw_ast_map already maps JUMPI PCs to their If AST
nodes. Instead of six JUMPI-finding functions (forward scan, backward
scan, noop backward, helper gap detection, path classification,
event building), just walk the raw trace and when we hit a JUMPI that
maps to an If node, check the next PC to determine direction.

coverage.py: 815 lines → 497 lines
- Remove _build_coverage_events, _find_jumpi_forward_scan,
  _find_jumpi_noop_backward, _find_jumpi_backward, _has_helper_gap,
  _classify_from_raw_trace, _resolve_jumpi_direction
- Replace CoverageCollector with BranchCollector
- Keep reporter improvements (noop branch exclusion, multiline
  handling, proper false target resolution)

environment.py: simplify _trace_computation to pass computation
directly to collector instead of building event segments
@benber86
Copy link
Collaborator Author

benber86 commented Mar 3, 2026

  • Forced disabling optimizations when using branch coverage (users get warning)
  • Disabling optimization allows to remove most of the yuge amount code that used heuristics to deal with branch removals/op code changes
  • Removed multiline statement handling (exclusion) logic (added complexity but only gives a slightly more accurate statement count in report, coverage still readable either way)
  • We now just walk the trace, if a PC is JUMPI we look up corresponding AST Node in pc_raw_ast_map, then walk AST to find branch targets (_branch_arcs_for_if). From the trace we infer which arc was executed by checking if next trace PC == next bytecode PC or not.
  • Trimmed down test suite to remove exotic edge cases

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