Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Materialize test files at the Workspace boundary, share downstream
Every function with a Workspace receiver or argument is invalidated
unconditionally. GoDirectory.tests() was crossing Workspace once per
test directory, which on dagger/dagger meant ~hundreds of invalidated
calls and ~12 minutes to enumerate go-test.

Thread a single Directory snapshot of all **/*_test.go files from the
Workspace boundary (Go.modules / Go.module) down through GoModules ->
GoModule -> GoTestDirs -> GoDirectory. GoDirectory.tests() now searches
that pre-materialized Directory and filters results by filePath. The
search arguments are identical for every directory, so the search hits
the dagql cache (Directory receiver -> content-addressed) after the
first call; per-directory restriction is pure-Dang on the cached result.

Net: one Workspace crossing and one ripgrep per session, no matter how
many directories the workspace contains.

Signed-off-by: Solomon Hykes <solomon@dagger.io>
  • Loading branch information
shykes committed Jun 12, 2026
commit 6ce779b40babcdb2de5c7a014978636006c58df2
53 changes: 45 additions & 8 deletions go.dang
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ type Go {
includeSkipTest: Boolean! = true,
includeSkipGenerate: Boolean! = true,
): GoModules! {
# Single workspace-wide snapshot of every *_test.go file, materialized
# once at this Workspace boundary and threaded down through the
# collection so GoDirectory.tests() can search/filter without ever
# touching Workspace again. Functions taking Workspace always invalidate;
# operations on a Directory receiver cache by content hash.
let testFilesDir = ws.directory("/", include: ["**/*_test.go"])
let paths = ws
.directory("/", include: ["**/go.mod"])
.glob("**/go.mod")
Expand All @@ -110,6 +116,7 @@ type Go {
skipLintPaths: skipLint,
skipTestPaths: skipTest,
skipGeneratePaths: skipGenerate,
testFilesDir: testFilesDir,
)
}
.filter { mod =>
Expand All @@ -127,6 +134,7 @@ type Go {
skipLintPaths: skipLint,
skipTestPaths: skipTest,
skipGeneratePaths: skipGenerate,
testFilesDir: testFilesDir,
)
}

Expand Down Expand Up @@ -175,6 +183,7 @@ type Go {
skipLintPaths: skipLint,
skipTestPaths: skipTest,
skipGeneratePaths: skipGenerate,
testFilesDir: ws.directory("/", include: ["**/*_test.go"]),
)
}

Expand Down Expand Up @@ -262,6 +271,7 @@ type GoModules {
let skipLintPaths: [String!]!
let skipTestPaths: [String!]!
let skipGeneratePaths: [String!]!
let testFilesDir: Directory!

"""
Return the discovered Go module with the given workspace-relative root path.
Expand All @@ -275,6 +285,7 @@ type GoModules {
skipLintPaths: skipLintPaths,
skipTestPaths: skipTestPaths,
skipGeneratePaths: skipGeneratePaths,
testFilesDir: testFilesDir,
)
}
}
Expand Down Expand Up @@ -318,6 +329,13 @@ type GoModule {
"""
let skipGeneratePaths: [String!]!

"""
Workspace-wide snapshot of every *_test.go file, threaded down from the
Go.modules / Go.module constructor. Used by GoDirectory.tests so that
test discovery never crosses Workspace again.
"""
let testFilesDir: Directory!

"""
Return a workspace-root path for a module-relative subpath.
"""
Expand Down Expand Up @@ -443,6 +461,7 @@ type GoModule {
baseImage: baseImage,
includeExtraFiles: includeExtraFiles,
skipTestPaths: skipTestPaths,
testFilesDir: testFilesDir,
)
}
}
Expand Down Expand Up @@ -470,6 +489,7 @@ type GoModule {
baseImage: baseImage,
includeExtraFiles: includeExtraFiles,
skipTestPaths: skipTestPaths,
testFilesDir: testFilesDir,
)
}

Expand Down Expand Up @@ -680,6 +700,7 @@ type GoTestDirs {
let baseImage: Container!
let includeExtraFiles: [String!]!
let skipTestPaths: [String!]!
let testFilesDir: Directory!

"""
Return the test directory with the given workspace-relative path.
Expand All @@ -692,6 +713,7 @@ type GoTestDirs {
baseImage: baseImage,
includeExtraFiles: includeExtraFiles,
skipTestPaths: skipTestPaths,
testFilesDir: testFilesDir,
)
}
}
Expand Down Expand Up @@ -727,6 +749,13 @@ type GoDirectory {
"""
let skipTestPaths: [String!]!

"""
Workspace-wide snapshot of every *_test.go file, threaded down from the
parent collection. tests() searches/filters this directory so the cost
is paid once per session (Directory receiver = content-addressed cache).
"""
let testFilesDir: Directory!

"""
Return a workspace-root path for a module-relative subpath.
"""
Expand Down Expand Up @@ -868,20 +897,28 @@ type GoDirectory {

Test names are discovered by statically matching top-level test function
declarations in *_test.go files, without compiling or running go test.

Search runs against testFilesDir, a Directory threaded from the parent
collection. The search arguments are identical for every GoDirectory,
so the result is cached once per session and reused; per-directory
restriction is a pure-Dang filter on the returned filePath.
"""
pub tests(): GoTests! {
let names = if (skipTest) {
[]
} else {
let glob = if (path == ".") {
"*_test.go"
} else {
path.trimSuffix("/") + "/*_test.go"
}
ws
.directory("/", include: [glob])
let prefix = if (path == ".") { "" } else { path.trimSuffix("/") + "/" }
testFilesDir
.search(pattern: "^func Test\\w+\\(")
.{matchedLines}
.{filePath, matchedLines}
.filter { result =>
if (path == ".") {
result.filePath.contains("/") == false
} else {
result.filePath.hasPrefix(prefix) and
result.filePath.trimPrefix(prefix).contains("/") == false
}
}
.map { result =>
result.matchedLines.trimSpace.trimPrefix("func ").split("(")[0] ?? ""
}
Expand Down