From bb75dc3157ffc36e8729181ede613ada416cb561 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Tue, 24 Nov 2026 18:56:08 +0300 Subject: [PATCH 1/2] Read the wasm differential test's cases from test-cases-java21 The test cases moved to test-cases-java21 in 970c3487, but wasmDifferentialTest still passed the old folder, so the release's wasm job failed with ENOENT before comparing anything. The jar it compares with runs on JDK 21, so the cases for JDK 21 are the ones. --- open-java-format-wasm/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-java-format-wasm/build.gradle b/open-java-format-wasm/build.gradle index cef77cd00..766d34734 100644 --- a/open-java-format-wasm/build.gradle +++ b/open-java-format-wasm/build.gradle @@ -118,7 +118,7 @@ def wasmDifferentialTest = tasks.register('wasmDifferentialTest', Exec) { wrapper.get(), java21.get().executablePath.asFile.path, allJar.get().archiveFile.get().asFile.path, - project(':open-java-format').file('src/test/resources/test-cases').path, + project(':open-java-format').file('src/test/resources/test-cases-java21').path, layout.buildDirectory.dir('wasm-differential').get().asFile.path, ] } as CommandLineArgumentProvider) From 4332239e09ee63f0b8c61b9e8a7ed55ea47509a7 Mon Sep 17 00:00:00 2001 From: Alex Abashev Date: Tue, 24 Nov 2026 19:01:29 +0300 Subject: [PATCH 2/2] Build and test the wasm module in CI, on the Java 25 cases too Until now only the release built the module, so a change that broke it showed in a release: the moved test-cases folder did. CI's new wasm job runs wasmTest as the release's does, after build. The differential test now runs the jar on the Oracle GraalVM 25 the module is built with, rather than on JDK 21, so that both parse with the same javac, and gives it the cases in test-cases-java25 as well as those in test-cases-java21. differential.mjs takes any number of case folders and names each input after its folder. --- .github/workflows/ci.yml | 66 +++++++++++++++++++ .github/workflows/release.yml | 2 +- README.md | 4 +- open-java-format-wasm/build.gradle | 8 ++- .../src/test/js/differential.mjs | 26 ++++---- settings.gradle | 2 +- 6 files changed, 89 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1b9c83a6..ec8401e5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -249,3 +249,69 @@ jobs: report_paths: '**/build/test-results/test/*.xml' annotate_only: true job_summary: true + + # The WebAssembly module, built and tested as the release's `wasm` job does, so that a change that breaks it shows + # in its pull request rather than in a release. The module itself is not kept. + wasm: + name: wasm + needs: build + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # The jars compile with Java 21 through JDK21_HOME, as in `native`. Installed before GraalVM, so that Gradle + # still runs on GraalVM. No problem matcher: `build` annotates the warnings. + - name: Install JDK 21 for the jars + id: jdk21 + uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0 + with: + distribution: temurin + java-version: '21' + problem-matcher: false + + # The same release as in release.yml: Web Image is experimental, and its options and output change between + # releases. + - name: Install Oracle GraalVM 25 for the module + uses: graalvm/setup-graalvm@f70bc8032f90a104502824a54bcb94b6f01715bc # v1.6.8 + with: + java-version: '25.0.4' + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + + # Web Image runs wasm-opt from the PATH, and needs Binaryen 119 or later; Ubuntu's package is older. + - name: Install Binaryen + env: + BINARYEN_VERSION: version_133 + BINARYEN_SHA256: 2dc9c7813f5375db93d96ead4b78222fcc3e2677bbb832297af4797782a37489 + run: | + archive="binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz" + curl --fail --silent --show-error --location --output "${RUNNER_TEMP}/${archive}" \ + "https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/${archive}" + echo "${BINARYEN_SHA256} ${RUNNER_TEMP}/${archive}" | sha256sum --check + tar -xzf "${RUNNER_TEMP}/${archive}" -C "${RUNNER_TEMP}" + echo "${RUNNER_TEMP}/binaryen-${BINARYEN_VERSION}/bin" >> "$GITHUB_PATH" + + # Node 24 has the WebAssembly GC and exception handling the module needs. + - name: Install Node.js 24 for the tests + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '24' + package-manager-cache: false + + # The same cache as in `build`. + - name: Cache Gradle's downloads + uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 + with: + gradle-home-cache-excludes: | + caches/build-cache-1 + caches/modules-2/files-2.1/com.jetbrains.intellij.idea + caches/*/transforms + + # wasmTest: the smoke test, then every Java 21 and Java 25 test case's input against the runnable jar. + - name: Build and test the module + run: ./gradlew -Pwasm=true :open-java-format-wasm:wasmTest + env: + JDK21_HOME: ${{ steps.jdk21.outputs.path }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f65c94c05..f0eef7ed5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -290,7 +290,7 @@ jobs: node-version: '24' package-manager-cache: false - # wasmTest: the native image's smoke test, then every test case's input against the runnable jar. + # wasmTest: the smoke test, then every Java 21 and Java 25 test case's input against the runnable jar. - name: Build and test the module run: ./gradlew -Pwasm=true :open-java-format-wasm:wasmTest :open-java-format-wasm:wasmZip env: diff --git a/README.md b/README.md index 9ee8a279d..00c244d54 100644 --- a/README.md +++ b/README.md @@ -164,8 +164,8 @@ unexecutable file. ### WebAssembly module The playground on openjavaformat.dev runs the formatter in the browser, compiled to WebAssembly by -GraalVM's Web Image backend. Only the release workflow builds it, in its `wasm` job, and the zip goes -on the GitHub release; `./gradlew build` leaves it out. Web Image ships in Oracle GraalVM only, so the +GraalVM's Web Image backend. CI builds and tests it in its `wasm` job, the release workflow in its +own, and the zip goes on the GitHub release; `./gradlew build` leaves it out. Web Image ships in Oracle GraalVM only, so the module needs Oracle GraalVM 25 behind `GRAALVM_HOME`, Binaryen 119 or later (`wasm-opt`) on the `PATH`, and Node.js 24 or later for the tests: diff --git a/open-java-format-wasm/build.gradle b/open-java-format-wasm/build.gradle index 766d34734..149ca418c 100644 --- a/open-java-format-wasm/build.gradle +++ b/open-java-format-wasm/build.gradle @@ -105,8 +105,9 @@ def wasmSmokeTest = tasks.register('wasmSmokeTest', Exec) { } def allJar = project(':open-java-format').tasks.named('allJar', Jar) -def java21 = javaToolchains.launcherFor { it.languageVersion.set(JavaLanguageVersion.of(21)) } +// The jar runs on the JDK the module is built with, so that both parse with the same javac, and so on the cases for +// Java 25 as well as those for 21. The ones for 28 need a newer javac than the module has. def wasmDifferentialTest = tasks.register('wasmDifferentialTest', Exec) { description = 'Formats every test case input with the module and with the runnable jar, and compares.' group = 'verification' @@ -116,10 +117,11 @@ def wasmDifferentialTest = tasks.register('wasmDifferentialTest', Exec) { argumentProviders.add({ [ wrapper.get(), - java21.get().executablePath.asFile.path, + javaToolchains.launcherFor(oracleGraalVm).get().executablePath.asFile.path, allJar.get().archiveFile.get().asFile.path, - project(':open-java-format').file('src/test/resources/test-cases-java21').path, layout.buildDirectory.dir('wasm-differential').get().asFile.path, + project(':open-java-format').file('src/test/resources/test-cases-java21').path, + project(':open-java-format').file('src/test/resources/test-cases-java25').path, ] } as CommandLineArgumentProvider) } diff --git a/open-java-format-wasm/src/test/js/differential.mjs b/open-java-format-wasm/src/test/js/differential.mjs index 3f691cea5..2a4a34d2f 100644 --- a/open-java-format-wasm/src/test/js/differential.mjs +++ b/open-java-format-wasm/src/test/js/differential.mjs @@ -14,14 +14,14 @@ // The module against the runnable jar of the same build, on the input of every test case: both must give the same // bytes, or the same diagnostics. The jar formats all the inputs in one run with --replace, so the JVM starts once. -// Usage: node differential.mjs +// Usage: node differential.mjs ... import { spawnSync } from "node:child_process"; import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; -import { join, relative } from "node:path"; +import { dirname, join, relative } from "node:path"; import { load } from "./load.mjs"; -const [wrapperPath, java, jar, casesRoot, workDir] = process.argv.slice(2); +const [wrapperPath, java, jar, workDir, ...casesRoots] = process.argv.slice(2); // As CaseFile.java reads a case: the input is what lies between the first two lines of six or more dashes. const SEPARATOR = /-{6,}(?:\r\n|\r|\n|$)/g; @@ -38,16 +38,18 @@ function caseFiles(dir) { .sort(); } -// One .java file per case, named after it, so that the jar's diagnostics name the case too. +// One .java file per case, named after its folder and itself, so that the jar's diagnostics name the case too. rmSync(workDir, { recursive: true, force: true }); -const inputs = caseFiles(casesRoot).map(caseFile => { - const name = relative(casesRoot, caseFile).replaceAll(/[\\/]/g, "__").replace(/\.case$/, ".java"); - const path = join(workDir, name); - const input = inputOf(readFileSync(caseFile, "utf8")); - mkdirSync(workDir, { recursive: true }); - writeFileSync(path, input); - return { name, path, input }; -}); +const inputs = casesRoots.flatMap(casesRoot => + caseFiles(casesRoot).map(caseFile => { + const name = relative(dirname(casesRoot), caseFile).replaceAll(/[\\/]/g, "__").replace(/\.case$/, ".java"); + const path = join(workDir, name); + const input = inputOf(readFileSync(caseFile, "utf8")); + mkdirSync(workDir, { recursive: true }); + writeFileSync(path, input); + return { name, path, input }; + }), +); const jvm = spawnSync(java, ["-jar", jar, "--replace", ...inputs.map(input => input.path)], { encoding: "utf8", diff --git a/settings.gradle b/settings.gradle index 5fca69411..21bf7b1e0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,7 @@ include ':open-java-format-benchmarks' include ':open-java-format-native' // The WebAssembly module compiles against Oracle GraalVM, which nobody who only wants the jars has, so it is part of -// the build only with -Pwasm=true. The release workflow builds it that way; nothing else does. +// the build only with -Pwasm=true. CI's and the release's `wasm` jobs build it that way; nothing else does. if (Boolean.parseBoolean(providers.gradleProperty('wasm').getOrElse('false'))) { include ':open-java-format-wasm' }