8000 Keep combined coverage when Go cannot resolve a package by Boulea7 · Pull Request #1697 · onsi/ginkgo · GitHub
[go: up one dir, main page]

Skip to content

Keep combined coverage when Go cannot resolve a package - #1697

Merged
onsi merged 2 commits into
onsi:masterfrom
Boulea7:fix/summarize-cross-module-coverage
Dec 2, 2026
Merged

onsi merged 2 commits into
onsi:masterfrom
Boulea7:fix/summarize-cross-module-coverage

Conversation

@Boulea7
@Boulea7 Boulea7 commented Dec 2, 2026
Copy link
Copy Markdown
Contributor

Fixes #1323.

Ginkgo writes a valid merged coverage profile after suites pass across multiple Go modules. It can still exit with an error when go tool cover -func cannot resolve a covered package from the invoking module.

When Go’s package lookup confirms that failure, compute composite coverage from the covered and total statement counts in the merged profile. Keep Go’s existing summary when it succeeds and retain errors from invalid profiles or other failures.

A CLI regression exercises two modules with different statement counts and checks the 50.0% total in default and vendor modes. All 225 CLI integration specs and go vet ./... passed. The full suite had one Gomega timeout stack assertion failure on Go 1.27.4, also reproduced on the base commit.

Developed and verified with assistance from OpenAI Codex.

@onsi
onsi commented Dec 2, 2026
Copy link
Copy Markdown
Owner

Thanks @Boulea7 - this is a real fix for a long-standing issue, and I've confirmed the new spec fails on master with #1323's exact error and passes with this PR.

I like how you've approached it - the counting fallback is a good compromise though it doesn't always produce exactly the same numbers as go tool cover -func (Go's total: line only counts blocks inside top-level func declarations, so blocks in package-level function literals (var handler = func() {...}) are left out of Go's number but included in a profile-wide count. (On a small example I get 66.7% from Go vs 62.5% from the profile.)) I think that's ok and better than failing outright.

One request: could we drop the go list lookup and the error-text suffix match in hasCoverPackageLookupFailure? Matching on the wording of go tool cover's error output is brittle - if a future Go release rewords it. I think it's simpler to just fall back whenever go tool cover fails but the merged profile parses (cover.ParseProfiles will still reject a genuinely invalid profile, so those keep erroring).

Please also add a small docs note in docs/index.md that a composite computed via the fallback can differ slightly from Go's.

Also, a question: you've mentioned twice now that a Gomega timeout-stack spec fails for you locally on Go 1.27.4. Which spec is it, and what does the failure output look like? I just upgraded to 1.27.4 here and Ginkgo's full race suite (and Gomega's and Biloba's) pass, so I'd love to know what's different in your setup.

Thanks again!

@Boulea7
Boulea7 commented Dec 2, 2026
Copy link
Copy Markdown
Contributor Author

Thanks for checking the repro. 6a25581 removes Ginkgo’s extra package lookup and error-text matching. If go tool cover -func fails, the CLI now uses the statement counts from a parseable merged profile. A malformed profile still fails. I added the docs note about package-level function literals and regression cases for moved source and a damaged profile.

The timeout spec was “doesn't get stuck because Eventually will exit and it includes the additional report provided by eventually” in internal/internal_integration/interrupt_and_timeout_test.go. The assertion on Failure.AdditionalFailure at line 950 reported Value for field 'Failure.Location' failed to satisfy matcher. Both locations pointed to line 938. The actual FullStackTrace contained frames for RunTracker.TSC and Suite.runNode, while the matcher expected "".

I traced that to my checkout path. On macOS 27.0.1 arm64 with Go 1.27.4, the same f5e8c843 snapshot failed in a folder named renamed and passed in a folder named ginkgo, both with and without --race (--procs=2 --seed=42). types.PruneStack filters source paths containing /ginkgo/. The updated PR head passes all 435 specs in that internal suite in the ginkgo layout, and the focused race check passes too.

@onsi
onsi merged commit c8ce458 into onsi:master Dec 2, 2026
6 checks passed
@onsi
onsi commented Dec 2, 2026
Copy link
Copy Markdown
Owner

Merged - thanks @Boulea7! The simplified fallback reads much better, and the after-run-hook specs are a neat way to force go tool cover -func to fail deterministically.

And thank you for tracking down the timeout-spec failure: you're right that it's the checkout directory name. PruneStack identifies Ginkgo's frames by a /ginkgo/ path component, so a checkout in renamed/ leaks Ginkgo's frames into FullStackTrace. I'm switching it to recognise Ginkgo's frames by package instead, which also stops it from hiding user frames that happen to live under a directory named ginkgo.

onsi added a commit that referenced this pull request Dec 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FockBuVhFMJNJ2AzJrBbBn
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.

Could not process Coverprofile for multi-module project

2 participants

0