RecreationBench / android /dozingcat-vector-pinball /tests /test_android_navigation.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 2)
d292518 verified
Raw History Blame Contribute Delete
25.8 kB
#!/usr/bin/env python3
"""NAVIGATION lane — surface REACHABILITY + back-stack integrity for Vector Pinball.
This lane is the SOLE owner of jump_kind="reach" and of the depth>=2 chains. Every
jump is proven with and_reach(before, after, target, source): the TARGET surface's
discriminating element APPEARED *and* the SOURCE surface's element DISAPPEARED — a
screen that was in the dump all along was never reached. Back navigation is proven
the same way (the surface you left is gone, the one you returned to is back), and the
deep chains unwind hop-by-hop with and_back().
The playfield + score are canvas/GL views that never reach the view tree, so the five
VLM records assert canvas-only ARRIVAL end-states (gameplay field shown, paused overlay
atop field, the two AlertDialogs, a different table after next). Everything else is
tree-observable and stays a rule assertion.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
RESULTS = RESULTS_DIR
# ══════════════════════════════════════════════════════════════════════════════
# Depth-family helpers (the and_reach_* / and_enter_* NAME is what the depth audit
# looks for; each returns the (before, after) surface snapshots it observed so the
# caller can build its own reach verdict, or already carries a proven reach).
# ══════════════════════════════════════════════════════════════════════════════
def and_reach_menu():
"""Fresh launch -> main menu (game NOT in progress). depth 0 entry point."""
restart_app()
wait_for_foreground(10)
return ui()
def and_reach_preferences():
"""Main menu -> Preferences activity. Returns (before, after) snapshots."""
before_nodes = and_reach_menu()
before = and_showing(before_nodes)
tap_node(node_by_id(before_nodes, "preferencesButton"))
settle("tap")
after_nodes = ui()
and_enter("Preferences")
return before, and_showing(after_nodes), after_nodes
def and_reach_about():
"""Main menu -> About activity. Returns (before, after) snapshots."""
before_nodes = and_reach_menu()
before = and_showing(before_nodes)
tap_node(node_by_id(before_nodes, "aboutButton"))
settle("tap")
after_nodes = ui()
and_enter("About")
return before, and_showing(after_nodes)
def and_reach_highscores():
"""Main menu -> High Scores panel (panel swap, same activity)."""
before_nodes = and_reach_menu()
before = and_showing(before_nodes)
tap_node(node_by_id(before_nodes, "highScoreButton"))
settle("tap")
after_nodes = ui()
and_enter("HighScores")
return before, and_showing(after_nodes), after_nodes
def and_reach_gameplay():
"""Main menu -> gameplay (buttonPanel gone, pauseIcon shown). depth 1."""
before_nodes = and_reach_menu()
before = and_showing(before_nodes)
tap_node(node_by_id(before_nodes, "startGameButton"))
settle("tap")
settle("tap")
after_nodes = ui()
ok = and_reach(before, and_showing(after_nodes), "pauseIcon", "buttonPanel")
if ok:
and_enter("Gameplay")
return ok, after_nodes
def and_reach_paused_via_icon():
"""menu -> gameplay -> paused (tap pauseIcon). depth 2. Returns (ok, nodes)."""
ok, game_nodes = and_reach_gameplay()
if not ok:
return False, game_nodes
before = and_showing(game_nodes)
tap_node(node_by_id(game_nodes, "pauseIcon"))
settle("tap")
paused_nodes = ui()
reached = and_reach(before, and_showing(paused_nodes), "RESUME GAME", "pauseIcon")
if reached:
and_enter("Paused")
return reached, paused_nodes
def and_reach_gamespeed_dialog():
"""menu -> prefs -> Game speed dialog. depth 2. Returns (ok, before, after)."""
_b, _prefs, prefs_nodes = and_reach_preferences()
row = find_node(prefs_nodes, text="Game speed")
if row is None:
return False, set(), set()
before = and_showing(prefs_nodes)
tap_node(row)
settle("tap")
after = and_showing()
ok = and_reach(before, after, "Fast", "Sound")
if ok:
and_enter("GameSpeedDialog")
return ok, before, after
def and_reach_linewidth_dialog():
"""menu -> prefs -> Line width dialog. depth 2. Returns (ok, before, after)."""
_b, _prefs, prefs_nodes = and_reach_preferences()
row = find_node(prefs_nodes, text="Line width") or scroll_into_view("Line width")
prefs_nodes = ui()
row = find_node(prefs_nodes, text="Line width")
if row is None:
return False, set(), set()
before = and_showing(prefs_nodes)
tap_node(row)
settle("tap")
after = and_showing()
ok = and_reach(before, after, "OK", "Sound")
if ok:
and_enter("LineWidthDialog")
return ok, before, after
# ══════════════════════════════════════════════════════════════════════════════
# (A) Top-level destinations — one hop each (depth 1, reach)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_preferences",))
def test_reach_preferences():
if not device_online():
record("nav_reach_preferences", False,
"setup_failed: device offline", depth=1, jump_kind="reach",
expect="Preferences activity shown")
return
before, after, _n = and_reach_preferences()
ok = and_reach(before, after, "Sound", "START GAME")
record("nav_reach_preferences", ok,
"" if ok else "feature_missing: Preferences did not open (Sound row absent or menu still shown)",
depth=1, jump_kind="reach",
expect="Preferences: Sound row appeared; main-menu START GAME gone")
@and_test(expects=("nav_reach_about",))
def test_reach_about():
before, after = and_reach_about()
# aboutTextView's node_key is its long text; match a stable substring inside it.
ok = and_reach(before, after, "Brian Nenninger", "START GAME")
record("nav_reach_about", ok,
"" if ok else "feature_missing: About did not open (about text absent or menu still shown)",
depth=1, jump_kind="reach",
expect="About: aboutTextView (with 'Brian Nenninger') appeared; START GAME gone")
@and_test(expects=("nav_reach_highscores",))
def test_reach_highscores():
before, after, _n = and_reach_highscores()
ok = and_reach(before, after, "OK", "START GAME")
record("nav_reach_highscores", ok,
"" if ok else "feature_missing: High Scores panel did not open (OK button absent or menu still shown)",
depth=1, jump_kind="reach",
expect="High Scores: hideHighScoreButton (OK) appeared; START GAME gone")
@and_test(expects=("nav_reach_gameplay", "nav_reach_gameplay_vlm"))
def test_reach_gameplay():
ok, _n = and_reach_gameplay()
record("nav_reach_gameplay", ok,
"" if ok else "behavior_wrong: Start Game did not enter gameplay (pauseIcon absent or buttonPanel still present)",
depth=1, jump_kind="reach",
expect="Gameplay: pauseIcon appeared; menu buttonPanel gone")
vlm_assert("nav_reach_gameplay",
"Is the pinball playfield (a large vector line drawing with colored "
"circular bumpers) now fully visible with NO grey menu panel of buttons "
"overlaying its center?",
RESULTS, depth=1, jump_kind="reach", tag="layout")
# ══════════════════════════════════════════════════════════════════════════════
# (B) Back navigation from each destination (reach back, depth 1)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_highscores_ok_back",))
def test_highscores_ok_returns_to_menu():
_b, _panel, panel_nodes = and_reach_highscores()
ok_btn = node_by_id(panel_nodes, "hideHighScoreButton")
if ok_btn is None:
record("nav_highscores_ok_back", False,
"setup_failed: High Scores panel/OK button not reached", depth=1,
jump_kind="reach", expect="menu restored after tapping OK")
return
before = and_showing(panel_nodes)
tap_node(ok_btn)
settle("tap")
after = and_showing()
ok = and_reach(before, after, "START GAME", "OK")
record("nav_highscores_ok_back", ok,
"" if ok else "behavior_wrong: OK did not return to the main menu (START GAME absent or OK still shown)",
depth=1, jump_kind="reach",
expect="menu START GAME back; panel OK button gone")
@and_test(expects=("nav_highscores_key_back",))
def test_highscores_back_key_closes_panel():
_b, _panel, panel_nodes = and_reach_highscores()
if node_by_id(panel_nodes, "hideHighScoreButton") is None:
record("nav_highscores_key_back", False,
"setup_failed: High Scores panel not reached", depth=1,
jump_kind="reach", expect="menu restored after BACK; app foreground")
return
before = and_showing(panel_nodes)
and_back() # BACK pops the panel
after = and_showing()
fg = is_app_foreground()
ok = fg and and_reach(before, after, "START GAME", "OK")
record("nav_highscores_key_back", ok,
"" if ok else "behavior_wrong: BACK did not close High Scores back to menu (or app left foreground)",
depth=1, jump_kind="reach",
expect="menu START GAME back; panel OK gone; app still foreground")
@and_test(expects=("nav_preferences_back",))
def test_preferences_back_to_menu():
_b, prefs, _n = and_reach_preferences()
if not any("Sound" in k for k in prefs):
record("nav_preferences_back", False,
"setup_failed: Preferences not reached", depth=1, jump_kind="reach",
expect="menu restored after BACK from Preferences")
return
and_back() # BACK leaves the Preferences activity
after = and_showing()
fg = is_app_foreground()
ok = fg and and_reach(prefs, after, "START GAME", "Sound")
record("nav_preferences_back", ok,
"" if ok else "behavior_wrong: BACK from Preferences did not restore the main menu",
depth=1, jump_kind="reach",
expect="menu START GAME back; Preferences Sound row gone; app foreground")
@and_test(expects=("nav_about_back",))
def test_about_back_to_menu():
before, about = and_reach_about()
if not any("Brian Nenninger" in k for k in about):
record("nav_about_back", False,
"setup_failed: About not reached", depth=1, jump_kind="reach",
expect="menu restored after BACK from About")
return
and_back() # BACK leaves the About activity
after = and_showing()
fg = is_app_foreground()
ok = fg and and_reach(about, after, "START GAME", "Brian Nenninger")
record("nav_about_back", ok,
"" if ok else "behavior_wrong: BACK from About did not restore the main menu",
depth=1, jump_kind="reach",
expect="menu START GAME back; about text gone; app foreground")
# ══════════════════════════════════════════════════════════════════════════════
# (C) State-machine transitions treated as reach — depth 2 (gameplay is depth 1;
# the paused menu / resume / end are one hop deeper)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_pause_via_icon",))
def test_pause_via_icon():
ok, _n = and_reach_paused_via_icon()
record("nav_pause_via_icon", ok,
"" if ok else "behavior_wrong: tapping pauseIcon did not open the paused menu (RESUME GAME absent or pauseIcon still shown)",
depth=2, jump_kind="reach",
expect="Paused: RESUME GAME appeared; pauseIcon gone")
@and_test(expects=("nav_pause_via_score", "nav_pause_via_score_vlm"))
def test_pause_via_score_area():
ok_game, game_nodes = and_reach_gameplay()
if not ok_game:
record("nav_pause_via_score", False,
"setup_failed: gameplay not reached", depth=2, jump_kind="reach",
expect="Paused menu via score-area tap")
vlm_assert("nav_pause_via_score",
"Is a vertical menu of grey buttons (with RESUME GAME at the top) "
"shown overlaying the pinball playfield?",
RESULTS, depth=2, jump_kind="reach", tag="layout")
return
score = node_by_id(game_nodes, "scoreView")
before = and_showing(game_nodes)
tap_node(score)
settle("tap")
after = and_showing()
ok = and_reach(before, after, "RESUME GAME", "pauseIcon")
if ok:
and_enter("Paused")
record("nav_pause_via_score", ok,
"" if ok else "behavior_wrong: tapping the score area did not open the paused menu",
depth=2, jump_kind="reach",
expect="Paused: RESUME GAME appeared; pauseIcon gone")
vlm_assert("nav_pause_via_score",
"Is a vertical menu of grey buttons (with RESUME GAME at the top) "
"shown overlaying the pinball playfield?",
RESULTS, depth=2, jump_kind="reach", tag="layout")
@and_test(expects=("nav_resume_to_game",))
def test_resume_returns_to_game():
ok_p, paused_nodes = and_reach_paused_via_icon()
resume = node_by_id(paused_nodes, "resumeGameButton") if ok_p else None
if resume is None:
record("nav_resume_to_game", False,
"setup_failed: paused menu / resume button not reached", depth=2,
jump_kind="reach", expect="gameplay restored after Resume")
return
before = and_showing(paused_nodes)
tap_node(resume)
settle("tap")
after = and_showing()
ok = and_reach(before, after, "pauseIcon", "RESUME GAME")
record("nav_resume_to_game", ok,
"" if ok else "behavior_wrong: Resume did not return to gameplay (pauseIcon absent or RESUME GAME still shown)",
depth=2, jump_kind="reach",
expect="gameplay pauseIcon back; paused RESUME GAME gone")
@and_test(expects=("nav_endgame_to_menu",))
def test_endgame_returns_to_fresh_menu():
ok_p, paused_nodes = and_reach_paused_via_icon()
end = node_by_id(paused_nodes, "endGameButton") if ok_p else None
if end is None:
record("nav_endgame_to_menu", False,
"setup_failed: paused menu / End Game button not reached", depth=2,
jump_kind="reach", expect="fresh main menu after End Game")
return
before = and_showing(paused_nodes)
tap_node(end)
settle("tap")
settle("tap")
after_nodes = ui()
after = and_showing(after_nodes)
# Fresh menu is discriminated from the paused menu by START GAME + selectTableRow
# reappearing while RESUME GAME leaves.
ok = (and_reach(before, after, "START GAME", "RESUME GAME")
and node_by_id(after_nodes, "selectTableRow") is not None)
record("nav_endgame_to_menu", ok,
"" if ok else "behavior_wrong: End Game did not restore the fresh main menu (START GAME/selectTableRow absent or RESUME GAME still shown)",
depth=2, jump_kind="reach",
expect="fresh menu START GAME + selectTableRow back; paused RESUME GAME gone")
@and_test(expects=("nav_back_during_game",))
def test_back_during_game_pauses():
ok_game, game_nodes = and_reach_gameplay()
if not ok_game:
record("nav_back_during_game", False,
"setup_failed: gameplay not reached", depth=2, jump_kind="reach",
expect="paused menu after BACK during gameplay; app foreground")
return
before = and_showing(game_nodes)
and_back() # custom back: pauses instead of exiting
after = and_showing()
fg = is_app_foreground()
ok = fg and and_reach(before, after, "RESUME GAME", "pauseIcon")
record("nav_back_during_game", ok,
"" if ok else "behavior_wrong: BACK during gameplay did not pause (RESUME GAME absent, pauseIcon still shown, or app exited)",
depth=2, jump_kind="reach",
expect="paused RESUME GAME appeared; pauseIcon gone; app still foreground")
# ══════════════════════════════════════════════════════════════════════════════
# (D) DEEP CHAINS — menu -> prefs -> dialog (depth 2 reach) + hop-by-hop back-stack
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_gamespeed_dialog", "nav_gamespeed_dialog_vlm"))
def test_gamespeed_dialog_opens():
ok, _before, _after = and_reach_gamespeed_dialog()
record("nav_gamespeed_dialog", ok,
"" if ok else "feature_missing: Game speed dialog did not open (Fast option absent or prefs list still shown)",
depth=2, jump_kind="reach",
expect="Game speed dialog: 'Fast' option appeared; prefs Sound row covered")
vlm_assert("nav_gamespeed_dialog",
"Is a dialog titled 'Game speed' shown with three radio-button rows "
"labelled Slow, Normal and Fast stacked vertically?",
RESULTS, depth=2, jump_kind="reach", tag="shape")
@and_test(expects=("nav_linewidth_dialog", "nav_linewidth_dialog_vlm"))
def test_linewidth_dialog_opens():
ok, _before, _after = and_reach_linewidth_dialog()
record("nav_linewidth_dialog", ok,
"" if ok else "feature_missing: Line width dialog did not open (OK/EditText absent or prefs list still shown)",
depth=2, jump_kind="reach",
expect="Line width dialog: OK button + EditText appeared; prefs Sound row covered")
vlm_assert("nav_linewidth_dialog",
"Is a dialog titled 'Line width' shown with a single-line text input "
"field above a CANCEL and an OK button at the bottom-right?",
RESULTS, depth=2, jump_kind="reach", tag="position")
@and_test(expects=("nav_backstack_prefs_dialog_unwind",))
def test_backstack_prefs_dialog_unwinds():
"""DEEP 2-hop back-stack: menu -> prefs -> Game speed dialog, then BACK unwinds
it hop by hop: BACK #1 -> prefs list restored; BACK #2 -> main menu restored."""
ok, _before, dialog = and_reach_gamespeed_dialog()
if not ok:
record("nav_backstack_prefs_dialog_unwind", False,
"setup_failed: could not reach the Game speed dialog to unwind",
depth=2, jump_kind="reach",
expect="dialog -> prefs -> menu unwound by two BACK presses")
return
# hop 1 back: dialog -> prefs list (Sound row returns, Fast option gone)
and_back()
prefs_again = and_showing()
hop1 = and_reach(dialog, prefs_again, "Sound", "Fast")
# hop 2 back: prefs -> main menu (START GAME returns, Sound row gone)
and_back()
menu_again = and_showing()
fg = is_app_foreground()
hop2 = and_reach(prefs_again, menu_again, "START GAME", "Sound")
ok_all = hop1 and hop2 and fg
record("nav_backstack_prefs_dialog_unwind", ok_all,
"" if ok_all else "behavior_wrong: BACK did not unwind dialog->prefs->menu one hop at a time",
depth=2, jump_kind="reach",
expect="BACK#1 restores prefs (Sound back, Fast gone); BACK#2 restores menu (START GAME back)")
@and_test(expects=("nav_backstack_game_pause_resume",))
def test_backstack_game_pause_resume():
"""DEEP chain: menu -> gameplay -> paused (BACK) -> gameplay (Resume). Proves the
in-game BACK pauses (one hop deeper) and Resume unwinds it back to the field."""
ok_game, game_nodes = and_reach_gameplay()
if not ok_game:
record("nav_backstack_game_pause_resume", False,
"setup_failed: gameplay not reached", depth=2, jump_kind="reach",
expect="game -> paused -> game round trip")
return
before_game = and_showing(game_nodes)
and_back() # gameplay -> paused
paused = and_showing()
into_paused = and_reach(before_game, paused, "RESUME GAME", "pauseIcon")
resume = node_by_id(ui(), "resumeGameButton")
if resume is None:
record("nav_backstack_game_pause_resume", False,
"behavior_wrong: BACK during gameplay did not surface RESUME GAME",
depth=2, jump_kind="reach",
expect="game -> paused -> game round trip")
return
before_resume = and_showing()
tap_node(resume) # paused -> gameplay
settle("tap")
back_in_game = and_showing()
into_game = and_reach(before_resume, back_in_game, "pauseIcon", "RESUME GAME")
ok = into_paused and into_game
record("nav_backstack_game_pause_resume", ok,
"" if ok else "behavior_wrong: game->paused->game round trip did not unwind correctly",
depth=2, jump_kind="reach",
expect="BACK yields paused (RESUME GAME); Resume returns the field (pauseIcon)")
# ══════════════════════════════════════════════════════════════════════════════
# (E) Table selector host — pick a different table, then reach gameplay on it
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_table_next_then_play", "nav_table_next_then_play_vlm"))
def test_table_next_then_play():
"""The table picker changes only the canvas (tree unchanged), so the reach is
proven by entering gameplay on the newly-selected table; the VLM confirms the
arrived field is a pinball table layout drawn behind no menu."""
menu_nodes = and_reach_menu()
nxt = node_by_id(menu_nodes, "nextTableButton")
if nxt is None:
record("nav_table_next_then_play", False,
"feature_missing: nextTableButton not present on the menu", depth=1,
jump_kind="reach", expect="gameplay reached after selecting next table")
vlm_assert("nav_table_next_then_play",
"In the large central play area (below the thin top status strip), "
"is a pinball table drawn as a vector outline containing "
"several solid colored circular bumpers (yellow, red, blue, "
"green, magenta) and NOT a grey panel of labelled menu buttons?",
RESULTS, depth=1, jump_kind="reach", tag="content")
return
tap_node(nxt) # advance the table picker (still on the menu)
settle("tap")
menu2 = ui()
still_menu = node_by_id(menu2, "selectTableRow") is not None
before = and_showing(menu2)
tap_node(node_by_id(menu2, "startGameButton"))
settle("tap")
settle("tap")
after = and_showing()
ok = still_menu and and_reach(before, after, "pauseIcon", "buttonPanel")
if ok:
and_enter("Gameplay")
record("nav_table_next_then_play", ok,
"" if ok else "behavior_wrong: could not reach gameplay after selecting the next table",
depth=1, jump_kind="reach",
expect="picker stayed on menu; then Start Game reached gameplay (pauseIcon; buttonPanel gone)")
vlm_assert("nav_table_next_then_play",
"In the large central play area (below the thin top status strip), is a "
"pinball table drawn as a vector outline containing several "
"solid colored circular bumpers (yellow, red, blue, green, "
"magenta) and NOT a grey panel of labelled menu buttons?",
RESULTS, depth=1, jump_kind="reach", tag="content")
TESTS = [
test_reach_preferences,
test_reach_about,
test_reach_highscores,
test_reach_gameplay,
test_highscores_ok_returns_to_menu,
test_highscores_back_key_closes_panel,
test_preferences_back_to_menu,
test_about_back_to_menu,
test_pause_via_icon,
test_pause_via_score_area,
test_resume_returns_to_game,
test_endgame_returns_to_fresh_menu,
test_back_during_game_pauses,
test_gamespeed_dialog_opens,
test_linewidth_dialog_opens,
test_backstack_prefs_dialog_unwinds,
test_backstack_game_pause_resume,
test_table_next_then_play,
]
if __name__ == "__main__":
run_suite(TESTS, "navigation")