RecreationBench / android /markusfisch-shadereditor /tests /test_android_structure.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 3)
c1c6a0c verified
Raw History Blame Contribute Delete
22.9 kB
#!/usr/bin/env python3
"""STRUCTURE tests for "Shader Editor" (GLSL fragment-shader editor).
LANE: the GATE (app launches + top-level surfaces exist) and tree-SHAPE deltas
(an interaction changes the SHAPE of the view tree: a container appears/disappears,
node counts jump, a row list grows). SHAPE ONLY — never content strings, never
checked/selected state, never reachability of a named screen (those are other
lanes). A dead shell that clones the layout but does nothing must FAIL the
interactive shape tests.
Every delta below was OBSERVED on the running original before being asserted.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
RESULTS_DIR = sys.argv[2] if len(sys.argv) > 2 else "/workspace/testgen/eval"
# ── Portable launch helper (recon: LeakCanary registers a 2nd LAUNCHER; the kit's
# launch_app lands on the leak list, so resolve the app's OWN non-leakcanary
# LAUNCHER activity at runtime and verify the editor toolbar appeared). Uses
# only PACKAGE — portable to the recreation (no LeakCanary => filter no-ops). ──
def launch_editor():
"""Land on MainActivity (not LeakCanary), verified + retried."""
out = adb_shell("cmd", "package", "query-activities", "--brief",
"-a", "android.intent.action.MAIN",
"-c", "android.intent.category.LAUNCHER", PACKAGE)
comp = next((l.strip() for l in out.splitlines()
if l.strip().startswith(PACKAGE + "/")
and "leakcanary" not in l.lower()), "")
for _ in range(4):
force_stop()
if comp:
adb_shell("am", "start", "-n", comp)
else:
launch_app() # recreation w/ no explicit launcher listing
settle("launch")
wait_for_foreground()
if node_by_id(ui(), "menu_btn") or node_by_id(ui(), "editor"):
return True
back()
settle("tap")
return False
def _bracket_btns(nodes):
"""The six extra-keys bracket buttons: Buttons whose text is a bracket char."""
return [n for n in find_by_class(nodes, "Button")
if n.get("text") in ("{", "}", "(", ")", "[", "]")]
def _open_menu():
"""Open the custom overflow popup. Returns (before_showing, after_nodes, ok)."""
n = ui()
before = and_showing(n)
mb = node_by_id(n, "menu_btn")
if not mb or not tap_node(mb):
return before, ui(), False
settle("tap")
return before, ui(), True
def and_enter_menu_item(rid):
"""Open overflow menu, tap a menu item, cross into its activity. Backs depth.
Returns (nodes_after, ok). Named and_enter_* so the depth audit sees a real
surface crossing.
"""
_before, menu_nodes, opened = _open_menu()
if not opened:
return ui(), False
item = node_by_id(menu_nodes, rid)
if not item or not is_safe(item) or not tap_node(item):
return ui(), False
settle("launch")
and_enter(rid)
return ui(), True
def and_enter_drawer():
"""Open the navigation drawer via the hamburger. Backs depth. Returns (nodes, ok)."""
n = ui()
ham = find_node(n, content_desc="Open drawer")
if not ham or not tap_node(ham):
return ui(), False
settle("tap")
settle("tap") # recon: drawer animation must finish before rows appear
and_enter("drawer")
return ui(), True
# ══════════════════════════════════════════════════════════════════════════════
# GATE — the app launches and its top-level surfaces exist (jump_kind="none").
# This is the ONE place existence is OK. Non-VLM gate tests kept to 3/12 = 25%.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("structure_gate_launch", "structure_gate_launch_vlm"))
def test_gate_launch():
"""Editor comes to the foreground: menu_btn + editor + toolbar present."""
if not device_online():
record("structure_gate_launch", False,
"setup_failed: device offline (adb tunnel down)",
depth=0, jump_kind="none")
return
clear_data()
launched = launch_editor()
nodes = ui()
menu = node_by_id(nodes, "menu_btn")
editor = node_by_id(nodes, "editor")
toolbar = node_by_id(nodes, "toolbar")
ok = bool(launched and menu and editor and toolbar)
record("structure_gate_launch", ok,
"" if ok else "setup_failed: editor surface (menu_btn+editor+toolbar) "
"not present after launch",
depth=0, jump_kind="none")
# SPATIAL/POSITION the tree can't express: the toolbar is a thin strip pinned
# to the very top, with the editor body directly beneath it (01_main.png).
vlm_assert("structure_gate_launch",
"Is there a thin horizontal toolbar strip at the very top of the "
"screen, with a large code/text editor area occupying everything "
"directly below it?",
RESULTS_DIR, tag="position")
@and_test(expects=("structure_gate_toolbar_host",))
def test_gate_toolbar_host():
"""The toolbar host carries its expected controls (hamburger, quality, eye, overflow)."""
clear_data()
launch_editor()
nodes = ui()
ham = find_node(nodes, content_desc="Open drawer")
quality = node_by_id(nodes, "quality")
toggle = node_by_id(nodes, "toggle_code")
menu = node_by_id(nodes, "menu_btn")
ok = bool(ham and quality and toggle and menu)
record("structure_gate_toolbar_host", ok,
"" if ok else "setup_failed: toolbar host missing one of "
"hamburger/quality/toggle_code/menu_btn",
depth=0, jump_kind="none")
@and_test(expects=("structure_gate_body_container",))
def test_gate_body_container():
"""The body scaffold exists: drawer_layout wrapping the editor_container + preview."""
clear_data()
launch_editor()
nodes = ui()
drawer = node_by_id(nodes, "drawer_layout")
container = node_by_id(nodes, "editor_container")
preview = node_by_id(nodes, "preview")
ok = bool(drawer and container and preview)
record("structure_gate_body_container", ok,
"" if ok else "setup_failed: body scaffold missing one of "
"drawer_layout/editor_container/preview",
depth=0, jump_kind="none")
# ══════════════════════════════════════════════════════════════════════════════
# TREE-SHAPE DELTAS — an interaction changes the SHAPE of the tree, reversed to
# assert restore where in-place. surface_changed() is the honest primitive.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("structure_overflow_menu_grows", "structure_overflow_menu_vlm"))
def test_overflow_menu_grows():
"""Tap menu_btn -> custom popup adds many Buttons (3 -> 12 observed)."""
clear_data()
launch_editor()
n = ui()
before_btns = len(find_by_class(n, "Button"))
before = and_showing(n)
mb = node_by_id(n, "menu_btn")
tapped = tap_node(mb)
settle("tap")
n2 = ui()
after_btns = len(find_by_class(n2, "Button"))
after = and_showing(n2)
# The popup adds undo/redo + New/Save/Save-as/Delete/Share/Update/Add-uniform/
# Load-sample/Settings/FAQ Buttons: observed jump 3 -> 12 (delta +9).
grew = after_btns >= before_btns + 6
ok = bool(tapped and grew and surface_changed(before, after))
msg = ""
if not tapped:
msg = "setup_failed: menu_btn not tappable"
elif not grew:
msg = (f"behavior_wrong: Button count did not grow enough on menu open "
f"({before_btns} -> {after_btns})")
elif not surface_changed(before, after):
msg = "behavior_wrong: surface did not change on menu open"
record("structure_overflow_menu_grows", ok, msg,
depth=1, jump_kind="transition",
expect="Button count 3->12 (>=+6) when overflow popup opens")
and_enter("overflow_menu")
# POSITION: the popup anchors to the top-right and stacks downward, NOT a
# centered/full-width sheet (11_menu.png). Precise placement the tree omits.
vlm_assert("structure_overflow_menu",
"Is there a popup menu anchored to the upper-right corner of the "
"screen whose options are stacked vertically (not a centered or "
"full-width dialog)?",
RESULTS_DIR, tag="position")
@and_test(expects=("structure_extra_keys_row", "structure_extra_keys_row_vlm"))
def test_extra_keys_row_appears():
"""Focus editor -> extra-keys row appears: 6 bracket btns + insert_tab + completions (0->8)."""
clear_data()
launch_editor()
n = ui()
before_extra = (len(_bracket_btns(n))
+ (1 if node_by_id(n, "insert_tab") else 0)
+ (1 if node_by_id(n, "completions") else 0))
ed = node_by_id(n, "editor")
tapped = tap_node(ed)
settle("tap")
n2 = ui()
after_brk = len(_bracket_btns(n2))
after_tab = 1 if node_by_id(n2, "insert_tab") else 0
after_comp = 1 if node_by_id(n2, "completions") else 0
after_extra = after_brk + after_tab + after_comp
# Observed: before 0 -> after 8 (6 brackets + insert_tab + completions).
ok = bool(tapped and before_extra == 0 and after_brk == 6
and after_tab == 1 and after_comp == 1)
msg = ""
if not tapped:
msg = "setup_failed: editor not tappable"
elif not (after_brk == 6 and after_tab == 1 and after_comp == 1):
msg = (f"behavior_wrong: extra-keys row did not materialize "
f"(brackets={after_brk}/6 insert_tab={after_tab} completions={after_comp})")
record("structure_extra_keys_row", ok, msg,
depth=0, jump_kind="transition",
expect="extra-keys nodes 0->8 (6 brackets + insert_tab + completions) on editor focus")
# POSITION: a single horizontal strip of bracket/symbol buttons wedged
# directly above the on-screen keyboard (16_extrakeys.png).
vlm_assert("structure_extra_keys_row",
"Is there a single horizontal row of small bracket/symbol buttons "
"(like { } ( ) [ ]) positioned directly above the on-screen "
"keyboard, spanning the full width?",
RESULTS_DIR, tag="position")
@and_test(expects=("structure_toggle_code_hides_editor", "structure_toggle_code_vlm"))
def test_toggle_code_hides_editor():
"""Tap eye -> editor_container leaves the tree; tap again -> it returns."""
clear_data()
launch_editor()
n = ui()
before_ec = node_by_id(n, "editor_container") is not None
before = and_showing(n)
tc = node_by_id(n, "toggle_code")
tapped = tap_node(tc)
settle("tap")
n2 = ui()
after_ec = node_by_id(n2, "editor_container") is not None
after = and_showing(n2)
# Reverse: tap eye again -> editor_container restored.
tc2 = node_by_id(ui(), "toggle_code")
reversed_ok = tap_node(tc2)
settle("tap")
n3 = ui()
restored_ec = node_by_id(n3, "editor_container") is not None
ok = bool(tapped and reversed_ok and before_ec and not after_ec
and restored_ec and surface_changed(before, after))
msg = ""
if not tapped:
msg = "setup_failed: toggle_code not tappable"
elif not (before_ec and not after_ec):
msg = "behavior_wrong: editor_container did not disappear on toggle_code"
elif not restored_ec:
msg = "behavior_wrong: editor_container did not restore on second toggle_code"
record("structure_toggle_code_hides_editor", ok, msg,
depth=0, jump_kind="transition",
expect="editor_container present->absent on eye, restored on second eye")
# After the reversal the editor is back; toggle once more so the VLM sees the
# full-screen gradient. COLOR: the GL surface is opaque to the tree, so its
# exact rendered colors can ONLY be checked visually (23_togglecode.png).
tc3 = node_by_id(ui(), "toggle_code")
tap_node(tc3)
settle("tap")
vlm_assert("structure_toggle_code",
"In the area below the top toolbar, is the screen filled by a smooth "
"vertical colour gradient whose TOP is noticeably brighter and more "
"vividly GREEN than the darker BOTTOM, with NO lines of source code "
"or text visible?",
RESULTS_DIR, tag="color")
@and_test(expects=("structure_quality_dropdown_grows",))
def test_quality_dropdown_grows():
"""Tap quality spinner -> dropdown adds 7 CheckedTextView (0 -> 7)."""
clear_data()
launch_editor()
n = ui()
before_ctv = len(find_by_class(n, "CheckedTextView"))
before = and_showing(n)
q = node_by_id(n, "quality")
tapped = tap_node(q)
settle("tap")
n2 = ui()
after_ctv = len(find_by_class(n2, "CheckedTextView"))
after = and_showing(n2)
# Observed: 0 -> 7 (1/32, 1/16, 1/8, 1/4, 1/2, 1/1, 2/1).
ok = bool(tapped and before_ctv == 0 and after_ctv == 7
and surface_changed(before, after))
msg = ""
if not tapped:
msg = "setup_failed: quality spinner not tappable"
elif not (before_ctv == 0 and after_ctv == 7):
msg = (f"behavior_wrong: quality dropdown did not add 7 rows "
f"({before_ctv} -> {after_ctv})")
# In-place popup (spinner dropdown over the same surface, no navigation) =>
# depth 0, like the extra-keys / toggle-code in-place shape deltas.
record("structure_quality_dropdown_grows", ok, msg,
depth=0, jump_kind="transition",
expect="CheckedTextView 0->7 when quality spinner dropdown opens")
@and_test(expects=("structure_drawer_shows_shaders", "structure_drawer_shows_shaders_vlm"))
def test_drawer_shows_shaders():
"""Open drawer -> shaders ListView + shader_title row enter the tree (0 -> present)."""
clear_data()
launch_editor()
n = ui()
before_shaders = node_by_id(n, "shaders") is not None
before = and_showing(n)
nodes, ok_nav = and_enter_drawer()
after_shaders = node_by_id(nodes, "shaders") is not None
has_title = node_by_id(nodes, "shader_title") is not None
after = and_showing(nodes)
ok = bool(ok_nav and not before_shaders and after_shaders and has_title
and surface_changed(before, after))
msg = ""
if not ok_nav:
msg = "setup_failed: could not open drawer"
elif not (after_shaders and has_title):
msg = ("behavior_wrong: shaders list / shader_title row did not appear "
"when drawer opened")
record("structure_drawer_shows_shaders", ok, msg,
depth=1, jump_kind="transition",
expect="shaders ListView + shader_title row appear (absent->present) on drawer open")
# POSITION: the drawer slides in from the LEFT edge as a partial-width panel,
# not a full-screen replacement (12_drawer.png). Don't close with back()
# (exits app) — next test relaunches.
vlm_assert("structure_drawer_shows_shaders",
"Is a navigation drawer panel overlaying the LEFT side of the "
"screen (leaving the right edge of the previous screen visible), "
"with a shader list row and a small square icon?",
RESULTS_DIR, tag="position")
@and_test(expects=("structure_settings_recycler", "structure_settings_recycler_vlm"))
def test_settings_has_populated_recycler():
"""Menu -> Settings: recycler_view exists with >=5 preference-row TextViews."""
clear_data()
launch_editor()
before = and_showing()
nodes, ok_nav = and_enter_menu_item("settings")
rv = node_by_id(nodes, "recycler_view")
n_tv = len(find_by_class(nodes, "TextView"))
after = and_showing(nodes)
# Observed: recycler_view present, ~22 TextViews (many preference rows).
ok = bool(ok_nav and rv and n_tv >= 5 and surface_changed(before, after))
msg = ""
if not ok_nav:
msg = "setup_failed: could not reach Settings"
elif not rv:
msg = "feature_missing: recycler_view not present on Settings"
elif n_tv < 5:
msg = f"behavior_wrong: Settings recycler has too few rows ({n_tv} TextViews)"
record("structure_settings_recycler", ok, msg,
depth=1, jump_kind="transition",
expect="Settings shows recycler_view with >=5 preference-row TextViews")
# SHAPE: preference rows are single-column full-width entries stacked top to
# bottom, each a bold title over a smaller description (13_settings.png).
vlm_assert("structure_settings_recycler",
"Is this screen a single vertical column of full-width settings "
"rows stacked from top to bottom, each showing a bold title with a "
"smaller grey description line beneath it?",
RESULTS_DIR, tag="shape")
@and_test(expects=("structure_add_uniform_shape", "structure_add_uniform_shape_vlm"))
def test_add_uniform_shape():
"""Menu -> Add uniform/texture: 3 tabs + a uniforms ListView with many rows."""
clear_data()
launch_editor()
nodes, ok_nav = and_enter_menu_item("add_uniform")
tab_layout = node_by_id(nodes, "tab_layout")
uniforms = node_by_id(nodes, "uniforms")
tab_preset = find_node(nodes, text="preset")
tab_s2d = find_node(nodes, text="sampler2D")
tab_scube = find_node(nodes, text="samplerCube")
name_rows = [x for x in nodes if x.get("resource-id", "").endswith("/name")]
# Observed: tab_layout + uniforms present, 3 named tabs, 9 visible name rows.
ok = bool(ok_nav and tab_layout and uniforms
and tab_preset and tab_s2d and tab_scube
and len(name_rows) >= 5)
msg = ""
if not ok_nav:
msg = "setup_failed: could not reach Add uniform/texture"
elif not (tab_layout and uniforms):
msg = "feature_missing: tab_layout or uniforms list missing"
elif not (tab_preset and tab_s2d and tab_scube):
msg = "feature_missing: the 3 tabs (preset/sampler2D/samplerCube) not all present"
elif len(name_rows) < 5:
msg = f"behavior_wrong: uniforms list has too few rows ({len(name_rows)})"
record("structure_add_uniform_shape", ok, msg,
depth=1, jump_kind="transition",
expect="Add-uniform shows 3 tabs + uniforms list with >=5 name rows")
# POSITION: a single row of exactly three tabs sits just under the app-bar,
# with the scrollable list occupying the area below (14_uniform.png).
vlm_assert("structure_add_uniform_shape",
"Are there exactly three tabs in one horizontal row just below the "
"top app bar, with a scrollable list of items filling the area "
"below the tabs?",
RESULTS_DIR, tag="position")
@and_test(expects=("structure_load_sample_list",))
def test_load_sample_list():
"""Menu -> Load sample: samples ListView with many rows (>=8)."""
clear_data()
launch_editor()
nodes, ok_nav = and_enter_menu_item("load_sample")
samples = node_by_id(nodes, "samples")
name_rows = [x for x in nodes if x.get("resource-id", "").endswith("/name")]
# Observed: samples list present, 10 visible name rows (12 total samples).
ok = bool(ok_nav and samples and len(name_rows) >= 5)
msg = ""
if not ok_nav:
msg = "setup_failed: could not reach Load sample"
elif not samples:
msg = "feature_missing: samples list not present"
elif len(name_rows) < 5:
msg = f"behavior_wrong: samples list has too few rows ({len(name_rows)})"
record("structure_load_sample_list", ok, msg,
depth=1, jump_kind="transition",
expect="Load-sample shows samples list with >=5 visible name rows")
@and_test(expects=("structure_rename_dialog_shape",))
def test_rename_dialog_shape():
"""Drawer -> long-press shader row -> dialog layer adds alertTitle + name + 2 buttons."""
clear_data()
launch_editor()
nodes, ok_nav = and_enter_drawer()
if not ok_nav:
record("structure_rename_dialog_shape", False,
"setup_failed: could not open drawer for long-press",
depth=2, jump_kind="transition",
expect="Rename dialog adds alertTitle + name EditText + 2 buttons")
return
before = and_showing(nodes)
row = node_by_id(nodes, "shader_title")
if not row:
record("structure_rename_dialog_shape", False,
"setup_failed: shader_title row not present in drawer",
depth=2, jump_kind="transition",
expect="Rename dialog adds alertTitle + name EditText + 2 buttons")
return
long_press(row, ms=1200)
settle("tap")
and_enter("rename_dialog") # long-press opens the dialog layer -> depth 2
n2 = ui()
after = and_showing(n2)
alert = node_by_id(n2, "alertTitle")
name = node_by_id(n2, "name")
b1 = node_by_id(n2, "button1")
b2 = node_by_id(n2, "button2")
# Observed: a new window layer with alertTitle="Rename shader", name EditText,
# button1 (OK) + button2 (Cancel). SHAPE: the dialog layer appeared.
ok = bool(alert and name and b1 and b2 and surface_changed(before, after))
msg = ""
if not (alert and name):
msg = "behavior_wrong: rename dialog layer (alertTitle + name field) did not appear"
elif not (b1 and b2):
msg = "behavior_wrong: rename dialog missing its two buttons"
record("structure_rename_dialog_shape", ok, msg,
depth=2, jump_kind="transition",
expect="long-press adds a dialog layer: alertTitle + name EditText + button1 + button2")
# Dismiss the dialog via Cancel so we don't rename; then this test ends.
cancel = node_by_id(ui(), "button2")
if cancel and is_safe(cancel):
tap_node(cancel)
settle("tap")
TESTS = [
test_gate_launch,
test_gate_toolbar_host,
test_gate_body_container,
test_overflow_menu_grows,
test_extra_keys_row_appears,
test_toggle_code_hides_editor,
test_quality_dropdown_grows,
test_drawer_shows_shaders,
test_settings_has_populated_recycler,
test_add_uniform_shape,
test_load_sample_list,
test_rename_dialog_shape,
]
if __name__ == "__main__":
run_suite(TESTS, "structure")