Skip to content

coverage: add per-file branch coverage metrics#775

Open
dguido wants to merge 1 commit into
masterfrom
dev/branch-coverage-per-file
Open

coverage: add per-file branch coverage metrics#775
dguido wants to merge 1 commit into
masterfrom
dev/branch-coverage-per-file

Conversation

@dguido

@dguido dguido commented Jan 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Add per-file branch coverage calculation alongside existing line coverage
  • Update HTML coverage report to display branch coverage metrics at both overall and per-file levels
  • Track branches as JUMPI (conditional jump) instructions in EVM bytecode

Changes

fuzzing/coverage/source_analysis.go:

  • Add TotalBranches and CoveredBranches fields to SourceFileAnalysis
  • Add TotalBranchCount() and CoveredBranchCount() methods to SourceAnalysis
  • Add analyzeContractBranchCoverage() function that identifies JUMPI instructions and maps them to source files

fuzzing/coverage/report_template.gohtml:

  • Add Branch Coverage stat card to the overview section
  • Update per-file headers to show both line and branch coverage badges
  • Update per-file stats section to show branches alongside lines
  • Update file tree tooltips to include branch coverage information

Test plan

  • Build passes: go build ./...
  • Vet passes: go vet ./...
  • Manual testing: Run medusa on a contract with conditionals and verify branch coverage appears in the HTML report
  • Verify the branch coverage percentage accurately reflects conditional paths tested

Fixes #285


Generated with Claude Code

Add branch coverage tracking alongside existing line coverage to help
users understand if all conditional paths are being tested. The coverage
report now displays:

- Overall branch coverage statistics (total branches, covered branches)
- Per-file branch coverage percentage in the file header
- Branch coverage in the file stats section
- Branch coverage information in the file tree tooltips

Branches are identified as JUMPI instructions in EVM bytecode, which
represent conditional jumps in Solidity code (if statements, loops,
ternary operators, etc.).

Fixes #285

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

Calculate and show branch coverage per file

1 participant