#!/usr/bin/env bash # Visual audit harness: builds forge, starts it on a throwaway data dir, seeds realistic data, # screenshots every GET page in several variants and writes target/audit/index.md. # # Usage: scripts/audit/run.sh [--no-build] [--keep-data] # Env: AUDIT_FILTER=regex only routes whose pattern/url matches (e.g. '/issues') # AUDIT_VARIANTS=a,b subset of: desktop-light mobile-light desktop-light-sbright desktop-dark # mobile-dark anon-desktop-light anon-mobile-light anon-desktop-dark # AUDIT_BROWSER=chromium chromium (default, flatpak org.chromium.Chromium), firefox, or both # AUDIT_PORT=17660 forge port (proxy is +10, user content +1) # AUDIT_SSH_PORT=12222 ssh port # AUDIT_OUT=dir output dir (default target/audit) # AUDIT_TARGET=dir cargo target dir (default target/agent-audit) # --keep-data reuses an already seeded data dir (skips seeding) for quick re-shoots. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" OUT="${AUDIT_OUT:-$ROOT/target/audit}" DATA="$OUT/data" PORT="${AUDIT_PORT:-17660}" TARGET="${AUDIT_TARGET:-target/agent-audit}" BIN="$ROOT/$TARGET/debug/forge" SSH_PORT="${AUDIT_SSH_PORT:-12222}" BUILD=1 KEEP=0 for a in "$@"; do case "$a" in --no-build) BUILD=0 ;; --keep-data) KEEP=1 ;; *) echo "unknown arg $a" >&2; exit 2 ;; esac done if [[ $BUILD == 1 ]]; then echo "[run] building forge-web (dev profile)" (cd "$ROOT" && CARGO_TARGET_DIR="$TARGET" cargo build -p forge-web) fi [[ -x $BIN ]] || { echo "[run] missing $BIN" >&2; exit 1; } # Stop anything left over from an earlier run on our ports. pkill -f -- "--config $OUT/forge.toml" 2>/dev/null || true if [[ $KEEP == 0 || ! -f $OUT/seed.json ]]; then KEEP=0 rm -rf "$DATA" "$OUT/work" "$OUT/githome" "$OUT/sshkey" "$OUT/seed.json" fi rm -rf "$OUT/shots" "$OUT/tmp" "$OUT/index.md" "$OUT/index.json" mkdir -p "$DATA" "$OUT/shots" "$OUT/tmp" cat > "$OUT/forge.toml" < "$OUT/forge.log" 2>&1 & FORGE_PID=$! cleanup() { kill "$FORGE_PID" 2>/dev/null || true wait "$FORGE_PID" 2>/dev/null || true pkill -f "[f]orge-audit-ff-" 2>/dev/null || true pkill -f "[u]ser-data-dir=.*forge-audit-cr-" 2>/dev/null || true rm -rf "$OUT/tmp" echo "[run] server stopped" } trap cleanup EXIT INT TERM for _ in $(seq 1 120); do curl -fsS "http://127.0.0.1:$PORT/healthz" >/dev/null 2>&1 && break kill -0 "$FORGE_PID" 2>/dev/null || { echo "[run] forge exited, see $OUT/forge.log" >&2; tail -20 "$OUT/forge.log" >&2; exit 1; } sleep 0.5 done if [[ $KEEP == 0 ]]; then echo "[run] seeding" python3 "$ROOT/scripts/audit/seed.py" "http://127.0.0.1:$PORT" "$OUT" 2>&1 | tee "$OUT/seed.log" fi echo "[run] screenshots" AUDIT_PROXY_PORT="${AUDIT_PROXY_PORT:-$((PORT + 10))}" \ python3 "$ROOT/scripts/audit/shoot.py" "http://127.0.0.1:$PORT" "$OUT" "$ROOT/crates/forge-web/src" 2>&1 | tee "$OUT/shoot.log" echo "[run] done: $OUT/index.md"