Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6897PWcUEwHiqZMcVnNF6
29 lines
1.3 KiB
Bash
29 lines
1.3 KiB
Bash
#!/bin/sh
|
|
# tools/harness.sh: the playback regression run. Appends tools/harness.html's script to index.html, runs it in headless
|
|
# Chrome with autoplay allowed, prints one state line per step. Needs Chrome/Chromium and python3.
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
CHROME=${CHROME:-}
|
|
for c in "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "$(command -v chromium || true)" "$(command -v google-chrome || true)"; do
|
|
if [ -z "$CHROME" ] && [ -n "$c" ] && [ -x "$c" ]; then CHROME=$c; fi
|
|
done
|
|
[ -n "$CHROME" ] || { echo "no Chrome found; set CHROME" >&2; exit 1; }
|
|
out=$(mktemp -d)
|
|
python3 - "$out" <<'EOF'
|
|
import sys, pathlib
|
|
out = pathlib.Path(sys.argv[1])
|
|
page = pathlib.Path("index.html").read_text()
|
|
h = pathlib.Path("tools/harness.html").read_text()
|
|
script = h[h.index("<!-- harness -->"):]
|
|
(out / "run.html").write_text(page.replace("</body>", script + "</body>"))
|
|
EOF
|
|
# shellcheck disable=SC2086
|
|
"$CHROME" --headless=new --disable-gpu --autoplay-policy=no-user-gesture-required --virtual-time-budget=25000 ${CHROME_FLAGS:-} --dump-dom "file://$out/run.html" 2>/dev/null > "$out/dom.html" || true
|
|
python3 - "$out/dom.html" <<'EOF'
|
|
import sys, re, html
|
|
s = open(sys.argv[1]).read()
|
|
m = re.search(r'<pre id="diag">(.*?)</pre>', s, re.S)
|
|
print(html.unescape(m.group(1)) if m else "no diag: the harness did not run")
|
|
EOF
|
|
rm -rf "$out"
|