diff --git a/.dagger/modules/e2e/clients.dang b/.dagger/modules/e2e/clients.dang index da1fad7..02920ab 100644 --- a/.dagger/modules/e2e/clients.dang +++ b/.dagger/modules/e2e/clients.dang @@ -37,7 +37,7 @@ type ClientChecks { .withDirectory( playgroundRoot, ws.directory("/", exclude: [".git", "**/target/**"]) - .withFile("dagger.toml", ws.file("/.dagger/modules/engine-e2e/workspace.toml")), + .withFile("dagger.toml", ws.file("/.dagger/modules/e2e/workspace.toml")), ) .withWorkdir(playgroundRoot) .withExec(["git", "init", "--quiet"]) @@ -144,10 +144,10 @@ type ClientChecks { let callResult: String! = "result() { r=$(dagger \"$@\"); echo \"$r\"; }\n" """ - A git server for one repository, pinned.git, whose one commit, tagged + A git repository, pinned.git, served on port 9418, whose one commit, tagged v1.0.0, is a module whose message is its version. """ - let gitServer: Service! { + let gitRepo: Container! { container .from("alpine:3.22") .withoutEntrypoint @@ -161,15 +161,28 @@ type ClientChecks { .withExec(["git", "tag", "v1.0.0"]) .withExec(["git", "clone", "-q", "--bare", ".", "/srv/pinned.git"]) .withExposedPort(9418) - .withDefaultArgs(["git", "daemon", "--export-all", "--base-path=/srv", "/srv"]) + } + + let gitServer: Service! { + gitRepo.withDefaultArgs(["git", "daemon", "--export-all", "--base-path=/srv", "/srv"]).asService + } + + """ + A git server that takes pushes. It differs from gitServer, so the engine + starts one for it alone: a push to a server that another check shares + would move that check's tag. + """ + let pushableGitServer: Service! { + gitRepo + .withDefaultArgs(["git", "daemon", "--export-all", "--enable=receive-pack", "--base-path=/srv", "/srv"]) .asService } """ A module calls a git client through its entrypoint. The client is added at the version query @v1, and generated with the commit v1.0.0 resolved to as - its pin. engine-e2e's pinned-git-client-check shows that the pin holds after - a newer tag matches @v1, which takes a session per call. + its pin. pinnedGitClientCheck shows that the pin holds after a newer tag + matches @v1, which takes a session per call. The address names the server by its IP: the engine refuses a git host without a dot, which a service hostname is. One script does everything, @@ -211,6 +224,57 @@ type ClientChecks { null } + """ + A git client of a module on the Dang entrypoint stays on the commit it was + generated against after a newer tag matches its ref (dagger/dagger#14284). + The client is added at @v1 when only v1.0.0 exists, and v1.0.1 is pushed + after. The workspace lock records what @v1 resolved to, so its entries for + the repository are dropped, and the next call resolves @v1 again, to + v1.0.1. Each CLI call is a session of its own, because a session keeps + what @v1 resolved to in it. + + The address names the server by its IP, as in gitCheck, and one script + does everything, because the tag pushed to the server lasts only as long + as the exec that holds the server. + """ + pub pinnedGitClientCheck(ws: Workspace!): Void @check { + let server = pushableGitServer + let host = server.hostname + let ready = javaModule( + playground(ws).withServiceBinding(host, server), + pinAppPath, + "pin-app", + "src/main/java/io/dagger/modules/pinapp/PinApp.java", + pinAppSource, + ) + let script = "set -e\n" + + callResult + + "address=git://$(getent hosts " + host + " | cut -d ' ' -f 1)/pinned.git@v1\n" + + "dagger --auto-apply module client add \"$address\" --sdk java >&2\n" + + "result -m . call message\n" + + "git clone -q git://" + host + "/pinned.git /tmp/pinned\n" + + "(cd /tmp/pinned && sed -i 's/v1.0.0/v1.0.1/' main.dang &&\n" + + " git -c user.name=e2e -c user.email=e2e@example.com commit -q -am v1.0.1 &&\n" + + " git tag v1.0.1 && git push -q origin main v1.0.1)\n" + + "grep -v '/pinned\"' " + playgroundRoot + "/dagger.lock > /tmp/dagger.lock\n" + + "cp /tmp/dagger.lock " + playgroundRoot + "/dagger.lock\n" + + "result -m \"$address\" call message\n" + + "result -m . call message\n" + let ran = ready + .withWorkdir(pinAppPath) + .withExec(["sh", "-c", script], daggerInDaggerNewSession: true, expect: ReturnType.ANY) + let said = ran.stdout + ran.stderr + assert(ran.exitCode == 0, "the calls of the git client failed:\n" + said) + let results = ran.stdout.trimSpace.split("\n") + assert((results[0] ?? "") == "pinned: v1.0.0", "the module did not call its git client: " + JSON.encode(results) + "\n" + said) + assert((results[1] ?? "") == "v1.0.1", "@v1 did not resolve to the newer tag: " + JSON.encode(results) + "\n" + said) + assert( + (results[2] ?? "") == "pinned: v1.0.0", + "the git client left its pinned commit for the newer tag: " + JSON.encode(results) + "\n" + said, + ) + null + } + """ A module calls a passing and a failing check of its client and reads pass and error off each. A client runs in a v1 session, where a check is the core @@ -350,7 +414,7 @@ type ClientChecks { + "\n" + "@Object\n" + "public class PinApp {\n" - + " @Function\n" + + " @Function(cache = \"never\")\n" + " public String message()\n" + " throws ExecutionException, DaggerQueryException, InterruptedException {\n" + " return \"pinned: \" + pinned().message();\n" diff --git a/.dagger/modules/e2e/collections.dang b/.dagger/modules/e2e/collections.dang index 6cfdab2..930a027 100644 --- a/.dagger/modules/e2e/collections.dang +++ b/.dagger/modules/e2e/collections.dang @@ -1,8 +1,8 @@ """ Checks of a module whose objects are collections, on the Dang entrypoint generated into it, driven through the CLI of the engine that runs them. The -engine serves keys, get, list, subset and batch on a collection, from the -markers the module declares. +engine serves keys, get, list and subset on a collection, from the markers the +module declares. """ type CollectionChecks { let fixturePath: String! = ".dagger/modules/e2e/fixtures/collections/shelf" @@ -77,9 +77,10 @@ type CollectionChecks { } """ - The engine serves keys, list, get, subset and batch on a collection whose - members it finds by their markers, and fills the delta field with the keys - added and removed since the module returned the collection. + The engine serves keys, list, get and subset on a collection whose members + it finds by their markers, beside the collection's own functions, and fills + the delta field with the keys added and removed since the module returned + the collection. A collection that a function changes and returns keeps its base, so its delta compares it with the keys the module first returned. A new instance @@ -95,21 +96,22 @@ type CollectionChecks { " keys\n" + " list { name }\n" + " get(key: \"a\") { name }\n" + - " batch { selected removed }\n" + - " subset(keys: [\"c\", \"b\"]) { keys batch { selected removed } }\n" + - " changed: batch { change(names: [\"c\", \"d\"]) { keys batch { added removed } } }\n" + - " fresh: subset(keys: [\"c\"]) { batch { fresh { keys batch { added removed } } } }\n" + + " selected removed\n" + + " subset(keys: [\"c\", \"b\"]) { keys selected removed }\n" + + " changed: change(names: [\"c\", \"d\"]) { keys added removed }\n" + + " fresh: subset(keys: [\"c\"]) { fresh { keys added removed } }\n" + "} }" """The answer to itemsQuery, with its keys sorted the way the CLI prints them.""" let itemsAnswer: String! = "{\"items\":{" + - "\"batch\":{\"removed\":[],\"selected\":[\"b\",\"a\",\"c\"]}," + - "\"changed\":{\"change\":{\"batch\":{\"added\":[\"d\"],\"removed\":[\"b\",\"a\"]},\"keys\":[\"c\",\"d\"]}}," + - "\"fresh\":{\"batch\":{\"fresh\":{\"batch\":{\"added\":[],\"removed\":[]},\"keys\":[\"z\"]}}}," + + "\"changed\":{\"added\":[\"d\"],\"keys\":[\"c\",\"d\"],\"removed\":[\"b\",\"a\"]}," + + "\"fresh\":{\"fresh\":{\"added\":[],\"keys\":[\"z\"],\"removed\":[]}}," + "\"get\":{\"name\":\"item:a\"}," + "\"keys\":[\"b\",\"a\",\"c\"]," + "\"list\":[{\"name\":\"item:b\"},{\"name\":\"item:a\"},{\"name\":\"item:c\"}]," + - "\"subset\":{\"batch\":{\"removed\":[\"a\"],\"selected\":[\"b\",\"c\"]},\"keys\":[\"b\",\"c\"]}" + + "\"removed\":[]," + + "\"selected\":[\"b\",\"a\",\"c\"]," + + "\"subset\":{\"keys\":[\"b\",\"c\"],\"removed\":[\"a\"],\"selected\":[\"b\",\"c\"]}" + "}}" """ @@ -123,57 +125,57 @@ type CollectionChecks { } let kindsQuery: String! = "{\n" + - " numbers { keys get(key: 2) { name } subset(keys: [3, 1]) { keys batch { removed } } }\n" + - " ratios { keys get(key: 1.5) { name } subset(keys: [1.5]) { batch { removed } } }\n" + - " flags { keys get(key: false) { name } subset(keys: [false]) { batch { removed } } }\n" + - " colors { keys get(key: BLUE) { name } subset(keys: [BLUE]) { batch { removed } } }\n" + - " platforms { keys get(key: \"linux/arm64\") { name } subset(keys: [\"linux/arm64\"]) { batch { removed } } }\n" + - " racks { keys get(key: \"r2\") { keys get(key: \"r2-1\") { name } subset(keys: [\"r2-2\"]) { batch { selected } } } subset(keys: [\"r1\"]) { batch { count } } }\n" + + " numbers { keys get(key: 2) { name } subset(keys: [3, 1]) { keys removed } }\n" + + " ratios { keys get(key: 1.5) { name } subset(keys: [1.5]) { removed } }\n" + + " flags { keys get(key: false) { name } subset(keys: [false]) { removed } }\n" + + " colors { keys get(key: BLUE) { name } subset(keys: [BLUE]) { removed } }\n" + + " platforms { keys get(key: \"linux/arm64\") { name } subset(keys: [\"linux/arm64\"]) { removed } }\n" + + " racks { keys get(key: \"r2\") { keys get(key: \"r2-1\") { name } subset(keys: [\"r2-2\"]) { selected } } subset(keys: [\"r1\"]) { count } }\n" + "}" """The answer to kindsQuery, with its keys sorted the way the CLI prints them.""" let kindsAnswer: String! = "{" + - "\"colors\":{\"get\":{\"name\":\"blue\"},\"keys\":[\"RED\",\"BLUE\"],\"subset\":{\"batch\":{\"removed\":[\"RED\"]}}}," + - "\"flags\":{\"get\":{\"name\":\"ffalse\"},\"keys\":[true,false],\"subset\":{\"batch\":{\"removed\":[\"true\"]}}}," + - "\"numbers\":{\"get\":{\"name\":\"n2\"},\"keys\":[2,1,3],\"subset\":{\"batch\":{\"removed\":[\"2\"]},\"keys\":[1,3]}}," + - "\"platforms\":{\"get\":{\"name\":\"linux/arm64\"},\"keys\":[\"linux/amd64\",\"linux/arm64\"],\"subset\":{\"batch\":{\"removed\":[\"linux/amd64\"]}}}," + - "\"racks\":{\"get\":{\"get\":{\"name\":\"r2-1\"},\"keys\":[\"r2-1\",\"r2-2\"],\"subset\":{\"batch\":{\"selected\":[\"r2-2\"]}}},\"keys\":[\"r1\",\"r2\"],\"subset\":{\"batch\":{\"count\":1}}}," + - "\"ratios\":{\"get\":{\"name\":\"r1.5\"},\"keys\":[0.5,1.5],\"subset\":{\"batch\":{\"removed\":[\"0.5\"]}}}" + + "\"colors\":{\"get\":{\"name\":\"blue\"},\"keys\":[\"RED\",\"BLUE\"],\"subset\":{\"removed\":[\"RED\"]}}," + + "\"flags\":{\"get\":{\"name\":\"ffalse\"},\"keys\":[true,false],\"subset\":{\"removed\":[\"true\"]}}," + + "\"numbers\":{\"get\":{\"name\":\"n2\"},\"keys\":[2,1,3],\"subset\":{\"keys\":[1,3],\"removed\":[\"2\"]}}," + + "\"platforms\":{\"get\":{\"name\":\"linux/arm64\"},\"keys\":[\"linux/amd64\",\"linux/arm64\"],\"subset\":{\"removed\":[\"linux/amd64\"]}}," + + "\"racks\":{\"get\":{\"get\":{\"name\":\"r2-1\"},\"keys\":[\"r2-1\",\"r2-2\"],\"subset\":{\"selected\":[\"r2-2\"]}},\"keys\":[\"r1\",\"r2\"],\"subset\":{\"count\":1}}," + + "\"ratios\":{\"get\":{\"name\":\"r1.5\"},\"keys\":[0.5,1.5],\"subset\":{\"removed\":[\"0.5\"]}}" + "}" """ The CLI names an item of a collection with a selector named after the module - and the item type: after the collection, in place of the path to it, and - repeated to select a subset for a batch function. + and the item type: after the collection, and in place of the path to it. + subset selects several items for the collection's own functions. """ pub collectionSelectorsCheck(ws: Workspace!): Void @check { let pg = playground(app(ws)) assertCall(pg, ["items", "name", "--shelf-item=a"], "item:a") assertCall(pg, ["--shelf-item=c", "name"], "item:c") - assertCall(pg, ["items", "selected", "--shelf-item=c", "--shelf-item=b"], "b\nc") + assertCall(pg, ["items", "subset", "--keys=c,b", "selected"], "b\nc") null } """ - `dagger check` runs a batch check once over the items its selectors name, - in place of the check of the same name on the item type. With -m, the - selectors go in the check's link. Items.verify rejects item c, and - Item.verify fails wherever it runs. + `dagger check` runs an item's check once for each item its selectors name, + and hands each the collection narrowed to those items: Item.verify takes + its Items, and rejects item c. With -m, the selectors go in the check's + link. """ - pub collectionBatchCheck(ws: Workspace!): Void @check { + pub collectionItemCheck(ws: Workspace!): Void @check { let pg = playground(app(ws)) let passed = cli(pg, ["-m", "app", "check", "items/verify?shelf-item=a&shelf-item=b"]) assert( - passed.exitCode == 0 and passed.stderr.contains("1 passed"), - "the batch check over a and b did not pass once:\n" + passed.stdout + passed.stderr, + passed.exitCode == 0 and passed.stderr.contains("2 passed"), + "the checks of a and b did not both pass:\n" + passed.stdout + passed.stderr, ) let failed = cli(pg, ["-m", "app", "check", "items/verify?shelf-item=a&shelf-item=c"]) let said = failed.stdout + failed.stderr assert( - failed.exitCode != 0 and said.contains("1 failed") and said.contains("verified a,c: c is rejected"), - "the batch check over a and c did not fail once with its error:\n" + said, + failed.exitCode != 0 and said.contains("1 passed") and said.contains("1 failed") and + said.contains("verified a,c: c is rejected"), + "the check of c did not fail alone, with the selected items in its error:\n" + said, ) - assert(said.contains("the item's verify ran") == false, "the item's own check ran:\n" + said) null } @@ -227,7 +229,7 @@ type CollectionChecks { .withDirectory( checkoutRoot, ws.directory("/", exclude: [".git", "**/target/**"]) - .withFile("dagger.toml", ws.file("/.dagger/modules/engine-e2e/workspace.toml")), + .withFile("dagger.toml", ws.file("/.dagger/modules/e2e/workspace.toml")), ) .withDirectory(checkoutRoot + "/.dagger/modules/shelf", app(ws)) .withWorkdir(checkoutRoot) @@ -240,7 +242,7 @@ type CollectionChecks { """ A Java module calls the collections of the fixture module through the - client generated from it: keys, list, get, subset and batch, with keys of + client generated from it: keys, list, get and subset, with keys of the types Int, an enum and Platform, and an item that is a collection. """ pub collectionClientCheck(ws: Workspace!): Void @check { diff --git a/.dagger/modules/e2e/entrypoint.dang b/.dagger/modules/e2e/entrypoint.dang index ee88987..684157a 100644 --- a/.dagger/modules/e2e/entrypoint.dang +++ b/.dagger/modules/e2e/entrypoint.dang @@ -158,8 +158,8 @@ type EntrypointChecks { Each cache policy holds in a session: a default or per-session result is reused, a never result is not, and a result with an explicit TTL is reused until it expires and computed again after (dagger/dagger#14694). Every CLI - call here shares the session that runs the check; engine-e2e's - cache-policy-sessions-check calls across sessions. + call here shares the session that runs the check; + cachePolicySessionsCheck calls across sessions. """ pub cachePolicyCheck(ws: Workspace!): Void @check { let script = "set -e\n" + @@ -180,6 +180,29 @@ type EntrypointChecks { null } + """ + Results of a module on the Dang entrypoint follow their cache policy across + sessions: a default result is reused, a per-session or a never result is + not. Each CLI call here is a session of its own. + + The module gets a file of its own, so its calls share no cache entry with + cachePolicyCheck's: a result that check stores while this one runs would + replace the one this check compares. + """ + pub cachePolicySessionsCheck(ws: Workspace!): Void @check { + let script = "set -e\n" + + "c() { dagger -m app call \"$1\"; }\n" + + "echo $(c cached) $(c cached) $(c per-session) $(c per-session) $(c fresh) $(c fresh)\n" + let ran = playground(app(ws).withNewFile("cache-policy-sessions", "")).withExec(["sh", "-c", script], daggerInDaggerNewSession: true, expect: ReturnType.ANY) + let said = ran.stdout + ran.stderr + assert(ran.exitCode == 0, "the calls failed:\n" + said) + let calls = ran.stdout.trimSpace.split(" ") + assert(calls.length == 6 and calls[0] == calls[1], "a default result was not reused in another session:\n" + said) + assert(calls[2] != calls[3], "a per-session result was reused in another session:\n" + said) + assert(calls[4] != calls[5], "a never-cached result was reused:\n" + said) + null + } + """ `dagger check` runs the module's checks through the entrypoint: one passes, and one fails with its error. diff --git a/.dagger/modules/e2e/fixtures/collections/shelf-caller/src/main/java/io/dagger/modules/shelfcaller/ShelfCaller.java b/.dagger/modules/e2e/fixtures/collections/shelf-caller/src/main/java/io/dagger/modules/shelfcaller/ShelfCaller.java index 9b12b73..65e7590 100644 --- a/.dagger/modules/e2e/fixtures/collections/shelf-caller/src/main/java/io/dagger/modules/shelfcaller/ShelfCaller.java +++ b/.dagger/modules/e2e/fixtures/collections/shelf-caller/src/main/java/io/dagger/modules/shelfcaller/ShelfCaller.java @@ -13,9 +13,9 @@ import java.util.concurrent.ExecutionException; /** - * Calls the shelf module's collections through its client. keys, get, list, subset and batch exist - * only in the engine's projection of a collection, so the client has them only if it was generated - * from that. + * Calls the shelf module's collections through its client. keys, get, list and subset exist only + * in the engine's projection of a collection, so the client has them only if it was generated from + * that. */ @Object public class ShelfCaller { @@ -33,7 +33,7 @@ public String report() throws ExecutionException, DaggerQueryException, Interrup + " get=" + items.get("a").name() + " removed=" - + items.subset(List.of("c")).batch().removed(); + + items.subset(List.of("c")).removed(); } @Function diff --git a/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Item.java b/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Item.java index a80306d..dfa6534 100644 --- a/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Item.java +++ b/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Item.java @@ -14,10 +14,13 @@ public Item() {} this.name = name; } - /** Items.verify replaces this check, so it never runs on an item of Items. */ + /** Rejects item c. The engine passes the collection the selectors narrowed, as items. */ @Function @Check - public void verify() { - throw new IllegalStateException("the item's verify ran for " + name); + public void verify(Items items) { + if (name.equals("item:c")) { + throw new IllegalStateException( + "verified " + String.join(",", items.selected()) + ": c is rejected"); + } } } diff --git a/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Items.java b/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Items.java index 8ddb6df..b6f367d 100644 --- a/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Items.java +++ b/.dagger/modules/e2e/fixtures/collections/shelf/src/main/java/io/dagger/modules/shelf/Items.java @@ -2,7 +2,6 @@ import io.dagger.client.exception.DaggerQueryException; import io.dagger.client.modules.core.CollectionDelta; -import io.dagger.module.annotation.Check; import io.dagger.module.annotation.Collection; import io.dagger.module.annotation.Delta; import io.dagger.module.annotation.Function; @@ -65,13 +64,4 @@ public Items change(List names) { public Items fresh() { return new Items(List.of("z"), prefix); } - - /** Replaces Item.verify: runs once over the selected items, and rejects item c. */ - @Function - @Check - public void verify() { - if (names.contains("c")) { - throw new IllegalStateException("verified " + String.join(",", names) + ": c is rejected"); - } - } } diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 7fe41f9..3a67b49 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -2,10 +2,8 @@ End-to-end checks for the Java SDK helper module. Every check here calls the java-sdk module, which needs an engine at its floor, -v1.0.0-beta.26, or later. dagger.toml does not install this module, so -`dagger check` runs these checks only through `engine-e2e:floor-check`, on an -engine built from the floor's commit. AGENTS.md has the commands that run them -on the local engine. +v1.0.0-beta.26, or later. dagger.toml installs this module, so `dagger check` +runs these checks on the engine that runs it. """ type E2e { let fixtureRoot: String! = ".dagger/modules/e2e/fixtures" @@ -697,28 +695,12 @@ type E2e { .withExec(["mvn", "compile", "--no-transfer-progress"], expect: ReturnType.ANY) } - """ - floorCheck's precondition, not a check of its own: the engine running these - checks is the floor release, by the version it reports itself. A release - reports its build after a "+", which is not part of the version; a dev or - later build is refused. engine-e2e's floorCheck calls it before the checks, so - that check cannot pass on another engine. - """ - assertFloorEngine: Void { - if ((version.split("+")[0] ?? "") != floorVersion) { - raise "the floor is " + floorVersion + " and the engine running these checks is " + version + - ": a pass would not prove the floor. Run `dagger check engine-e2e:floor-check`, which provisions its engine" - } - null - } - """ The SDK refuses an engine release older than its floor before it generates anything, and names the floor and the version it found. Every other version passes, a development build and one it cannot read among them, so an unexpected format never blocks a user. On an engine the SDK refuses, - generation itself refuses; engine-e2e's belowFloorCheck runs this check on - one. + generation itself refuses. """ engineFloorRefusalCheck(ws: Workspace!): Void @check { let refused = [ @@ -752,6 +734,53 @@ type E2e { null } + """ + The CLI of the engine running the check lists this checkout as the java + SDK, initializes a Java module on the Dang entrypoint from it, and runs the + module. Each CLI call is a session of its own, as a user's is. The module's + class is E2eSmoke, as the engine formats a Java class name. + """ + devSdkCheck(ws: Workspace!): Void @check { + let modulePath = ".dagger/modules/e2e-smoke" + let checkout = container + .from("registry.dagger.io/engine:" + (version.split("+")[0] ?? version)) + .withoutEntrypoint + .withDirectory( + "/work/java-sdk", + ws.directory("/", exclude: [".git", "**/target/**"]) + .withFile("dagger.toml", ws.file("/.dagger/modules/e2e/workspace.toml")), + ) + .withWorkdir("/work/java-sdk") + .withExec(["git", "init", "--quiet"]) + let listed = checkout.withExec(["dagger", "sdk", "list"], daggerInDaggerNewSession: true) + assert(listed.stdout.contains("java"), "the development Java SDK was not listed") + + let initialized = listed + .withExec( + ["dagger", "--auto-apply", "module", "init", "java", "--name", "e2e-smoke", "--path", modulePath], + daggerInDaggerNewSession: true, + ) + .withExec(["test", "-f", modulePath + "/dagger-module.toml"]) + .withExec(["test", "!", "-e", modulePath + "/dagger.json"]) + .withExec(["test", "-f", modulePath + "/pom.xml"]) + .withExec(["test", "-f", modulePath + "/src/main/java/io/dagger/modules/e2esmoke/E2eSmoke.java"]) + .withExec(["test", "-f", modulePath + "/sdk/src/main/java/io/dagger/client/Dagger.java"]) + .withExec(["test", "-f", modulePath + "/clients/core/src/main/java/io/dagger/client/modules/core/Core.java"]) + .withExec(["test", "!", "-e", modulePath + "/sdk/src/generated"]) + .withExec(["test", "-f", modulePath + "/src/generated/java/io/dagger/gen/entrypoint/Entrypoint.java"]) + .withExec(["test", "-f", modulePath + "/src/generated/dang/entrypoint/main.dang"]) + .withExec(["grep", "-q", "^\\[entrypoint\\]$", modulePath + "/dagger-module.toml"]) + + let release = initialized + .withExec( + ["dagger", "-m", modulePath, "call", "container", "file", "--path", "/etc/alpine-release", "contents"], + daggerInDaggerNewSession: true, + ) + .stdout + assert(release.trimSpace != "", "the generated module did not run") + 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. diff --git a/.dagger/modules/e2e/standalone.dang b/.dagger/modules/e2e/standalone.dang index 00989f1..2f22944 100644 --- a/.dagger/modules/e2e/standalone.dang +++ b/.dagger/modules/e2e/standalone.dang @@ -1,13 +1,13 @@ """ Checks of clients generated into a plain Maven project, a scope with a pom.xml -and no module. engine-e2e's standalone-client-check runs the project's program -with java -jar, which takes a session of its own. +and no module. """ type StandaloneChecks { let appPath: String! = ".dagger/modules/e2e/fixtures/standalone/app" let clientDepPath: String! = ".dagger/modules/e2e/fixtures/clients/dep" let clientDepDir: String! = "clients/client-dep" let moduleAppPath: String! = ".dagger/modules/e2e/out/client-app" + let checkoutRoot: String! = "/work/java-sdk" let assert(condition: Boolean!, message: String!): Void { if (condition == false) { raise message } @@ -122,4 +122,56 @@ type StandaloneChecks { assert(built.directory("/app/target").exists("app.jar"), "mvn package did not build target/app.jar") null } + + """ + A plain Maven project calls a module through a client the CLI added to it, + from a program run with java -jar that holds no connection code. With no + session in its environment, the program starts `dagger session` on its + first call and stops it before the JVM exits, so no session process + outlives the program. The project builds with mvn package in a container + with no engine and no dagger CLI. + """ + pub standaloneClientCheck(ws: Workspace!): Void @check { + let cli = container.from("registry.dagger.io/engine:" + (version.split("+")[0] ?? version)).file("/usr/local/bin/dagger") + let added = container + .from(runtimeImage(ws, "java")) + .withExec(["apk", "add", "--no-cache", "git"]) + .withFile("/usr/local/bin/dagger", cli) + .withDirectory( + checkoutRoot, + ws.directory("/", exclude: [".git", "**/target/**"]) + .withFile("dagger.toml", ws.file("/.dagger/modules/e2e/workspace.toml")), + ) + .withWorkdir(checkoutRoot) + .withExec(["git", "init", "--quiet"]) + .withExec(["cp", "-R", appPath, "standalone-app"]) + .withWorkdir("standalone-app") + .withExec( + ["dagger", "--auto-apply", "module", "client", "add", "../" + clientDepPath, "--sdk", "java"], + daggerInDaggerNewSession: true, + ) + let jar = container + .from(runtimeImage(ws, "maven")) + .withoutEntrypoint + .withMountedCache("/root/.m2", cacheVolume("e2e-maven-m2")) + .withDirectory("/app", added.directory(".")) + .withWorkdir("/app") + .withExec(["mvn", "package", "--no-transfer-progress"]) + .file("/app/target/app.jar") + let script = "set -e\n" + + "java -jar app.jar\n" + + "if ps -o args | grep -qE '[d]agger[^ ]* session'; then ps -o pid,args >&2; exit 1; fi\n" + let ran = added.withFile("app.jar", jar).withExec(["sh", "-c", script], daggerInDaggerNewSession: true, expect: ReturnType.ANY) + let said = ran.stdout + ran.stderr + assert(ran.exitCode == 0, "the program failed, or left its dagger session running:\n" + said) + assert(ran.stdout.trimSpace == "hello from the client dependency", "the program did not call its client:\n" + said) + null + } + + """ + The image a single-FROM Dockerfile under runtime/images names. + """ + let runtimeImage(ws: Workspace!, name: String!): String! { + ws.file("/runtime/images/" + name + "/Dockerfile").contents.trimSpace.trimPrefix("FROM ") + } } diff --git a/.dagger/modules/e2e/workspace.toml b/.dagger/modules/e2e/workspace.toml new file mode 100644 index 0000000..d72df0b --- /dev/null +++ b/.dagger/modules/e2e/workspace.toml @@ -0,0 +1,13 @@ +# The workspace of the CLI that e2e checks run: this checkout as its java SDK. +# The checks put this file in place of dagger.toml in the copy the CLI works +# in, so that CLI loads none of the checkout's other modules. + +[modules.e2e] +source = ".dagger/modules/e2e" + +[modules.java-sdk] +source = "." +check.skip = ["*"] + +[sdks.java] +module = "java-sdk" diff --git a/.dagger/modules/engine-e2e/dagger-module.toml b/.dagger/modules/engine-e2e/dagger-module.toml deleted file mode 100644 index e1ea6e1..0000000 --- a/.dagger/modules/engine-e2e/dagger-module.toml +++ /dev/null @@ -1,15 +0,0 @@ -name = "engine-e2e" -engineVersion = "v1.0.0-0" - -[runtime] - source = "dang" - -[[dependencies]] - name = "engine-dev" - source = "github.com/dagger/dagger/.dagger/modules/engine-dev@9f15293b2d3960d9eeee567d2e50bd60dcf0df80" - pin = "9f15293b2d3960d9eeee567d2e50bd60dcf0df80" - -[[dependencies]] - name = "below-floor-engine-dev" - source = "github.com/dagger/dagger/.dagger/modules/engine-dev@a45241b20a5e07fbfc5954479ef0b61da843499c" - pin = "a45241b20a5e07fbfc5954479ef0b61da843499c" diff --git a/.dagger/modules/engine-e2e/main.dang b/.dagger/modules/engine-e2e/main.dang deleted file mode 100644 index 7ca70f5..0000000 --- a/.dagger/modules/engine-e2e/main.dang +++ /dev/null @@ -1,300 +0,0 @@ -""" -Checks the Java SDK on engines built from pinned dagger/dagger commits, so a run -proves the floor whatever engine runs it. Keep each commit aligned with its -engine-dev dependency in dagger-module.toml. -""" -type EngineE2e { - """ - Commit of v1.0.0-beta.26, this SDK's floor. - """ - let floorCommit: String! = "9f15293b2d3960d9eeee567d2e50bd60dcf0df80" - - """ - Commit of v1.0.0-beta.25, the last release below the floor. - """ - let belowFloorCommit: String! = "a45241b20a5e07fbfc5954479ef0b61da843499c" - - let modulePath: String! = ".dagger/modules/sdk-smoke" - - let assert(condition: Boolean!, message: String!): Void { - if (condition == false) { - raise message - } - null - } - - let daggerSource(commit: String!): Workspace! { - git("https://github.com/dagger/dagger").ref(commit).asWorkspace - } - - """ - The checks need git, which the default client lacks. - """ - let clientBase: Container! { - container.from("alpine:3.22").withExec(["apk", "add", "--no-cache", "git"]) - } - - """ - This checkout, mounted in a client of the given engine, as a workspace the CLI - inside can act on. Its dagger.toml is workspace.toml, which registers only the - e2e module and this SDK: this checkout's own also registers engine-e2e, whose - checks `dagger check` would then run inside the engine again. - """ - let sdkClient(ws: Workspace!, engine: Container!): Container! { - let sdkSource = ws.directory("/", exclude: [".git", "**/target/**"]) - .withFile("dagger.toml", ws.file("/.dagger/modules/engine-e2e/workspace.toml")) - engine - .withMountedDirectory("/work/java-sdk", sdkSource) - .withWorkdir("/work/java-sdk") - # .git is left out of the mount; workspace detection walks up to a .git to - # find the workspace root, and without one there is no workspace at all. - .withExec(["git", "init", "--quiet"]) - } - - let floorClient(ws: Workspace!): Container! { - sdkClient(ws, engineDev(ws: daggerSource(floorCommit)).installClient(client: clientBase)) - } - - """ - The outer engine hands each exec a session of its own, which a client prefers - over the engine installClient configures, and it sets it when the process - starts, so only the process can drop it. - """ - let withoutOuterSession(args: [String!]!): [String!]! { - ["env", "-u", "DAGGER_SESSION_PORT", "-u", "DAGGER_SESSION_TOKEN", "dagger"] + args - } - - """ - Every e2e check, on the floor release's engine, which they first confirm is - the one they reach. - """ - pub floorCheck(ws: Workspace!): Void @check { - floorClient(ws) - .withExec(withoutOuterSession(["call", "-m", ".dagger/modules/e2e", "assert-floor-engine"])) - .withExec(withoutOuterSession(["check", "-m", ".dagger/modules/e2e"])) - .sync - - null - } - - """ - The release below the floor is refused: on its engine, generation and - `dagger module init` name the floor. - """ - pub belowFloorCheck(ws: Workspace!): Void @check { - let client = sdkClient(ws, belowFloorEngineDev(ws: daggerSource(belowFloorCommit)).installClient(client: clientBase)) - let checked = client - .withExec(withoutOuterSession(["check", "-m", ".dagger/modules/e2e", "engine-floor-refusal-check"])) - # A pattern that matches no check passes too. - let said = checked.stdout + checked.stderr - assert(said.contains("1 passed"), "engine-floor-refusal-check did not run on the engine below the floor:\n" + said) - - let initialized = client.withExec( - withoutOuterSession(["--auto-apply", "module", "init", "java", "--name", "sdk-smoke", "--path", modulePath]), - expect: ReturnType.FAILURE, - ) - let refusal = initialized.stdout + initialized.stderr - assert( - refusal.contains("needs Dagger engine v1.0.0-beta.26 or later"), - "dagger module init on the engine below the floor did not name the floor:\n" + refusal, - ) - - null - } - - """ - The floor engine should list this checkout as the java SDK, initialize a Java - module on the Dang entrypoint from it, and run the module. - """ - pub devSdkCheck(ws: Workspace!): Void @check { - let listed = floorClient(ws).withExec(withoutOuterSession(["sdk", "list"])) - assert(listed.stdout.contains("java"), "the development Java SDK was not listed") - - let initialized = listed - .withExec(withoutOuterSession(["--auto-apply", "module", "init", "java", "--name", "sdk-smoke", "--path", modulePath])) - .withExec(["test", "-f", modulePath + "/dagger-module.toml"]) - .withExec(["test", "!", "-e", modulePath + "/dagger.json"]) - .withExec(["test", "-f", modulePath + "/pom.xml"]) - .withExec(["test", "-f", modulePath + "/src/main/java/io/dagger/modules/sdksmoke/SdkSmoke.java"]) - .withExec(["test", "-f", modulePath + "/sdk/src/main/java/io/dagger/client/Dagger.java"]) - .withExec(["test", "-f", modulePath + "/clients/core/src/main/java/io/dagger/client/modules/core/Core.java"]) - .withExec(["test", "!", "-e", modulePath + "/sdk/src/generated"]) - .withExec(["test", "-f", modulePath + "/src/generated/java/io/dagger/gen/entrypoint/Entrypoint.java"]) - .withExec(["test", "-f", modulePath + "/src/generated/dang/entrypoint/main.dang"]) - .withExec(["grep", "-q", "^\\[entrypoint\\]$", modulePath + "/dagger-module.toml"]) - - let release = initialized - .withExec(withoutOuterSession(["-m", modulePath, "call", "container", "file", "--path", "/etc/alpine-release", "contents"])) - .stdout - assert(release.trimSpace != "", "the generated module did not run") - - null - } - - """ - Results of a module on the Dang entrypoint follow their cache policy across - sessions of the floor engine: a default result is reused, a per-session or a - never result is not. Each CLI call here is a session of its own, which the - e2e checks cannot show: their CLI calls share the session that runs them. - """ - pub cachePolicySessionsCheck(ws: Workspace!): Void @check { - let appPath = ".dagger/modules/entry-app" - let generated = floorClient(ws) - .withExec(withoutOuterSession(["--auto-apply", "module", "init", "java", "--name", "entry-app", "--path", appPath])) - .withExec(["cp", "-R", ".dagger/modules/e2e/fixtures/entrypoint/src", appPath + "/"]) - .withWorkdir(appPath) - .withExec(withoutOuterSession(["--auto-apply", "generate"])) - let script = "set -e\n" + - "c() { env -u DAGGER_SESSION_PORT -u DAGGER_SESSION_TOKEN dagger -m . call \"$1\"; }\n" + - "echo $(c cached) $(c cached) $(c per-session) $(c per-session) $(c fresh) $(c fresh)\n" - let results = generated.withExec(["sh", "-c", script]).stdout.trimSpace - let calls = results.split(" ") - assert(calls.length == 6 and calls[0] == calls[1], "a default result was not reused in another session: " + results) - assert(calls[2] != calls[3], "a per-session result was reused in another session: " + results) - assert(calls[4] != calls[5], "a never-cached result was reused: " + results) - - null - } - - """ - A git client of a module on the Dang entrypoint stays on the commit it was - generated against after a newer tag matches its ref (dagger/dagger#14284). - The client is added at @v1 when only v1.0.0 exists, and v1.0.1 is pushed - after. The workspace lock records what @v1 resolved to, so its entries for - the repository are dropped, and the next call resolves @v1 again, to - v1.0.1. Each CLI call is a session of its own, because a session keeps - what @v1 resolved to in it; the e2e checks, whose calls share one session, - cannot show this. - - The address names the git server by its IP, because the engine refuses a - git host without a dot, and one script does everything, because the - server's IP and the tag pushed to it last only as long as the exec that - holds the server. - """ - pub pinnedGitClientCheck(ws: Workspace!): Void @check { - let appPath = ".dagger/modules/pin-app" - let server = gitServer - let host = server.hostname - let initialized = floorClient(ws) - .withServiceBinding(host, server) - .withExec(withoutOuterSession(["--auto-apply", "module", "init", "java", "--name", "pin-app", "--path", appPath])) - .withNewFile(appPath + "/src/main/java/io/dagger/modules/pinapp/PinApp.java", pinAppSource) - .withWorkdir(appPath) - let script = "set -e\n" + - "d() { env -u DAGGER_SESSION_PORT -u DAGGER_SESSION_TOKEN dagger \"$@\"; }\n" + - "result() { r=$(d \"$@\"); echo \"$r\"; }\n" + - "address=git://$(getent hosts " + host + " | cut -d ' ' -f 1)/pinned.git@v1\n" + - "d --auto-apply module client add \"$address\" --sdk java >&2\n" + - "result -m . call message\n" + - "git clone -q git://" + host + "/pinned.git /tmp/pinned\n" + - "(cd /tmp/pinned && sed -i 's/v1.0.0/v1.0.1/' main.dang &&\n" + - " git -c user.name=e2e -c user.email=e2e@example.com commit -q -am v1.0.1 &&\n" + - " git tag v1.0.1 && git push -q origin main v1.0.1)\n" + - "grep -v '/pinned\"' /work/java-sdk/dagger.lock > /tmp/dagger.lock\n" + - "cp /tmp/dagger.lock /work/java-sdk/dagger.lock\n" + - "result -m \"$address\" call message\n" + - "result -m . call message\n" - let ran = initialized.withExec(["sh", "-c", script], expect: ReturnType.ANY) - let said = ran.stdout + ran.stderr - assert(ran.exitCode == 0, "the calls of the git client failed:\n" + said) - let results = ran.stdout.trimSpace.split("\n") - assert((results[0] ?? "") == "pinned: v1.0.0", "the module did not call its git client: " + JSON.encode(results) + "\n" + said) - assert((results[1] ?? "") == "v1.0.1", "@v1 did not resolve to the newer tag: " + JSON.encode(results) + "\n" + said) - assert( - (results[2] ?? "") == "pinned: v1.0.0", - "the git client left its pinned commit for the newer tag: " + JSON.encode(results) + "\n" + said, - ) - - null - } - - """ - A plain Maven project calls a module through a client the CLI added to it, - from a program run with java -jar that holds no connection code. With no - session in its environment, the program starts `dagger session` on its - first call and stops it before the JVM exits, so no session process - outlives the program. The project builds with mvn package in a container - with no engine and no dagger CLI. - """ - pub standaloneClientCheck(ws: Workspace!): Void @check { - let appPath = "standalone-app" - let javaClient = container.from(runtimeImage(ws, "java")).withExec(["apk", "add", "--no-cache", "git"]) - let added = sdkClient(ws, engineDev(ws: daggerSource(floorCommit)).installClient(client: javaClient)) - .withExec(["cp", "-R", ".dagger/modules/e2e/fixtures/standalone/app", appPath]) - .withWorkdir(appPath) - .withExec(withoutOuterSession([ - "--auto-apply", "module", "client", "add", "../.dagger/modules/e2e/fixtures/clients/dep", "--sdk", "java", - ])) - let jar = container - .from(runtimeImage(ws, "maven")) - .withoutEntrypoint - .withMountedCache("/root/.m2", cacheVolume("engine-e2e-maven-m2")) - .withDirectory("/app", added.directory(".")) - .withWorkdir("/app") - .withExec(["mvn", "package", "--no-transfer-progress"]) - .file("/app/target/app.jar") - # CLISession runs the CLI installClient mounts at /.dagger-cli. - let script = "set -e\n" + - "env -u DAGGER_SESSION_PORT -u DAGGER_SESSION_TOKEN java -jar app.jar\n" + - "if ps -o args | grep -qE '[d]agger[^ ]* session'; then ps -o pid,args >&2; exit 1; fi\n" - let ran = added.withFile("app.jar", jar).withExec(["sh", "-c", script], expect: ReturnType.ANY) - let said = ran.stdout + ran.stderr - assert(ran.exitCode == 0, "the program failed, or left its dagger session running:\n" + said) - assert(ran.stdout.trimSpace == "hello from the client dependency", "the program did not call its client:\n" + said) - - null - } - - """ - The image a single-FROM Dockerfile under runtime/images names. - """ - let runtimeImage(ws: Workspace!, name: String!): String! { - ws.file("/runtime/images/" + name + "/Dockerfile").contents.trimSpace.trimPrefix("FROM ") - } - - """ - A git server for one repository, pinned.git, that a push can add to. Its - first commit, tagged v1.0.0, is a module whose message is its version. - """ - let gitServer: Service! { - container - .from("alpine:3.22") - .withoutEntrypoint - .withExec(["apk", "add", "--no-cache", "git", "git-daemon"]) - .withNewFile("/src/dagger-module.toml", "name = \"pinned\"\nengineVersion = \"v1.0.0-0\"\n\n[runtime]\n source = \"dang\"\n") - .withNewFile("/src/main.dang", "type Pinned {\n pub message: String! { \"v1.0.0\" }\n}\n") - .withWorkdir("/src") - .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", "v1.0.0"]) - .withExec(["git", "tag", "v1.0.0"]) - .withExec(["git", "clone", "-q", "--bare", ".", "/srv/pinned.git"]) - .withExposedPort(9418) - .withDefaultArgs(["git", "daemon", "--export-all", "--enable=receive-pack", "--base-path=/srv", "/srv"]) - .asService - } - - """ - A module whose call of its git client is never cached, so a call in a later - session loads the client again. - """ - let pinAppSource: String! { - "package io.dagger.modules.pinapp;\n" - + "\n" - + "import static io.dagger.client.modules.pinned.Pinned.pinned;\n" - + "\n" - + "import io.dagger.client.exception.DaggerQueryException;\n" - + "import io.dagger.module.annotation.Function;\n" - + "import io.dagger.module.annotation.Object;\n" - + "import java.util.concurrent.ExecutionException;\n" - + "\n" - + "@Object\n" - + "public class PinApp {\n" - + " @Function(cache = \"never\")\n" - + " public String message()\n" - + " throws ExecutionException, DaggerQueryException, InterruptedException {\n" - + " return \"pinned: \" + pinned().message();\n" - + " }\n" - + "}\n" - } -} diff --git a/.dagger/modules/engine-e2e/workspace.toml b/.dagger/modules/engine-e2e/workspace.toml deleted file mode 100644 index 70e8069..0000000 --- a/.dagger/modules/engine-e2e/workspace.toml +++ /dev/null @@ -1,13 +0,0 @@ -# The workspace the e2e checks run in: this checkout as its java SDK, and the -# e2e checks of it. engine-e2e puts this file in place of dagger.toml in the -# copy it runs the checks on. - -[modules.e2e] -source = ".dagger/modules/e2e" - -[modules.java-sdk] -source = "." -check.skip = ["*"] - -[sdks.java] -module = "java-sdk" diff --git a/AGENTS.md b/AGENTS.md index 8973d84..21443d2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,6 +18,10 @@ dagger check -m .dagger/modules/e2e find-client-root-check generate-scope-init-c dagger check -m .dagger/modules/e2e 'e2e:*' ``` +A check of a namespace is named with its path, such as +`collections:collection-check`. A name that matches no check passes, so +confirm a pattern with `-l` first. + Run the SDK library's unit tests and the staleness checks of the committed assets: @@ -26,24 +30,8 @@ dagger check packager:unit-tests dagger check packager:generate:stale templates:generate:stale ``` -Without a pattern, `dagger check` also selects the `engine-e2e` checks, which -build engines from dagger/dagger commits: - -```sh -dagger check engine-e2e:floor-check -dagger check engine-e2e:below-floor-check -dagger check engine-e2e:dev-sdk-check -``` - -`floor-check` runs every e2e check on the floor engine, built from its commit. -`below-floor-check` checks that v1.0.0-beta.25 is refused. `dev-sdk-check` -initializes a Java module through the CLI on the floor engine and calls it. To -run e2e checks on the floor's released engine instead: - -```sh -dagger check --engine=image://registry.dagger.io/engine:v1.0.0-beta.26 \ - -m .dagger/modules/e2e find-client-root-check -``` +The root `dagger.toml` installs the e2e module, so `dagger check` without a +pattern runs all of these checks. Judge a check by `dagger check`, never by `dagger call `: on v1.0.0-beta.18, `dagger call` exits 0 when the check fails. diff --git a/README.md b/README.md index 666b8e6..7129d1a 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,7 @@ add one, such as `slf4j-simple`, to see the session's progress. ## Collections `@Collection` marks an object whose items the engine serves by key, as `keys`, -`get`, `list`, `subset` and `batch`. `@Keys` marks its keys field, `@Get` its +`get`, `list` and `subset`. `@Keys` marks its keys field, `@Get` its get function, and `@Delta` a `CollectionDelta` field that receives the keys added and removed since the module returned it. A function that returns its receiver keeps the collection's base; a new instance starts its own. @@ -397,21 +397,12 @@ dagger check ``` On the engine the CLI runs on, this runs the SDK library's unit tests -(`packager:unit-tests`) and the staleness checks of the prebuilt assets and the -templates. The `engine-e2e` checks build engines from the dagger/dagger commits -pinned in `.dagger/modules/engine-e2e`: - -- `engine-e2e:floor-check` builds the floor release, `v1.0.0-beta.26`, and runs - every e2e check on it. -- `engine-e2e:dev-sdk-check` installs this checkout as the `java` SDK on the - same engine, initializes a Java module through the CLI, and calls it. -- `engine-e2e:below-floor-check` builds `v1.0.0-beta.25` and checks that - generation and `dagger module init` refuse it. -- `engine-e2e:cache-policy-sessions-check`, `pinned-git-client-check` and - `standalone-client-check` run calls in sessions of their own on the same - engine, which the e2e checks cannot do: their calls share the check's - session. - -`dagger.toml` does not install the `e2e` module, so `dagger check` runs the e2e -checks only on the floor engine. AGENTS.md has the commands that run them on the -local engine. +(`packager:unit-tests`), the staleness checks of the prebuilt assets and the +templates, and the e2e checks of `.dagger/modules/e2e`. They are not run on an +engine at the floor, `v1.0.0-beta.26`. + +The e2e checks drive the CLI of the engine that runs them. Most CLI calls share +the check's session. `entrypoint:cache-policy-sessions-check`, +`clients:pinned-git-client-check` and `standalone:standalone-client-check` give +each call a session of its own. `dev-sdk-check` installs this checkout as the +`java` SDK, initializes a Java module through the CLI, and calls it. diff --git a/dagger.lock b/dagger.lock index d446eb7..bfffb3c 100644 --- a/dagger.lock +++ b/dagger.lock @@ -20,4 +20,5 @@ ["","oci-sha",["docker.io/library/golang:1.25-alpine"],"sha256:1ae0735f00daffa3aaf1363a5184c0d2dc55c78e3db4ec70241cdac97bf84b59"] ["","oci-sha",["docker.io/library/golang:1.26-alpine"],"sha256:ce864e7223ac17b1775e6fd0b4c0db580c2eb50e7953a427916379e4b92a1628"] ["","oci-sha",["docker.io/tonistiigi/xx:1.2.1"],"sha256:8879a398dedf0aadaacfbd332b29ff2f84bc39ae6d4e9c0a1109db27ac5ba012"] +["","oci-sha",["registry.dagger.io/engine:v1.0.0-beta.28"],"sha256:06d04ebed5f4042a0aad7fcff7dd3734bc06f9f994a7338e0138326c9605fb5c"] ["","vanity-url",["https://dagger.io/linux/alpine"],"https://github.com/dagger/alpine"] \ No newline at end of file diff --git a/dagger.toml b/dagger.toml index 3feaeed..8a1ebbb 100644 --- a/dagger.toml +++ b/dagger.toml @@ -3,8 +3,8 @@ # Example: # dagger module install github.com/dagger/dagger/modules/wolfi -[modules.engine-e2e] -source = ".dagger/modules/engine-e2e" +[modules.e2e] +source = ".dagger/modules/e2e" [modules.packager] source = ".dagger/modules/packager" diff --git a/docs/collections.md b/docs/collections.md index 81200a0..e0e200c 100644 --- a/docs/collections.md +++ b/docs/collections.md @@ -9,6 +9,8 @@ resolves ([dagger/dagger#14447](https://github.com/dagger/dagger/pull/14447)), and item selectors on `dagger call` ([dagger/dagger#14590](https://github.com/dagger/dagger/pull/14590), [dagger/dagger#14602](https://github.com/dagger/dagger/pull/14602)). +v1.0.0-beta.22 replaces the `batch` operation with filtered collection views +([dagger/dagger#14802](https://github.com/dagger/dagger/pull/14802)). ## Declare a collection @@ -102,15 +104,22 @@ collection: | `list` | Every item | | `get` | The item with the given key | | `subset` | A collection of the items with the given keys | -| `batch` | The collection's other functions | -Every function other than the get function is a batch function. The engine -calls a batch function on a copy of the collection whose keys field holds only -the selected keys. In the example, `selected` returns those keys. The engine -adds `batch` only when the collection has a batch function. +The collection keeps its other functions. The engine calls them on a copy of +the collection whose keys field holds only the selected keys. In the example, +`selected` returns those keys. -A batch check or generator replaces the check or generator with the same name -on the item type. Without one, the item's check runs once per selected item. +A check or generator on the item type runs once per selected item. When +`dagger check` runs an item's check that takes the collection as an argument, +the engine passes the collection narrowed to the selected items: + +```java +@Function +@Check +public void verify(Items items) { + // items.selected() lists every item the selectors name +} +``` An item can be a collection itself. @@ -130,7 +139,7 @@ import io.dagger.client.modules.shelf.ShelfItems; ShelfItems items = shelf().items(); List keys = items.keys(); String name = items.get("a").name(); -List removed = items.subset(List.of("c")).batch().removed(); +List removed = items.subset(List.of("c")).removed(); ``` ## Select items on the command line @@ -141,13 +150,14 @@ module and the item type, so `Item` in the `shelf` module adds `--shelf-item`: ```shell dagger call items name --shelf-item=a dagger call --shelf-item=a name -dagger call items selected --shelf-item=a --shelf-item=c +dagger call items subset --keys=a,c selected dagger call items get --key=a name ``` A selector after the collection selects within it. A selector before the first -function starts the pipeline at the item. A repeated selector selects a subset -for a batch function. `get` and `subset` remain available by name. +function starts the pipeline at the item. `get` and `subset` remain available +by name, and `subset` selects several items for the collection's other +functions. When more than one function returns the collection, each flag also names its function. If `items` and `others` both return `Items`, the flags are @@ -158,8 +168,8 @@ The help of a command after the collection lists the flags under `SELECTION`, for example `dagger call items selected --help`. `dagger call --help` does not list them. -`dagger check` takes the flags for a module that the workspace registers. For -a check `verify` on `Items`: +`dagger check` takes the flags for a module that the workspace registers. A +check `verify` on `Item` runs once for each selected item: ```shell dagger check --shelf --check=verify --shelf-item=a --shelf-item=b diff --git a/helpers/render-java-template/main.go b/helpers/render-java-template/main.go index c04ab40..49ac675 100644 --- a/helpers/render-java-template/main.go +++ b/helpers/render-java-template/main.go @@ -9,14 +9,14 @@ import ( "github.com/iancoleman/strcase" ) -// render-java-template NAME TEMPLATE_DIR OUT_DIR +// render-java-template NAME CLASS TEMPLATE_DIR OUT_DIR // // Substitutes the Dagger module name into both file paths and file contents, // matching the placeholders used by the default Java template: // // dagger-module-placeholder -> kebab(name) (artifactId / name) // daggermoduleplaceholder -> pkg(name) (package segment) -// DaggerModule -> camel(name) (class name + file name) +// DaggerModule -> CLASS (class name + file name) // // pkg(name) lowercases name and drops "-" and "_", so it is a valid single // Java package segment (e.g. "my-module" -> "mymodule"). @@ -28,15 +28,15 @@ func main() { } func run(args []string) error { - if len(args) != 3 { - return fmt.Errorf("usage: render-java-template NAME TEMPLATE_DIR OUT_DIR") + if len(args) != 4 { + return fmt.Errorf("usage: render-java-template NAME CLASS TEMPLATE_DIR OUT_DIR") } - name, templateDir, outDir := args[0], args[1], args[2] + name, class, templateDir, outDir := args[0], args[1], args[2], args[3] pkg := strings.NewReplacer("-", "", "_", "").Replace(strings.ToLower(name)) repl := strings.NewReplacer( "dagger-module-placeholder", strcase.ToKebab(name), "daggermoduleplaceholder", pkg, - "DaggerModule", strcase.ToCamel(name), + "DaggerModule", class, ) return filepath.WalkDir(templateDir, func(path string, entry os.DirEntry, err error) error { if err != nil { diff --git a/main.dang b/main.dang index f556678..daf1a36 100644 --- a/main.dang +++ b/main.dang @@ -500,9 +500,16 @@ type JavaSdk { } """ - Render a Java template, substituting the requested module name. + Render a Java template, substituting the requested module name. The main + class is named as the engine formats a Java class name, the way codegen + names the class of the module's client. """ let renderedTemplate(name: String!, template: String!): Directory! { + let className = naming(version: entrypointTarget) + .formatIdentifiers(names: [name], casing: Casing.PASCAL, acronyms: AcronymStyle.CAPITALIZED)[0] ?? "" + if (className == "") { + raise "the engine formatted no Java class name for module " + JSON.encode(name) + } container .from("golang:1.25-alpine") .withoutEntrypoint @@ -523,7 +530,7 @@ type JavaSdk { ) .withWorkdir("/helper") .withExec(["go", "build", "-o", "/usr/local/bin/render-java-template", "."]) - .withExec(["render-java-template", name, "/template", "/rendered"]) + .withExec(["render-java-template", name, className, "/template", "/rendered"]) .directory("/rendered") } diff --git a/main.dang.tmpl b/main.dang.tmpl index dc88e4a..e829dff 100644 --- a/main.dang.tmpl +++ b/main.dang.tmpl @@ -500,9 +500,16 @@ type JavaSdk { } """ - Render a Java template, substituting the requested module name. + Render a Java template, substituting the requested module name. The main + class is named as the engine formats a Java class name, the way codegen + names the class of the module's client. """ let renderedTemplate(name: String!, template: String!): Directory! { + let className = naming(version: entrypointTarget) + .formatIdentifiers(names: [name], casing: Casing.PASCAL, acronyms: AcronymStyle.CAPITALIZED)[0] ?? "" + if (className == "") { + raise "the engine formatted no Java class name for module " + JSON.encode(name) + } container .from("golang:1.25-alpine") .withoutEntrypoint @@ -523,7 +530,7 @@ type JavaSdk { ) .withWorkdir("/helper") .withExec(["go", "build", "-o", "/usr/local/bin/render-java-template", "."]) - .withExec(["render-java-template", name, "/template", "/rendered"]) + .withExec(["render-java-template", name, className, "/template", "/rendered"]) .directory("/rendered") } diff --git a/mod.dang b/mod.dang index 2f41ac8..dd26f41 100644 --- a/mod.dang +++ b/mod.dang @@ -155,13 +155,56 @@ type Mod { serveModule reads in the calling module's own tree. """ 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 a checkout generates. A Git client is a module of the + workspace when it is pinned at the workspace's commit, and its ref and the + workspace address name the same repository with the same selector, or the + address names none. The Go and Python SDKs bind clients by the same rule + (dagger/go-sdk#73, dagger/go-sdk#78, dagger/go-sdk#79). + """ + let inWorkspace(client: ModuleSource!): Boolean! { + let commit = ws.git.head.commitSha rescue { err: Error => "" } + if (client.cloneRef == "" or client.pin == "" or client.pin != commit) { + false + } else { + let workspaceSelector = gitSelector(ws.address, client.cloneRef) + let moduleSelector = gitSelector(client.asString, client.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. A workspace address + has the form [/]@; a module of the workspace, + #[:]. Both are compared without their URL scheme. + """ + let gitSelector(ref: String!, cloneRef: String!): String { + let repo = cloneRef.split("://", limit: 2)[1] ?? cloneRef + let path = ref.split("://", limit: 2)[1] ?? 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] ?? "" + } + } + """ The live engine version, without build metadata. diff --git a/sdk/dagger-java-sdk/src/main/java/io/dagger/module/annotation/Collection.java b/sdk/dagger-java-sdk/src/main/java/io/dagger/module/annotation/Collection.java index d2df74b..9906dda 100644 --- a/sdk/dagger-java-sdk/src/main/java/io/dagger/module/annotation/Collection.java +++ b/sdk/dagger-java-sdk/src/main/java/io/dagger/module/annotation/Collection.java @@ -8,10 +8,10 @@ /** * Mark an object as a collection: a set of items, each with a unique key. * - *

Callers do not see the collection's own members. The engine serves {@code keys}, {@code get}, - * {@code list}, {@code subset}, and {@code batch} on it instead. A collection has a keys field, - * marked with {@link Keys}, and a get function, marked with {@link Get}. Without the markers, the - * engine looks for members named {@code keys} and {@code get}. + *

Callers do not see the collection's keys field and get function. The engine serves {@code + * keys}, {@code get}, {@code list}, and {@code subset} on it instead, beside its other functions. A + * collection has a keys field, marked with {@link Keys}, and a get function, marked with {@link + * Get}. Without the markers, the engine looks for members named {@code keys} and {@code get}. * *

{@code
  * @Object