forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.010.5 MiB0a2c24cTahinli1 month ago179 commits

run.sh95 lines, 3.4 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Visual audit harness: builds forge, starts it on a throwaway data dir, seeds realistic data,
3# screenshots every GET page in several variants and writes target/audit/index.md.
4#
5# Usage: scripts/audit/run.sh [--no-build] [--keep-data]
6# Env: AUDIT_FILTER=regex only routes whose pattern/url matches (e.g. '/issues')
7# AUDIT_VARIANTS=a,b subset of: desktop-light mobile-light desktop-light-sbright desktop-dark
8# mobile-dark anon-desktop-light anon-mobile-light anon-desktop-dark
9# AUDIT_BROWSER=chromium chromium (default, flatpak org.chromium.Chromium), firefox, or both
10# AUDIT_PORT=17660 forge port (proxy is +10, user content +1)
11# AUDIT_SSH_PORT=12222 ssh port
12# AUDIT_OUT=dir output dir (default target/audit)
13# AUDIT_TARGET=dir cargo target dir (default target/agent-audit)
14# --keep-data reuses an already seeded data dir (skips seeding) for quick re-shoots.
15set -euo pipefail
16
17ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
18OUT="${AUDIT_OUT:-$ROOT/target/audit}"
19DATA="$OUT/data"
20PORT="${AUDIT_PORT:-17660}"
21TARGET="${AUDIT_TARGET:-target/agent-audit}"
22BIN="$ROOT/$TARGET/debug/forge"
23SSH_PORT="${AUDIT_SSH_PORT:-12222}"
24BUILD=1 KEEP=0
25for a in "$@"; do
26 case "$a" in
27 --no-build) BUILD=0 ;;
28 --keep-data) KEEP=1 ;;
29 *) echo "unknown arg $a" >&2; exit 2 ;;
30 esac
31done
32
33if [[ $BUILD == 1 ]]; then
34 echo "[run] building forge-web (dev profile)"
35 (cd "$ROOT" && CARGO_TARGET_DIR="$TARGET" cargo build -p forge-web)
36fi
37[[ -x $BIN ]] || { echo "[run] missing $BIN" >&2; exit 1; }
38
39# Stop anything left over from an earlier run on our ports.
40pkill -f -- "--config $OUT/forge.toml" 2>/dev/null || true
41if [[ $KEEP == 0 || ! -f $OUT/seed.json ]]; then
42 KEEP=0
43 rm -rf "$DATA" "$OUT/work" "$OUT/githome" "$OUT/sshkey" "$OUT/seed.json"
44fi
45rm -rf "$OUT/shots" "$OUT/tmp" "$OUT/index.md" "$OUT/index.json"
46mkdir -p "$DATA" "$OUT/shots" "$OUT/tmp"
47
48cat > "$OUT/forge.toml" <<EOF
49database = "$DATA/forge.db"
50data_dir = "$DATA"
51listen = "127.0.0.1:$PORT"
52base_url = "http://127.0.0.1:$PORT"
53user_content_base_url = "http://127.0.0.1:$((PORT + 1))"
54user_content_listen = "127.0.0.1:$((PORT + 1))"
55ssh_listen = "127.0.0.1:$SSH_PORT"
56ssh_public_host = "127.0.0.1"
57ssh_public_port = $SSH_PORT
58registration = "open"
59trusted_proxies = []
60
61[mail]
62transport = "log"
63
64[ci]
65enabled = true
66EOF
67
68echo "[run] starting forge on 127.0.0.1:$PORT"
69"$BIN" --config "$OUT/forge.toml" > "$OUT/forge.log" 2>&1 &
70FORGE_PID=$!
71cleanup() {
72 kill "$FORGE_PID" 2>/dev/null || true
73 wait "$FORGE_PID" 2>/dev/null || true
74 pkill -f "[f]orge-audit-ff-" 2>/dev/null || true
75 pkill -f "[u]ser-data-dir=.*forge-audit-cr-" 2>/dev/null || true
76 rm -rf "$OUT/tmp"
77 echo "[run] server stopped"
78}
79trap cleanup EXIT INT TERM
80
81for _ in $(seq 1 120); do
82 curl -fsS "http://127.0.0.1:$PORT/healthz" >/dev/null 2>&1 && break
83 kill -0 "$FORGE_PID" 2>/dev/null || { echo "[run] forge exited, see $OUT/forge.log" >&2; tail -20 "$OUT/forge.log" >&2; exit 1; }
84 sleep 0.5
85done
86
87if [[ $KEEP == 0 ]]; then
88 echo "[run] seeding"
89 python3 "$ROOT/scripts/audit/seed.py" "http://127.0.0.1:$PORT" "$OUT" 2>&1 | tee "$OUT/seed.log"
90fi
91
92echo "[run] screenshots"
93AUDIT_PROXY_PORT="${AUDIT_PROXY_PORT:-$((PORT + 10))}" \
94 python3 "$ROOT/scripts/audit/shoot.py" "http://127.0.0.1:$PORT" "$OUT" "$ROOT/crates/forge-web/src" 2>&1 | tee "$OUT/shoot.log"
95echo "[run] done: $OUT/index.md"