diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a9fe9bdfb..c256ce1200 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -282,6 +282,45 @@ jobs: # npm b/c Yarn 4 doesn't work in Node 12 run: cd packages/ses && npm run test:platform-compatibility + hermes-test: + name: hermes-test + + # begin macro + + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + node-version: [20.x] + platform: [ubuntu-latest] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # without this, setup-node errors on mismatched yarn versions + - run: corepack enable + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: yarn + + - name: Echo node version + run: node --version + + - name: Install dependencies + run: yarn install --immutable + + # end macro + + - name: 'build' + run: yarn run build + + - name: Run SES smoke test on Hermes + run: cd packages/ses && yarn test:hermes + viable-release: name: viable-release diff --git a/packages/ses/package.json b/packages/ses/package.json index e562a123e7..78c4fcd5a6 100644 --- a/packages/ses/package.json +++ b/packages/ses/package.json @@ -73,7 +73,9 @@ "prepare": "npm run clean && npm run build", "qt": "ava", "test": "tsd && ava", - "test:platform-compatibility": "node test/package/test.cjs" + "test:platform-compatibility": "node test/package/test.cjs", + "test:create-hermes-bin-symlinks": "./scripts/hermes-bin-symlinks.sh", + "test:hermes": "./scripts/hermes.sh" }, "dependencies": { "@endo/env-options": "^1.1.4" @@ -91,6 +93,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.29.1", + "hermes-engine-cli": "0.12.0", "prettier": "^3.2.5", "sinon": "^15.1.0", "terser": "^5.16.6", diff --git a/packages/ses/scripts/hermes-bin-symlinks.sh b/packages/ses/scripts/hermes-bin-symlinks.sh new file mode 100755 index 0000000000..1dc08b161a --- /dev/null +++ b/packages/ses/scripts/hermes-bin-symlinks.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +OS="$(uname -s)" + +case "$OS" in + Linux*) + OS_DIR="linux64-bin" + ;; + Darwin*) + OS_DIR="osx-bin" + ;; + CYGWIN*|MINGW*|MSYS*) + OS_DIR="win64-bin" + ;; + *) + echo "Unsupported OS: $OS" + exit 1 + ;; +esac + +# Path from 'packages/ses' +cd ../../node_modules/.bin + +if [[ "$OS" == linux* || "$OS" == Darwin* ]]; then + ln -s ../hermes-engine-cli/$OS_DIR/hbcdump hbcdump + ln -s ../hermes-engine-cli/$OS_DIR/hdb hdb + ln -s ../hermes-engine-cli/$OS_DIR/hermes hermes + ln -s ../hermes-engine-cli/$OS_DIR/hermesc hermesc +elif [[ "$OS" == CYGWIN* || "$OS" == MINGW* || "$OS" == MSYS* ]]; then + mklink -s ../hermes-engine-cli/$OS_DIR/hbcdump.exe hbcdump + mklink -s ../hermes-engine-cli/$OS_DIR/hdb.exe hdb + mklink -s ../hermes-engine-cli/$OS_DIR/hermes.exe hermes + mklink -s ../hermes-engine-cli/$OS_DIR/hermesc.exe hermesc +fi diff --git a/packages/ses/scripts/hermes.sh b/packages/ses/scripts/hermes.sh new file mode 100755 index 0000000000..974634f044 --- /dev/null +++ b/packages/ses/scripts/hermes.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +OS="$(uname -s)" + +case "$OS" in + Linux*) + OS_DIR="linux64-bin" + ;; + Darwin*) + OS_DIR="osx-bin" + ;; + CYGWIN*|MINGW*|MSYS*) + OS_DIR="win64-bin" + ;; + *) + echo "Unsupported OS: $OS" + exit 1 + ;; +esac + +# Paths relative to 'packages/ses' +HERMESC="../../node_modules/hermes-engine-cli/$OS_DIR/hermesc" +HERMES="../../node_modules/hermes-engine-cli/$OS_DIR/hermes" + +echo "Catenating: dist/ses.cjs + test/hermes-smoke.js" +cat dist/ses.cjs test/hermes-smoke.js > test/hermes-smoke-dist.js +echo "Generated: test/hermes-smoke-dist.js" + +# Errors on async arrow functions and async generators +# Both are unsupported on Hermes +echo "Executing: test/hermes-smoke-dist.js on Hermes compiler" +$HERMESC -emit-binary -out test/hermes-smoke-dist.hbc test/hermes-smoke-dist.js +echo "Generated: test/hermes-smoke-dist.hbc" +echo "Hermes compiler done" + +# TODO: Disabled until https://github.com/endojs/endo/issues/1891 complete +# echo "Executing generated bytecode file on Hermes VM" +# $HERMES -b hermes-smoke.hbc +# echo "Hermes VM done" +echo "Skipping: Hermes VM" + +echo "Hermes tests complete" + +echo "Removing: test/hermes-smoke-dist.js" +rm test/hermes-smoke-dist.js +echo "Removing: test/hermes-smoke-dist.hbc" +rm test/hermes-smoke-dist.hbc diff --git a/packages/ses/test/hermes-smoke.js b/packages/ses/test/hermes-smoke.js new file mode 100644 index 0000000000..52dfe88892 --- /dev/null +++ b/packages/ses/test/hermes-smoke.js @@ -0,0 +1,53 @@ +// Hermes doesn't support native I/O, +// so we concat the SES shim above, +// when running this test on Hermes. + +/** + * Test calling SES lockdown. + */ +const testLockdown = () => { + lockdown(); +}; + +/** + * TODO: Test creating a new Compartment. + */ +// eslint-disable-next-line no-unused-vars +const testCompartment = () => { + // eslint-disable-next-line no-unused-vars + const c = new Compartment(); +}; + +/** + * TODO: Test Compartment import hook and resolve hook. + */ +// eslint-disable-next-line no-unused-vars +async function testCompartmentHooks() { + const resolveHook = a => a; + + async function importHook() { + return { + imports: [], + exports: ['meaning'], + execute(exports) { + exports.meaning = 42; + }, + }; + } + + const compartment = new Compartment({}, {}, { resolveHook, importHook }); + + const module = compartment.module('.'); + + const { + namespace: { _meaning }, + } = await compartment.import('.'); + + assert(module); +} + +testLockdown(); + +// testCompartment(); + +// testCompartmentHooks(); diff --git a/yarn.lock b/yarn.lock index 748bddba0d..94af5669ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6606,6 +6606,13 @@ __metadata: languageName: node linkType: hard +"hermes-engine-cli@npm:0.12.0": + version: 0.12.0 + resolution: "hermes-engine-cli@npm:0.12.0" + checksum: 10c0/53a00336632cc7a743e9a88a5199865cf922d118f42f15bed4d2ed2fee635acd0d4d8563803b47e7c1bc2d17650281eb9188be8cfdaa25887243cfee840523be + languageName: node + linkType: hard + "hosted-git-info@npm:^2.1.4": version: 2.8.9 resolution: "hosted-git-info@npm:2.8.9" @@ -10523,6 +10530,7 @@ __metadata: eslint-config-prettier: "npm:^9.1.0" eslint-plugin-eslint-comments: "npm:^3.2.0" eslint-plugin-import: "npm:^2.29.1" + hermes-engine-cli: "npm:0.12.0" prettier: "npm:^3.2.5" sinon: "npm:^15.1.0" terser: "npm:^5.16.6"