Files
marqdo-view/tools/test-browser.sh
T
marqdo-view dev 1f34daffb0 feat(PR-05): pure static export and hardened Live boundary
- export.rs: marqdo view export PATH --out DIR through the same ReaderRenderer;
  index.html + pages/<relative>.html + hash-named assets + manifest.json
- export never calls Core run; refuses output inside project root and unrelated
  non-empty dirs; staging + atomic rename replaces only prior View exports
- offline by construction: embedded asset bytes, data-URI images, relative
  links, no remote subresources; --no-annotations hides anchors only
- HTTP hardening: max 32 concurrent requests (503), detail-free public error
  JSON/pages (no absolute paths/subprocess text), 30s page check budget
- tools/test-export.sh (manifest hashes + file:// Chromium offline check),
  tools/test-security.sh, adversarial security-project browser fixture
- tests/export.rs export contracts; ADR-0005; docs updated
2026-11-22 11:52:22 +08:00

88 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Browser acceptance for the Live reader: real Chromium, real frozen core.
#
# Usage:
# MARQDO_BIN=/abs/path/marqdo tools/test-browser.sh
#
# Requires `cd tests/browser && npm install` once (Playwright + Chromium).
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo binary}"
if [[ ! -x "$MARQDO_BIN" ]]; then
echo "error: MARQDO_BIN is not executable: $MARQDO_BIN" >&2
exit 1
fi
core_before="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-$repo_root/tests/.cache/pw-browsers}"
export MQ_SCREENSHOT_DIR="${MQ_SCREENSHOT_DIR:-$repo_root/tests/browser/artifacts}"
if [[ ! -d "$repo_root/tests/browser/node_modules/playwright" ]]; then
echo "error: Playwright is not installed; run: (cd tests/browser && npm install)" >&2
exit 1
fi
if [[ ! -d "$PLAYWRIGHT_BROWSERS_PATH" ]]; then
echo "error: Chromium is not installed; run: (cd tests/browser && npx playwright install chromium)" >&2
exit 1
fi
binary="$repo_root/target/release/marqdo-view"
if [[ ! -x "$binary" ]]; then
echo "==> cargo build --release --locked"
cargo build --release --locked
fi
server_pid=""
cleanup() {
if [[ -n "$server_pid" ]] && kill -0 "$server_pid" 2>/dev/null; then
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
fi
}
trap cleanup EXIT
run_suite() {
local project="$1"
local log
log="$(mktemp "$repo_root/tests/.cache/browser-server.XXXXXX.log")"
echo "==> browser suite: $project"
"$binary" "$project" --port 0 --no-open >"$log" 2>&1 &
server_pid=$!
local url=""
for _ in $(seq 1 100); do
url="$(grep -o 'http://127.0.0.1:[0-9]*/' "$log" | head -1 || true)"
[[ -n "$url" ]] && break
if ! kill -0 "$server_pid" 2>/dev/null; then
echo "error: server exited during startup:" >&2
cat "$log" >&2
exit 1
fi
sleep 0.1
done
if [[ -z "$url" ]]; then
echo "error: server did not print a URL" >&2
cat "$log" >&2
exit 1
fi
MQ_URL="$url" MQ_PROJECT="$project" node tests/browser/reader.browser.cjs
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
server_pid=""
rm -f "$log"
}
mkdir -p "$repo_root/tests/.cache" "$MQ_SCREENSHOT_DIR"
run_suite examples/welcome
run_suite examples/control-flow
run_suite tests/fixtures/security-project
core_after="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
if [[ "$core_before" != "$core_after" ]]; then
echo "error: frozen core binary changed during browser tests" >&2
exit 1
fi
echo "browser: PASS (core sha256 $core_before unchanged; screenshots: $MQ_SCREENSHOT_DIR)"