|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 3 | +# |
| 4 | +# ADR-015 S3 gated smoke: compile a core module that carries the |
| 5 | +# `affinescript.ownership` section, run it through the componentize |
| 6 | +# on-ramp, and assert the result is a valid WASI-0.2 component with the |
| 7 | +# ownership section intact (and that wasmtime can load it). |
| 8 | +# |
| 9 | +# SKIPs cleanly (exit 0) when the component toolchain is not provisioned |
| 10 | +# — it is opt-in (run tools/provision-component-toolchain.sh first / |
| 11 | +# the toolchain-bearing CI lane), so it never breaks the base gate. |
| 12 | +set -euo pipefail |
| 13 | +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 14 | +cd "$ROOT" |
| 15 | + |
| 16 | +if ! command -v wasm-tools >/dev/null \ |
| 17 | + || [ ! -f tools/vendor/wasi_snapshot_preview1.reactor.wasm ]; then |
| 18 | + echo "SKIP: component toolchain not provisioned (tools/provision-component-toolchain.sh)" |
| 19 | + exit 0 |
| 20 | +fi |
| 21 | + |
| 22 | +COMPILER="${AFFINESCRIPT:-$ROOT/_build/default/bin/main.exe}" |
| 23 | +[ -x "$COMPILER" ] || COMPILER="dune exec affinescript --" |
| 24 | + |
| 25 | +work="$(mktemp -d)" |
| 26 | +trap 'rm -rf "$work"' EXIT |
| 27 | + |
| 28 | +# Known-good ownership fixture (emits the affinescript.ownership |
| 29 | +# section) + a main so the module is non-trivial. |
| 30 | +cp test/e2e/fixtures/verify_ownership_clean.affine "$work/cz.affine" |
| 31 | +printf '\nfn main() -> Int { add(2, 3) }\n' >> "$work/cz.affine" |
| 32 | + |
| 33 | +# `grep -c | … || true`: read all input (no early-close SIGPIPE that |
| 34 | +# `set -o pipefail` would mis-report — the `grep -q` footgun). |
| 35 | +has_section() { |
| 36 | + [ "$(wasm-tools print "$1" 2>/dev/null | grep -c 'affinescript.ownership' || true)" -gt 0 ] |
| 37 | +} |
| 38 | + |
| 39 | +$COMPILER compile "$work/cz.affine" -o "$work/cz.wasm" |
| 40 | +has_section "$work/cz.wasm" \ |
| 41 | + || { echo "FAIL: fixture did not emit the ownership section"; exit 1; } |
| 42 | + |
| 43 | +tools/componentize.sh "$work/cz.wasm" "$work/cz.component.wasm" |
| 44 | +wasm-tools validate --features component-model "$work/cz.component.wasm" |
| 45 | +has_section "$work/cz.component.wasm" \ |
| 46 | + || { echo "FAIL: ownership section lost through componentization"; exit 1; } |
| 47 | + |
| 48 | +if command -v wasmtime >/dev/null; then |
| 49 | + # Reactor component: no command entrypoint, so a successful |
| 50 | + # instantiate (no trap) is the smoke. `--invoke` a missing export |
| 51 | + # would error; instead just validate it loads as a component. |
| 52 | + wasmtime compile "$work/cz.component.wasm" -o "$work/cz.cwasm" >/dev/null 2>&1 \ |
| 53 | + && echo "wasmtime: component compiles/loads ✓" \ |
| 54 | + || { echo "FAIL: wasmtime could not compile the component"; exit 1; } |
| 55 | +fi |
| 56 | + |
| 57 | +echo "ADR-015 S3 componentize smoke: PASSED ✓" |
0 commit comments