#!/usr/bin/env bash set -euo pipefail root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$root_dir" GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" if [[ ! -x "$GODOT_BIN" ]]; then GODOT_BIN="$(command -v godot4 || command -v godot || true)" fi if [[ -z "$GODOT_BIN" ]]; then echo "visual check unavailable: set GODOT_BIN or install godot4/godot" >&2 exit 2 fi mkdir -p artifacts log_path="artifacts/visual-check.log" capture_path="artifacts/visual-check.png" rm -f "$capture_path" runner=() if [[ -z "${DISPLAY:-}" ]]; then if command -v xvfb-run >/dev/null 2>&1; then runner=(xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24") else echo "visual check unavailable: DISPLAY is unset and xvfb-run is not installed" | tee "$log_path" >&2 exit 2 fi fi set +e timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --capture-door >"$log_path" 2>&1 status=$? set -e if (( status != 0 )); then echo "visual check failed: Godot exited with status $status; see $log_path" >&2 exit "$status" fi if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$log_path"; then echo "visual check failed: Godot reported errors; see $log_path" >&2 exit 1 fi if [[ ! -s "$capture_path" ]]; then echo "visual check failed: missing capture $capture_path" >&2 exit 1 fi if ! python3 - "$capture_path" <<'PY' import struct import sys path = sys.argv[1] with open(path, "rb") as capture: signature = capture.read(8) length = struct.unpack(">I", capture.read(4))[0] kind = capture.read(4) data = capture.read(length) if signature != b"\x89PNG\r\n\x1a\n" or kind != b"IHDR" or len(data) != 13: raise SystemExit("invalid PNG") width, height = struct.unpack(">II", data[:8]) if (width, height) != (1280, 720): raise SystemExit(f"expected 1280x720 PNG, got {width}x{height}") print(f"visual capture: {path} ({width}x{height})") PY then echo "visual check failed: capture is not a nonempty valid PNG" >&2 exit 1 fi