From 6eef939905c3f303f86db3ba4f98e1c7a8d6a387 Mon Sep 17 00:00:00 2001 From: goose Date: Thu, 1 Oct 2026 16:28:28 -0400 Subject: [PATCH] fix: import Godot project before test runners --- README.md | 2 + scripts/godot-import.sh | 13 ++++ scripts/run-visual-check.sh | 2 + scripts/test-e2e.sh | 3 + scripts/test-unit.sh | 3 + tests/scripts/test_godot_import_runners.sh | 73 ++++++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100755 scripts/godot-import.sh create mode 100755 tests/scripts/test_godot_import_runners.sh diff --git a/README.md b/README.md index 87f7526..09b291e 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ GODOT_BIN=/snap/bin/godot4 ./scripts/run-visual-check.sh GODOT_BIN=/snap/bin/godot4 ./scripts/verify.sh ``` +Each runner first executes `godot --headless --path . --import`. This generates the ignored `.godot` cache required for global script classes and imported assets, so the commands are reproducible from a newly checked-out worktree. Import failures stop the runner and retain Godot's error output. + `run-visual-check.sh` runs the actual project twice: `--capture` records the initial state at `artifacts/visual-check.png`, while `--capture-exit` records the reached-exit state at `artifacts/visual-check-exit.png`. Both must be valid **1280×720** PNGs, and output is logged to `artifacts/visual-check.log`. It chooses `xvfb-run` with a 1280×720 screen when no display is available, enforces a timeout, and reports **unavailable** (rather than a false pass) when neither a display nor Xvfb exists. `verify.sh` runs unit tests and headless E2E before visual verification; unavailable visual verification is reported distinctly from a failed test or failed visual capture. For a direct headless startup check: diff --git a/scripts/godot-import.sh b/scripts/godot-import.sh new file mode 100755 index 0000000..5900b03 --- /dev/null +++ b/scripts/godot-import.sh @@ -0,0 +1,13 @@ +#!/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 +: "${GODOT_BIN:?Set GODOT_BIN or install godot4/godot}" + +"$GODOT_BIN" --headless --path . --import diff --git a/scripts/run-visual-check.sh b/scripts/run-visual-check.sh index 944fac4..dc3cfcb 100755 --- a/scripts/run-visual-check.sh +++ b/scripts/run-visual-check.sh @@ -12,6 +12,8 @@ if [[ -z "$GODOT_BIN" ]]; then exit 2 fi +"$root_dir/scripts/godot-import.sh" + mkdir -p artifacts log_path="artifacts/visual-check.log" initial_capture_path="artifacts/visual-check.png" diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh index fed1347..8bbbdba 100755 --- a/scripts/test-e2e.sh +++ b/scripts/test-e2e.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash set -euo pipefail +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +"$script_dir/godot-import.sh" + GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" if [[ ! -x "$GODOT_BIN" ]]; then GODOT_BIN="$(command -v godot4 || command -v godot || true)" diff --git a/scripts/test-unit.sh b/scripts/test-unit.sh index dfa88df..361b810 100755 --- a/scripts/test-unit.sh +++ b/scripts/test-unit.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash set -euo pipefail +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +"$script_dir/godot-import.sh" + GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" if [[ ! -x "$GODOT_BIN" ]]; then GODOT_BIN="$(command -v godot4 || command -v godot || true)" diff --git a/tests/scripts/test_godot_import_runners.sh b/tests/scripts/test_godot_import_runners.sh new file mode 100755 index 0000000..e1f8b29 --- /dev/null +++ b/tests/scripts/test_godot_import_runners.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +set -euo pipefail + +root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +tmp_dir="$(mktemp -d)" +trap 'rm -rf "$tmp_dir"' EXIT +project_dir="$tmp_dir/project" +cp -a "$root_dir" "$project_dir" +rm -rf "$project_dir/.git" "$project_dir/.godot" "$project_dir/artifacts" + +fake_godot="$tmp_dir/godot4" +cat > "$fake_godot" <<'FAKE_GODOT' +#!/usr/bin/env bash +set -euo pipefail +printf '%s\n' "$*" >> "$FAKE_GODOT_LOG" +if [[ " $* " == *" --import "* ]]; then + printf '%s\n' "fake import output" >&2 + exit "${FAKE_IMPORT_STATUS:-0}" +fi +if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* ]]; then + if [[ " $* " == *" --capture-exit "* ]]; then + capture_name="visual-check-exit.png" + else + capture_name="visual-check.png" + fi + python3 - "$capture_name" <<'PY' +import os +import struct +import sys + +os.makedirs("artifacts", exist_ok=True) +with open(f"artifacts/{sys.argv[1]}", "wb") as capture: + capture.write(b"\x89PNG\r\n\x1a\n") + capture.write(struct.pack(">I4sII5B", 13, b"IHDR", 1280, 720, 8, 2, 0, 0, 0)) +PY +fi +exit 0 +FAKE_GODOT +chmod +x "$fake_godot" + +assert_import_precedes_run() { + local runner="$1" + local log="$tmp_dir/${runner}.log" + FAKE_GODOT_LOG="$log" GODOT_BIN="$fake_godot" DISPLAY=:99 "$project_dir/scripts/$runner" + local first_line + first_line="$(head -n 1 "$log")" + [[ "$first_line" == *"--headless"* && "$first_line" == *"--import"* ]] || { + echo "$runner did not invoke headless import before its runner command" >&2 + return 1 + } + [[ "$(wc -l < "$log")" -ge 2 ]] || { + echo "$runner did not invoke its runner command after importing" >&2 + return 1 + } +} + +assert_import_precedes_run test-unit.sh +assert_import_precedes_run test-e2e.sh +assert_import_precedes_run run-visual-check.sh + +failure_log="$tmp_dir/import-failure.log" +set +e +failure_output="$(FAKE_GODOT_LOG="$failure_log" FAKE_IMPORT_STATUS=42 GODOT_BIN="$fake_godot" "$project_dir/scripts/test-unit.sh" 2>&1)" +failure_status=$? +set -e +[[ "$failure_status" -eq 42 ]] || { + echo "test-unit.sh did not return the import failure status" >&2 + exit 1 +} +[[ "$failure_output" == *"fake import output"* ]] || { + echo "test-unit.sh did not preserve import error output" >&2 + exit 1 +} -- 2.54.0