Skip to content

test(util): skip build caches in source walker - #178

Merged
kaitranntt merged 1 commit into
kaitranntt:mainfrom
warelik:fix/nocopy-walker-build-dirs
Aug 19, 2026
Merged

test(util): skip build caches in source walker#178
kaitranntt merged 1 commit into
kaitranntt:mainfrom
warelik:fix/nocopy-walker-build-dirs

Conversation

@warelik

@warelik warelik commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

test(util): skip build caches in source walker

The no-copy invariant source walker (forEachSourceFile) hard-coded a small
set of directories to skip before descending (.git, vendor,
node_modules, testdata). It did not skip the workspace's own build/tool
directories (.tmp_build, .go-cache, .go-tmp, .gocache), so the scan
could walk cloned or generated Go sources that must not be treated as product
code.

This PR generalizes the exclusion into a named skippedWalkDirs map and adds
the 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, .gocache

This is an explicit allow/skip list — not a broad "skip all hidden dirs"
weakening. Arbitrary hidden source directories (e.g. .hidden-source) are
still scanned by the walker.

Regression coverage

TestForEachSourceFileSkipsBuildDirs:

  • seeds every listed skip dir under a temp root with a poisoned *.go file,
  • asserts none of those dirs are walked (no FORBIDDEN content observed),
  • seeds a .hidden-source dir 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
  • focused test normal, -race, -race -count=3 — PASS
  • go test ./internal/utilok; -raceok
  • go test ./... — all packages ok
  • go build ./... — clean
  • go vet ./internal/util — exit 0

Note: on this machine two packages (sdk/cliproxy, test) initially
failed with link: mkdir /tmp/go-link-*: operation not permitted — a system
/tmp permission issue unrelated to this change. Both pass when TMPDIR is
redirected to a writable directory.

Changes

  • internal/util/nocopy_invariant_test.go (+54 / −2)

Mirror

CPA: router-for-me/CLIProxyAPI#4947 (identical changes)

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.
@warelik

warelik commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@kaitranntt
kaitranntt merged commit b8f94a8 into kaitranntt:main Aug 19, 2026
2 checks passed
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.

2 participants