test: add reproducible 720p visual capture

This commit is contained in:
goose
2026-10-08 22:33:52 -04:00
parent cf102e1e95
commit 23acd47495
6 changed files with 166 additions and 16 deletions
@@ -0,0 +1,103 @@
# Task 5 — Visual validation and responsive HUD completion
## Scope completed
Task 5 closes the visual-capture and responsive-HUD issues without changing gameplay, map generation, combat, or input behavior.
### Root-cause audit of inherited changes
The three pre-existing working-tree edits were retained because they address actual capture-contract causes:
1. **Explored-fog validator (`scripts/check-visual-capture.py`)**
- The old detector required the single RGB value `(19, 29, 39)`.
- Actual texture-preserving fog is a range of dark blue-shifted pixels: floor texture and GPU blend rounding make a renderer-independent exact RGB assertion invalid.
- The replacement accepts only a bounded, blue-shifted palette (`R 4–14`, `G 8–22`, `B 17–32`, with channel-separation guards), excluding HUD chrome and unmodulated brown terrain.
- `tests/scripts/test_godot_import_runners.sh` now emits a representative accepted palette pixel `(9, 14, 23)`, covering the updated contract rather than encoding an obsolete exact renderer sample.
2. **Deterministic exit capture (`scripts/game/game.gd`)**
- `Camera2D` scroll is applied during the frame cycle. Capturing immediately after moving the player to the exit could retain the previous camera framing.
- The capture now calls `camera.force_update_scroll()` before its frame waits.
- The entry cell is outside the exit crop, so it could not prove the remembered/explored rendering contract. The deterministic exit state explicitly retains a neighboring exit floor tile as explored while removing it from visible cells.
- The visual runner then verifies both visible terrain and remembered texture-preserving fog in the actual exit image.
### Responsive 1280×720 correction
Manual inspection of the original 1280×720 capture showed the three header text rows were too tightly stacked: the dynamic header values intruded into the lower edge of the top bar and were visibly clipped/overlapped by the header ornament. The underlying issue was that the rectangles scaled to 2/3 but all label font overrides remained at their desktop sizes; also, the `ResponsiveLayout` chrome painted after the direct HUD labels.
The repair:
- places the decorative `ResponsiveLayout` chrome behind direct live HUD values via `z_index = -1` in `Game.tscn`;
- scales the HUD’s text overrides with the existing artboard scale (bounded by the same 0.66 compact minimum);
- moves the dynamic header value baseline from reference y=78 to y=75, giving the 1280 layout sufficient top-bar height;
- adds `test_compact_1280_layout_scales_header_text_and_keeps_it_inside_the_top_bar`, which asserts the compact 11px header font, top-bar containment, and adequate label height.
No gameplay logic changed.
## Manual capture inspection
### 1920×1080
- Captured the initial state and deterministic exit state.
- The full shell is legible and the live header text remains clear of the ornament; no material clipping or overlap observed.
- The rails, command band, and centered map frame are distinct. The header deliberately uses three compact rows, but they have visible separation at this resolution.
- The exit capture shows visible terrain, unknown fog, and a dark blue remembered-terrain patch as required by the visual contract.
### 1280×720
- Before the repair, the header text was visibly crowded and partly clipped/overdrawn at the lower header edge; command/rail texts were correspondingly cramped.
- After the repair, header rows are contained in the top bar and no longer overdraw the ornament. Rail and command text are smaller but readable for a compact 720p presentation.
- The visual density remains necessarily high because this is the complete 1920×1080 artboard at two-thirds scale; however, no material header clipping/overlap remains.
Temporary comparison captures were removed after inspection; no capture PNG, `.import`, or other artifact is included in the commit.
## Cleanup
- Terminated the lingering `godot4 --headless --script res://tests/tmp_inspect_hud.gd` process.
- Removed `tests/tmp_inspect_hud.gd` and its UID if present.
- Removed the one-off HUD diagnostic script after use.
- Emptied generated `artifacts/` before commit. Existing Godot-generated `.import` files remain ignored and untracked.
## Verification
All commands completed successfully:
| Command | Result |
| --- | --- |
| `./scripts/test-unit.sh` | **221 / 221** tests passed, **34,509** assertions |
| `./scripts/run-visual-check.sh` | Passed initial + exit capture measurements |
| `./tests/scripts/test_godot_import_runners.sh` | Passed |
| `./scripts/verify.sh` | Passed unit, integration, E2E, visual, and strict parity gates |
`./scripts/verify.sh` results:
| Suite | Passing | Tests | Assertions |
| --- | ---: | ---: | ---: |
| Unit | 221 | 221 | 34,509 |
| Integration | 19 | 19 | 1,696,729 |
| E2E | 78 | 78 | 676 |
Visual measurements reported by the final verifier:
- `visual-check.png`: `dungeon_non_black_pixels=1102464`, `visible_pixels=82944`, `explored_pixels=18965`, `explored_luminance=0.004`, `unknown_pixels=890112`, `unknown_luminance=0.001`.
- `visual-check-exit.png`: `dungeon_non_black_pixels=1102464`, `visible_pixels=10368`, `explored_pixels=18965`, `explored_luminance=0.004`, `unknown_pixels=976128`, `unknown_luminance=0.001`.
- Strict parity: `matrix gate passed (rows=43 invalid=0)`.
Godot emitted pre-existing GUT invalid-UID and resource-cleanup warnings; none were script/parse/test failures, and all verifier commands exited 0.
## Round 1 Task 5 — reproducible compact capture follow-up
The visual runner now performs three real captures: the existing 1920×1080 initial and exit captures, plus a separate windowed `1280x720` run using `--visual-check-compact`. The game’s capture hook recognizes that user argument and writes `artifacts/visual-check-compact.png` without changing the initial or exit state preparation. The menu capture shortcut also recognizes the compact mode so the run starts deterministically.
The PNG checker now maps each supported capture filename to its required dimensions, scales the central dungeon measurement crop from the 1920×1080 reference artboard, and applies the existing content contract to the compact image. Runner regression coverage uses a generated 1280×720 fixture and asserts that the visual runner passes `--windowed --resolution 1280x720` and produces the compact artifact.
### Round 1 verification evidence
- `./tests/scripts/test_godot_import_runners.sh` — passed; fake runner validated import ordering, compact dimensions, content, and resolution flags.
- `./scripts/run-visual-check.sh` — passed; initial and exit remain 1920×1080, compact is 1280×720.
- `./scripts/verify.sh` — passed unit, integration, E2E, visual, and strict parity gates (`matrix gate passed`, 43 rows).
- `artifacts/visual-check-compact.png` — measured as `1280x720`; content measurement passed with `dungeon_non_black_pixels=489984`, `visible_pixels=36926`, `explored_pixels=8227`, `unknown_pixels=393984`.
- The generated compact PNG was inspected after capture; it shows the complete compact HUD/map composition with no capture truncation or black-frame failure.
## Git
The Task 5 implementation, regression coverage, and this report are committed locally. No push was performed.
+29 -10
View File
@@ -13,11 +13,16 @@ import sys
import zlib
from pathlib import Path
WIDTH = 1920
HEIGHT = 1080
# Central dungeon measurement region, proportionally equivalent to the former
# 16:9 reference crop while excluding the anchored HUD panels.
VIEWPORT = (384, 60, 1536, 1017)
REFERENCE_WIDTH = 1920
REFERENCE_HEIGHT = 1080
EXPECTED_DIMENSIONS = {
"visual-check.png": (REFERENCE_WIDTH, REFERENCE_HEIGHT),
"visual-check-exit.png": (REFERENCE_WIDTH, REFERENCE_HEIGHT),
"visual-check-compact.png": (1280, 720),
}
# Central dungeon measurement region in the reference 1920×1080 artboard.
# It excludes the anchored HUD panels and is scaled for the real 720p capture.
REFERENCE_VIEWPORT = (384, 60, 1536, 1017)
UNKNOWN = (1, 2, 5)
# Captured explored tiles are texture modulated, so classify their blue-black
# pixels by palette range rather than expecting one flat overlay color.
@@ -70,8 +75,14 @@ def read_png(path: Path) -> tuple[int, int, list[bytes]]:
if header is None or not saw_iend or offset != len(data):
fail("incomplete PNG")
width, height, depth, color_type, compression, filtering, interlace = header
if (width, height) != (WIDTH, HEIGHT):
fail(f"expected {WIDTH}x{HEIGHT} PNG, got {width}x{height}")
expected_dimensions = EXPECTED_DIMENSIONS.get(path.name)
if expected_dimensions is None:
fail(f"unsupported visual capture name: {path.name}")
if (width, height) != expected_dimensions:
fail(
f"expected {expected_dimensions[0]}x{expected_dimensions[1]} PNG, "
f"got {width}x{height}"
)
if depth != 8 or color_type not in (2, 6):
fail("visual capture must be an 8-bit RGB or RGBA PNG")
if (compression, filtering, interlace) != (0, 0, 0):
@@ -162,12 +173,20 @@ def is_explored(pixel: tuple[int, int, int]) -> bool:
return 4 <= red <= 14 and 8 <= green <= 22 and 17 <= blue <= 32 and blue >= green + 4 and green >= red + 3
def viewport_for(width: int, height: int) -> tuple[int, int, int, int]:
scale_x = width / REFERENCE_WIDTH
scale_y = height / REFERENCE_HEIGHT
return tuple(round(coordinate * (scale_x if index % 2 == 0 else scale_y)) for index, coordinate in enumerate(REFERENCE_VIEWPORT))
def measure(path: Path) -> None:
width, height = EXPECTED_DIMENSIONS[path.name]
observed = list(pixels(path))
viewport = viewport_for(width, height)
dungeon_pixels = [
observed[y * WIDTH + x]
for y in range(VIEWPORT[1], VIEWPORT[3])
for x in range(VIEWPORT[0], VIEWPORT[2])
observed[y * width + x]
for y in range(viewport[1], viewport[3])
for x in range(viewport[0], viewport[2])
]
non_black = sum(pixel != (0, 0, 0) for pixel in dungeon_pixels)
unknown_pixels = [pixel for pixel in dungeon_pixels if pixel == UNKNOWN]
+7 -1
View File
@@ -302,6 +302,8 @@ func _get_capture_mode() -> String:
var arguments := OS.get_cmdline_user_args()
if "--capture-exit" in arguments:
return "exit"
if "--visual-check-compact" in arguments:
return "compact"
if "--capture" in arguments:
return "initial"
return ""
@@ -315,7 +317,11 @@ func _capture_visual_check(capture_mode: String) -> void:
await get_tree().process_frame
await get_tree().process_frame
await RenderingServer.frame_post_draw
var filename := "visual-check-exit.png" if capture_mode == "exit" else "visual-check.png"
var filename := "visual-check.png"
if capture_mode == "exit":
filename = "visual-check-exit.png"
elif capture_mode == "compact":
filename = "visual-check-compact.png"
var capture_path := ProjectSettings.globalize_path("res://artifacts/" + filename)
DirAccess.make_dir_recursive_absolute(capture_path.get_base_dir())
var image := get_viewport().get_texture().get_image()
+1 -1
View File
@@ -33,7 +33,7 @@ func _ready() -> void:
func _get_capture_mode() -> bool:
var arguments := OS.get_cmdline_user_args()
return "--capture" in arguments or "--capture-exit" in arguments
return "--capture" in arguments or "--capture-exit" in arguments or "--visual-check-compact" in arguments
func _show_character_creation() -> void:
menu.visible = false
+9 -2
View File
@@ -18,7 +18,8 @@ mkdir -p artifacts
log_path="artifacts/visual-check.log"
initial_capture_path="artifacts/visual-check.png"
exit_capture_path="artifacts/visual-check-exit.png"
rm -f "$initial_capture_path" "$exit_capture_path"
compact_capture_path="artifacts/visual-check-compact.png"
rm -f "$initial_capture_path" "$exit_capture_path" "$compact_capture_path"
: > "$log_path"
runner=()
@@ -34,8 +35,9 @@ fi
run_capture() {
local label="$1"
local capture_argument="$2"
shift 2
set +e
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --"$capture_argument" >>"$log_path" 2>&1
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . "$@" -- --"$capture_argument" >>"$log_path" 2>&1
local status=$?
set -e
if (( status != 0 )); then
@@ -46,6 +48,10 @@ run_capture() {
run_capture "initial" "capture"
run_capture "exit" "capture-exit"
# This is a real 1280×720 window capture, not a unit-level HUD relayout call.
# The fixed window size makes the compact artboard and PNG reproducible under
# Xvfb as well as an interactive DISPLAY.
run_capture "compact" "visual-check-compact" --windowed --resolution 1280x720
# Godot's SCRIPT ERROR / Parse Error diagnostics are actionable application
# failures. Do not treat unrelated backend diagnostics (for example the
# expected xkbcommon Compose warnings emitted by some Snap/Xvfb setups) as an
@@ -65,3 +71,4 @@ measure_capture() {
measure_capture "$initial_capture_path"
measure_capture "$exit_capture_path"
measure_capture "$compact_capture_path"
+17 -2
View File
@@ -17,9 +17,11 @@ if [[ " $* " == *" --import "* ]]; then
printf '%s\n' "fake import output" >&2
exit "${FAKE_IMPORT_STATUS:-0}"
fi
if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* ]]; then
if [[ " $* " == *" --capture "* || " $* " == *" --capture-exit "* || " $* " == *" --visual-check-compact "* ]]; then
if [[ " $* " == *" --capture-exit "* ]]; then
capture_name="visual-check-exit.png"
elif [[ " $* " == *" --visual-check-compact "* ]]; then
capture_name="visual-check-compact.png"
else
capture_name="visual-check.png"
fi
@@ -30,7 +32,8 @@ import sys
import zlib
os.makedirs("artifacts", exist_ok=True)
width, height = 1920, 1080
compact = sys.argv[1] == "visual-check-compact.png"
width, height = (1280, 720) if compact else (1920, 1080)
unknown = (1, 2, 5)
visible = (176, 176, 176)
# Match the blue-black explored tile palette accepted by the real capture
@@ -74,6 +77,18 @@ assert_import_precedes_run() {
}
}
visual_log="$tmp_dir/run-visual-check.sh.log"
FAKE_GODOT_LOG="$visual_log" GODOT_BIN="$fake_godot" DISPLAY=:99 "$project_dir/scripts/run-visual-check.sh"
compact_run="$(grep -- '--visual-check-compact' "$visual_log")"
[[ "$compact_run" == *"--windowed"* && "$compact_run" == *"--resolution 1280x720"* ]] || {
echo "run-visual-check.sh did not request a real 1280x720 compact window" >&2
exit 1
}
[[ -s "$project_dir/artifacts/visual-check-compact.png" ]] || {
echo "run-visual-check.sh did not produce a compact capture" >&2
exit 1
}
assert_import_precedes_run test-unit.sh
assert_import_precedes_run test-e2e.sh
assert_import_precedes_run run-visual-check.sh