VoyagerXHF's picture
Upload folder using huggingface_hub (part 3)
c1c6a0c verified
Raw History Blame Contribute Delete
48.3 kB
#!/usr/bin/env python3
"""TEXT eval for Shader Editor — CONTENT strings an ACTION PRODUCES.
This lane is the SOLE owner of exact-string equality: dynamic labels, status
text, hints, section headers, button labels and content-desc that an interaction
PRODUCES. Every test drives the app through the user path to the surface, then
reads the string back out of a FRESH ui() and asserts the exact/substring words
the running ORIGINAL rendered. The discriminating half is the CHANGE — the string
is ABSENT on the prior surface and PRESENT after the action, so a hardcoded label
sitting on a dead shell does not pass.
Ground truth (all verified on the running original, package
de.markusfisch.android.shadereditor.debug):
* fps subtitle is a TextView matching '^\\d+\\s*fps$' (e.g. "38 fps") while
rendering (absent on the Preferences activity).
* Quality spinner child TextView (id `text1`) reads exactly "1/1"; selecting
"1/8" from its dropdown makes the label read exactly "1/8".
* Fresh DB: toolbar title AND the single drawer row `shader_title` both read
exactly "Default".
* Long-press the drawer row -> "Rename shader" dialog (alertTitle "Rename
shader", name field prefilled "Default", buttons "Cancel"/"OK"); OK writes the
new name into BOTH the drawer row and the toolbar title.
* menu -> Load sample -> activity titled "Load sample" with rows
"Circles"/"Draw some circles", "Game of Life"/"Conway's Game of Life...",
and "Orientation"/"How to use the orienation uniform" (the app's own typo).
* menu -> Add uniform/texture -> activity titled "Add uniform/texture", tabs
"preset"/"sampler2D"/"samplerCube", preset rows formatted "name (type)"
("battery (float)" with rationale "Battery level from 0.0 to 1.0",
"date (vec4)", "frame (int)").
* The sampler2D tab of that activity is NOT empty on this build — it produces
texture rows sized "256 x 256" (absent on the preset tab). (So the recon's
"No textures available" empty-state does NOT hold and is not asserted.)
* menu -> Settings -> activity titled "Preferences" with summaries
"Auto run on change", "1.0s", "Small", "Monospace", "2 characters".
* The hamburger's content-desc is "Open drawer" and becomes "Close drawer"
once the drawer is open.
* Focusing the editor produces the extra-keys row: six `btn` buttons
"{ } ( ) [ ]" and an `insert_tab` button with content-desc "Insert tab"
(all absent before the editor is focused).
* Menu produces the labels "Save as new shader", "Add uniform/texture",
"Load sample", "Settings" (asserted as CONTENT, not tapped).
VLM (exactly 3 — for OPAQUE / transient text only):
* Toast "Shader saved" after menu -> Save shader NEVER reaches the view tree
(verified: absent from the dump) — a genuinely opaque core (tag content).
* A rule-asserted string double-checked as actually RENDERED on screen: the
"Rename shader" dialog heading (tag position) and the renamed shader title in
the top toolbar (tag position).
python3 test_android_text.py <PACKAGE> <RESULTS_DIR>
"""
import os
import re
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
# ── Portable launch: land on MainActivity, NOT LeakCanary's leak list ────────────
# The debug build ships LeakCanary, which registers a SECOND MAIN/LAUNCHER activity,
# so the kit's launch_app()/restart_app() land on the wrong screen. Resolve the
# app's own non-leakcanary LAUNCHER activity at runtime (works for the recreation
# too, which has no LeakCanary — the filter is then a no-op), verify the editor
# toolbar appeared, and retry. Uses only PACKAGE, so it is fully portable.
def launch_editor():
out = adb_shell("cmd", "package", "query-activities", "--brief",
"-a", "android.intent.action.MAIN",
"-c", "android.intent.category.LAUNCHER", PACKAGE)
comp = next((ln.strip() for ln in out.splitlines()
if ln.strip().startswith(PACKAGE + "/")
and "leakcanary" not in ln.lower()), "")
for _ in range(4):
force_stop()
if comp:
adb_shell("am", "start", "-n", comp)
else:
launch_app() # recreation: 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") # dismiss whatever we landed on, then retry
return False
# ── Small domain helpers ─────────────────────────────────────────────────────────
def all_text(nodes):
"""Every visible text string joined — the flat content of the surface."""
return " | ".join(n.get("text", "") for n in nodes if n.get("text", ""))
def texts_and_descs(nodes):
"""text + content-desc joined (content-desc is dump-readable text this lane
owns for icon-only controls)."""
out = []
for n in nodes:
if n.get("text", ""):
out.append(n.get("text", ""))
if n.get("content-desc", ""):
out.append(n.get("content-desc", ""))
return " | ".join(out)
def has_text(nodes, s):
"""Case-insensitive substring presence across text + content-desc."""
return s.strip().lower() in texts_and_descs(nodes).lower()
def toolbar_title(nodes=None):
"""The editor toolbar's shader-name TextView: an id-less TextView high on the
toolbar that is neither the 'fps' subtitle nor the '1/1'-style quality label."""
nodes = ui() if nodes is None else nodes
for n in nodes:
b = n.get("_bounds")
if not b:
continue
t = n.get("text", "")
if (t and not n.get("resource-id", "")
and n.get("class", "").endswith("TextView")
and b[1] < 320
and not re.match(r"^\d+\s*fps$", t.strip())
and "/" not in t):
return t
return None
def spinner_label(nodes=None):
"""The quality Spinner's child TextView (id ends /text1) currently shown on
the toolbar (bounds high up), so it is not confused with a dropdown item."""
nodes = ui() if nodes is None else nodes
best = None
for n in nodes:
if n.get("resource-id", "").endswith("/text1"):
b = n.get("_bounds")
if b and b[1] < 320:
return n.get("text", "")
best = best or n.get("text", "")
return best
def shader_titles(nodes=None):
nodes = ui() if nodes is None else nodes
return [n.get("text", "") for n in nodes
if n.get("resource-id", "").endswith("/shader_title")]
def drawer_is_open(nodes=None):
nodes = ui() if nodes is None else nodes
return find_node(nodes, content_desc="Close drawer") is not None
def and_enter_drawer():
"""Ensure the navigation drawer is OPEN, then count one surface. Idempotent.
NEVER closed with back() (BACK from an open drawer exits the app), so callers
relaunch for the next test instead of closing it."""
for _ in range(3):
nodes = ui()
if drawer_is_open(nodes):
and_enter("drawer")
return True
ham = find_node(nodes, content_desc="Open drawer")
if ham is None or not tap_node(ham):
return False
settle("tap")
settle("tap")
if drawer_is_open():
and_enter("drawer")
return True
return False
def open_menu():
"""Editor -> overflow popup (menu_btn). Returns True once a known row shows."""
mb = node_by_id(ui(), "menu_btn")
if mb is None or not tap_node(mb):
return False
settle("tap")
return (node_by_id(ui(), "load_sample") is not None
or node_by_id(ui(), "save_shader") is not None)
def and_enter_quality_dropdown():
"""Editor -> tap the quality Spinner -> its dropdown popup. One surface."""
q = node_by_id(ui(), "quality")
if q is None or not tap_node(q):
return False
settle("tap")
# the popup lists several CheckedTextView id=text1 items
items = [n for n in ui() if n.get("resource-id", "").endswith("/text1")]
if len(items) < 2:
return False
and_enter("quality_dropdown")
return True
def and_enter_load_sample():
"""Editor -> menu -> LoadSampleActivity (menu popup, then the activity)."""
if not open_menu():
return False
and_enter("menu")
ls = node_by_id(ui(), "load_sample")
if ls is None or not tap_node(ls):
return False
settle("launch")
wait_for_foreground()
if not has_text(ui(), "Load sample"):
return False
and_enter("load_sample_activity")
return True
def and_enter_add_uniform():
"""Editor -> menu -> AddUniformActivity (menu popup, then the activity)."""
if not open_menu():
return False
and_enter("menu")
au = node_by_id(ui(), "add_uniform")
if au is None or not tap_node(au):
return False
settle("launch")
wait_for_foreground()
if not has_text(ui(), "Add uniform/texture"):
return False
and_enter("add_uniform_activity")
return True
def and_enter_settings():
"""Editor -> menu -> PreferencesActivity (menu popup, then the activity)."""
if not open_menu():
return False
and_enter("menu")
st = node_by_id(ui(), "settings")
if st is None or not tap_node(st):
return False
settle("launch")
wait_for_foreground()
if not has_text(ui(), "Preferences"):
return False
and_enter("settings_activity")
return True
def and_enter_rename_dialog(row_title):
"""Open drawer -> long-press the row whose shader_title == row_title -> the
"Rename shader" dialog. Two surfaces (drawer, dialog). Returns the focused
name EditText or None."""
if not and_enter_drawer():
return None
row = None
for _ in range(5):
settle("tap")
for n in ui():
if (n.get("resource-id", "").endswith("/shader_title")
and n.get("text") == row_title and "_center" in n):
row = n
break
if row:
break
if row is None:
return None
long_press(row, 1500) # ms>=1000; long-press the row itself
settle("tap")
settle("tap")
if not has_text(ui(), "Rename shader"):
return None
and_enter("rename_dialog")
field = node_by_id(ui(), "name")
if field is None:
return None
for _ in range(3): # the field intermittently drops first focus
if not tap_node(field):
return None
settle("keyboard")
fresh = node_by_id(ui(), "name")
if fresh and fresh.get("focused") == "true":
return fresh
field = fresh or field
return field
def focus_editor():
"""Tap the editor EditText so the keyboard + extra-keys row appear."""
ed = node_by_id(ui(), "editor")
if ed is None or not tap_node(ed):
return False
settle("keyboard")
return True
# ══════════════════════════════════════════════════════════════════════════════
# 1) fps subtitle format — a rendered content pattern "<int> fps"
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_fps_subtitle_pattern",))
def test_fps_subtitle_pattern():
"""The toolbar fps subtitle is content the RENDERER produces: it is absent on
the Preferences activity and present (matching '<int> fps') back on the
editor. Asserted as a stable PATTERN — the exact integer is emulator-flaky."""
pat = re.compile(r"^\d+\s*fps$")
def fps_text(nodes):
for n in nodes:
if pat.match(n.get("text", "").strip()):
return n.get("text", "").strip()
return None
clear_data()
if not launch_editor():
record("text_fps_subtitle_pattern", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="a toolbar label matches '<int> fps' while rendering")
return
# Prove the string is produced by the editor: it must be ABSENT on Preferences.
absent_elsewhere = True
if and_enter_settings():
absent_elsewhere = fps_text(ui()) is None
# Back to a clean editor and read the produced fps subtitle.
clear_data()
if not launch_editor():
record("text_fps_subtitle_pattern", False,
"setup_failed: could not return to the editor",
depth=1, jump_kind="transition",
expect="a toolbar label matches '<int> fps' while rendering")
return
got = fps_text(ui())
ok = absent_elsewhere and got is not None
record("text_fps_subtitle_pattern", ok,
"" if ok else "behavior_wrong: no '<int> fps' subtitle produced on the "
f"editor (absent_on_prefs={absent_elsewhere}, got={got!r})",
depth=1, jump_kind="transition",
expect="a toolbar label matches '<int> fps' while rendering")
# ══════════════════════════════════════════════════════════════════════════════
# 2) Quality spinner label content 1/1 -> 1/8 (produced by selecting an item)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_quality_label_change",))
def test_quality_label_change():
clear_data()
if not launch_editor():
record("text_quality_label_change", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="quality spinner label content '1/1' -> '1/8'")
return
before = spinner_label()
if not and_enter_quality_dropdown():
record("text_quality_label_change", False,
"feature_missing: no quality spinner dropdown",
depth=1, jump_kind="transition",
expect="quality spinner label content '1/1' -> '1/8'")
return
item = None
for n in ui():
if n.get("resource-id", "").endswith("/text1") and n.get("text") == "1/8":
item = n
break
if item is None or not tap_node(item):
record("text_quality_label_change", False,
"feature_missing: no '1/8' item in the quality dropdown",
depth=1, jump_kind="transition",
expect="quality spinner label content '1/1' -> '1/8'")
return
settle("tap")
after = spinner_label()
ok = before == "1/1" and after == "1/8"
record("text_quality_label_change", ok,
"" if ok else "behavior_wrong: quality label did not change 1/1 -> 1/8 "
f"(before={before!r}, after={after!r})",
depth=1, jump_kind="transition",
expect="quality spinner label content '1/1' -> '1/8'")
# ══════════════════════════════════════════════════════════════════════════════
# 3) Shader title content "Default" in the toolbar AND the drawer (fresh DB)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_default_title_toolbar_and_drawer",))
def test_default_title():
"""A fresh DB renders exactly 'Default' as the toolbar title; opening the
drawer PRODUCES the same 'Default' as the single row title (that row string is
absent before the drawer is opened)."""
clear_data()
if not launch_editor():
record("text_default_title_toolbar_and_drawer", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="toolbar + drawer row both read 'Default'")
return
toolbar = toolbar_title()
row_absent_before = not shader_titles() # drawer row not yet produced
if not and_enter_drawer():
record("text_default_title_toolbar_and_drawer", False,
"setup_failed: could not open the drawer",
depth=1, jump_kind="transition",
expect="toolbar + drawer row both read 'Default'")
return
rows = shader_titles()
ok = (toolbar == "Default" and row_absent_before
and rows == ["Default"])
record("text_default_title_toolbar_and_drawer", ok,
"" if ok else "behavior_wrong: 'Default' not shown in both toolbar and "
f"drawer (toolbar={toolbar!r}, drawer_rows={rows})",
depth=1, jump_kind="transition",
expect="toolbar + drawer row both read 'Default'")
# ══════════════════════════════════════════════════════════════════════════════
# 4) Rename produces the new title string in toolbar + drawer (strong)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_rename_produces_title",))
def test_rename_produces_title():
clear_data()
if not launch_editor():
record("text_rename_produces_title", False,
"setup_failed: could not reach the editor",
depth=2, jump_kind="transition",
expect="shader title content 'Default' -> 'kit_txt_R'")
return
field = and_enter_rename_dialog("Default")
if field is None:
record("text_rename_produces_title", False,
"feature_missing: long-press did not open a Rename dialog with a "
"name field",
depth=2, jump_kind="transition",
expect="shader title content 'Default' -> 'kit_txt_R'")
return
press_key("KEYCODE_MOVE_END")
for _ in range(20):
press_key(67) # KEYCODE_DEL — clear the prefilled 'Default'
settle("text")
type_text(field, "kit_txt_R")
ok_btn = node_by_id(ui(), "button1") # OK
if ok_btn is None or not tap_node(ok_btn):
record("text_rename_produces_title", False,
"feature_missing: no OK button in the Rename dialog",
depth=2, jump_kind="transition",
expect="shader title content 'Default' -> 'kit_txt_R'")
return
settle("tap")
settle("tap")
new_toolbar = toolbar_title()
if not and_enter_drawer():
record("text_rename_produces_title", False,
"setup_failed: could not reopen the drawer to verify",
depth=2, jump_kind="transition",
expect="shader title content 'Default' -> 'kit_txt_R'")
return
rows = shader_titles()
ok = (new_toolbar == "kit_txt_R" and "kit_txt_R" in rows
and "Default" not in rows)
record("text_rename_produces_title", ok,
"" if ok else "behavior_wrong: rename did not produce 'kit_txt_R' in "
f"toolbar+drawer (toolbar={new_toolbar!r}, rows={rows})",
depth=2, jump_kind="transition",
expect="shader title content 'Default' -> 'kit_txt_R'")
# ══════════════════════════════════════════════════════════════════════════════
# 5) Rename dialog labels: title "Rename shader" + buttons "Cancel"/"OK"
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_rename_dialog_labels",))
def test_rename_dialog_labels():
"""Long-press produces the dialog's static strings: the heading 'Rename
shader' and the two button labels 'Cancel'/'OK' (all absent on the drawer
before the long-press)."""
clear_data()
if not launch_editor():
record("text_rename_dialog_labels", False,
"setup_failed: could not reach the editor",
depth=2, jump_kind="transition",
expect="dialog shows 'Rename shader' + 'Cancel'/'OK'")
return
if not and_enter_drawer():
record("text_rename_dialog_labels", False,
"setup_failed: could not open the drawer",
depth=2, jump_kind="transition",
expect="dialog shows 'Rename shader' + 'Cancel'/'OK'")
return
absent_before = not has_text(ui(), "Rename shader")
# Long-press the row to raise the dialog.
row = None
for _ in range(5):
settle("tap")
for n in ui():
if (n.get("resource-id", "").endswith("/shader_title")
and n.get("text") == "Default" and "_center" in n):
row = n
break
if row:
break
if row is None:
record("text_rename_dialog_labels", False,
"setup_failed: no 'Default' drawer row to long-press",
depth=2, jump_kind="transition",
expect="dialog shows 'Rename shader' + 'Cancel'/'OK'")
return
long_press(row, 1500)
settle("tap")
settle("tap")
and_enter("rename_dialog")
nodes = ui()
title_ok = has_text(nodes, "Rename shader")
b1 = node_by_id(nodes, "button1") # OK
b2 = node_by_id(nodes, "button2") # Cancel
ok_label = (b1 or {}).get("text", "")
cancel_label = (b2 or {}).get("text", "")
ok = (absent_before and title_ok
and ok_label.strip().lower() == "ok"
and cancel_label.strip().lower() == "cancel")
record("text_rename_dialog_labels", ok,
"" if ok else "behavior_wrong: rename dialog labels wrong "
f"(absent_before={absent_before}, title={title_ok}, "
f"ok={ok_label!r}, cancel={cancel_label!r})",
depth=2, jump_kind="transition",
expect="dialog shows 'Rename shader' + 'Cancel'/'OK'")
# Dismiss the dialog (Cancel) so the drawer state is clean; test isolation is
# still guaranteed by the next test's own clear_data()+launch_editor().
if b2 is not None:
tap_node(b2)
settle("tap")
# ══════════════════════════════════════════════════════════════════════════════
# 6) Load sample activity produces the sample name/rationale strings
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_load_sample_rows",))
def test_load_sample_rows():
clear_data()
if not launch_editor():
record("text_load_sample_rows", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="Load sample list shows sample names + rationales")
return
absent_before = not has_text(ui(), "Draw some circles")
if not and_enter_load_sample():
record("text_load_sample_rows", False,
"feature_missing: no Load sample path",
depth=1, jump_kind="transition",
expect="Load sample list shows sample names + rationales")
return
nodes = ui()
title_ok = has_text(nodes, "Load sample")
# Three name+rationale pairs, one of them the app's own typo 'orienation'.
pairs = [
("Circles", "Draw some circles"),
("Game of Life", "Conway's Game of Life"),
("Orientation", "How to use the orienation uniform"),
]
hits = sum(1 for name, rat in pairs
if find_node(nodes, text=name) is not None and has_text(nodes, rat))
ok = absent_before and title_ok and hits >= 3
record("text_load_sample_rows", ok,
"" if ok else "behavior_wrong: Load sample did not produce the expected "
f"name+rationale rows (absent_before={absent_before}, title={title_ok}, "
f"pairs_matched={hits}/3)",
depth=1, jump_kind="transition",
expect="Load sample list shows sample names + rationales")
# ══════════════════════════════════════════════════════════════════════════════
# 7) Add uniform activity produces the "name (type)" preset labels + rationale
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_add_uniform_preset_labels",))
def test_add_uniform_preset_labels():
clear_data()
if not launch_editor():
record("text_add_uniform_preset_labels", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="preset rows formatted 'name (type)'")
return
absent_before = not has_text(ui(), "battery (float)")
if not and_enter_add_uniform():
record("text_add_uniform_preset_labels", False,
"feature_missing: no Add uniform/texture path",
depth=1, jump_kind="transition",
expect="preset rows formatted 'name (type)'")
return
nodes = ui()
# Preset rows formatted exactly "name (type)".
labels = ["battery (float)", "date (vec4)", "frame (int)"]
hits = sum(1 for lbl in labels if find_node(nodes, text=lbl) is not None)
rationale_ok = has_text(nodes, "Battery level from 0.0 to 1.0")
ok = absent_before and hits >= 3 and rationale_ok
record("text_add_uniform_preset_labels", ok,
"" if ok else "behavior_wrong: preset 'name (type)' labels/rationale "
f"not produced (absent_before={absent_before}, labels={hits}/3, "
f"rationale={rationale_ok})",
depth=1, jump_kind="transition",
expect="preset rows formatted 'name (type)'")
# ══════════════════════════════════════════════════════════════════════════════
# 8) Tab layout labels "preset" / "sampler2D" / "samplerCube"
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_add_uniform_tab_labels",))
def test_add_uniform_tab_labels():
clear_data()
if not launch_editor():
record("text_add_uniform_tab_labels", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="tabs 'preset','sampler2D','samplerCube' present")
return
absent_before = not has_text(ui(), "samplerCube")
if not and_enter_add_uniform():
record("text_add_uniform_tab_labels", False,
"feature_missing: no Add uniform/texture path",
depth=1, jump_kind="transition",
expect="tabs 'preset','sampler2D','samplerCube' present")
return
nodes = ui()
tabs = ["preset", "sampler2D", "samplerCube"]
hits = sum(1 for t in tabs if find_node(nodes, text=t) is not None)
ok = absent_before and hits == 3
record("text_add_uniform_tab_labels", ok,
"" if ok else "behavior_wrong: not all three tab labels produced "
f"(absent_before={absent_before}, tabs_matched={hits}/3)",
depth=1, jump_kind="transition",
expect="tabs 'preset','sampler2D','samplerCube' present")
# ══════════════════════════════════════════════════════════════════════════════
# 9) Switching to the sampler2D tab produces the texture-size content "256 x 256"
# (absent on the preset tab). NOTE: this build ships seeded textures, so the
# recon's "No textures available" empty-state does NOT hold here.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_sampler2d_tab_content",))
def test_sampler2d_tab_content():
clear_data()
if not launch_editor():
record("text_sampler2d_tab_content", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="'256 x 256' texture-size appears on the sampler2D tab")
return
if not and_enter_add_uniform():
record("text_sampler2d_tab_content", False,
"feature_missing: no Add uniform/texture path",
depth=1, jump_kind="transition",
expect="'256 x 256' texture-size appears on the sampler2D tab")
return
absent_on_preset = not has_text(ui(), "256 x 256")
tab = find_node(ui(), text="sampler2D")
if tab is None or not tap_node(tab):
record("text_sampler2d_tab_content", False,
"feature_missing: no sampler2D tab to switch to",
depth=1, jump_kind="transition",
expect="'256 x 256' texture-size appears on the sampler2D tab")
return
settle("tap")
settle("tap")
present_after = has_text(ui(), "256 x 256")
ok = absent_on_preset and present_after
record("text_sampler2d_tab_content", ok,
"" if ok else "behavior_wrong: sampler2D tab did not produce a "
f"'256 x 256' texture-size (absent_on_preset={absent_on_preset}, "
f"present_after={present_after})",
depth=1, jump_kind="transition",
expect="'256 x 256' texture-size appears on the sampler2D tab")
# ══════════════════════════════════════════════════════════════════════════════
# 10) Settings summary strings produced on the Preferences activity
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_settings_summaries",))
def test_settings_summaries():
clear_data()
if not launch_editor():
record("text_settings_summaries", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="settings summaries 'Auto run on change','1.0s','Small'...")
return
absent_before = not has_text(ui(), "Auto run on change")
if not and_enter_settings():
record("text_settings_summaries", False,
"feature_missing: no Settings path",
depth=1, jump_kind="transition",
expect="settings summaries 'Auto run on change','1.0s','Small'...")
return
# Read summaries above the fold; re-find any missing one by scrolling.
summaries = ["Auto run on change", "1.0s", "Small", "Monospace", "2 characters"]
nodes = ui()
hits = 0
for s in summaries:
if has_text(nodes, s):
hits += 1
elif scroll_into_view(s, max_swipes=3) is not None:
hits += 1
ok = absent_before and hits >= 3
record("text_settings_summaries", ok,
"" if ok else "behavior_wrong: settings summaries not produced "
f"(absent_before={absent_before}, summaries_matched={hits}/5)",
depth=1, jump_kind="transition",
expect="settings summaries 'Auto run on change','1.0s','Small'...")
# ══════════════════════════════════════════════════════════════════════════════
# 11) Preferences screen title string "Preferences" produced on entry
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_preferences_title",))
def test_preferences_title():
clear_data()
if not launch_editor():
record("text_preferences_title", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="title 'Preferences' shown in settings")
return
absent_before = not has_text(ui(), "Preferences")
if not and_enter_settings():
record("text_preferences_title", False,
"feature_missing: no Settings path",
depth=1, jump_kind="transition",
expect="title 'Preferences' shown in settings")
return
present_after = has_text(ui(), "Preferences")
ok = absent_before and present_after
record("text_preferences_title", ok,
"" if ok else "behavior_wrong: 'Preferences' title not produced on "
f"the settings activity (absent_before={absent_before}, "
f"present_after={present_after})",
depth=1, jump_kind="transition",
expect="title 'Preferences' shown in settings")
# ══════════════════════════════════════════════════════════════════════════════
# 12) Content-desc on the hamburger: "Open drawer" -> "Close drawer" when opened
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_hamburger_content_desc",))
def test_hamburger_content_desc():
clear_data()
if not launch_editor():
record("text_hamburger_content_desc", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="hamburger content-desc 'Open drawer' -> 'Close drawer'")
return
open_present = find_node(ui(), content_desc="Open drawer") is not None
close_absent = find_node(ui(), content_desc="Close drawer") is None
if not and_enter_drawer():
record("text_hamburger_content_desc", False,
"setup_failed: could not open the drawer",
depth=1, jump_kind="transition",
expect="hamburger content-desc 'Open drawer' -> 'Close drawer'")
return
close_present = find_node(ui(), content_desc="Close drawer") is not None
ok = open_present and close_absent and close_present
record("text_hamburger_content_desc", ok,
"" if ok else "behavior_wrong: hamburger content-desc did not toggle "
f"Open->Close (open_present={open_present}, close_absent_before="
f"{close_absent}, close_present_after={close_present})",
depth=1, jump_kind="transition",
expect="hamburger content-desc 'Open drawer' -> 'Close drawer'")
# ══════════════════════════════════════════════════════════════════════════════
# 13) Extra-keys row produces the bracket button labels + 'Insert tab' content-desc
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_extra_keys_labels",))
def test_extra_keys_labels():
"""Focusing the editor PRODUCES the extra-keys row: the six bracket button
labels '{ } ( ) [ ]' and an insert_tab button with content-desc 'Insert tab',
all absent before the editor is focused."""
clear_data()
if not launch_editor():
record("text_extra_keys_labels", False,
"setup_failed: could not reach the editor",
depth=0, jump_kind="transition",
expect="'{ } ( ) [ ]' + 'Insert tab' appear when editor focused")
return
def bracket_chars(nodes):
return sorted(n.get("text", "") for n in nodes
if n.get("resource-id", "").endswith("/btn")
and n.get("text", "") in set("{}()[]"))
before_chars = bracket_chars(ui())
tab_absent_before = find_node(ui(), content_desc="Insert tab") is None
if not focus_editor():
record("text_extra_keys_labels", False,
"setup_failed: could not focus the editor",
depth=0, jump_kind="transition",
expect="'{ } ( ) [ ]' + 'Insert tab' appear when editor focused")
return
nodes = ui()
after_chars = bracket_chars(nodes)
tab_present_after = find_node(nodes, content_desc="Insert tab") is not None
ok = (before_chars == []
and after_chars == sorted("{}()[]")
and tab_absent_before and tab_present_after)
record("text_extra_keys_labels", ok,
"" if ok else "behavior_wrong: extra-keys labels not produced on focus "
f"(before={before_chars}, after={after_chars}, "
f"tab_before={not tab_absent_before}, tab_after={tab_present_after})",
depth=0, jump_kind="transition",
expect="'{ } ( ) [ ]' + 'Insert tab' appear when editor focused")
# ══════════════════════════════════════════════════════════════════════════════
# 14) Overflow menu produces its action labels (asserted as CONTENT, not tapped)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_menu_labels",))
def test_menu_labels():
"""Opening the overflow menu PRODUCES its row labels. These are asserted as
CONTENT (equality against what the original renders), NOT as navigation
triggers — no row is tapped. All are absent before the menu opens."""
clear_data()
if not launch_editor():
record("text_menu_labels", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition",
expect="menu shows 'Save as new shader','Load sample','Settings'...")
return
absent_before = not has_text(ui(), "Save as new shader")
if not open_menu():
record("text_menu_labels", False,
"feature_missing: overflow menu did not open",
depth=1, jump_kind="transition",
expect="menu shows 'Save as new shader','Load sample','Settings'...")
return
and_enter("menu")
nodes = ui()
# Match each label against its stable id's node text (exact content equality).
expected = {
"add_shader": "New shader",
"duplicate_shader": "Save as new shader",
"add_uniform": "Add uniform/texture",
"load_sample": "Load sample",
"settings": "Settings",
}
hits = 0
seen = {}
for rid, label in expected.items():
node = node_by_id(nodes, rid)
txt = (node or {}).get("text", "")
seen[rid] = txt
if txt.strip().lower() == label.lower():
hits += 1
ok = absent_before and hits == len(expected)
record("text_menu_labels", ok,
"" if ok else "behavior_wrong: overflow menu labels wrong "
f"(absent_before={absent_before}, matched={hits}/{len(expected)}, "
f"seen={seen})",
depth=1, jump_kind="transition",
expect="menu shows 'Save as new shader','Load sample','Settings'...")
# ══════════════════════════════════════════════════════════════════════════════
# 15) VLM — OPAQUE toast "Shader saved" (never reaches the view tree)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_save_toast_vlm",))
def test_save_toast_vlm():
"""menu -> Save shader shows a transient Toast 'Shader saved'. Verified to be
ABSENT from the uiautomator dump — a genuinely opaque text core, so it goes to
the VLM (tag content) instead of a dump read. Save is SAFE (it only saves the
current shader)."""
clear_data()
if not launch_editor():
record("text_save_toast_vlm", False,
"setup_failed: could not reach the editor",
depth=1, jump_kind="transition", tag="content")
return
if not open_menu():
record("text_save_toast_vlm", False,
"feature_missing: overflow menu did not open",
depth=1, jump_kind="transition", tag="content")
return
and_enter("menu")
save_btn = node_by_id(ui(), "save_shader")
if save_btn is None or not tap_node(save_btn):
record("text_save_toast_vlm", False,
"feature_missing: no 'Save shader' control",
depth=1, jump_kind="transition", tag="content")
return
# The toast appears immediately and fades — capture it before it disappears.
vlm_assert("text_save_toast",
"Is a small rounded popup message reading 'Shader saved' visible "
"near the bottom-center of the screen?",
RESULTS_DIR, depth=1, jump_kind="transition", tag="content")
# ══════════════════════════════════════════════════════════════════════════════
# 16) VLM — rule-asserted string double-check: the "Rename shader" dialog heading
# is actually RENDERED as the dialog title (fine-grained: position).
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_rename_dialog_rendered_vlm",))
def test_rename_dialog_rendered_vlm():
clear_data()
if not launch_editor():
record("text_rename_dialog_rendered_vlm", False,
"setup_failed: could not reach the editor",
depth=2, jump_kind="transition", tag="position")
return
field = and_enter_rename_dialog("Default")
if field is None:
record("text_rename_dialog_rendered_vlm", False,
"feature_missing: long-press did not open a Rename dialog",
depth=2, jump_kind="transition", tag="position")
return
vlm_assert("text_rename_dialog_rendered",
"Is the text 'Rename shader' shown as the heading at the TOP of a "
"pop-up dialog box (above an editable text field and OK/Cancel "
"buttons)?",
RESULTS_DIR, depth=2, jump_kind="transition", tag="position")
# Dismiss the dialog with Cancel so the drawer state is left clean.
cancel = node_by_id(ui(), "button2")
if cancel is not None:
tap_node(cancel)
settle("tap")
# ══════════════════════════════════════════════════════════════════════════════
# 17) VLM — rule-asserted string double-check: the renamed shader title is
# actually RENDERED in the top toolbar (fine-grained: position).
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("text_renamed_title_rendered_vlm",))
def test_renamed_title_rendered_vlm():
clear_data()
if not launch_editor():
record("text_renamed_title_rendered_vlm", False,
"setup_failed: could not reach the editor",
depth=2, jump_kind="transition", tag="position")
return
field = and_enter_rename_dialog("Default")
if field is None:
record("text_renamed_title_rendered_vlm", False,
"feature_missing: long-press did not open a Rename dialog",
depth=2, jump_kind="transition", tag="position")
return
press_key("KEYCODE_MOVE_END")
for _ in range(20):
press_key(67)
settle("text")
type_text(field, "kit_txt_V")
ok_btn = node_by_id(ui(), "button1") # OK
if ok_btn is None or not tap_node(ok_btn):
record("text_renamed_title_rendered_vlm", False,
"feature_missing: no OK button in the Rename dialog",
depth=2, jump_kind="transition", tag="position")
return
settle("tap")
settle("tap")
vlm_assert("text_renamed_title_rendered",
"Is the text 'kit_txt_V' shown as the title in the TOP toolbar / "
"app bar at the top of the screen?",
RESULTS_DIR, depth=2, jump_kind="transition", tag="position")
TESTS = [
test_fps_subtitle_pattern,
test_quality_label_change,
test_default_title,
test_rename_produces_title,
test_rename_dialog_labels,
test_load_sample_rows,
test_add_uniform_preset_labels,
test_add_uniform_tab_labels,
test_sampler2d_tab_content,
test_settings_summaries,
test_preferences_title,
test_hamburger_content_desc,
test_extra_keys_labels,
test_menu_labels,
test_save_toast_vlm,
test_rename_dialog_rendered_vlm,
test_renamed_title_rendered_vlm,
]
if __name__ == "__main__":
if not device_online():
print("Device offline — aborting; a whole module of setup_failed usually "
"means the tunnel died, not that the app is broken.")
sys.exit(1)
run_suite(TESTS, "text")