Repository navigation
feat(coverage,cli,mcp): read Go coverprofile reports natively - #2192
Merged
Merged
Conversation
Add a go-coverprofile format: a parser that expands each block to the lines it spans (larger count wins where blocks overlap, statement-less blocks are skipped), detection on the mode: header, and the --report-format value on coverage diff, coverage merge and the MCP tool. A Go profile's import paths lose the module path from the go.mod at the repository root so they are repo-relative; --strip-prefix covers other layouts. Refs #2186
Describe the line model, the module-path mapping and the new --report-format value, and add the changelog entry. Refs #2186
…e blocks coverage merge looked for go.mod in the invocation directory, so running it from a subdirectory left import paths unmapped; it now uses the repository working directory, like the default strip prefix. module_path reads the parenthesised module ( ... ) form, the Go parser builds each file once rather than per block, and the docs say that blank and comment lines inside a block count and that the working-tree go.mod also maps the baseline. Refs #2186
CoverageTotal: 97.95% ⚪ 0 pp vs Comparing
🔇 269 ignored region(s), 0 tolerated region(s)
Patch coveragePatch: 99.76% (419/420 new lines covered)
Uncovered new lines (1)
|
3 tasks done
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.
Description
Closes #2186
coverage diffandcoverage mergenow read Gogo test -coverprofilefiles natively, with nogocover-cobertura/gcov2lcovstep.src/coverage/go_coverprofile.rs): eachfile:startLine.startCol,endLine.endCol numStmts countblock is expanded to every line it spans; where blocks overlap the larger count wins (the model's existing rule), so a line shared by two blocks (} else {) reads covered if either ran. A line is executable when a block with statements spans it, so the total counts lines and differs fromgo tool cover -func's statement-weighted figure; statement-less blocks (empty bodies) are not lines.set/count/atomicshare one grammar; a repeatedmode:line (acatof shards) is accepted.Format::GoCoverprofiledetected by a leadingmode:;go-coverprofileis a--report-format/--baseline-report-formatvalue on both commands and on the MCP tool.read_reportstrips the module path from the repo-rootgo.mod(looked up in the git workdir, as the default strip prefix is). A module not at the root, or nogo.mod, leaves paths as written;--strip-prefix <import path of the repo root>covers that.docs/coverage.mdnew "Go coverprofiles" section, README, docs index),CHANGELOG.md, and thehelp_all_outputsnapshot (reviewed: only the five intended help lines changed).The plan was posted on the issue: #2186 (comment). The work followed it; the only addition is that the
go.modlookup uses the git workdir (found in review).Type of Change
Testing
--report-formatvalue list grows)Verification
cargo fmt --check: cleancargo clippy --all-targets -- -D warnings, with and without--features mcp: cleancargo test --features mcp: 14071 lib tests + all integration suites passed (run before the review-fix commit); after it,cargo test --features mcp --lib coverage(304) and--test integration_test(64, includes the snapshot) passcargo doc --no-deps --document-private-itemswith-D rustdoc::broken_intra_doc_links: clean (-D warningsalso trips pre-existing private-link errors in unrelated modules)python3 scripts/check_changelog.py --base origin/main: ok;omni-dev git commit message lint --strict: 0 errors:and spaces in names,go.modparsing, sharded profiles throughcoverage mergeandcoverage diff(equal figures), thego.modmapping, its absence, a non-matching module, the--strip-prefixoverride, and running from a subdirectory.Validated against real Go output
With Go 1.27.1 I built a two-package module, committed a base and a head revision, and ran
go test -covermode=set|count|atomic -coverprofilefor each mode, plus one profile per package, with the branch build:catof them, and--report-format go-coverprofileall give the same figures, andcoverage mergewrites repo-relative lcov (SF:pkg/a/a.go) with the rootgo.modmapping applied;--strip-prefix example.com/monomaps it, as documented;func Empty() {}is a0 0block,else ifshares one line between a covered and an uncovered block (reads covered), and a block starts at its first statement and ends at its last, so a comment before the first statement is outside the range. The docs' caveat was narrowed to that (last commit).Not verified
omni-dev git commit message check(AI-backed) could not run here: the configured API key is rejected (401). The non-AI lint passed.Review findings not acted on
ignoremarkers can mask them.go.mod, so a baseline measured before a module rename won't map: documented (--strip-prefixis the answer); readinggo.modfrom the base revision is a larger change.go.modis missing/unmatched: no warning added; paths left as written and the docs say what to pass. A warning would false-positive when--strip-prefixis the intended route.mode:lines merge by max: deliberate and tested; only zero-vs-nonzero reaches the output.resolvemade public, split resolve/parse inread_report: no doubled error context in practice; kept simple.Follow-ups
None filed.
Checklist
docs/coverage.md, README, CHANGELOG)-D warnings)