diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb637bf..3ba139e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,8 @@ jobs: key: guest-bundle-${{ steps.guest-keys.outputs.guest-key }} - name: Install clang run: sudo apt-get update && sudo apt-get install -y clang + - name: Test JavaScript guest build + run: just wasm js-guest-test - name: Build guests run: just wasm guest-bundle - name: Upload guest bundle diff --git a/Justfile b/Justfile index 9e3280a..6d87c5a 100644 --- a/Justfile +++ b/Justfile @@ -32,7 +32,7 @@ fmt-check-rust: #### TESTS #### -test: wasm::test-build wasm::guest-build wasm::js-guest-build python::build python::python-test test-rust wasm::test dotnet::test-rust dotnet::test +test: wasm::test-build wasm::js-guest-test wasm::guest-build wasm::js-guest-build python::build python::python-test test-rust wasm::test dotnet::test-rust dotnet::test fuzz seconds="60": (python::python-fuzz seconds) diff --git a/src/wasm_sandbox/Justfile b/src/wasm_sandbox/Justfile index 789dc77..fbe4891 100644 --- a/src/wasm_sandbox/Justfile +++ b/src/wasm_sandbox/Justfile @@ -101,6 +101,11 @@ js-guest-build: js-guest-build-wasm js-guest-build-aot js-guest-install: uv run --no-project --python 3.14 python {{repo-root}}/scripts/guest_build.py javascript +# Test componentization against the installed JavaScript dependencies. +js-guest-test: + cd {{repo-root}}/src/wasm_sandbox/guests/javascript && npm ci + cd {{repo-root}}/src/wasm_sandbox/guests/javascript && npm test + build target=default-target: _clean-stale-wasm (guest-build target) (js-guest-build) cargo build --manifest-path {{repo-root}}/src/wasm_sandbox/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} diff --git a/src/wasm_sandbox/guests/javascript/build.js b/src/wasm_sandbox/guests/javascript/build.js index 2293510..79ead71 100644 --- a/src/wasm_sandbox/guests/javascript/build.js +++ b/src/wasm_sandbox/guests/javascript/build.js @@ -32,10 +32,11 @@ const outputPath = "js-sandbox.wasm"; async function build() { console.log("Reading source..."); const source = await readFile(sourcePath, "utf-8"); + const witWorld = await readFile(witPath, "utf-8"); console.log("Componentizing..."); const { component, imports } = await componentize(source, { - witPath, + witWorld, worldName: "hyperlight:sandbox/sandbox", }); diff --git a/src/wasm_sandbox/guests/javascript/build.test.js b/src/wasm_sandbox/guests/javascript/build.test.js new file mode 100644 index 0000000..d70cf33 --- /dev/null +++ b/src/wasm_sandbox/guests/javascript/build.test.js @@ -0,0 +1,15 @@ +import assert from "node:assert/strict"; +import { execFile } from "node:child_process"; +import { readFile } from "node:fs/promises"; +import { promisify } from "node:util"; +import { test } from "node:test"; + +test("builds the JavaScript component with the installed WASI shim", async () => { + const cwd = new URL(".", import.meta.url); + await promisify(execFile)(process.execPath, ["build.js"], { + cwd, + timeout: 120_000, + }); + const component = await readFile(new URL("js-sandbox.wasm", cwd)); + assert.deepEqual(component.subarray(0, 8), Buffer.from([0, 97, 115, 109, 13, 0, 1, 0])); +}); diff --git a/src/wasm_sandbox/guests/javascript/package-lock.json b/src/wasm_sandbox/guests/javascript/package-lock.json index cad2781..8b68542 100644 --- a/src/wasm_sandbox/guests/javascript/package-lock.json +++ b/src/wasm_sandbox/guests/javascript/package-lock.json @@ -10,7 +10,7 @@ "devDependencies": { "@bytecodealliance/componentize-js": "^0.23.0", "@bytecodealliance/jco": "^1.39.0", - "@bytecodealliance/preview2-shim": "^0.25.0" + "@bytecodealliance/preview2-shim": "^0.31.0" } }, "node_modules/@andreiltd/componentize-qjs-binding-darwin-arm64": { @@ -453,9 +453,9 @@ } }, "node_modules/@bytecodealliance/preview2-shim": { - "version": "0.25.0", - "resolved": "https://registry.npmjs.org/@bytecodealliance/preview2-shim/-/preview2-shim-0.25.0.tgz", - "integrity": "sha512-6ZSDRJ8hJc/febZepzd68z3KzLcOXyCOKtRm8LB2rgAU88xV7ykq6dMb5I4a+sBh1cuV2Yb1159gDzI1q8UsoQ==", + "version": "0.31.0", + "resolved": "https://registry.npmjs.org/@bytecodealliance/preview2-shim/-/preview2-shim-0.31.0.tgz", + "integrity": "sha512-9Gv4wn/DCz1NOqTZFcPSIko9jsTwmps67QZ6PPytypmmWLSz5AQf3Xn2EjItfudWwSh5d+9EPD3BrNlvqKWNtA==", "dev": true, "license": "(Apache-2.0 WITH LLVM-exception)", "dependencies": { diff --git a/src/wasm_sandbox/guests/javascript/package.json b/src/wasm_sandbox/guests/javascript/package.json index cbb922e..d71e641 100644 --- a/src/wasm_sandbox/guests/javascript/package.json +++ b/src/wasm_sandbox/guests/javascript/package.json @@ -4,11 +4,12 @@ "private": true, "type": "module", "scripts": { - "build": "node build.js" + "build": "node build.js", + "test": "node --test build.test.js" }, "devDependencies": { "@bytecodealliance/componentize-js": "^0.23.0", "@bytecodealliance/jco": "^1.39.0", - "@bytecodealliance/preview2-shim": "^0.25.0" + "@bytecodealliance/preview2-shim": "^0.31.0" } }