You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make module discovery cwd-aware and resolve dagger-module.toml
Mirror the cwd-aware discovery change already landed in the Go, Python and
TypeScript SDKs (dagger/dagger#13688): modules are discovered relative to
the client's current directory rather than the whole workspace, and both
the CLI 1.0 dagger-module.toml and the legacy dagger.json mark a module
root.
- Mod.path becomes rootPath (workspace-root-relative, the module's stable
identity); a new cwd-relative Mod.path renders listings the way a shell
user sees them.
- JavaSdk.modules(ws) discovers managed modules through the polyfill's
cwd-aware findConfigDirs, intersected with the engine-owned asSDK list,
and generateAll now goes through it — so running from a subdirectory
acts on the project you're in and the projects beneath it.
- Point the polyfill dependency in dagger-module.toml (the effective
module config) at github.com/dagger/polyfill@main, which provides
findConfigDirs.
- Wire the workspace dagger.toml for e2e (register java-sdk as the "java"
SDK with fixtures) and add modulesCheck / modulesCwdCheck covering both
config formats and cwd scoping.
Signed-off-by: Tom Chauveau <tom@dagger.io>
Copy file name to clipboardExpand all lines: .dagger/modules/e2e/main.dang
+79Lines changed: 79 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,17 @@ End-to-end checks for the Java SDK helper module.
4
4
type E2e {
5
5
let outputRoot: String! = ".dagger/modules/e2e/out"
6
6
7
+
let fixtureRoot: String! = ".dagger/modules/e2e/fixtures"
8
+
let generateModulePath: String! = fixtureRoot + "/generate/app"
9
+
let lookupModulePath: String! = fixtureRoot + "/lookup/app"
10
+
let lookupNestedPath: String! = lookupModulePath + "/nested"
11
+
let depsModulePath: String! = fixtureRoot + "/deps/app"
12
+
let skipModulePath: String! = fixtureRoot + "/skip/app"
13
+
# A CLI 1.0 managed module: configured by dagger-module.toml, not dagger.json.
14
+
let managedTomlModulePath: String! = fixtureRoot + "/managed-toml/app"
15
+
# A module using a different SDK; this SDK must never manage it.
16
+
let nonJavaModulePath: String! = fixtureRoot + "/lookup/not-java"
17
+
7
18
"""Fail the current check when a condition is false."""
8
19
let assert(condition: Boolean!, message: String!): Void {
9
20
if (condition == false) { raise message }
@@ -81,4 +92,72 @@ type E2e {
81
92
82
93
null
83
94
}
95
+
96
+
"""
97
+
From the workspace root the whole workspace is in scope, so modules() should
98
+
return every Java SDK module this workspace manages — whether it is configured
99
+
by the legacy dagger.json or the CLI 1.0 dagger-module.toml — and nothing that
100
+
isn't managed by this SDK (e.g. a sibling module using another SDK).
101
+
"""
102
+
pub modulesCheck(ws: Workspace!): Void @check {
103
+
let pathRecords = javaSdk.modules(ws).{{rootPath}}
104
+
105
+
assert(pathRecords.filter { r => r.rootPath == lookupModulePath }.length > 0, "lookup Java module should be listed")
106
+
assert(pathRecords.filter { r => r.rootPath == skipModulePath }.length > 0, "skip-marked Java module should still be listed (skip only affects generate)")
107
+
assert(pathRecords.filter { r => r.rootPath == generateModulePath }.length > 0, "generate Java module should be listed")
108
+
assert(pathRecords.filter { r => r.rootPath == depsModulePath }.length > 0, "deps Java module should be listed")
109
+
assert(pathRecords.filter { r => r.rootPath == managedTomlModulePath }.length > 0, "a dagger-module.toml (CLI 1.0) managed module should be listed")
110
+
assert(pathRecords.filter { r => r.rootPath == nonJavaModulePath }.length == 0, "a module not managed by this SDK should be excluded from modules listing")
111
+
112
+
null
113
+
}
114
+
115
+
"""
116
+
Discovery is anchored at the client's cwd, not the workspace root. Re-anchoring
117
+
the workspace to a subdirectory scopes modules() to the managed modules in that
118
+
cone (walk-down) plus the nearest enclosing one (find-up), and excludes managed
# A stable snapshot of the workspace, re-anchorable at any cwd. Keep every
123
+
# module config (both dagger.json and dagger-module.toml, for discovery) and
124
+
# the nested .keep so lookup/app/nested survives the include filter and can
125
+
# serve as a config-less subdirectory.
126
+
let root = ws.directory("/", include: ["**/dagger.json", "**/dagger-module.toml", "**/.keep"])
127
+
128
+
# Walk-down: from fixtures/generate only generate/app is in the cone; the
129
+
# sibling managed modules live outside it and must be excluded. Its
130
+
# cwd-relative path is "app" — a directory beneath the cwd.
131
+
let fromGenerate = javaSdk.modules(root.asWorkspace(cwd: fixtureRoot + "/generate"))
132
+
let fromGenerateRoots = fromGenerate.{{rootPath}}
133
+
assert(fromGenerateRoots.filter { r => r.rootPath == generateModulePath }.length > 0, "cwd=generate: the managed module in the cone should be discovered")
134
+
assert(fromGenerateRoots.filter { r => r.rootPath == lookupModulePath }.length == 0, "cwd=generate: lookup/app is outside the cone and must be excluded")
135
+
assert(fromGenerateRoots.filter { r => r.rootPath == depsModulePath }.length == 0, "cwd=generate: deps/app is outside the cone and must be excluded")
136
+
assert(fromGenerateRoots.filter { r => r.rootPath == skipModulePath }.length == 0, "cwd=generate: skip/app is outside the cone and must be excluded")
137
+
assert(fromGenerateRoots.length == 1, "cwd=generate: exactly one managed module is in the cone")
138
+
assert(fromGenerate.{{path}}.filter { r => r.path == "app" }.length > 0, "cwd=generate: the discovered module's path should be cwd-relative (app)")
139
+
140
+
# Find-up: from inside lookup/app (a nested subdir with no config of its own)
141
+
# the enclosing managed module is discovered; siblings are not. Its
142
+
# cwd-relative path is ".." — an ancestor of the cwd.
143
+
let fromNested = javaSdk.modules(root.asWorkspace(cwd: lookupNestedPath))
144
+
let fromNestedRoots = fromNested.{{rootPath}}
145
+
assert(fromNestedRoots.filter { r => r.rootPath == lookupModulePath }.length > 0, "cwd=lookup/app/nested: find-up should discover the enclosing lookup/app")
146
+
assert(fromNestedRoots.filter { r => r.rootPath == generateModulePath }.length == 0, "cwd=lookup/app/nested: generate/app is outside the cone")
147
+
assert(fromNestedRoots.length == 1, "cwd=lookup/app/nested: only the enclosing module should be discovered")
148
+
assert(fromNested.{{path}}.filter { r => r.path == ".." }.length > 0, "cwd=lookup/app/nested: the enclosing module's path should be cwd-relative (..)")
149
+
150
+
# Root cwd: the whole workspace is in scope, so every managed module — and
151
+
# only the managed ones — is discovered, whether marked by dagger.json or
152
+
# dagger-module.toml.
153
+
let fromRoot = javaSdk.modules(root.asWorkspace(cwd: "/")).{{rootPath}}
154
+
assert(fromRoot.filter { r => r.rootPath == generateModulePath }.length > 0, "cwd=/: generate/app should be listed")
155
+
assert(fromRoot.filter { r => r.rootPath == lookupModulePath }.length > 0, "cwd=/: lookup/app should be listed")
156
+
assert(fromRoot.filter { r => r.rootPath == depsModulePath }.length > 0, "cwd=/: deps/app should be listed")
157
+
assert(fromRoot.filter { r => r.rootPath == skipModulePath }.length > 0, "cwd=/: skip/app should be listed")
158
+
assert(fromRoot.filter { r => r.rootPath == managedTomlModulePath }.length > 0, "cwd=/: the dagger-module.toml managed module should be listed")
159
+
assert(fromRoot.length == 5, "cwd=/: exactly the five managed modules should be listed")
0 commit comments