test(qa): add log-guarded headless QA suites

qa_all.ps1 runs the class scan, smoke, UI, core, input, and UI QA suites, checks PASS markers, and fails on any engine error in the log. New suites cover save migrations, daily logic, frames, level data, navigation, win overlays, and input gestures.
This commit is contained in:
Ratdoku Builder committed 2026-12-02 22:48:09 -06:00
1 parent 48c14864a4
commit 077c08bb5f
7 files changed
+1361

No files matched your search

+428
View File
@@ -0,0 +1,428 @@
extends SceneTree
## Headless input QA: board placement modes, Guest Book tap/scroll gestures,
## and scroll pass-through on the scrolling screens.
## <godot> --headless --path <project> --script res://tools/qa_input.gd --quit-after 1800
var failures := 0
var finished := false
func _init() -> void:
call_deferred("_run")
func _check(condition: bool, message: String) -> void:
if not condition:
failures += 1
print("FAIL: ", message)
func _finish() -> void:
if finished:
return
finished = true
print("QA INPUT: ", "PASS" if failures == 0 else "FAIL (%d)" % failures)
quit(0 if failures == 0 else 1)
func _run() -> void:
# Failsafe: never leave the command line hanging.
var watchdog := Timer.new()
watchdog.wait_time = 20.0
watchdog.one_shot = true
watchdog.timeout.connect(func() -> void:
if not finished:
_check(false, "QA timed out")
_finish()
)
root.add_child(watchdog)
watchdog.start()
var save = root.get_node_or_null("SaveGame")
_check(save != null, "SaveGame autoload missing")
if save == null:
_finish()
return
# Snapshot so the user's settings are exactly as we found them.
var original_settings: Dictionary = save.data["settings"].duplicate(true)
_test_board_modes(save)
var err := change_scene_to_file("res://scenes/Main.tscn")
if err != OK:
_check(false, "could not load Main (%d)" % err)
_restore_settings(save, original_settings)
_finish()
return
await process_frame
await process_frame
var main = current_scene
_check(main != null, "Main scene missing")
if main == null:
_restore_settings(save, original_settings)
_finish()
return
await _test_scroll_pass_through(main)
await _test_guest_book_input(main)
_restore_settings(save, original_settings)
_finish()
func _restore_settings(save, original: Dictionary) -> void:
for key in original:
save.set_setting(key, original[key])
save.save_game()
# --- Board -------------------------------------------------------------------
func _test_board_modes(save) -> void:
var levels: Array = Levels.load_all()
_check(levels.size() > 0, "no levels available")
if levels.is_empty():
return
var level: Dictionary = levels[0]
var board := Board.new()
root.add_child(board)
board.size = Vector2(640, 640)
board.set_level(level)
board._update_layout()
_reset_press(board)
# ---------------------------------------------------------------- hold mode
save.set_setting("hold_seconds", 0.35)
save.set_setting("double_tap_place", false)
_check(not board.double_tap_place, "hold mode setting did not reach Board")
# Quick press + release marks an X.
var tap_cell := _find_empty(board)
_check(tap_cell.x >= 0, "no empty cell for hold-mode tap")
if tap_cell.x >= 0:
_mouse_button(board, tap_cell, true)
_mouse_button(board, tap_cell, false)
_check(int(board.cells[tap_cell.x][tap_cell.y]) == Board.X,
"hold mode: press + release should mark X")
# A press held past the threshold checks a guest in, and releasing keeps it.
var hold_cell := _find_empty(board)
_check(hold_cell.x >= 0, "no empty cell for hold")
if hold_cell.x >= 0:
_mouse_button(board, hold_cell, true)
board._process(board.hold_seconds + 0.05)
_check(int(board.cells[hold_cell.x][hold_cell.y]) == Board.RAT,
"hold past the threshold should place a rat")
_check(board.hold_fired, "hold_fired should be set after the threshold")
_mouse_button(board, hold_cell, false)
_check(int(board.cells[hold_cell.x][hold_cell.y]) == Board.RAT,
"releasing after a hold should keep the rat")
_check(board.press_cell == Vector2i(-1, -1), "release should clear press_cell")
_check(not board.hold_fired, "release should clear hold_fired")
# Right-click checks a guest in, then out.
var right_cell := _find_empty(board)
_check(right_cell.x >= 0, "no empty cell for right-click")
if right_cell.x >= 0:
_right_click(board, right_cell)
_check(int(board.cells[right_cell.x][right_cell.y]) == Board.RAT,
"right-click should check a guest in")
_right_click(board, right_cell)
_check(int(board.cells[right_cell.x][right_cell.y]) == Board.EMPTY,
"right-click should check a guest out")
# Fixed clues cannot be changed by any input path.
if board.fixed.is_empty():
_check(false, "test level has no fixed clues")
else:
var fixed_cell: Vector2i = board.fixed.keys()[0]
_check(int(board.cells[fixed_cell.x][fixed_cell.y]) == Board.RAT,
"fixed clue should start as a rat")
board._toggle_rat(fixed_cell)
_check(int(board.cells[fixed_cell.x][fixed_cell.y]) == Board.RAT,
"right-click must not remove a fixed clue")
board._tap(fixed_cell)
_check(int(board.cells[fixed_cell.x][fixed_cell.y]) == Board.RAT,
"tap must not clear a fixed clue")
_reset_press(board)
_mouse_button(board, fixed_cell, true)
_mouse_button(board, fixed_cell, false)
_check(int(board.cells[fixed_cell.x][fixed_cell.y]) == Board.RAT,
"press + release must not change a fixed clue")
# Undo and restart discard a tap waiting for its partner.
var undo_cell := _find_empty(board)
_check(undo_cell.x >= 0, "no empty cell for pending-undo test")
_check(not board.history.is_empty(), "board history should be non-empty before undo")
board.pending_tap_cell = undo_cell
board.pending_tap_at = Time.get_ticks_msec()
board.undo()
_check(board.pending_tap_cell == Vector2i(-1, -1), "undo should clear a pending tap")
var restart_cell := _find_empty(board)
_check(restart_cell.x >= 0, "no empty cell for pending-restart test")
board.pending_tap_cell = restart_cell
board.pending_tap_at = Time.get_ticks_msec()
board.restart()
_check(board.pending_tap_cell == Vector2i(-1, -1), "restart should clear a pending tap")
# --------------------------------------------------------- double-tap mode
save.set_setting("double_tap_place", true)
_check(board.double_tap_place, "double-tap setting did not reach Board")
board.set_level(level)
board._update_layout()
_reset_press(board)
# One tap leaves the cell untouched until the window expires.
var first := _find_empty(board)
_check(first.x >= 0, "no empty cell for first tap")
if first.x >= 0:
board._handle_tap(first)
_check(int(board.cells[first.x][first.y]) == Board.EMPTY,
"first tap should leave the cell empty")
_check(board.pending_tap_cell == first, "first tap should be pending")
board.pending_tap_at -= Board.DOUBLE_TAP_MS + 1
board._process(0.0)
_check(int(board.cells[first.x][first.y]) == Board.X,
"a lone tap should mark X after the double-tap window")
# Two quick taps check a guest in, then out again.
var pair := _find_empty(board)
_check(pair.x >= 0, "no empty cell for double tap")
if pair.x >= 0:
board._handle_tap(pair)
board._handle_tap(pair)
_check(int(board.cells[pair.x][pair.y]) == Board.RAT,
"two quick taps should check a guest in")
board._handle_tap(pair)
board._handle_tap(pair)
_check(int(board.cells[pair.x][pair.y]) == Board.EMPTY,
"two quick taps on a rat should check them out")
# Holding does nothing while double-tap mode is on.
var held := _find_empty(board)
_check(held.x >= 0, "no empty cell for hold-in-double-tap test")
if held.x >= 0:
_reset_press(board)
_mouse_button(board, held, true)
board._process(board.hold_seconds + 1.0)
_check(int(board.cells[held.x][held.y]) == Board.EMPTY,
"hold should not place a rat in double-tap mode")
_check(not board.hold_fired, "hold_fired must stay clear in double-tap mode")
_mouse_button(board, held, false)
board.pending_tap_cell = Vector2i(-1, -1)
# Right-click still works in double-tap mode.
var right2 := _find_empty(board)
_check(right2.x >= 0, "no empty cell for double-tap right-click")
if right2.x >= 0:
_right_click(board, right2)
_check(int(board.cells[right2.x][right2.y]) == Board.RAT,
"right-click should check in during double-tap mode")
_right_click(board, right2)
_check(int(board.cells[right2.x][right2.y]) == Board.EMPTY,
"right-click should check out during double-tap mode")
# Switching modes flushes a pending tap (and a half-finished hold).
var flush := _find_empty(board)
_check(flush.x >= 0, "no empty cell for mode-switch test")
if flush.x >= 0:
board._handle_tap(flush)
_check(board.pending_tap_cell == flush, "pending tap should be set up")
save.set_setting("double_tap_place", false)
_check(not board.double_tap_place, "switch to hold mode did not reach Board")
_check(board.pending_tap_cell == Vector2i(-1, -1),
"switching out of double-tap should flush the pending tap")
_check(int(board.cells[flush.x][flush.y]) == Board.X,
"flushed pending tap should mark X")
board.press_cell = flush
board.hold_fired = true
save.set_setting("double_tap_place", true)
_check(board.double_tap_place, "switch back to double-tap did not reach Board")
_check(board.press_cell == Vector2i(-1, -1),
"switching to double-tap should clear a held press")
_check(not board.hold_fired, "switching to double-tap should clear hold_fired")
board.free()
func _find_empty(board: Board) -> Vector2i:
for r in board.n:
for c in board.n:
if (
int(board.cells[r][c]) == Board.EMPTY
and not board.fixed.has(Vector2i(r, c))
and not board.auto_x[r][c]
):
return Vector2i(r, c)
return Vector2i(-1, -1)
func _reset_press(board: Board) -> void:
board.press_cell = Vector2i(-1, -1)
board.press_elapsed = 0.0
board.hold_fired = false
board.pending_tap_cell = Vector2i(-1, -1)
func _mouse_button(board: Board, cell: Vector2i, pressed: bool) -> void:
var event := InputEventMouseButton.new()
event.button_index = MOUSE_BUTTON_LEFT
event.pressed = pressed
event.position = board._cell_rect(cell.x, cell.y).get_center()
board._gui_input(event)
func _right_click(board: Board, cell: Vector2i) -> void:
var event := InputEventMouseButton.new()
event.button_index = MOUSE_BUTTON_RIGHT
event.pressed = true
event.position = board._cell_rect(cell.x, cell.y).get_center()
board._gui_input(event)
# --- Scroll pass-through ------------------------------------------------------
func _test_scroll_pass_through(main) -> void:
main.open_settings("home")
await process_frame
var sheet = main.settings_sheet
_check(sheet != null, "settings sheet missing")
if sheet != null:
for key in ["patterns", "show_timer", "reduce_motion", "double_tap_place"]:
if sheet.toggles.has(key):
_check(sheet.toggles[key].mouse_filter == Control.MOUSE_FILTER_PASS,
"settings row '%s' should pass swipes" % key)
main.close_settings()
main.show_screen("guest_book")
await process_frame
var book = main.guest_book
_check(book != null, "Guest Book missing")
if book != null:
_check(book.grid.mouse_filter == Control.MOUSE_FILTER_PASS,
"guest grid should pass swipes")
for card in book.grid.get_children():
_check(card.mouse_filter == Control.MOUSE_FILTER_PASS,
"guest cards should pass swipes")
main.show_screen("rules")
await process_frame
var rulebook = main.rulebook
_check(rulebook != null, "Rulebook missing")
if rulebook != null:
var scrolls = rulebook.find_children("*", "ScrollContainer", true, false)
_check(scrolls.size() > 0, "rules ScrollContainer missing")
if scrolls.size() > 0:
var content = scrolls[0].get_child(0)
_check(content.mouse_filter == Control.MOUSE_FILTER_PASS,
"rules content should pass swipes")
var tutorial = rulebook.tutorial_board
_check(tutorial != null, "tutorial board missing")
if tutorial != null:
_check(tutorial.mouse_filter == Control.MOUSE_FILTER_STOP,
"tutorial board should keep its own input")
# --- Guest Book input ---------------------------------------------------------
func _test_guest_book_input(main) -> void:
main.show_screen("guest_book")
await process_frame
var book = main.guest_book
_check(book != null, "Guest Book missing")
if book == null:
return
var guests: Array = Guests.all()
_check(guests.size() > 0, "no guests to test")
if guests.is_empty():
return
var guest: Dictionary = guests[0]
book.scroll.scroll_vertical = 0
book._press_scroll = 0
book._suppress_until = 0
book._dragged = false
book.detail_layer.visible = false
# A short, stationary press + release opens the card.
_card_mouse(book, guest, Vector2(100, 300), true)
_card_mouse(book, guest, Vector2(100, 300), false)
_check(book.detail_layer.visible, "stationary press/release should open detail")
book.detail_layer.visible = false
book._suppress_until = 0
book._dragged = false
book.scroll.scroll_vertical = 0
# Movement beyond 12dp makes it a scroll, not a tap.
_card_mouse(book, guest, Vector2(100, 300), true)
var motion := InputEventMouseMotion.new()
motion.global_position = Vector2(170, 300)
book._on_card_input(motion, guest, false)
_card_mouse(book, guest, Vector2(170, 300), false)
_check(not book.detail_layer.visible, "a >12dp drag should not open detail")
book._suppress_until = 0
book._dragged = false
book.scroll.scroll_vertical = 0
# A press whose scroll offset changes is a scroll, not a tap.
_card_mouse(book, guest, Vector2(100, 300), true)
book.scroll.scroll_vertical = 60
if absi(book.scroll.scroll_vertical - book._press_scroll) <= 1:
# The headless layout may clamp scrolling; emulate the changed offset.
book._press_scroll = book.scroll.scroll_vertical - 60
_card_mouse(book, guest, Vector2(100, 300), false)
_check(not book.detail_layer.visible, "a scrolled press should not open detail")
book.scroll.scroll_vertical = 0
book._press_scroll = 0
book._suppress_until = 0
book._dragged = false
# A tap right after a fling is suppressed.
book._suppress_until = Time.get_ticks_msec() + 1000
_card_mouse(book, guest, Vector2(100, 300), true)
_card_mouse(book, guest, Vector2(100, 300), false)
_check(not book.detail_layer.visible, "post-drag suppression should block a tap")
book._suppress_until = 0
book._dragged = false
# The opening tap must not immediately close the sheet.
_card_mouse(book, guest, Vector2(100, 300), true)
_card_mouse(book, guest, Vector2(100, 300), false)
_check(book.detail_layer.visible, "a clean tap should open detail")
book._try_close_detail()
_check(book.detail_layer.visible, "close should be guarded right after opening")
book._detail_opened_at -= 300
book._try_close_detail()
_check(not book.detail_layer.visible, "close should work after the guard")
# A later release on the scrim closes the sheet.
_card_mouse(book, guest, Vector2(100, 300), true)
_card_mouse(book, guest, Vector2(100, 300), false)
_check(book.detail_layer.visible, "a clean tap should reopen detail")
book._detail_opened_at -= 300
var up := InputEventMouseButton.new()
up.button_index = MOUSE_BUTTON_LEFT
up.pressed = false
up.global_position = Vector2(20, 20)
book.detail_layer.emit_signal("gui_input", up)
_check(not book.detail_layer.visible, "a later scrim release should close detail")
func _card_mouse(book, guest: Dictionary, pos: Vector2, pressed: bool) -> void:
var event := InputEventMouseButton.new()
event.button_index = MOUSE_BUTTON_LEFT
event.pressed = pressed
event.global_position = pos
book._on_card_input(event, guest, false)