From 5e5b30c7229063720fbc4b144f8273124b3ad442 Mon Sep 17 00:00:00 2001 From: Vitalii Pedchenko Date: Sat, 31 Oct 2026 00:27:02 +0200 Subject: [PATCH] test: fix local test failures and require race runs only for touched packages --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CLAUDE.md | 8 +++++++- CONTRIBUTING.md | 5 +++-- Makefile | 4 +++- README.md | 2 +- .../graph/store_sqlite/checkpoint_generation_bulk_test.go | 8 ++++++-- internal/parser/forest/dump_kinds_test.go | 4 +++- internal/releases/releases_test.go | 1 + 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index f8e966337..5e5c24ee7 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,7 +8,7 @@ Brief description of what this PR does. ## Testing -- [ ] All tests pass (`go test -race ./...`) +- [ ] Tests for the touched packages pass (`make test PKGS=./internal//...`); CI runs the full suite - [ ] New tests added for new functionality - [ ] Benchmarks run if performance-relevant diff --git a/CLAUDE.md b/CLAUDE.md index d86c1ad4a..0cdc093f6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,9 +7,15 @@ Code intelligence engine written in Go. Indexes repositories into a knowledge gr ```bash CGO_CFLAGS="-O2 -g -fno-strict-aliasing" CGO_CXXFLAGS="-O2 -g -fno-strict-aliasing" \ go build -o gortex ./cmd/gortex/ # requires CGO (tree-sitter C bindings) -go test -race ./... # all test packages must pass +make test PKGS=./internal//... # packages you touched; CI runs the full suite ``` +`make test` (all packages when `PKGS` is unset) runs `go test -race` with SQLite's transpiled C and libc left out of +race instrumentation, as CI does. Plain `go test -race ./...` instruments them +too, which makes `store_sqlite`, `indexer` and `mcp` several times slower and +can trip package timeouts. To run a heavy package with one worker per CPU like +CI: `TEST_RACE=true go run ./scripts/ci-test --partition indexer:1/2`. + Gcc builds must disable strict aliasing in C and C++ dependency packages to avoid [tree-sitter heap corruption (#821)](https://github.com/zzet/gortex/issues/821). The flags above preserve Go's default `-O2 -g`; `make` sets them automatically. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d6f9a35f6..8818ce0a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -73,7 +73,8 @@ checks and is the right default for most work. Other optional build tags: ### Running Tests ```bash -go test -race ./... +make test PKGS=./internal//... # the packages you touched +make test # every package ``` CI runs the suite under `-race` on Linux. A few packages — `internal/indexer`, @@ -163,7 +164,7 @@ tests, and skill drift. 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/my-feature`) 3. Write tests for your changes -4. Ensure all tests pass (`go test -race ./...`) +4. Ensure tests for the packages you touched pass (`make test PKGS=./internal//...`); CI runs the full suite 5. Ensure the linter is clean (`make lint`) 6. Commit with a clear message 7. Open a pull request and fill in the template diff --git a/Makefile b/Makefile index ded3ffbee..c6fcd82eb 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,10 @@ build-gomlx: deps-gomlx build-hugot: deps-hugot go build -ldflags '$(LDFLAGS)' -o $(BINARY) ./cmd/gortex/ +PKGS ?= ./... + test: - go test -race ./... + go test -race -gcflags=modernc.org/sqlite/lib=-race=false -gcflags=modernc.org/libc/...=-race=false $(PKGS) bench: go test -bench=. -benchmem -count=1 -benchtime=1s \ diff --git a/README.md b/README.md index aafc0b67e..05b76af3c 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ Data flow, graph schema (node and edge kinds, multi-repo fields, test taxonomy), ```bash make build # binary with version stamping -make test # go test -race ./... +make test # go test -race; PKGS=./internal//... narrows it make lint # golangci-lint ``` diff --git a/internal/graph/store_sqlite/checkpoint_generation_bulk_test.go b/internal/graph/store_sqlite/checkpoint_generation_bulk_test.go index 31ff67aa3..ed975111b 100644 --- a/internal/graph/store_sqlite/checkpoint_generation_bulk_test.go +++ b/internal/graph/store_sqlite/checkpoint_generation_bulk_test.go @@ -23,11 +23,15 @@ type checkpointBeginResult struct { err error } +// checkpointWaitTimeout only bounds a broken fixture; a race-instrumented +// SQLite needs well over 2s for a 4096-row chunk. +const checkpointWaitTimeout = 30 * time.Second + func waitCheckpointSignal(t *testing.T, signal <-chan struct{}) { t.Helper() select { case <-signal: - case <-time.After(2 * time.Second): + case <-time.After(checkpointWaitTimeout): t.Fatal("timed out waiting for checkpoint signal") } } @@ -37,7 +41,7 @@ func waitCheckpointAttemptResult(t *testing.T, result <-chan checkpointAttemptRe select { case got := <-result: return got - case <-time.After(2 * time.Second): + case <-time.After(checkpointWaitTimeout): t.Fatal("timed out waiting for checkpoint attempt") return checkpointAttemptResult{} } diff --git a/internal/parser/forest/dump_kinds_test.go b/internal/parser/forest/dump_kinds_test.go index 139b029f2..0e38a1a39 100644 --- a/internal/parser/forest/dump_kinds_test.go +++ b/internal/parser/forest/dump_kinds_test.go @@ -1,3 +1,5 @@ +//go:build grammardump + package forest import ( @@ -53,7 +55,7 @@ import ( // TestDumpGrammarKinds is a research helper. It parses a small // fixture per grammar and prints every named node kind seen, with // frequencies — feeds the per-language node-kind dispatch table. -// Run with: go test -run TestDumpGrammarKinds -v ./internal/parser/forest/ +// Run with: go test -tags grammardump -run TestDumpGrammarKinds -v ./internal/parser/forest/ func TestDumpGrammarKinds(t *testing.T) { cases := []struct { name string diff --git a/internal/releases/releases_test.go b/internal/releases/releases_test.go index 98a373e50..61146a8a1 100644 --- a/internal/releases/releases_test.go +++ b/internal/releases/releases_test.go @@ -40,6 +40,7 @@ func setupTaggedRepo(t *testing.T) string { runCmd(t, dir, "git", "init", "-q") runCmd(t, dir, "git", "config", "user.email", "test@example.com") runCmd(t, dir, "git", "config", "user.name", "Tester") + runCmd(t, dir, "git", "config", "tag.gpgsign", "false") writeFile(t, filepath.Join(dir, "a.go"), "package main\n") runCmd(t, dir, "git", "add", "a.go")