diff --git a/.dagger/modules/e2e/entrypoint.dang b/.dagger/modules/e2e/entrypoint.dang index e3a427d..ee88987 100644 --- a/.dagger/modules/e2e/entrypoint.dang +++ b/.dagger/modules/e2e/entrypoint.dang @@ -216,6 +216,66 @@ type EntrypointChecks { null } + let regenerate(ws: Workspace!): Workspace! { + javaSdk.generateScope(ws, isModule: true, name: appName, clients: []) + } + + """ + Generation writes the entrypoint's dang.toml with language 2.1 and the + release the entrypoint declares on its process, replaces an owned Dagger + version, keeps other settings, and changes nothing the second time. + """ + pub dangConfigCheck(ws: Workspace!): Void @check { + let configPath = "/" + appPath + "/src/generated/dang/entrypoint/dang.toml" + let seeded = regenerate(ws.withWorkdir(appPath)) + .withNewFile(configPath, "[imports.Dagger]\ndagger = true\n\n[imports.Helpers]\npath = \"./helpers\"\n") + .withNewFile("/" + appPath + "/src/generated/dang/entrypoint/helpers/main.dang", "pub helper: String! { \"kept\" }\n") + let generated = regenerate(seeded) + let config = json.withContents((JSON.encode(TOML.decode(generated.file(configPath).contents)) :: Dagger.JSON!)) + let declared = config.field(["imports", "Dagger", "dagger"]).asString + let main = generated.file("/" + appPath + "/src/generated/dang/entrypoint/main.dang").contents + assert(config.field(["dang"]).asString == "2.1", "dang.toml does not set language 2.1") + assert(declared == javaSdk.clientVersion, "dang.toml declares " + declared) + assert(main.contains(".withEnvVariable(\"DAGGER_CLIENT_VERSION\", \"" + declared + "\")"), "the entrypoint declares another release:\n" + main) + assert(config.field(["imports", "Helpers", "path"]).asString == "./helpers", "another import was lost") + assert(generated.directory("/" + appPath + "/src/generated/dang/entrypoint").exists("helpers/main.dang"), "a file beside dang.toml was lost") + assert(generated.file("/" + appPath + "/src/generated/sha256sums").contents.contains("dang/entrypoint/dang.toml"), "the generated sums do not list dang.toml") + assert(regenerate(generated).changes(generated).isEmpty, "a second generation changed the module") + let inherited = generated.withoutFile(configPath).withNewFile("/" + appPath + "/src/dang.toml", "dang = \"2.1\"\n\n[imports.Dagger]\ndagger = true\n") + assert((regenerate(inherited).cwd rescue { err: Error => err.message }) == generated.cwd, "a default dang.toml above the entrypoint was refused") + [ + [configPath, "dang = \"2.0\"\n", "sets dang = \"2.0\""], + [configPath, "[imports.Dagger]\npath = \"../dagger\"\n", "a path for the Dagger import"], + [configPath, "[imports.Old]\ndagger = \"v1.0.0-beta.20\"\n", "imports.Old.dagger"], + ["/" + appPath + "/src/dang.toml", "[imports.Other]\npath = \"../other\"\n", "would hide"], + ["/" + appPath + "/src/dang.toml", "[imports.Dagger]\ndagger = \"v1.0.0-beta.20\"\n", "would hide"], + ["/" + appPath + "/src/dang.toml", "dang = \"2.0\"\n", "would hide"], + ].each { c => + let refused = regenerate(generated.withoutFile(configPath).withNewFile(c[0] ?? "", c[1] ?? "")).cwd rescue { err: Error => err.message } + assert(refused.contains(c[2] ?? ""), "dang.toml " + JSON.encode(c[1] ?? "") + " was not refused: " + refused) + } + null + } + + """ + The targetVersion setting accepts the release this SDK generates for, in any + spelling, and refuses every other value before anything is written. + """ + pub targetVersionCheck(ws: Workspace!): Void @check { + let target = javaSdk.clientVersion + let scope = ws.withWorkdir(appPath) + let generated = regenerate(scope) + ["v1.0.0-beta.20", "latest"].each { pin => + let refused = javaSdk(targetVersion: pin).generateScope(scope, isModule: true, name: appName, clients: []) + .cwd rescue { err: Error => err.message } + assert(refused.contains("targetVersion \"" + pin + "\" is not " + target), "targetVersion " + pin + " was not refused: " + refused) + } + let pinned = javaSdk(targetVersion: target.trimPrefix("v") + "+abc") + .generateScope(scope, isModule: true, name: appName, clients: []) + assert(pinned.changes(generated).isEmpty, "targetVersion naming " + target + " changed the module") + null + } + """ A module loaded by git reference builds from its commit, with no checkout of the caller's. diff --git a/README.md b/README.md index b4b11c4..cfa82dd 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.8` tag. ## Install @@ -64,6 +64,7 @@ generates the SDK bindings in one step: src/generated/java/io/dagger/gen/entrypoint/Entrypoint.java # generated entrypoint src/generated/dang/entrypoint/main.dang # the module's types and its calls src/generated/dang/entrypoint/build.dang # the jar's Maven build + src/generated/dang/entrypoint/dang.toml # the Dang and Dagger versions it is written against src/generated/sha256sums # every generated file, with its SHA-256 sdk/src/main/java/... # vendored SDK library sdk/src/processor/java/... # vendored annotation processor @@ -147,6 +148,17 @@ as `include`. `"never"`, `"session"`, or a duration such as `"10m"` after which the result is computed again. +### The engine release a module targets + +A module on the entrypoint targets `v1.0.0-beta.25`: its bindings use the +running engine's view of that release, its entrypoint sets +`DAGGER_CLIENT_VERSION` on the process that runs a call, and generation writes +`src/generated/dang/entrypoint/dang.toml` with `dang = "2.1"` and that release +on the `Dagger` import. Generation keeps other files and settings there, drops +comments, and refuses settings it would break. Those files are listed in +`src/generated/sha256sums`, so after editing one, run `dagger generate`. The +`targetVersion` scope setting accepts only that release. + ### Stale generated files A call refuses a module on the entrypoint whose generated files are stale, and diff --git a/dagger-module.toml b/dagger-module.toml index 5072199..5c7aeaf 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.8" diff --git a/dagger.json b/dagger.json index b30b78f..deba4d6 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.8" } ] } diff --git a/dagger.lock b/dagger.lock index 2a8d459..201aec2 100644 --- a/dagger.lock +++ b/dagger.lock @@ -4,13 +4,13 @@ [["version","2"]] ["","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.8"]],"refs/tags/v1.0.8"] ["","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.8"],"31dafd0c74d9a08faa00c09dce87a5af072e7a9d"] ["","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/entrypoint/build.dang.tmpl b/entrypoint/build.dang.tmpl index 6d6abd3..683fc12 100644 --- a/entrypoint/build.dang.tmpl +++ b/entrypoint/build.dang.tmpl @@ -30,6 +30,7 @@ type JavaModuleBuild { ) let built = module .withEnvVariable("_DAGGER_JAVA_SDK_MODULE_NAME", "") + .withEnvVariable("_DAGGER_JAVA_SDK_CLIENT_VERSION", "") .withExec(["sh", "-c", buildScript]) refuseStale( built.file("/tmp/stale").contents, diff --git a/main.dang b/main.dang index ce88c76..75c662e 100644 --- a/main.dang +++ b/main.dang @@ -44,6 +44,12 @@ type JavaSdk { """ dangEntrypoint: Boolean + """ + The engine release a module on the entrypoint targets. Only the release this + SDK generates for is accepted until Java libraries exist for older ones. + """ + targetVersion: String! = "" + """ Runtime source written into the dagger-module.toml of a new module on the runtime. @@ -112,6 +118,7 @@ type JavaSdk { vendorSdkJar: false, dangEntrypoint: null, clients: clients, + clientVersion: "", ).generated } else { let scope = normalizePath(ws.cwd) @@ -143,6 +150,7 @@ type JavaSdk { vendorSdkJar: vendorSdkJar, dangEntrypoint: null, clients: [], + clientVersion: "", ).generated.withWorkdir(scope) } } @@ -181,7 +189,7 @@ type JavaSdk { refuseEntrypointSettings(ws, scope, "dagger.json", "sdk", clients) let staged = sdkHelpers.moduleManifest .withName(name: name) - .withLegacyDangRuntime(engineVersion: entrypointTarget) + .withLegacyDangRuntime(engineVersion: clientVersion) .generate(ws.withWorkdir(scope), legacyJson: false) .withWorkdir(".") let generated = Mod( @@ -191,6 +199,7 @@ type JavaSdk { vendorSdkJar: vendorSdkJar, dangEntrypoint: entrypointPath, clients: clients, + clientVersion: clientVersion, ).generated sdkHelpers.moduleManifest .withName(name: name) @@ -369,10 +378,22 @@ type JavaSdk { The engine release a module on the entrypoint is staged at, so its bindings are generated from the API view the engine serves the module: an entrypoint module carries no engine version, and the engine serves it a release before - the identifier-casing cut of v1.0.0-beta.22. Pre-cut until the Java codegen - is ported to the beta.22 naming rules. + the identifier-casing cut. Pre-cut until the Java codegen is ported to the + new naming rules. + """ + let entrypointTarget: String! = "v1.0.0-beta.25" + + """ + The engine release a module on the entrypoint targets, refusing a + targetVersion setting for any other release. """ - let entrypointTarget: String! = "v1.0.0-beta.21" + clientVersion: String! { + let pinned = "v" + (targetVersion.trimPrefix("v").split("+")[0] ?? targetVersion) + if (targetVersion != "" and pinned != entrypointTarget) { + raise "targetVersion " + JSON.encode(targetVersion) + " is not " + entrypointTarget + ", the only release this SDK generates for" + } + entrypointTarget + } """ The first engine release this SDK runs on. diff --git a/main.dang.tmpl b/main.dang.tmpl index 7f23c6e..5e566ee 100644 --- a/main.dang.tmpl +++ b/main.dang.tmpl @@ -44,6 +44,12 @@ type JavaSdk { """ dangEntrypoint: Boolean + """ + The engine release a module on the entrypoint targets. Only the release this + SDK generates for is accepted until Java libraries exist for older ones. + """ + targetVersion: String! = "" + """ Runtime source written into the dagger-module.toml of a new module on the runtime. @@ -112,6 +118,7 @@ type JavaSdk { vendorSdkJar: false, dangEntrypoint: null, clients: clients, + clientVersion: "", ).generated } else { let scope = normalizePath(ws.cwd) @@ -143,6 +150,7 @@ type JavaSdk { vendorSdkJar: vendorSdkJar, dangEntrypoint: null, clients: [], + clientVersion: "", ).generated.withWorkdir(scope) } } @@ -181,7 +189,7 @@ type JavaSdk { refuseEntrypointSettings(ws, scope, "dagger.json", "sdk", clients) let staged = sdkHelpers.moduleManifest .withName(name: name) - .withLegacyDangRuntime(engineVersion: entrypointTarget) + .withLegacyDangRuntime(engineVersion: clientVersion) .generate(ws.withWorkdir(scope), legacyJson: false) .withWorkdir(".") let generated = Mod( @@ -191,6 +199,7 @@ type JavaSdk { vendorSdkJar: vendorSdkJar, dangEntrypoint: entrypointPath, clients: clients, + clientVersion: clientVersion, ).generated sdkHelpers.moduleManifest .withName(name: name) @@ -369,10 +378,22 @@ type JavaSdk { The engine release a module on the entrypoint is staged at, so its bindings are generated from the API view the engine serves the module: an entrypoint module carries no engine version, and the engine serves it a release before - the identifier-casing cut of v1.0.0-beta.22. Pre-cut until the Java codegen - is ported to the beta.22 naming rules. + the identifier-casing cut. Pre-cut until the Java codegen is ported to the + new naming rules. + """ + let entrypointTarget: String! = "v1.0.0-beta.25" + + """ + The engine release a module on the entrypoint targets, refusing a + targetVersion setting for any other release. """ - let entrypointTarget: String! = "v1.0.0-beta.21" + clientVersion: String! { + let pinned = "v" + (targetVersion.trimPrefix("v").split("+")[0] ?? targetVersion) + if (targetVersion != "" and pinned != entrypointTarget) { + raise "targetVersion " + JSON.encode(targetVersion) + " is not " + entrypointTarget + ", the only release this SDK generates for" + } + entrypointTarget + } """ The first engine release this SDK runs on. diff --git a/mod.dang b/mod.dang index ca94042..f23a44c 100644 --- a/mod.dang +++ b/mod.dang @@ -39,6 +39,12 @@ type Mod { """ let clients: [ModuleSource!]! + """ + The engine release the generated entrypoint declares in its process and its + dang.toml, empty without one. + """ + let clientVersion: String! + """ The shared local Maven repository. @@ -471,6 +477,7 @@ type Mod { .withDirectory("/module", moduleDir) .withWorkdir("/module") .withEnvVariable("_DAGGER_JAVA_SDK_MODULE_NAME", name) + .withEnvVariable("_DAGGER_JAVA_SDK_CLIENT_VERSION", clientVersion) .withExec(["mvn", "compile", "-Ddagger.proc=full", "-Ddagger.sdk=prebuilt", "-Ddagger.sdk.version=" + name, "--no-transfer-progress"]) } @@ -488,7 +495,8 @@ type Mod { currentModule.source.file("entrypoint/build.dang.tmpl").contents .replace("", dockerfileImage("runtime/images/maven/Dockerfile")) .replace("", dockerfileImage("runtime/images/java/Dockerfile")) - .replace("", name), + .replace("", name) + .replace("", clientVersion), ) } @@ -518,6 +526,58 @@ type Mod { .stdout } + let entrypointDir: String! { joinPath(rootPath, dangEntrypoint ?? "") } + + let entrypointConfig: String! { entrypointDir + "/dang.toml" } + + let decodedDangConfig(file: File!): Dagger.JSONValue! { + json.withContents((JSON.encode(TOML.decode(file.contents)) :: Dagger.JSON!)) + } + + """ + Refuse what the Go SDK refuses: another language, a path on the Dagger + import, another Dagger version, or an ancestor dang.toml the new file hides, + unless it holds only what generation writes. + """ + let refuseDangConfig: Void { + let above = (dangEntrypoint ?? "").split("/").dropLast(1) + .reduce([rootPath]) { dirs, part => dirs + [joinPath(dirs.takeLast(1)[0] ?? rootPath, part)] } + .map { dir => joinPath(dir, "dang.toml") } + let present = ws.directory("/", include: [entrypointConfig] + above) + if (present.exists(entrypointConfig) == false) { + let inherited = above.filter { path => present.exists(path) }.takeLast(1)[0] ?? "" + if (inherited == "") { + return null + } + let config = decodedDangConfig(present.file(inherited)) + let dagger = toString(config.field(["imports", "Dagger", "dagger"]).contents) rescue "true" + let isDefault = config.fields.all { f => f == "dang" or f == "imports" } and + (toString(config.field(["dang"]).contents) rescue "\"2.1\"") == "\"2.1\"" and + (config.field(["imports"]).fields rescue []).all { i => i == "Dagger" } and + (config.field(["imports", "Dagger"]).fields rescue []).all { f => f == "dagger" } and + (dagger == "true" or dagger == JSON.encode(clientVersion)) + if (isDefault == false) { + raise inherited + " has settings that a generated " + entrypointConfig + " would hide, because the engine reads only the nearest dang.toml; move them to " + entrypointConfig + } + return null + } + let file = present.file(entrypointConfig) + let config = sdkHelpers.dangConfig(loadToml: file) + if (config.version != "2.1") { + raise entrypointConfig + " sets dang = " + JSON.encode(config.version) + ", and the generated entrypoint is written in 2.1" + } + config.daggerImports.{{name, version}}.each { declared => + if (declared.name != "Dagger" and declared.version != null and declared.version != clientVersion) { + raise entrypointConfig + " sets imports." + declared.name + ".dagger = " + JSON.encode(declared.version ?? "") + ", and this module targets " + clientVersion + } + } + # sdk-helpers drops a path on the import it sets without a word. + if (decodedDangConfig(file).field(["imports", "Dagger"]).fields.contains("path") rescue false) { + raise entrypointConfig + " sets a path for the Dagger import, which the generated entrypoint needs from the engine" + } + null + } + """ The image a single-FROM Dockerfile of the runtime names, which Dependabot keeps up to date. @@ -539,6 +599,9 @@ type Mod { return withSdkAndClients(staleClientDirs(committed), vendored, projectCoreSchema, projectSdkVersion, pom) } requireCoreClientSource(committed) + if (dangEntrypoint != null) { + refuseDangConfig + } let modSource = ws.moduleSource(workspaceRef(rootPath)) let name = modSource.moduleName let introspectionJSON = modSource.introspectionSchemaJSON @@ -580,13 +643,17 @@ type Mod { if (dangEntrypoint == null) { return staged } - let withEntrypoint = staged.withNewDirectory( - workspaceRef(joinPath(rootPath, dangEntrypoint ?? "")), - dangEntrypointDir(processedModule, name), - ) - withEntrypoint.withNewFile( + let withEntrypoint = staged.withDirectory(workspaceRef(entrypointDir), dangEntrypointDir(processedModule, name)) + let leaf = ws.directory("/", include: [entrypointConfig]) + let configured = sdkHelpers + .dangConfig(loadToml: if (leaf.exists(entrypointConfig)) { leaf.file(entrypointConfig) } else { null }) + .withVersion("2.1") + .withDaggerImport(name: "Dagger", version: clientVersion) + .generate(withEntrypoint.withWorkdir(entrypointDir)) + .withWorkdir(".") + configured.withNewFile( workspaceRef(joinPath(rootPath, generatedSumsPath)), - generatedSums(withEntrypoint), + generatedSums(configured), ) } diff --git a/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DaggerModuleAnnotationProcessor.java b/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DaggerModuleAnnotationProcessor.java index 3ae44c5..3cd669b 100644 --- a/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DaggerModuleAnnotationProcessor.java +++ b/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DaggerModuleAnnotationProcessor.java @@ -893,7 +893,10 @@ private void writeDangEntrypoint(ModuleInfo moduleInfo) throws IOException { .createResource(StandardLocation.CLASS_OUTPUT, "", "dagger/entrypoint/main.dang"); try (Writer writer = file.openWriter()) { writer.write( - DangEntrypointRenderer.render(moduleInfo, System.getenv("_DAGGER_JAVA_SDK_MODULE_NAME"))); + DangEntrypointRenderer.render( + moduleInfo, + System.getenv("_DAGGER_JAVA_SDK_MODULE_NAME"), + Objects.requireNonNullElse(System.getenv("_DAGGER_JAVA_SDK_CLIENT_VERSION"), ""))); } } diff --git a/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DangEntrypointRenderer.java b/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DangEntrypointRenderer.java index d2379c8..a3d756b 100644 --- a/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DangEntrypointRenderer.java +++ b/sdk/dagger-java-annotation-processor/src/main/java/io/dagger/annotation/processor/DangEntrypointRenderer.java @@ -12,7 +12,8 @@ /** * Renders the module's Dang entrypoint: the {@link ModuleInfo} that {@code register()} sends to the * engine at run time, as static {@code types}, and a {@code call} that runs the generated {@code - * Entrypoint} in {@code engine-call} mode. Both backends must describe the same schema. + * Entrypoint} in {@code engine-call} mode, declaring the engine release its bindings target on the + * process it starts. Both backends must describe the same schema. */ final class DangEntrypointRenderer { @@ -24,7 +25,7 @@ final class DangEntrypointRenderer { private DangEntrypointRenderer() {} - static String render(ModuleInfo moduleInfo, String moduleName) { + static String render(ModuleInfo moduleInfo, String moduleName, String clientVersion) { DaggerType.setKnownEnums(moduleInfo.enumInfos().keySet()); List defs = new ArrayList<>(); @@ -43,7 +44,7 @@ static String render(ModuleInfo moduleInfo, String moduleName) { b.append(Dang.indent(def, 6)).append(",\n"); } b.append(" ]\n }\n\n"); - b.append(CALL); + b.append(CALL.replace("", Dang.quote(clientVersion))); b.append("}\n"); return b.toString(); } @@ -82,6 +83,7 @@ static String render(ModuleInfo moduleInfo, String moduleName) { " let result = build", " .runtime(jar)", " .withEnvVariable(\"DAGGER_MODULE_CALL_DIGEST\", callDigest ?? \"\")", + " .withEnvVariable(\"DAGGER_CLIENT_VERSION\", )", " .withExec(", " [\"java\", \"-jar\", \"/opt/module/module.jar\", \"engine-call\", \"--output\", " + Dang.quote(RESULT_PATH) diff --git a/sdk/dagger-java-annotation-processor/src/test/java/io/dagger/annotation/processor/DangEntrypointRendererTest.java b/sdk/dagger-java-annotation-processor/src/test/java/io/dagger/annotation/processor/DangEntrypointRendererTest.java index 3418495..eb2bc91 100644 --- a/sdk/dagger-java-annotation-processor/src/test/java/io/dagger/annotation/processor/DangEntrypointRendererTest.java +++ b/sdk/dagger-java-annotation-processor/src/test/java/io/dagger/annotation/processor/DangEntrypointRendererTest.java @@ -21,6 +21,8 @@ class DangEntrypointRendererTest { private static final String ENUM_QNAME = "io.dagger.modules.demo.Severity"; + private static final String CLIENT_VERSION = "v1.2.3"; + @AfterEach void resetKnownEnums() { DaggerType.setKnownEnums(Set.of()); @@ -28,14 +30,14 @@ void resetKnownEnums() { @Test void theFileStartsWithTheOwnershipHeader() { - assertThat(DangEntrypointRenderer.render(module(), "demo")) + assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION)) .startsWith("# This file has been generated by dagger-java-sdk. DO NOT EDIT.\n"); } /** Pinned whole: nothing parses this output before the engine loads the module. */ @Test void typesDescribesEveryObjectAndEnumWithoutAWorkspace() { - assertThat(DangEntrypointRenderer.render(module(), "demo")) + assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION)) .contains( String.join( "\n", @@ -94,7 +96,9 @@ void theEntryObjectWithoutConstructorArgumentsStillDeclaresAConstructor() { String dang = DangEntrypointRenderer.render( - new ModuleInfo(null, new ObjectInfo[] {entry, other}, Map.of()), "hello"); + new ModuleInfo(null, new ObjectInfo[] {entry, other}, Map.of()), + "hello", + CLIENT_VERSION); assertThat(dang).contains(".withConstructor(function(\"\", typeDef.withObject(\"Hello\")))"); assertThat(dang.split("\\.withConstructor\\(", -1)).hasSize(2); @@ -102,7 +106,7 @@ void theEntryObjectWithoutConstructorArgumentsStillDeclaresAConstructor() { @Test void sourcesReturnsTheModuleDirectoryAtItsWorkspacePath() { - assertThat(DangEntrypointRenderer.render(module(), "demo")) + assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION)) .contains( String.join( "\n", @@ -117,7 +121,7 @@ void sourcesReturnsTheModuleDirectoryAtItsWorkspacePath() { @Test void callRunsTheJarInEngineCallModeKeyedOnTheCallDigest() { - assertThat(DangEntrypointRenderer.render(module(), "demo")) + assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION)) .contains( String.join( "\n", @@ -128,7 +132,12 @@ void callRunsTheJarInEngineCallModeKeyedOnTheCallDigest() { " fnArgs: JSON!,", " callDigest: String,", " ): JSON! {")) - .contains(".withEnvVariable(\"DAGGER_MODULE_CALL_DIGEST\", callDigest ?? \"\")") + .contains( + String.join( + "\n", + " .withEnvVariable(\"DAGGER_MODULE_CALL_DIGEST\", callDigest ?? \"\")", + " .withEnvVariable(\"DAGGER_CLIENT_VERSION\", \"" + CLIENT_VERSION + "\")", + " .withExec(")) .contains( "[\"java\", \"-jar\", \"/opt/module/module.jar\", \"engine-call\", \"--output\"," + " \"/dagger/result.json\"],") @@ -140,7 +149,7 @@ void callRunsTheJarInEngineCallModeKeyedOnTheCallDigest() { @Test void aFailedCallRaisesTheTextAfterTheLastErrorMarker() { - assertThat(DangEntrypointRenderer.render(module(), "demo")) + assertThat(DangEntrypointRenderer.render(module(), "demo", CLIENT_VERSION)) .contains("let jar = build.jar.sync") .contains(".contents rescue {\n err: GraphQLError => raiseFunctionError(err)\n") .contains("let marker = \"::dagger-function-error::\"") @@ -161,7 +170,7 @@ void descriptionsAreEscapedSoTheOutputStaysParseable() { String dang = DangEntrypointRenderer.render( - new ModuleInfo(null, new ObjectInfo[] {object}, Map.of()), "demo"); + new ModuleInfo(null, new ObjectInfo[] {object}, Map.of()), "demo", CLIENT_VERSION); assertThat(dang) .contains( @@ -192,7 +201,7 @@ private static String renderFunction(String cache) { Optional.empty(), false); return DangEntrypointRenderer.render( - new ModuleInfo(null, new ObjectInfo[] {object}, Map.of()), "demo"); + new ModuleInfo(null, new ObjectInfo[] {object}, Map.of()), "demo", CLIENT_VERSION); } private static ObjectInfo object(String name, Optional constructor) {