igneum/tools/ui-mock/capture.sh

33 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Headless captures of the miner UI on the mock engine, for a review folder (gpu-logos, 7 October 2026).
# Runs on igneum-build-2 (the Mac captures nothing: CLAUDE.md "Nothing heavy on the Mac"), one headless chromium at a
# time, against tools/ui-mock/server.mjs on a port of its own. Each line of the shot list is "<file> <query> <height>".
#
# tools/ui-mock/capture.sh <out dir> [<chromium binary>]
#
# The binary defaults to Playwright's headless shell in ~/.cache/ms-playwright (the box has it); no npm package is needed.
set -euo pipefail
OUT="${1:?out dir}"; CHROME="${2:-}"
HERE="$(cd "$(dirname "$0")" && pwd)"
if [ -z "$CHROME" ]; then CHROME="$(ls -d "$HOME"/.cache/ms-playwright/chromium_headless_shell-*/chrome-linux/headless_shell 2>/dev/null | sort | tail -1 || true)"; fi
[ -x "$CHROME" ] || { echo "no chromium headless shell (pass its path as the second argument)" >&2; exit 2; }
PORT="${IGNEUM_MOCK_PORT:-$((4400 + RANDOM % 400))}"
mkdir -p "$OUT"
node "$HERE/server.mjs" "$PORT" > "$OUT/mock.log" 2>&1 &
MOCK=$!
trap 'kill "$MOCK" 2>/dev/null || true' EXIT
for i in $(seq 1 40); do curl -fsS "http://127.0.0.1:$PORT/t/mock/api/state" > /dev/null 2>&1 && break; sleep 0.25; done
curl -fsS "http://127.0.0.1:$PORT/t/mock/api/state" > /dev/null || { echo "the mock did not answer on $PORT" >&2; cat "$OUT/mock.log" >&2; exit 3; }
WIDTH="${IGNEUM_SHOT_WIDTH:-1280}"
shot() { # <file> <query> <height>
local file="$1" query="$2" height="$3"
"$CHROME" --headless --no-sandbox --disable-gpu --hide-scrollbars --force-device-scale-factor=2 \
--force-prefers-reduced-motion --window-size="$WIDTH,$height" --virtual-time-budget=10000 --run-all-compositor-stages-before-draw \
--screenshot="$OUT/$file" "http://127.0.0.1:$PORT/t/mock/?$query" > "$OUT/$file.log" 2>&1 || { echo "FAILED $file"; cat "$OUT/$file.log"; return 1; }
echo "$file $(stat -c %s "$OUT/$file" 2>/dev/null || stat -f %z "$OUT/$file") B ?$query"
}
while read -r file query height; do
[ -n "$file" ] && [ "${file#\#}" = "$file" ] || continue
shot "$file" "$query" "$height"
done
echo "done: $OUT"