Repository navigation
ci: measure pull request coverage on the PR head - #108
Merged
Merged
Conversation
On a pull request, actions/checkout tests the merge with main, while codecov-action files the report under the PR head SHA, and Codecov draws it on that commit's lines. Once main changes a file the PR also touches, the line numbers no longer match: PR #107's patch reported 4 missing lines in src/language-model.ts that were main's uncovered branch at the same numbers, while all of the PR's own lines were hit. The required "Typecheck, test, build" job still tests the merge commit and uploads coverage only on pushes to main. A new "Coverage" job runs on pull requests from the PR head and uploads its report. Both run the same `bun run test:coverage`.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
[High impact] The PR appears safe to merge; the earlier coverage failure is fixed. SummaryThe PR separates coverage from merge testing so Codecov receives coverage measured on the PR head.
|
On pull_request the workflow comes from the merge commit, but the coverage job checks out the PR head. A branch cut before this change has no test:coverage script, so run the same two commands directly in both jobs. The script stays for local runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Codecov's patch check can fail on lines a PR never touched.
On a
pull_requestevent,actions/checkoutchecks out the merge commit withmain(its defaultref), so the tests and the lcov report come from the merged files. codecov-action v5 then files that report under the PR head SHA (its "Override commits and pr for pull requests" step falls back togithub.event.pull_request.head.sha), and Codecov draws it on the head commit's lines.When
mainhas changed a file the PR also touches, those line numbers differ. On #107, #105 had shiftedsrc/language-model.tsby about 22 lines. Codecov reported 4 missing lines, including a comment line; in the merged file those numbers are a pre-existing uncoveredfailRunProtocol(… request could not be handled …)branch. The PR's own lines, at their merged positions, were hit 104, 11 and 75 times. A Linuxbun test --coveragerun, merged or not, covered all 42 changed lines.Fix
main.mainhas no branch protection, so this is the only check that a PR still works on currentmain. It now uploads coverage only on pushes tomain, where the tested commit is the reported one.github.event.pull_request.head.shaand uploads from there, so the report matches the commit Codecov draws it on.bun test --coverage --coverage-reporter=lcov, thenbun scripts/strip-copied-coverage.ts), spelled out in the workflow. The Coverage job checks out PR heads that may predate any new script, while onpull_requestthe workflow itself comes from the merge commit.bun run test:coveragewraps the same commands for local runs.Trade-off
Tests run twice on a pull request, in parallel (about 3 more runner minutes). The alternatives were worse:
mainbefore merging.override_commit) files the report on a commit that isn't on the PR branch. codecov-action's docs don't say how Codecov compares a PR from such a commit, so I didn't rely on it.Verification
yamllintpasses, and both jobs parse with the expected names and conditions.bun run test:coveragelocally: 2377 pass, 0 fail, lcov written, 101 copied-module records stripped as before.test/architecture.test.tspasses (it scanspackage.json).No user-facing change, so no changelog entry. Adds a lesson and the
test:coveragecommand to AGENTS.md.