#!/usr/bin/env bash # next/tests/smoke_kernel_route.sh — m2 Blockers #4 unblock test. # # Proves a real HTTP listener over http:listen + http_server:start # CAN now serve kernel-aware routes (the surface Blockers #4 made # unreachable). Spins up a single sx_server instance, bootstraps an # actor, starts http_server with {kernel, nx_kernel} in Cfg, and # curls a route that fans through nx_kernel via gen_server:call. # # This is the kernel-route portion of Step 12's two-instance smoke # test. The full two-instance flow (Follow + auto-accept + Note # delivery) layers on top of this surface; this test is the # load-bearing proof point that the underlying wiring works. set -uo pipefail cd "$(git rev-parse --show-toplevel)" SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}" if [ ! -x "$SX_SERVER" ]; then SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe" fi if [ ! -x "$SX_SERVER" ]; then echo "ERROR: sx_server.exe not found." >&2 exit 1 fi VERBOSE="${1:-}" PASS=0; FAIL=0; ERRORS="" PORT=$(python3 -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1]);s.close()') EF=$(mktemp); LOG=$(mktemp); FIFO=$(mktemp -u); mkfifo "$FIFO" cleanup() { for pid in ${SXP:-} ${HOLDP:-}; do kill -KILL "$pid" 2>/dev/null || true wait "$pid" 2>/dev/null || true done rm -f "$EF" "$LOG" "$FIFO" } trap cleanup EXIT cat > "$EF" <>, AKS = [{key_id,k1},{algorithm,ed25519},{value,AK}], AAS = [{public_keys,[[{id,k1},{created,0},{value,AK}]]}], nx_kernel:start_link(alice, AKS, AAS), http_server:start(${PORT}, [{kernel, nx_kernel}])\")") EPOCHS ( cat "$EF"; sleep 900 ) > "$FIFO" & HOLDP=$! "$SX_SERVER" < "$FIFO" > "$LOG" 2>&1 & SXP=$! rm -f "$FIFO" START=$(date +%s) BOUND= while [ $(($(date +%s) - START)) -lt 300 ]; do if (exec 3<>/dev/tcp/127.0.0.1/$PORT) 2>/dev/null; then exec 3<&-; exec 3>&- BOUND="yes after $(($(date +%s) - START))s" break fi sleep 1 done if [ -z "$BOUND" ]; then echo "FAIL: listener never bound on port $PORT" echo "--- log tail ---" tail -20 "$LOG" exit 1 fi [ "$VERBOSE" = "-v" ] && echo " ok listener up ($BOUND)" check() { local desc="$1" path="$2" needle="$3" local resp resp=$(curl -s --max-time 10 "http://127.0.0.1:$PORT$path" 2>/dev/null || echo "") if echo "$resp" | grep -qF -- "$needle"; then PASS=$((PASS+1)) [ "$VERBOSE" = "-v" ] && echo " ok $desc" else FAIL=$((FAIL+1)) ERRORS+=" FAIL [$desc] expected '$needle' in resp: $(echo "$resp" | head -c 100) " fi } check "non-kernel welcome /" "/" "fed-sx kernel m1" check "kernel-aware /actors/alice" "/actors/alice" "actor: alice" check "kernel-aware /actors/alice/outbox" "/actors/alice/outbox" "outbox: alice" check "kernel-aware /actors/alice/outbox tip" "/actors/alice/outbox" "tip: 0" check "kernel-aware /actors/alice/inbox" "/actors/alice/inbox" "inbox: alice" check "unknown actor /actors/zzz/outbox" "/actors/zzz/outbox" "outbox: zzz" TOTAL=$((PASS+FAIL)) if [ $FAIL -eq 0 ]; then echo "ok $PASS/$TOTAL next/tests/smoke_kernel_route.sh passed (port $PORT)" else echo "FAIL $PASS/$TOTAL passed, $FAIL failed:" echo "$ERRORS" if [ "$VERBOSE" = "-v" ]; then echo "--- log tail ---"; tail -20 "$LOG" fi fi [ $FAIL -eq 0 ]