Repository navigation
go: discover tests from a per-module index, as go test would build them - #89
Merged
sipsma merged 18 commits intoNov 2, 2026
Merged
Conversation
tiborvass
force-pushed
the
codex/pr14802-current-go
branch
4 times, most recently
from
November 1, 2026 01:21
4a65850 to
68a1c99
Compare
sipsma
force-pushed
the
perf/module-discovery-index-20261029
branch
from
November 2, 2026 20:26
81f2644 to
0ffb09d
Compare
sipsma
marked this pull request as ready for review
November 2, 2026 20:26
kpenfound
approved these changes
Nov 2, 2026
Signed-off-by: Guillaume de Rouville <[email protected]>
GoModule.packages merges the selected package paths, sorted by workspace path, against the module catalogue's records in one pass. The scanner sorted those records by module-relative directory instead, which differs when a directory's name sorts before ".": in a module at m, "-tools" comes before "." but m comes before m/-tools. The merge then skipped m/-tools and listing the module failed with "package catalogue does not contain every selected path". Sort the directories by workspace path, so the records are in the order the merge expects. Signed-off-by: Erik Sipsma <[email protected]>
catalogueIndexCheck called GoPackages.package, the collection's get function, by its Dang name. The engine exposes that function only as get(key:), so go-dev failed to load and every one of its checks failed. The removed assertion asked for a directory outside the collection, which get refuses. Nothing can reach such a directory any more, so drop it rather than rewrite it. Signed-off-by: Erik Sipsma <[email protected]>
With packages read from each module's catalogue, nothing reads the scanner's global _discovery_ file. GoModule.testNames, which read the global _testnames_ file, served only GoPackage.tests's fallback for a package without an entry, and every key of a GoPackages collection now has one: GoModule.packages builds an entry for each selected path, subset narrows only the keys, and get refuses a key outside them. Stop writing both files, remove their readers, and make a package's selected tests required. The discovery line format is now documented on the module catalogue that carries it. Signed-off-by: Erik Sipsma <[email protected]>
helperCheck ran only the source scanner's tests, so go-test-report's never ran in any check. Run both helpers' tests. Signed-off-by: Erik Sipsma <[email protected]>
A selected test with no result in the report passed whenever its package passed, on the grounds that a build constraint may have excluded it. Such a test never ran, so its check showed a pass with nothing behind it. Report it as not run instead, saying go test passed its package without it. Signed-off-by: Erik Sipsma <[email protected]>
Discovery listed every test function in every _test.go file, whatever its build constraints, so a test in a file go test leaves out on the engine's platform became a check. A file marked //go:build !linux, say, listed tests that never run on Linux. Examples without an output comment were listed too, though go test compiles them and never runs them. The scanner now lists a test file's tests only when go/build would build the file for go test: for the platform the scan runs on, which is the engine's and so the test container's, with the build tags of the GOFLAGS go test runs with, the release tags of its Go toolchain, and cgo as it is configured. The go module passes those settings to the scan: its goflags and version settings, with no cgo, since the default containers have no C compiler; or, for a custom base, what the base's own go env reports. With nothing to pass, the scan stays the one every module and tool shares. GOFLAGS is split and its -tags parsed as cmd/go does it, and -race, -msan and -asan add their tags as cmd/go adds them. An example counts only when go/doc finds the output comment go test needs to run it. This changes the scanner's earlier intent, which mirrored the old ripgrep search and listed tests from files marked //go:build never. Signed-off-by: Erik Sipsma <[email protected]>
The README still said build constraints were not evaluated and that a test excluded by one was listed anyway. Describe what discovery lists now, and that a selected test that did not run fails. The scan's own documentation now says that test settings passed for discovery make a scan of their own. Signed-off-by: Erik Sipsma <[email protected]>
GoPackage.tests took a Workspace argument it no longer read. A host workspace gets a new identity in every session, so the function ran again in every session for every package. As a stored field it is read from the object without calling the module. Signed-off-by: Erik Sipsma <[email protected]>
The go-includes helper kept a second mode that read the workspace through the Dagger API, and so linked dagger.io/dagger, otel-go and their gRPC and OpenTelemetry tree. Nothing has called that mode since the scan moved to a local pass over a snapshot of the workspace, but every fresh engine still compiled it: the helper's go build is most of discovery's time there. Remove that mode and make the local scan the helper's only one, so it links only the standard library and golang.org/x/mod. A cold build of the helper goes from 465 packages to 95, and the binary from 24 MB to 4.6 MB. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
The scanner was one chain: the image, the helper's go build, then the
workspace mounted into it. Dang has to resolve the workspace directory's
ID before it can send that chain, and resolving it is when the engine
syncs the files from the host. Only then did the engine resolve the
image, and only the read of the scan's output ran the pull and the build.
So on a fresh engine the sync, the resolve, the pull and the build ran
one after another, though the helper doesn't depend on the workspace.
Ask for the built helper and the synced workspace in one {{ }}, whose
fields run at once, and mount the one into the other.
Signed-off-by: Erik Sipsma <[email protected]>
A scan allocates quickly and exits within a fraction of a second, but at the default GOGC of 100 the collector runs many times during it. In the scanner's image on dagger/dagger's tree, GOGC=400 takes a scan from 109 ms to 93 ms, with peak memory going from 70 MB to 115 MB. Higher settings save no more: with the collector off, the scan takes 103 ms and 315 MB. Signed-off-by: Erik Sipsma <[email protected]>
…brary The scanner builds its helper from source on every fresh engine, and most of that build is compiling Go's standard library. Without inlining there (-gcflags=std=-l), the build takes 2.15 s instead of 2.85 s in the scanner's image. On its own the change makes each scan about 25 ms slower: the garbage collector and the strings functions lose their inlined helpers. Running the scan with less garbage collection, the commit before this one, makes up for it: 109 ms with both, against 109 ms before either. Signed-off-by: Erik Sipsma <[email protected]>
Comment-only. The scan takes about 0.1 s, not under it, the quarter is of the whole build, and the 15% is against a helper built with inlining. Signed-off-by: Erik Sipsma <[email protected]>
runTests gathered, deduplicated and sorted every selected test name in the module, with the merge sort in Dang, but only a narrowed run uses them, for its -run pattern. Every check of the module evaluates runTests, so a full run of a module with about 900 tests did that sort once per test. A CPU profile of an unchanged rerun of such a suite put 56 of the engine's 218 CPU-seconds under Dang's map builtin, most of it likely this sort's merge step. Signed-off-by: Erik Sipsma <[email protected]>
GoTest.test worked out its package's import path from the module's discovery lines, and runTests, which it calls, did the same again: two lookups per check, each three scanner queries plus the calls around them, about 45 engine calls. The selections runTests returns already hold each package's import path next to its module-relative directory, so the check now finds its selection by directory and takes the import path from it. A package missing from the selection is now named by its workspace path rather than its import path, as the check's other failures already are. Signed-off-by: Erik Sipsma <[email protected]>
testEnv mounted the workspace's dagger-module.toml and dagger.json files with its own Workspace.directory call. The engine keys that call per client, and every check is a client of its own, so a full run of 1,233 tests read the host checkout for them 1,233 times. gomod.daggerConfigs makes the same read as a module call, which the engine shares between checks in a session, as it already shares the module's source and testdata. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
perf/module-discovery-index-20261029
branch
from
November 2, 2026 21:09
0ffb09d to
c7a589d
Compare
sipsma
added a commit
to dagger/dagger
that referenced
this pull request
Nov 4, 2026
Move the workspace's Go module from dagger/go#84's merge commit to the v0.4.0 release. That brings in Go 1.27 (dagger/go#90), the faster workspace scan (dagger/go#91) and the module discovery index and test check cuts (dagger/go#89). dagger.lock records the tag and the sub-modules the release resolves, as written by dagger. Signed-off-by: Erik Sipsma <[email protected]>
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.
This replaces the earlier draft of this PR. Of the draft's five commits, only Guillaume's discovery index commit stays, with his authorship. It is adapted to #84's final form, where its test callers and one module path changed. The rest of the stack builds on it.
Four are gone:
tests/ultrabatch.shcases (a renamed module, an unselected package that fails to build, aTestMainteardown failure, a failing test and a failing build) are go-dev checks on main.What it does for users
Listing tests is faster, most of all when nothing changed. Listing all 4,953 Go tests of dagger/dagger (
dagger check -lover the Go test collection, wall time, median of 3 interleaved runs per arm, on a 16-CPU arm64 machine with an engine built from dagger/dagger plus the collection changes still in review):The rest of the stack takes more off the scan and off each test check. Each commit message gives its own measurement. The largest:
GoPackage.testsis a stored field, so it no longer runs again in every session: an unchanged listing of dagger/dagger went from 4.34 s to 2.95 s.Test discovery is also more accurate:
go testwould run are listed. Before, every test function in every_test.gofile became a check, whatever its build constraints. A file marked//go:build !linux, for example, listed tests that never run on Linux. Discovery now applies Go's build rules for the engine's platform, with the build tags fromgoflags(and-race,-msan,-asan), the Go version and cgo as the test containers run them. A custombaseuses its owngo env. An example is listed only when it has an output comment, sincego testruns no other.go testpassed its package without running it.API changes
GoPackage.testsis a field and no longer takes aWorkspaceargument.Gomod.scantakes optionalgoflags,goVersionandcgosettings for discovery. With none given it is the same shared scan as before._discovery_and_testnames_files. Each module's discovery is in its own catalogue, listed by_discovery_index_.json.Relation to #91
This builds on #91's faster workspace scan. Discovery reads each file through #91's single read, and the per-module catalogue and the build-constraint filter sit on top of it.
Testing
dagger/go's own
dagger checkpasses all 80 checks on a fresh v1.0.0-beta.23 engine: main's 78 and two new ones,catalogue-index-checkandbuild-constraints-check.New tests cover the module layout the index failed to list, discovery under build constraints, and a selected test that never ran. The test report helper's unit tests now run in
helper-check. No check ran them before.