Skip to content

Commit f62c9c9

Browse files
authored
test(menu): run the hover-driven menu smoke tests headless (#87)
* test(menu): run the hover-driven menu smoke tests headless [Agent: Claude Code | Model: Opus 5.5 | Thinking: High | Acting on behalf of: Erik | Skill: none] Closes #56. menu_smoke and menu_hoppy_smoke were skipped in CI because their hover checks failed headless; everything else in them passed. Three causes: the 64x64 headless window's stretch transform scales a pointer event's position and the menu recenters in a 1280x1280 visible area, so fixed coordinates miss the buttons; Input.parse_input_event() never hovers anything headless; and push_input() is delivered at once while parsed events wait a frame, so the D-pad release sent just before re-selected the brawler after the hover. - tests/support/pointer.gd hovers a control at its actual rect with viewport.push_input(event, true), after flushing buffered input, the same way in rendered and headless runs. - Both suites use it; menu_smoke finishes with AudioService.settle(). - tools/tests/suites.toml no longer skips them. - CONTRIBUTING and docs/main-menu.md say hover works headless. * test(menu): aim the pointer in viewport coordinates [Agent: Claude Code | Model: Opus 5.5 | Thinking: High | Acting on behalf of: Erik | Skill: none] Addresses CodeRabbit review 5542805293 on #87: hover() maps the control's centre through get_global_transform_with_canvas(), so a control under a canvas layer or camera transform is still hit.
1 parent 7574b50 commit f62c9c9

7 files changed

Lines changed: 40 additions & 20 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ python3 tools/tests/run_tests.py -k runner # suites whose name
3737
python3 tools/tests/run_tests.py --list # what runs and what is skipped
3838
```
3939

40-
- **Every new `.gd` file under `tests/` that `extends SceneTree` or `MainLoop` runs automatically.** Shared helpers that extend anything else, such as `tests/support/`, are never run as suites. There's no list to update. To keep a suite out of CI (it needs a GPU, a window or pointer hover), add it to `[skip]` in [`tools/tests/suites.toml`](tools/tests/suites.toml) with the reason.
40+
- **Every new `.gd` file under `tests/` that `extends SceneTree` or `MainLoop` runs automatically.** Shared helpers that extend anything else, such as `tests/support/`, are never run as suites. There's no list to update. To keep a suite out of CI (it needs a GPU or a window), add it to `[skip]` in [`tools/tests/suites.toml`](tools/tests/suites.toml) with the reason. Pointer hover works headless through [`tests/support/pointer.gd`](hoppys-adventure-arcade/tests/support/pointer.gd); `Input.parse_input_event()` never hovers anything in a headless run.
4141
- **A suite fails if it exits nonzero, times out, or prints an engine or script error or an exit-time leak.** Suites run with `--verbose`, so a leak names the objects involved. The one tolerated shape is the engine's audio-teardown race: only `AudioStream*` playbacks and audio files, reported as a note. Anything else that leaks fails. That includes `ERROR:`, `SCRIPT ERROR`, parse errors and "leaked at exit". If a test provokes an engine error on purpose, list a pattern for it under `[expected_errors]`; the runner fails if that pattern stops matching.
4242
- **Finish a suite with `await root.get_node("AudioService").settle()` before `quit()`.** It stops the shared music and waits until the audio thread has released it. A fixed delay is not enough under parallel load.
4343
- Each suite gets a private user-data root (`HOME`, the XDG directories, and `APPDATA` on Windows), so `user://` files (settings, leaderboards) never touch your real ones. The runner checks this with Godot before starting and refuses to run if `user://` would escape. Suites listed under `[serial]` (wall-clock budgets, or suites that occupy every core) run alone after the parallel batch. Results are written to `build/test-results/summary.json`.

‎docs/main-menu.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Updated 2026-10-08: all menu previews now use current stage artwork or captured
5555
/Applications/Godot.app/Contents/MacOS/Godot --path hoppys-adventure-arcade --script res://tests/menu_smoke.gd
5656
```
5757

58-
The behavioral smoke test covers preview timing and preservation, rapid input coalescing, bounded preview count, all thirteen previews, modal focus restoration, invalid routes, duplicate navigation, all three mode round trips, and audio player counts. It also dispatches keyboard, simulated gamepad, and mouse events. A rendered run writes menu/settings screenshots to `/tmp` for layout inspection. It uses the normal settings path, so run against a disposable user profile if preserving settings during tests matters.
58+
The behavioral smoke test covers preview timing and preservation, rapid input coalescing, bounded preview count, all thirteen previews, modal focus restoration, invalid routes, duplicate navigation, all three mode round trips, and audio player counts. It also dispatches keyboard, simulated gamepad, and mouse events. Mouse hover goes through `tests/support/pointer.gd`, so it and the character check below run headless in CI. A rendered run writes menu/settings screenshots to `/tmp` for layout inspection. It uses the normal settings path, so run against a disposable user profile if preserving settings during tests matters.
5959

6060
Physical controller feel, audio loop quality, and Windows/Linux exports require later hands-on checks; no export presets or platform builds were added.
6161

‎hoppys-adventure-arcade/tests/menu_hoppy_smoke.gd‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
extends SceneTree
2+
## Hoppy's reactions on the main menu. Runs headless in CI; a rendered run also saves screenshots.
3+
## Pointer moves go through tests/support/pointer.gd so they hover headless.
4+
const Pointer := preload("res://tests/support/pointer.gd")
25
var failures := 0
36
func _initialize() -> void:
47
call_deferred("run")
@@ -20,10 +23,7 @@ func run() -> void:
2023
check(hoppy.sprite.animation == &"idle", "Default Hoppy idles in 2D")
2124
check(hoppy.runner_view.render_target_update_mode == SubViewport.UPDATE_DISABLED, "Hidden 3D render disabled")
2225
await capture("/tmp/menu-hoppy-2d.png")
23-
var mouse := InputEventMouseMotion.new()
24-
mouse.position = Vector2(200, 430)
25-
mouse.relative = Vector2(10, 10)
26-
Input.parse_input_event(mouse)
26+
Pointer.hover(menu.buttons[1])
2727
await wait(1)
2828
check(hoppy.runner_image.visible and hoppy.runner_image.modulate.a == 1, "Runner shows 3D")
2929
check(hoppy.sprite.modulate.a == 0, "2D fades away")

‎hoppys-adventure-arcade/tests/menu_smoke.gd‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends SceneTree
2-
## Run with --path <project> --script res://tests/menu_smoke.gd.
2+
## Run with --path <project> --script res://tests/menu_smoke.gd. Runs headless in CI; a rendered run
3+
## also saves screenshots. Pointer moves go through tests/support/pointer.gd so they hover headless.
4+
const Pointer := preload("res://tests/support/pointer.gd")
35
var failures := 0
46
func _initialize() -> void:
57
call_deferred("run")
@@ -97,16 +99,10 @@ func run() -> void:
9799
Input.parse_input_event(pad)
98100
check(root.gui_get_focus_owner() == current_scene.buttons[2], "Gamepad D-pad moves focus")
99101
check(current_scene.showcase.focus_group == 2, "Gamepad focus selects brawler")
100-
var mouse := InputEventMouseMotion.new()
101-
mouse.position = Vector2(200, 430)
102-
mouse.relative = Vector2(10, 10)
103-
Input.parse_input_event(mouse)
102+
Pointer.hover(current_scene.buttons[1])
104103
await process_frame
105104
check(current_scene.showcase.focus_group == 1, "Mouse hover overrides old gamepad focus")
106-
mouse = InputEventMouseMotion.new()
107-
mouse.position = Vector2(620, 680)
108-
mouse.relative = Vector2(420, 250)
109-
Input.parse_input_event(mouse)
105+
Pointer.move(root, Pointer.corner(root), Vector2(420, 250))
110106
await process_frame
111107
check(current_scene.showcase.focus_group == -1, "Pointer exit releases mode preview")
112108
current_scene.showcase.select_group(-1)
@@ -130,7 +126,6 @@ func run() -> void:
130126
# The verdict is already printed; a missing or renamed autoload must not stop quit(failures)
131127
# from running, or the process hangs instead of reporting.
132128
var shutdown_audio := root.get_node_or_null("AudioService")
133-
if shutdown_audio != null and shutdown_audio.has_method("shutdown"):
134-
shutdown_audio.shutdown()
135-
await wait(0.3)
129+
if shutdown_audio != null and shutdown_audio.has_method("settle"):
130+
await shutdown_audio.settle()
136131
quit(failures)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
extends RefCounted
2+
## Pointer input that hovers controls in headless runs too. Input.parse_input_event() never hovers
3+
## anything headless: the 64x64 headless window's stretch transform scales the event's position,
4+
## and the menu recenters itself in the visible area, so fixed coordinates miss the buttons.
5+
## Pushing the motion to the viewport in its own coordinates, aimed at a control's actual rect,
6+
## hovers it the same way in rendered and headless runs.
7+
8+
## Move the pointer to `point` in the viewport's coordinates, having moved by `relative`. Events
9+
## sent with Input.parse_input_event() wait for the next frame, while push_input() delivers at
10+
## once, so pending ones are flushed first to keep the order the suite sent them in.
11+
static func move(viewport: Viewport, point: Vector2, relative := Vector2(10, 10)) -> void:
12+
Input.flush_buffered_events()
13+
var motion := InputEventMouseMotion.new()
14+
motion.position = point
15+
motion.global_position = point
16+
motion.relative = relative
17+
viewport.push_input(motion, true)
18+
19+
## Move the pointer onto the middle of `control`, in viewport coordinates (through any canvas layer
20+
## or camera transform above it).
21+
static func hover(control: Control) -> void:
22+
move(control.get_viewport(), control.get_global_transform_with_canvas() * (control.size * 0.5))
23+
24+
## The bottom-right corner of the visible area, which no menu button covers.
25+
static func corner(viewport: Viewport) -> Vector2:
26+
return viewport.get_visible_rect().end - Vector2(8, 8)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://blamhp7yk5nqg

‎tools/tests/suites.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ capture_runner_menu_previews = "Writes menu preview screenshots; needs a window
99
perf_probe = "Measures GPU frame times, which are meaningless headless. Run it locally."
1010
runner_perf_probe = "Measures runner frame times on a GPU. Run it locally."
1111
runner_pickup_hitch = "Measures GPU hitches during pickups. Run it locally."
12-
menu_smoke = "Drives the menu with pointer hover, which a headless run never produces."
13-
menu_hoppy_smoke = "Drives the menu with pointer hover, which a headless run never produces."
1412
capture_code_city_bosses = "Writes the Code City boss stills into docs/previews/; a graphical run only."
1513
exit_leak = "Needs a --scenario per process; CI runs every scenario through tools/checks/exit_leak.py."
1614
"support/session_log_quit" = "Child process for booth_session_log: it quits through AppRouter on purpose."

0 commit comments

Comments
 (0)