mls-interop-test.sh raw
1 #!/usr/bin/env bash
2 # Marmot MLS interop test orchestrator.
3 #
4 # Builds Rust and Moxie interop binaries (if requested) then runs a
5 # bidirectional JSON-over-stdio test suite driven by Node.
6 #
7 # Usage:
8 # scripts/mls-interop-test.sh # run tests (assume binaries built)
9 # scripts/mls-interop-test.sh --build # build binaries first
10 # scripts/mls-interop-test.sh --build-only # just build, don't run
11 # MOXIE=/path/to/moxie scripts/mls-interop-test.sh --build
12 #
13 # Environment:
14 # MOXIE — path to moxie checkout (default: ../moxie)
15 # ORLY — path to orly.dev checkout (default: ../orly.dev)
16 # SKIP_RUST — if set, skip all Rust-side tests
17 # SKIP_MOXIE — if set, skip all Moxie-side tests
18
19 set -euo pipefail
20
21 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22 REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
23
24 MOXIE="${MOXIE:-$REPO_ROOT/../moxie}"
25 ORLY="${ORLY:-$REPO_ROOT/../orly.dev}"
26
27 BUILD=0
28 BUILD_ONLY=0
29 for arg in "$@"; do
30 case "$arg" in
31 --build) BUILD=1 ;;
32 --build-only) BUILD=1; BUILD_ONLY=1 ;;
33 --help|-h)
34 sed -n '3,20p' "$0"
35 exit 0
36 ;;
37 esac
38 done
39
40 if [[ $BUILD -eq 1 ]]; then
41 # moxiejs lives directly in the moxie checkout (see Makefile build-sw target),
42 # not under a bin/ subdirectory.
43 MOXIEJS="$MOXIE/moxiejs"
44 if [[ ! -x "$MOXIEJS" ]]; then
45 MOXIEJS="$(command -v moxiejs || true)"
46 fi
47 if [[ -z "$MOXIEJS" || ! -x "$MOXIEJS" ]]; then
48 echo "error: moxiejs binary not found at $MOXIE/moxiejs or on \$PATH" >&2
49 exit 2
50 fi
51
52 echo "== building Moxie interop binary =="
53 # GOROOT=$MOXIE forces moxiejs to resolve stdlib from the moxie-vendored .mx
54 # tree instead of host Go's .go stdlib (which triggers bytealg typecheck errors).
55 (
56 cd "$REPO_ROOT/web/mlsinterop"
57 GOROOT="$MOXIE" GOWORK=off MOXIEROOT="$MOXIE" "$MOXIEJS" \
58 -runtime "$MOXIE/jsruntime" \
59 -o "$REPO_ROOT/web/mlsinterop/static/" \
60 .
61 )
62
63 if [[ -z "${SKIP_RUST:-}" ]]; then
64 echo "== building Rust interop binary =="
65 (
66 cd "$ORLY/pkg/nostr/protocol/marmot/testdata/interop"
67 cargo build --release
68 )
69 fi
70 fi
71
72 if [[ $BUILD_ONLY -eq 1 ]]; then
73 exit 0
74 fi
75
76 MOXIE_ENTRY="$REPO_ROOT/web/mlsinterop/node-entry.mjs"
77 RUST_BIN="$ORLY/pkg/nostr/protocol/marmot/testdata/interop/target/release/mls-interop"
78
79 if [[ ! -f "$MOXIE_ENTRY" ]]; then
80 echo "error: Moxie entry not found at $MOXIE_ENTRY" >&2
81 echo "hint: run with --build to compile it" >&2
82 exit 1
83 fi
84
85 if [[ -z "${SKIP_RUST:-}" && ! -x "$RUST_BIN" ]]; then
86 echo "error: Rust binary not found at $RUST_BIN" >&2
87 echo "hint: run with --build to compile it, or set SKIP_RUST=1" >&2
88 exit 1
89 fi
90
91 MOXIE_ENTRY="$MOXIE_ENTRY" \
92 RUST_BIN="$RUST_BIN" \
93 SKIP_RUST="${SKIP_RUST:-}" \
94 SKIP_MOXIE="${SKIP_MOXIE:-}" \
95 exec node "$SCRIPT_DIR/mls-interop-test.mjs"
96