#!/bin/bash # Test cross-origin demo end-to-end. # Starts page server (8080) and CORS universe server (9090), # then runs Playwright to verify cross-origin loading works. set -euo pipefail SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) MONO=$(cd "$SCRIPT_DIR/.." && pwd) DOC_HTML="$MONO/_build/default/_doc/_html/odoc-interactive-extension" CROSSORIGIN_DIR="$MONO/_build/default/_doc/_html/_crossorigin_universes" cleanup() { [[ -n "${PAGE_PID:-}" ]] && kill "$PAGE_PID" 2>/dev/null || true [[ -n "${CORS_PID:-}" ]] && kill "$CORS_PID" 2>/dev/null || true wait 2>/dev/null || true } trap cleanup EXIT echo "=== Building demos ===" bash "$SCRIPT_DIR/deploy.sh" --no-serve echo "" echo "=== Starting servers ===" # Page server on port 8080 cd "$DOC_HTML/.." python3 -m http.server 8080 &>/dev/null & PAGE_PID=$! # CORS universe server on port 9090 python3 "$SCRIPT_DIR/cors_server.py" 9090 "$CROSSORIGIN_DIR" &>/dev/null & CORS_PID=$! sleep 2 echo " Page server: http://localhost:8080 (PID $PAGE_PID)" echo " CORS server: http://localhost:9090 (PID $CORS_PID)" # Verify both servers respond curl -sf http://localhost:8080/odoc-interactive-extension/demo4_crossorigin.html > /dev/null \ || { echo "FAIL: page server not responding"; exit 1; } curl -sf http://localhost:9090/universe/findlib_index.json > /dev/null \ || { echo "FAIL: CORS server not responding"; exit 1; } # Verify CORS headers CORS_HEADER=$(curl -sI http://localhost:9090/universe/findlib_index.json | grep -i 'access-control-allow-origin' || true) if [[ -z "$CORS_HEADER" ]]; then echo "FAIL: CORS server missing Access-Control-Allow-Origin header" exit 1 fi echo " CORS header: $CORS_HEADER" echo "" echo "=== Running Playwright test ===" NODE_PATH="$MONO/x-ocaml/test/node_modules" node "$SCRIPT_DIR/test_crossorigin.js"