#!/usr/bin/env bash # Headless-Chrome smoke test for frontend.html. # # Two kinds of checks: # • STATIC — markup that's in the file regardless of rendering (buttons, # controls). Grepped straight from frontend.html → 100% reliable. # • DYNAMIC — proof the page actually rendered: CodeMirror mounted (its CDN/ESM # imports ran), the editor wrap was revealed and the textarea fallback hidden. # These need a real browser, so we render with headless Chrome. # # Only the dynamic half can flake (CDN timing), so the headless dump is retried # until it's complete. Static checks never touch the browser. # # Usage: ./smoke-test.sh (exit 0 = pass, 1 = fail) set -euo pipefail cd "$(dirname "$0")" FILE="frontend.html" src="$(cat "$FILE")" CHROME="${CHROME:-/Applications/Google Chrome.app/Contents/MacOS/Google Chrome}" [ -x "$CHROME" ] || { echo "✗ Chrome not found at: $CHROME (set \$CHROME)"; exit 1; } # Retry the dump until it's a COMPLETE render (has AND the CodeMirror # mount), up to 5 attempts — guards against partial/pre-render dumps. dom="" for attempt in 1 2 3 4 5; do dom="$("$CHROME" --headless --disable-gpu --no-sandbox \ --virtual-time-budget=25000 \ --dump-dom "file://$PWD/$FILE" 2>/dev/null)" if grep -q '' <<<"$dom" && grep -q 'class="cm-editor' <<<"$dom"; then break fi [ "$attempt" -lt 5 ] && { echo "… incomplete render (attempt $attempt), retrying"; sleep 1; } done fail=0 chk() { # chk "" "