#!/usr/bin/env bash # next/tests/host_kernel.sh — the durable-execution kernel (host_kernel.erl) over HTTP. # Boots it as a background sx_server, then drives it with curl: category branching (newsletter → # suspend, urgent/draft → done), sequential instance ids, and RESUME of a suspended instance in a # SEPARATE request (durable state persists). This is the RA-live substrate. set -uo pipefail cd "$(git rev-parse --show-toplevel)" SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}" [ -x "$SX_SERVER" ] || SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe" PORT=51878 PASS=0; FAIL=0 EPOCH_FILE=$(mktemp); LOG_FILE=$(mktemp) cleanup() { [ -n "${SXPID:-}" ] && { kill -KILL "$SXPID" 2>/dev/null || true; wait "$SXPID" 2>/dev/null || true; } [ -n "${HOLDPID:-}" ] && { kill -KILL "$HOLDPID" 2>/dev/null || true; wait "$HOLDPID" 2>/dev/null || true; } rm -f "$EPOCH_FILE" "$LOG_FILE" } trap cleanup EXIT cat > "$EPOCH_FILE" < "$FIFO" & HOLDPID=$! "$SX_SERVER" < "$FIFO" > "$LOG_FILE" 2>&1 & SXPID=$! rm -f "$FIFO" echo "── waiting for host_kernel to bind :$PORT ──" BOUND="" for i in $(seq 1 300); do if (exec 3<>/dev/tcp/127.0.0.1/$PORT) 2>/dev/null; then BOUND=1; exec 3>&- 3<&-; echo "bound (iter $i)"; break; fi sleep 1 done if [ -z "$BOUND" ]; then echo "FAIL: never bound"; tail -25 "$LOG_FILE"; exit 1; fi ck() { local got; got=$(curl -s -m 8 "http://127.0.0.1:$PORT$1"); if echo "$got" | grep -q "$2"; then PASS=$((PASS+1)); echo " ok [$3] $1 → $got"; else FAIL=$((FAIL+1)); echo " FAIL [$3] $1 → '$got' (want '$2')"; fi; } echo "── driving the kernel over HTTP ──" ck /flow/start/newsletter "1:suspended" "newsletter → instance 1, SUSPENDED (durable wait)" ck /flow/start/urgent "2:done" "urgent → instance 2, DONE (sync branch)" ck /flow/start/draft "3:done" "draft → instance 3, DONE (skipped)" ck /flow/resume/1 "resume:done" "resume instance 1 (SEPARATE request) → DONE (persisted)" echo "─────────────────────────────────────────────────────" echo "PASS=$PASS FAIL=$FAIL" [ "$FAIL" -eq 0 ] || { echo "--- kernel log tail ---"; tail -20 "$LOG_FILE"; }