test(util): skip build caches in source walker - #178
Merged
Conversation
Switch the source walker's dir exclusion from a hand-written switch to a named map and extend it to cover build/tool dirs (.tmp_build, .go-cache, .go-tmp, .gocache) in addition to .git, vendor, node_modules, and testdata, so the no-copy invariant scan never descends into cloned or generated third-party sources. Add a regression test pinning that each skipped dir is not walked even when poisoned with a *.go file, and that an arbitrary hidden dir (.hidden-source) is still scanned. No walker behavior change for existing entries.
Contributor
Author
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
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.
Summary
test(util): skip build caches in source walker
The no-copy invariant source walker (
forEachSourceFile) hard-coded a smallset of directories to skip before descending (
.git,vendor,node_modules,testdata). It did not skip the workspace's own build/tooldirectories (
.tmp_build,.go-cache,.go-tmp,.gocache), so the scancould walk cloned or generated Go sources that must not be treated as product
code.
This PR generalizes the exclusion into a named
skippedWalkDirsmap and addsthe four build/tool dirs to it. Existing entries keep their exact behavior
(the switch becomes an equivalent map lookup, no walker behavior change for
entries already present).
Exact skip set
.git,vendor,node_modules,testdata,.tmp_build,.go-cache,.go-tmp,.gocacheThis is an explicit allow/skip list — not a broad "skip all hidden dirs"
weakening. Arbitrary hidden source directories (e.g.
.hidden-source) arestill scanned by the walker.
Regression coverage
TestForEachSourceFileSkipsBuildDirs:*.gofile,FORBIDDENcontent observed),.hidden-sourcedir and asserts it is scanned exactly once —guarding against an over-broad hidden-dir skip.
Verification (worktree-local
GOCACHE,GOTMPDIR,TMPDIR)gofmt -l internal/util/nocopy_invariant_test.go— clean-race,-race -count=3— PASSgo test ./internal/util—ok;-race—okgo test ./...— all packagesokgo build ./...— cleango vet ./internal/util— exit 0Changes
internal/util/nocopy_invariant_test.go(+54 / −2)Mirror
CPA: router-for-me/CLIProxyAPI#4947 (identical changes)