Repository navigation
Scope the Go scan of a module without go.sum to its go.mod requires - #2169
Conversation
A local Go scan looks up only the modules the project's go.sum records and its go.mod requires, but only when a go.sum exists. Without one the crawl walked the whole module cache, so a module on the standard library alone (no require, no go.sum) was reported as having every module other projects left in GOMODCACHE. The patch lookup then matched some of them and the write step refused each one as outside the build graph: a warning per module in hosted mode, an error per module and exit 1 in vendored mode, and an offer to patch them in place in agent mode. A missing go.sum now scopes the crawl to go.mod's requires. go writes a go.sum line for every module it loads from the cache, so without the file the build takes nothing from the cache that go.mod does not name. The walk is kept where go.mod may not describe the build: a Go workspace in effect, a go.sum that is there but cannot be read, and a -modfile in GOFLAGS (go then builds from another file with its own .sum). --global and --global-prefix still walk the cache. Three e2e_golang tests staged a cache next to a go.mod with no requires and expected the whole cache back; their projects now require the modules they stage. A new test covers the reported case end to end: nothing is scanned and no module is sent to the API. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of the previous commit: - A go.mod older than go 1.17 (or with no go directive) lists lower bounds only: what its requires need in turn is part of the build and is named only by go.mod files in the cache. With no go.sum, such a go.mod with requires keeps the whole-cache walk, so those modules are still scanned. A go.mod with no requires has no module graph and is scoped whatever its go version. - A -modfile in GOFLAGS keeps the walk whether or not a go.sum is there: go builds from the named file and its .sum, not from go.mod and go.sum. Before, a go.sum scoped the crawl to files go was not reading. - e2e_golang scrubs the developer's go settings (GOFLAGS, GOWORK and the go env -w file now change which modules a project scan looks up). - e2e_golang runs the discovery and case-encoding tests through --global-prefix too, so the walk's cache/ pruning and case decoding stay covered now that the project scans no longer walk. - crawl_all's comment points at go_sum_scope for the cases that walk. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview The full-cache walk is still used where the build graph cannot be inferred from the project files alone: Go workspaces, Tests invert the old “no go.sum → walk all” expectation, add cases for walk retention and Reviewed by Cursor Bugbot for commit 5e12b41. Configure here. |
Summary
A local Go scan looks up only the modules the project's
go.sumrecords and itsgo.modrequires, but only when ago.sumexists. Without one, the crawl walked the whole module cache. A module that imports only the standard library has norequireand nogo.sum, so it was reported as having every module other projects left inGOMODCACHE.A missing
go.sumnow scopes the crawl togo.mod's requires, when those are the build list: ago.modthat prunes the module graph (go 1.17 or later) requires every module that provides a package to the build, and one with no requires has no module graph.Behaviour
scanin a module with norequireand nogo.sum, on a machine whose module cache holds a few hundred modules from other projects, four of which have patches:not in this project's build graphwarning per patched module; exit 0No golang packages found.; exit 0Cannot vendorerror each; exit 1No golang packages found.; exit 0--dry-run)No golang packages found.; exit 0A go 1.17+ module that has requires but no
go.sumnow finds only those requires. The required module is patched as before, without the warnings (hosted) or errors and exit 1 (vendored) for unrelated cached modules.A project with a
go.sumis unchanged, with one exception:-modfile(below).What still walks the cache
The walk is kept where
go.modandgo.summay not describe the build:go.work, orGOWORK)-modfileinGOFLAGS: go builds from the named file and its.sum. This now holds with ago.sumpresent too. Before, ago.sumscoped the crawl to two files go was not readinggo.sumthat is there but cannot be readgo.sum, and ago.modthat cannot be readgo.sum, and ago.modolder than go 1.17 (or with nogodirective) that has requires: it lists lower bounds only, and what its requires need in turn is named only bygo.modfiles in the cache--globaland--global-prefixTests
go_crawlerunit tests: the test that pinned the old fallback is inverted (without_a_go_sum_only_the_requires_of_go_mod_are_crawled). Two new ones cover the cases that keep the walk (an_older_go_mod_with_requires_and_no_go_sum_keeps_the_walk,another_modfile_or_an_unreadable_go_sum_keeps_the_walk). The fixture now also unsetsGOFLAGSand setsGOENV=off, so a developer's own go settings cannot change the result.e2e_golang: three tests staged a cache beside ago.modwith no requires and expected the whole cache back. Their projects now require the modules they stage. The discovery and case-encoding tests also run through--global-prefix, so the walk'scache/pruning and case decoding stay covered. A new test,scan_of_a_module_without_dependencies_ignores_the_shared_cache, covers the reported case end to end: nothing is scanned and nothing is sent to the API. The helper scrubs the developer's go settings.socket-patch-coresuite, the 26 CLI test binaries that exercise Go, and CI's clippy command. The rest of the CLI suite was left to CI.go.sum(hosted and vendored), the same module declaredgo 1.16(walk kept), and a tidy module in hosted mode followed bygo build.Review
/code-review highreported five findings and all five are fixed in the second commit: the pre-1.17go.modcase,-modfilewith ago.sumpresent, the e2e helper's go settings, walk coverage ine2e_golang, and thecrawl_allcomment.Not in this PR
A
go.workworkspace still walks the whole cache, so it still gets the same false warnings in hosted mode and the same errors and exit 1 in vendored mode. Scoping it to its members'go.modandgo.sumplusgo.work.sumis a follow-up. So is scoping a pre-1.17 module without ago.sumfrom the module graph in the cache.🤖 Generated with Claude Code