#!/usr/bin/env bash # Marmot MLS interop test orchestrator. # # Builds Rust and Moxie interop binaries (if requested) then runs a # bidirectional JSON-over-stdio test suite driven by Node. # # Usage: # scripts/mls-interop-test.sh # run tests (assume binaries built) # scripts/mls-interop-test.sh --build # build binaries first # scripts/mls-interop-test.sh --build-only # just build, don't run # MOXIE=/path/to/moxie scripts/mls-interop-test.sh --build # # Environment: # MOXIE — path to moxie checkout (default: ../moxie) # ORLY — path to orly.dev checkout (default: ../orly.dev) # SKIP_RUST — if set, skip all Rust-side tests # SKIP_MOXIE — if set, skip all Moxie-side tests set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" MOXIE="${MOXIE:-$REPO_ROOT/../moxie}" ORLY="${ORLY:-$REPO_ROOT/../orly.dev}" BUILD=0 BUILD_ONLY=0 for arg in "$@"; do case "$arg" in --build) BUILD=1 ;; --build-only) BUILD=1; BUILD_ONLY=1 ;; --help|-h) sed -n '3,20p' "$0" exit 0 ;; esac done if [[ $BUILD -eq 1 ]]; then # moxiejs lives directly in the moxie checkout (see Makefile build-sw target), # not under a bin/ subdirectory. MOXIEJS="$MOXIE/moxiejs" if [[ ! -x "$MOXIEJS" ]]; then MOXIEJS="$(command -v moxiejs || true)" fi if [[ -z "$MOXIEJS" || ! -x "$MOXIEJS" ]]; then echo "error: moxiejs binary not found at $MOXIE/moxiejs or on \$PATH" >&2 exit 2 fi echo "== building Moxie interop binary ==" # GOROOT=$MOXIE forces moxiejs to resolve stdlib from the moxie-vendored .mx # tree instead of host Go's .go stdlib (which triggers bytealg typecheck errors). ( cd "$REPO_ROOT/web/mlsinterop" GOROOT="$MOXIE" GOWORK=off MOXIEROOT="$MOXIE" "$MOXIEJS" \ -runtime "$MOXIE/jsruntime" \ -o "$REPO_ROOT/web/mlsinterop/static/" \ . ) if [[ -z "${SKIP_RUST:-}" ]]; then echo "== building Rust interop binary ==" ( cd "$ORLY/pkg/nostr/protocol/marmot/testdata/interop" cargo build --release ) fi fi if [[ $BUILD_ONLY -eq 1 ]]; then exit 0 fi MOXIE_ENTRY="$REPO_ROOT/web/mlsinterop/node-entry.mjs" RUST_BIN="$ORLY/pkg/nostr/protocol/marmot/testdata/interop/target/release/mls-interop" if [[ ! -f "$MOXIE_ENTRY" ]]; then echo "error: Moxie entry not found at $MOXIE_ENTRY" >&2 echo "hint: run with --build to compile it" >&2 exit 1 fi if [[ -z "${SKIP_RUST:-}" && ! -x "$RUST_BIN" ]]; then echo "error: Rust binary not found at $RUST_BIN" >&2 echo "hint: run with --build to compile it, or set SKIP_RUST=1" >&2 exit 1 fi MOXIE_ENTRY="$MOXIE_ENTRY" \ RUST_BIN="$RUST_BIN" \ SKIP_RUST="${SKIP_RUST:-}" \ SKIP_MOXIE="${SKIP_MOXIE:-}" \ exec node "$SCRIPT_DIR/mls-interop-test.mjs"