Skip to content

fix(test): use Go overlay instead of file copying#40

Merged
kolkov merged 2 commits into
mainfrom
fix/overlay-test-command
Mar 12, 2026
Merged

fix(test): use Go overlay instead of file copying#40
kolkov merged 2 commits into
mainfrom
fix/overlay-test-command

Conversation

@kolkov

@kolkov kolkov commented Mar 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix: racedetector test broken for projects with internal/ packages and //go:embed directives
  • Root cause: File-copying approach incompatible with Go's internal/ import restrictions
  • Fix: Replace file-copying with Go's -overlay flag — instrumented files mapped via overlay JSON while Go compiles from the original module tree

Technical Details

  • Overlay JSON maps original file paths to instrumented replacements
  • -modfile + -mod=mod injects racedetector dependency without modifying user's go.mod
  • GOWORK=off ensures compatibility with Go workspace mode
  • GONOSUMCHECK skips checksum verification for racedetector module
  • race.mod/race.sum written to temp dir (user files never modified)

Test plan

  • Verified on gogpu/ui — multi-package project with internal/ dependencies
  • All target packages pass: primitives, app, widget, event, a11y, plugin
  • Racedetector's own go vet passes
  • CI green

The `racedetector test` command copied .go files to a temp directory
and ran `go test` from there. This broke projects that import internal/
packages from their own module (Go enforces internal/ imports only from
within the module tree). Same issue affected //go:embed directives.

Replace file-copying with Go's -overlay flag:
- Instrumented files written to temp dir with overlay JSON mapping
- Go compiles from original module tree (preserves internal/ and embed)
- -modfile + -mod=mod for dependency injection without modifying go.mod
- GOWORK=off for Go workspace mode compatibility
- GONOSUMCHECK for racedetector module checksum skip

Fixes test failures on projects like gogpu/ui with internal/ dependencies.
@codecov

codecov Bot commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 8.86076% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.04%. Comparing base (93ee7d7) to head (1080989).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cmd/racedetector/test.go 0.00% 65 Missing ⚠️
cmd/racedetector/runtime/link.go 36.36% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
- Coverage   71.58%   70.04%   -1.54%     
==========================================
  Files          28       28              
  Lines        4455     2951    -1504     
==========================================
- Hits         3189     2067    -1122     
+ Misses       1148      766     -382     
  Partials      118      118              
Flag Coverage Δ
unittests 70.04% <8.86%> (-1.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/racedetector/build.go 54.04% <ø> (-1.48%) ⬇️
internal/race/api/goid_generic.go 100.00% <ø> (ø)
internal/race/api/race.go 73.15% <100.00%> (-2.35%) ⬇️
internal/race/epoch/epoch.go 91.83% <ø> (-0.36%) ⬇️
cmd/racedetector/runtime/link.go 61.15% <36.36%> (-1.23%) ⬇️
cmd/racedetector/test.go 39.26% <0.00%> (+3.44%) ⬆️

... and 21 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93ee7d7...1080989. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Updated golangci-lint catches new issues:
- Remove unused //nolint:gosec directives (G115, G602 no longer flagged)
- Remove unused //nolint:prealloc directives
- Use fmt.Fprintf instead of WriteString(fmt.Sprintf(...)) (staticcheck QF1012)
- Fix getcallerpc() to capture PC from correct return position
- Preallocate stack slice in test
- Fix test.go formatting (trailing blank lines)
@kolkov kolkov merged commit b203ae8 into main Mar 12, 2026
12 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.

1 participant