Merge pull request 'Fix: import Godot project before test runners' (#9) from fix/s5-godot-import-runner into main
This commit was merged in pull request #9.
This commit is contained in:
@@ -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:
|
||||
|
||||
Executable
+13
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -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)"
|
||||
|
||||
Executable
+73
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user