Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
78 changes: 71 additions & 7 deletions .dagger/modules/e2e/clients.dang
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
82 changes: 42 additions & 40 deletions .dagger/modules/e2e/collections.dang
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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\"]}" +
"}}"

"""
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
27 changes: 25 additions & 2 deletions .dagger/modules/e2e/entrypoint.dang
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,13 +64,4 @@ public Items change(List<String> 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");
}
}
}
Loading