From 806923d00126b54ad8446df67b3575b0ee700b87 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Sat, 24 Oct 2026 00:11:51 +0200 Subject: [PATCH 1/4] test(e2e): generate a workspace opened from a Git ref Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/clients.dang | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/.dagger/modules/e2e/clients.dang b/.dagger/modules/e2e/clients.dang index da1fad7..764b978 100644 --- a/.dagger/modules/e2e/clients.dang +++ b/.dagger/modules/e2e/clients.dang @@ -20,6 +20,12 @@ type ClientChecks { # from this name by hand. let selfPath: String! = ".dagger/modules/self-app" let selfSourcePath: String! = "src/main/java/io/dagger/modules/selfapp/SelfApp.java" + # The client package path in workspaceClientPath is derived from the module + # name of workspaceDepPath by hand. + let workspaceDepPath: String! = ".dagger/modules/ws-dep" + let workspaceAppPath: String! = ".dagger/modules/ws-app" + let workspaceRuntimePath: String! = ".dagger/modules/ws-runtime" + let workspaceClientPath: String! = workspaceAppPath + "/clients/ws-dep/src/main/java/io/dagger/client/modules/wsdep/WsDep.java" let assert(condition: Boolean!, message: String!): Void { if (condition == false) { raise message } @@ -298,6 +304,86 @@ type ClientChecks { null } + """ + A workspace opened from a Git ref generates the files its checkout + generates. There the engine resolves a client declared by its path in the + workspace as a Git source at the workspace commit. Generation still binds + it by path: a module on the Dang entrypoint loads it by its path from the + workspace root, and a module on the runtime records it as a dependency + relative to its manifest. A commit of the generated files then stays clean + when generated from that commit, with the ref's selector and without one. + """ + pub gitWorkspaceGenerateCheck(ws: Workspace!): Void @check { + let config = ws.file("/.dagger/modules/engine-e2e/workspace.toml").contents + + workspaceScope(workspaceAppPath, "ws-app", "") + + workspaceScope(workspaceRuntimePath, "ws-runtime", "settings.dangEntrypoint = false\n") + let generated = cli( + playground(ws) + .withNewFile("dagger.toml", config) + .withNewFile(workspaceDepPath + "/dagger-module.toml", "name = \"ws-dep\"\nengineVersion = \"v1.0.0-0\"\n\n[runtime]\n source = \"dang\"\n") + .withNewFile(workspaceDepPath + "/main.dang", "type WsDep {\n pub greeting: String! { \"hello from ws-dep\" }\n}\n"), + ["--auto-apply", "generate"], + ) + let client = generated.file(workspaceClientPath).contents + assert( + client.contains("ModuleTarget.local(\"/" + workspaceDepPath + "\")"), + "the checkout does not bind the client by its path:\n" + client, + ) + let manifest = generated.file(workspaceRuntimePath + "/dagger-module.toml").contents + assert( + manifest.contains("source = \"../ws-dep\""), + "the checkout does not record the dependency by its path:\n" + manifest, + ) + assertGeneratesNothing(generated, "", "generating from the checkout") + + let server = container + .from("alpine:3.22") + .withoutEntrypoint + .withExec(["apk", "add", "--no-cache", "git", "git-daemon"]) + .withDirectory("/srv/repo", generated.directory(playgroundRoot), exclude: [".git"]) + .withWorkdir("/srv/repo") + .withExec(["git", "init", "-q", "-b", "main"]) + .withExec(["git", "add", "-A"]) + .withExec(["git", "-c", "user.name=e2e", "-c", "user.email=e2e@example.com", "commit", "-q", "-m", "generated scopes"]) + .withExec(["git", "clone", "-q", "--bare", ".", "/srv/repo.git"]) + .withExposedPort(9418) + .withDefaultArgs(["git", "daemon", "--export-all", "--base-path=/srv", "/srv"]) + .asService + # The engine takes a Git ref whose host has no dot for a Go import path + # and refuses it, so the ref names the server by its full name, in the + # session domain that resolv.conf searches last. + let repo = "git://" + server.hostname + ".$(awk '/^search/ {print $NF}' /etc/resolv.conf)/repo.git" + let served = generated.withServiceBinding(server.hostname, server) + assertGeneratesNothing(served, "-W \"" + repo + "@main\"", "generating from the Git ref at main") + assertGeneratesNothing(served, "-W \"" + repo + "\"", "generating from the Git ref without a selector") + null + } + + let workspaceScope(path: String!, name: String!, settings: String!): String! { + "\n[sdks.java.scopes.\"" + path + "\"]\nis-module = true\nname = \"" + name + "\"\n" + + "clients = [\"./" + workspaceDepPath + "\"]\n" + settings + } + + """ + The CLI reports an empty changeset in a log line, which plain progress + prints. It prints a changeset it does not apply as a summary near the end + of its output, so the tail is enough to tell what changed. + """ + let assertGeneratesNothing(ctr: Container!, flags: String!, what: String!): Void { + let attempt = ctr.withExec( + ["sh", "-c", "dagger --progress=plain " + flags + " generate --require-load --no-apply"], + experimentalPrivilegedNesting: true, + expect: ReturnType.ANY, + ) + let lines = attempt.stderr.split("\n") + let skipped = if (lines.length > 80) { lines.length - 80 } else { 0 } + assert( + attempt.exitCode == 0 and attempt.stderr.contains("no changes to apply") and + attempt.stderr.contains("Generated changes were not applied") == false, + what + " changed the files generated from the checkout:\n" + lines.dropFirst(skipped).join("\n"), + ) + } + let callerSource: String! { "package io.dagger.modules.hopa;\n" + "\n" From 041dffebfbe6c79410fd6a22ceab3525fe31dc1f Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Sat, 24 Oct 2026 00:13:11 +0200 Subject: [PATCH 2/4] fix(generate): bind a Git workspace's clients by path On the runtime sdk-helpers writes the clients into the manifest, and v1.0.5 writes a client of the Git workspace by its path. Signed-off-by: Yves Brissaud --- README.md | 2 +- dagger-module.toml | 2 +- dagger.json | 2 +- dagger.lock | 2 ++ main.dang | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.dang.tmpl | 44 ++++++++++++++++++++++++++++++++++++++++++++ mod.dang | 16 ++++++++++++++-- 7 files changed, 107 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b4b11c4..c0a7f86 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ generated when the engine loads the module**. The module builds with a plain > [`github.com/dagger/sdk-helpers`](https://github.com/dagger/sdk-helpers), the > manifest builder that > [dagger/dagger#13992](https://github.com/dagger/dagger/pull/13992) moved out of -> the engine, pinned at its `v1.0.2` tag. +> the engine, pinned at its `v1.0.5` tag. ## Install diff --git a/dagger-module.toml b/dagger-module.toml index 5072199..36a9198 100644 --- a/dagger-module.toml +++ b/dagger-module.toml @@ -6,4 +6,4 @@ engineVersion = "v1.0.0-beta.18" [[dependencies]] name = "sdk-helpers" - source = "github.com/dagger/sdk-helpers@v1.0.2" + source = "github.com/dagger/sdk-helpers@v1.0.5" diff --git a/dagger.json b/dagger.json index b30b78f..e994a51 100644 --- a/dagger.json +++ b/dagger.json @@ -7,7 +7,7 @@ "dependencies": [ { "name": "sdk-helpers", - "source": "github.com/dagger/sdk-helpers@v1.0.2" + "source": "github.com/dagger/sdk-helpers@v1.0.5" } ] } diff --git a/dagger.lock b/dagger.lock index 2a8d459..78e7867 100644 --- a/dagger.lock +++ b/dagger.lock @@ -5,12 +5,14 @@ ["","git-latest",["github.com/dagger/alpine"],"refs/heads/main"] ["","git-latest",["github.com/dagger/dang-sdk"],"refs/heads/main"] ["","git-latest",["github.com/dagger/sdk-helpers",["version","v1.0.2"]],"refs/tags/v1.0.2"] +["","git-latest",["github.com/dagger/sdk-helpers",["version","v1.0.5"]],"refs/tags/v1.0.5"] ["","git-sha",["github.com/containernetworking/plugins","refs/tags/v1.9.0"],"9b3772e1a7abf93cbb7c6526a28bc0d27b830e02"] ["","git-sha",["github.com/dagger/alpine","main"],"ff6a5f4c28364912d92c00e682dd0bf19f524ef9"] ["","git-sha",["github.com/dagger/alpine","refs/heads/main"],"ff6a5f4c28364912d92c00e682dd0bf19f524ef9"] ["","git-sha",["github.com/dagger/dagger","refs/tags/v1.0.0-beta.11"],"a4e1e4ff663e5e51c2b96c2c0772f3d2f00cfb94"] ["","git-sha",["github.com/dagger/dang-sdk","refs/heads/main"],"9c8e5c6f1927b9adc325846d47e66e697991797d"] ["","git-sha",["github.com/dagger/sdk-helpers","refs/tags/v1.0.2"],"e5e38a5f0778c5a804931d95e5d0d9953668049a"] +["","git-sha",["github.com/dagger/sdk-helpers","refs/tags/v1.0.5"],"2d593321b19e3519584b1bbd6e77d83b2be9de2f"] ["","git-sha",["github.com/libfuse/sshfs","refs/tags/sshfs-3.7.6"],"7a2d988775446ebe7af9b01c99b3b8e86bddb05a"] ["","git-sha",["github.com/opencontainers/runc","refs/tags/v1.4.2"],"c241c0bb5e60a8e8c1b2e53d4eca8d0068d8d57e"] ["","oci-latest",["docker.io/library/busybox"],"1.38.0"] diff --git a/main.dang b/main.dang index 0460807..43f6f04 100644 --- a/main.dang +++ b/main.dang @@ -282,6 +282,50 @@ type JavaSdk { .filter { label => label != "" } } + """ + Whether a Git client is a module of the Git workspace, at the workspace + commit. Both ref formats are read: the workspace address keeps + /@, while from engine v1.0.0-beta.20 a module of the + workspace prints #[:]. URL schemes are ignored, + because a GitHub address has none while its clone ref has https://. + Selectors are compared as written, so an alias such as HEAD for main keeps + the Git binding. + """ + workspaceRefMatches(address: String!, commit: String!, cloneRef: String!, ref: String!, pin: String!): Boolean! { + if (cloneRef == "" or pin == "" or pin != commit) { + false + } else { + let workspaceSelector = gitSelector(address, cloneRef) + let moduleSelector = gitSelector(ref, cloneRef) + if (workspaceSelector == null or moduleSelector == null) { + false + } else { + workspaceSelector == "" or workspaceSelector == moduleSelector + } + } + } + + """ + The selector of a ref of the repository at cloneRef, empty when the ref + names none, or null for a ref of another repository. + """ + let gitSelector(ref: String!, cloneRef: String!): String { + let repo = withoutURLScheme(cloneRef) + let path = withoutURLScheme(ref) + let rest = path.trimPrefix(repo) + if (path.hasPrefix(repo) == false or (rest != "" and rest.hasPrefix("/") == false and rest.hasPrefix("@") == false and rest.hasPrefix("#") == false)) { + null + } else if (rest.hasPrefix("#")) { + rest.trimPrefix("#").split(":", limit: 2)[0] ?? "" + } else { + rest.split("@", limit: 2)[1] ?? "" + } + } + + let withoutURLScheme(ref: String!): String! { + ref.split("://", limit: 2)[1] ?? ref + } + """ Whether the module's manifest names the entrypoint this SDK generates, at the path it generates it to. A main.dang there without the generated header is the diff --git a/main.dang.tmpl b/main.dang.tmpl index d2586c6..05dc5f4 100644 --- a/main.dang.tmpl +++ b/main.dang.tmpl @@ -282,6 +282,50 @@ type JavaSdk { .filter { label => label != "" } } + """ + Whether a Git client is a module of the Git workspace, at the workspace + commit. Both ref formats are read: the workspace address keeps + /@, while from engine v1.0.0-beta.20 a module of the + workspace prints #[:]. URL schemes are ignored, + because a GitHub address has none while its clone ref has https://. + Selectors are compared as written, so an alias such as HEAD for main keeps + the Git binding. + """ + workspaceRefMatches(address: String!, commit: String!, cloneRef: String!, ref: String!, pin: String!): Boolean! { + if (cloneRef == "" or pin == "" or pin != commit) { + false + } else { + let workspaceSelector = gitSelector(address, cloneRef) + let moduleSelector = gitSelector(ref, cloneRef) + if (workspaceSelector == null or moduleSelector == null) { + false + } else { + workspaceSelector == "" or workspaceSelector == moduleSelector + } + } + } + + """ + The selector of a ref of the repository at cloneRef, empty when the ref + names none, or null for a ref of another repository. + """ + let gitSelector(ref: String!, cloneRef: String!): String { + let repo = withoutURLScheme(cloneRef) + let path = withoutURLScheme(ref) + let rest = path.trimPrefix(repo) + if (path.hasPrefix(repo) == false or (rest != "" and rest.hasPrefix("/") == false and rest.hasPrefix("@") == false and rest.hasPrefix("#") == false)) { + null + } else if (rest.hasPrefix("#")) { + rest.trimPrefix("#").split(":", limit: 2)[0] ?? "" + } else { + rest.split("@", limit: 2)[1] ?? "" + } + } + + let withoutURLScheme(ref: String!): String! { + ref.split("://", limit: 2)[1] ?? ref + } + """ Whether the module's manifest names the entrypoint this SDK generates, at the path it generates it to. A main.dang there without the generated header is the diff --git a/mod.dang b/mod.dang index ca94042..872b53c 100644 --- a/mod.dang +++ b/mod.dang @@ -146,16 +146,28 @@ type Mod { """ Where a client loads its target from: a git ref with the commit it resolved to, or a module of the workspace by its path from the workspace root, which - serveModule reads in the calling module's own tree. + serveModule reads in the calling module's own tree, even when the workspace + is loaded from Git. """ let clientDescriptor(client: ModuleSource!): String! { - if (client.kind == ModuleSourceKind.GIT_SOURCE) { + if (client.kind == ModuleSourceKind.GIT_SOURCE and inWorkspace(client) == false) { "git\n" + client.asString + "\n" + client.pin + "\n" } else { "local\n" + workspaceRef(client.sourceRootSubpath) + "\n" } } + """ + A workspace loaded from Git resolves its own modules as Git sources at its + commit. Bound by that ref, a client would change with every commit and never + match what the checkout generates. An unknown workspace commit matches no + client, so the client keeps its Git binding and its pin. + """ + let inWorkspace(client: ModuleSource!): Boolean! { + let commit = ws.git.head.commit rescue { err: Error => "" } + JavaSdk().workspaceRefMatches(ws.address, commit, client.cloneRef, client.asString, client.pin) + } + """ The live engine version, without build metadata. From 52efe7e068920859a5f9fec9870605b80b1cdfc5 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Sat, 24 Oct 2026 00:13:28 +0200 Subject: [PATCH 3/4] test(e2e): match the clients of a Git workspace Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 275825d..1c46a4b 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -752,6 +752,43 @@ type E2e { null } + """ + A Git client is a module of the Git workspace that generates it when it is + in the workspace's repository, at its commit, and at its selector or in a + workspace that names none. The cases follow the Go SDK's TestWorkspaceModule + and TestWorkspaceModuleExplicitGitURL (dagger/go-sdk#73, #78 and #79). + """ + workspaceRefMatchCheck: Void @check { + let sha = "419c4afea78603265c40e273c455623a0291922e" + let other = "0000000000000000000000000000000000000000" + let clone = "http://h/r.git" + let github = "https://github.com/o/r" + [ + ["the workspace at the commit", clone + "@" + sha, sha, clone, clone + "/app@" + sha, sha, "true"], + ["a workspace without a selector", clone, sha, clone, clone + "/app@main", sha, "true"], + ["a workspace in a subdirectory", clone + "/ci@main", sha, clone, clone + "/app@main", sha, "true"], + ["another selector at the same commit", clone + "@main", sha, clone, clone + "/app@release", sha, "false"], + ["another commit", clone + "@main", other, clone, clone + "/app@main", sha, "false"], + ["another repository", clone + "-fork@" + sha, sha, clone, clone + "/app@" + sha, sha, "false"], + ["an unknown workspace commit", clone + "@" + sha, "", clone, clone + "/app@" + sha, sha, "false"], + ["a module without a pin", clone + "@" + sha, sha, clone, clone + "/app@" + sha, "", "false"], + ["a GitHub address without a scheme", "github.com/o/r@" + sha, sha, github, github + "/app@" + sha, sha, "true"], + ["another host without a scheme", "gitlab.com/o/r@" + sha, sha, github, github + "/app@" + sha, sha, "false"], + ["a repository the clone ref is a prefix of", "github.com/o/r2@" + sha, sha, github, github + "2/app@" + sha, sha, "false"], + ["the explicit Git URL form at the commit", clone + "@" + sha, sha, clone, clone + "#" + sha + ":app", sha, "true"], + ["the explicit Git URL form on GitHub", "github.com/o/r@" + sha, sha, github, github + "#" + sha + ":app", sha, "true"], + ["the explicit Git URL form at the repository root", "github.com/o/r@" + sha, sha, github, github + "#" + sha, sha, "true"], + ["the explicit Git URL form at a branch", clone + "@main", sha, clone, clone + "#main:app", sha, "true"], + ["the explicit Git URL form at another selector", clone + "@main", sha, clone, clone + "#release:app", sha, "false"], + ["the explicit Git URL form in another repository", "github.com/o/r@" + sha, sha, github + "-fork", github + "-fork#" + sha + ":app", sha, "false"], + ].each { row => + let name = row[0] ?? "" + let got = javaSdk.workspaceRefMatches(row[1] ?? "", row[2] ?? "", row[3] ?? "", row[4] ?? "", row[5] ?? "") + assert(got == (row[6] == "true"), name + ": want " + (row[6] ?? "")) + } + null + } + """ A module that reaches core over the session Dagger.dag() holds and over a session it names, with a core type in its signature. From 6ad0184aa69c3042982274d9540af1c8a02b9458 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Sat, 24 Oct 2026 00:14:30 +0200 Subject: [PATCH 4/4] docs: document clients of a workspace opened from Git Signed-off-by: Yves Brissaud --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c0a7f86..cb63ed4 100644 --- a/README.md +++ b/README.md @@ -234,9 +234,11 @@ String greeting = clientDep().greeting(); A client loads its target with `serveModule` when the module first calls it. A local target is named by its path from the workspace root, and the engine -resolves that path in the calling module's own tree. A git target is loaded at -the commit its ref resolved to when the client was generated, even after a newer -tag matches the ref; `dagger generate` moves the client to the newer commit. +resolves that path in the calling module's own tree. A client declared by a +path within the workspace keeps that binding when the workspace is opened from +Git. A git target is loaded at the commit its ref resolved to when the client +was generated, even after a newer tag matches the ref; `dagger generate` moves +the client to the newer commit. A client types each check of its target as the core object `Check`, whatever type the check's author wrote and whatever engine version the target declares. @@ -293,7 +295,8 @@ dependency set instead. Each client is recorded in the manifest the module has `dagger-module.toml`, or the `dagger.json` of a pre-1.0 module — and its types are generated into the core package, so module code reaches it through `core()`, as `core().clientDep()`. A client that is removed is dropped from -both. +both. A client declared by a path within the workspace keeps that binding when +the workspace is opened from Git. > [!WARNING] > On the runtime, the client set is the *whole* dependency set. A module that