#!/usr/bin/env python3 """INTERACTION eval for Shader Editor — EFFECT-BY-CONSEQUENCE on user DATA. This lane owns CRUD on the app's user data, 3+ step sequences, multi-record integrity, DATA persistence across process death, and (SOLE owner) long-press / context menus. The app's user DATA is the editor SOURCE TEXT and the SHADER LIST (SQLite). Every test drives the app to the surface via the user path, performs the mutation, then reads the CONSEQUENCE back out of a FRESH ui() and asserts it equals what was observed on the running original. A dead shell that shows the UI but does not actually mutate/persist data FAILS here. Ground truth (all verified on the running original, package de.markusfisch...debug): * Add uniform "battery (float)" grows the editor text 716 -> 743 and inserts the literal substring 'uniform float battery'. "date (vec4)" inserts 'uniform vec4 date' (716 -> 739). * Extra-key bracket button '{'/'(' inserts exactly one char at the cursor. * "Save as new shader" and "New shader" each grow the drawer shader count 1 -> 2. * "Load sample" -> "Circles" adds a new shader (count 1 -> 2) and replaces the editor source. * Long-press a drawer row -> "Rename shader" dialog; OK writes the new title, Cancel leaves it unchanged. * Persistence across force-stop: a "Save as new shader" duplicate and a rename BOTH survive; an editor edit survives ONLY after an explicit "Save shader" (a hard force-stop kills the process before onPause auto-save flushes). The drawer's hamburger toggles its content-desc 'Open drawer' <-> 'Close drawer'; 'Close drawer' is the reliable open-state signal. Tapping the editor to close the drawer is NOT reliable (the open drawer overlays that region), so close() taps the 'Close drawer' toggle itself; BACK is never used (it exits the app to home). NOTE on the parsed editor text: uiautomator emits the EditText value with HTML entities (newline -> ' ', tab -> ' ', '<' -> '<'), and the kit's parser leaves them un-decoded. Every asserted substring below ('uniform float battery', '{', '(', '//SAVE99', 'uniform float time') is entity-free, so it appears literally. python3 test_android_interaction.py """ import os 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 (plain helpers; the and_enter_* NAME below backs depth) ── def editor_text(nodes=None): """Current editor EditText value ('' if the editor is not on screen). Re-dumps once if the first tree is missing it, because the editor node can be transiently absent right after the keyboard opens/closes.""" for _ in range(2): nodes = ui() if nodes is None else nodes ed = node_by_id(nodes, "editor") if ed is not None: return ed.get("text", "") nodes = None return "" def shader_titles(nodes=None): """Every drawer row title, matched by the LAST id segment (portable).""" 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 shader_count(nodes=None): return len(shader_titles(nodes)) def drawer_is_open(nodes=None): """A visible 'Close drawer' button is the reliable open-state signal (the hamburger's content-desc toggles 'Open drawer' <-> 'Close drawer').""" nodes = ui() if nodes is None else nodes return find_node(nodes, content_desc="Close drawer") is not None def open_drawer_and_reach(): """Ensure the navigation drawer is OPEN, then count one surface. Idempotent: if it is already open it is already reached. Settles twice after opening so the drawer animation finishes (or the row nodes are absent).""" 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 close_drawer(): """Reliably close the drawer by tapping its own 'Close drawer' toggle button — NEVER BACK (BACK from an open drawer exits the app to home), and NOT by tapping the editor (the open drawer overlays that region). Returns True once closed.""" for _ in range(3): cb = find_node(ui(), content_desc="Close drawer") if cb is None: return True # already closed tap_node(cb) settle("tap") return not drawer_is_open() def open_menu(): """Editor -> overflow popup (menu_btn). Returns True once a known menu row is visible.""" 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(), "add_uniform") is not None \ or node_by_id(ui(), "save_shader") is not None def and_enter_add_uniform(): """Editor -> menu -> AddUniformActivity (crosses the menu popup, then the activity). Two surfaces: name each with and_enter so depth=2 is backed.""" 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 find_node_ci(ui(), "Add uniform/texture") is None: return False and_enter("add_uniform_activity") return True def and_enter_load_sample(): """Editor -> menu -> LoadSampleActivity (two surfaces).""" 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 find_node_ci(ui(), "Load sample") is None: return False and_enter("load_sample_activity") return True def tap_list_row(text): """Tap a list row identified by its visible text, re-dumping until the row is laid out (has _center) — LoadSample/AddUniform list rows report no bounds for a beat after the activity opens, so an immediate tap misses.""" row = None for _ in range(6): settle("tap") cand = find_node(ui(), text=text) if cand and "_center" in cand: row = cand break return bool(row) and tap_node(row) def focus_field(node): """Tap an EditText and retry until it reports focused=true; returns the fresh focused node or None. The rename dialog's field intermittently drops the first tap's focus, which silently swallows all subsequent input.""" n = node for _ in range(3): if not tap_node(n): return None settle("keyboard") fresh = node_by_id(ui(), "name") or find_closest_match(ui(), n) if fresh and fresh.get("focused") == "true": return fresh n = fresh or n return None 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). SOLE-owned long-press. Idempotent about the drawer's current state. Returns the focused name field or None.""" if not open_drawer_and_reach(): 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; settle twice before querying dialog settle("tap") settle("tap") if find_node_ci(ui(), "Rename shader") is None: return None and_enter("rename_dialog") name = node_by_id(ui(), "name") return focus_field(name) if name else None def rename_row(row_title, new_name): """Full rename of the drawer row titled `row_title` to `new_name`, ending back on the editor with the drawer closed. Clears the prefilled field (MOVE_END + DEL via the kit's press_key — never a raw `input text`), types with type_text, taps OK. Returns True iff the field ended up holding exactly `new_name`.""" field = and_enter_rename_dialog(row_title) if field is None: return False press_key("KEYCODE_MOVE_END") for _ in range(25): press_key(67) # KEYCODE_DEL — clear the prefilled title settle("text") type_text(field, new_name) got = "" nm = node_by_id(ui(), "name") if nm is not None: got = nm.get("text", "") ok_btn = node_by_id(ui(), "button1") # OK if ok_btn is not None: tap_node(ok_btn) settle("tap") settle("tap") close_drawer() # guarantee a clean state for the next step return got == new_name def make_new_shader(): """menu -> "New shader" (add_shader): inserts a new scratch shader and selects it. Returns True on success.""" if not open_menu(): return False nb = node_by_id(ui(), "add_shader") if nb is None or not tap_node(nb): return False settle("tap") settle("tap") return True def make_duplicate(): """menu -> "Save as new shader" (duplicate_shader): duplicates the current shader (drawer count +1). Returns True on success.""" if not open_menu(): return False dup = node_by_id(ui(), "duplicate_shader") if dup is None or not tap_node(dup): return False settle("tap") settle("tap") return True # ══════════════════════════════════════════════════════════════════════════════ # 1) FLAGSHIP: Add uniform inserts the exact declaration into the editor text # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_add_uniform_battery", "interaction_add_uniform_battery_vlm")) def test_add_uniform_inserts_text(): clear_data() if not launch_editor(): record("interaction_add_uniform_battery", False, "setup_failed: could not reach the editor", depth=2, jump_kind="value", expect="editor text contains 'uniform float battery'") return before = editor_text() absent_before = "uniform float battery" not in before if not and_enter_add_uniform(): record("interaction_add_uniform_battery", False, "feature_missing: no Add uniform/texture path", depth=2, jump_kind="value", expect="editor text contains 'uniform float battery'") return if not tap_list_row("battery (float)"): record("interaction_add_uniform_battery", False, "feature_missing: no 'battery (float)' preset row", depth=2, jump_kind="value", expect="editor text contains 'uniform float battery'") return wait_for_foreground() after = editor_text() ok = (absent_before and "uniform float battery" in after and len(after) > len(before)) record("interaction_add_uniform_battery", ok, "" if ok else "behavior_wrong: 'uniform float battery' not inserted " f"(len {len(before)} -> {len(after)})", depth=2, jump_kind="value", expect="editor text contains 'uniform float battery'") # VLM: the inserted code is rendered with GLSL syntax highlighting (multiple # colors) — a rendered property, not cleanly exposed by the tree's flat text. vlm_assert("interaction_add_uniform_battery", "Is the source code in the code editor shown in MULTIPLE different " "colors (syntax highlighting), rather than all one color?", depth=2, jump_kind="value", tag="color") @and_test(expects=("interaction_add_uniform_date",)) def test_add_uniform_date_vec4(): clear_data() if not launch_editor(): record("interaction_add_uniform_date", False, "setup_failed: could not reach the editor", depth=2, jump_kind="value", expect="editor text contains 'uniform vec4 date'") return before = editor_text() absent_before = "uniform vec4 date" not in before if not and_enter_add_uniform(): record("interaction_add_uniform_date", False, "feature_missing: no Add uniform/texture path", depth=2, jump_kind="value", expect="editor text contains 'uniform vec4 date'") return if not tap_list_row("date (vec4)"): record("interaction_add_uniform_date", False, "feature_missing: no 'date (vec4)' preset row", depth=2, jump_kind="value", expect="editor text contains 'uniform vec4 date'") return wait_for_foreground() after = editor_text() ok = (absent_before and "uniform vec4 date" in after and len(after) > len(before)) record("interaction_add_uniform_date", ok, "" if ok else "behavior_wrong: 'uniform vec4 date' not inserted " f"(len {len(before)} -> {len(after)})", depth=2, jump_kind="value", expect="editor text contains 'uniform vec4 date'") # ══════════════════════════════════════════════════════════════════════════════ # 2) Extra-key bracket buttons insert exactly one char at the cursor # ══════════════════════════════════════════════════════════════════════════════ def _extra_key_btn(nodes, ch): for n in nodes: if n.get("resource-id", "").endswith("/btn") and n.get("text", "") == ch: return n return None @and_test(expects=("interaction_extra_key_brace", "interaction_extra_key_brace_vlm")) def test_extra_key_brace_insert(): clear_data() if not launch_editor(): record("interaction_extra_key_brace", False, "setup_failed: could not reach the editor", depth=1, jump_kind="value", expect="editor gains one '{'") return ed = node_by_id(ui(), "editor") if ed is None or not tap_node(ed): # focus editor -> extra-keys row appears record("interaction_extra_key_brace", False, "setup_failed: could not focus the editor", depth=1, jump_kind="value", expect="editor gains one '{'") return settle("keyboard") and_enter("extra_keys_row") press_key("KEYCODE_MOVE_END") nodes = ui() before = editor_text(nodes) brace = _extra_key_btn(nodes, "{") if brace is None: record("interaction_extra_key_brace", False, "feature_missing: no '{' extra-key button", depth=1, jump_kind="value", expect="editor gains one '{'") return tap_node(brace) settle("tap") after = editor_text() ok = (len(after) == len(before) + 1 and after.count("{") == before.count("{") + 1) record("interaction_extra_key_brace", ok, "" if ok else "behavior_wrong: '{' button did not insert exactly one " f"brace (len {len(before)} -> {len(after)}, " f"braces {before.count('{')} -> {after.count('{')})", depth=1, jump_kind="value", expect="editor gains one '{'") # VLM: the extra-keys bracket row is drawn below the editor; confirm it renders. vlm_assert("interaction_extra_key_brace", "Are the six bracket buttons { } ( ) [ ] laid out side by side in a " "single horizontal row across the bottom of the screen?", depth=1, jump_kind="value", tag="position") @and_test(expects=("interaction_extra_key_paren",)) def test_extra_key_paren_insert(): clear_data() if not launch_editor(): record("interaction_extra_key_paren", False, "setup_failed: could not reach the editor", depth=1, jump_kind="value", expect="editor gains one '('") return ed = node_by_id(ui(), "editor") if ed is None or not tap_node(ed): record("interaction_extra_key_paren", False, "setup_failed: could not focus the editor", depth=1, jump_kind="value", expect="editor gains one '('") return settle("keyboard") and_enter("extra_keys_row") press_key("KEYCODE_MOVE_END") nodes = ui() before = editor_text(nodes) paren = _extra_key_btn(nodes, "(") if paren is None: record("interaction_extra_key_paren", False, "feature_missing: no '(' extra-key button", depth=1, jump_kind="value", expect="editor gains one '('") return tap_node(paren) settle("tap") after = editor_text() ok = (len(after) == len(before) + 1 and after.count("(") == before.count("(") + 1) record("interaction_extra_key_paren", ok, "" if ok else "behavior_wrong: '(' button did not insert exactly one " f"paren (len {len(before)} -> {len(after)})", depth=1, jump_kind="value", expect="editor gains one '('") # ══════════════════════════════════════════════════════════════════════════════ # 3) Typing into the editor grows its text by exactly the typed marker # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_type_into_editor",)) def test_type_into_editor(): clear_data() if not launch_editor(): record("interaction_type_into_editor", False, "setup_failed: could not reach the editor", depth=0, jump_kind="value", expect="editor contains '//kit_typed'") return ed = node_by_id(ui(), "editor") before = editor_text() absent_before = "//kit_typed" not in before if ed is None or not tap_node(ed): record("interaction_type_into_editor", False, "setup_failed: could not focus the editor", depth=0, jump_kind="value", expect="editor contains '//kit_typed'") return settle("keyboard") press_key("KEYCODE_MOVE_END") ed = node_by_id(ui(), "editor") or ed type_text(ed, "//kit_typed") after = editor_text() ok = absent_before and "//kit_typed" in after and len(after) > len(before) record("interaction_type_into_editor", ok, "" if ok else "behavior_wrong: typed marker did not land in the editor " f"(len {len(before)} -> {len(after)})", depth=0, jump_kind="value", expect="editor contains '//kit_typed'") # ══════════════════════════════════════════════════════════════════════════════ # 4) CRUD: Save as new shader -> drawer count 1 -> 2 # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_duplicate_adds_shader", "interaction_duplicate_adds_shader_vlm")) def test_duplicate_adds_shader(): clear_data() if not launch_editor(): record("interaction_duplicate_adds_shader", False, "setup_failed: could not reach the editor", depth=1, jump_kind="transition", expect="drawer shader count 1 -> 2") return if not open_drawer_and_reach(): record("interaction_duplicate_adds_shader", False, "setup_failed: could not open the drawer", depth=1, jump_kind="transition", expect="drawer shader count 1 -> 2") return n_before = shader_count() close_drawer() # reliable close via the toggle if not make_duplicate(): record("interaction_duplicate_adds_shader", False, "feature_missing: no 'Save as new shader' control", depth=1, jump_kind="transition", expect="drawer shader count 1 -> 2") return if not open_drawer_and_reach(): record("interaction_duplicate_adds_shader", False, "setup_failed: could not reopen the drawer", depth=1, jump_kind="transition", expect="drawer shader count 1 -> 2") return n_after = shader_count() ok = n_before == 1 and n_after == 2 record("interaction_duplicate_adds_shader", ok, "" if ok else "behavior_wrong: duplicate did not add a shader row " f"(count {n_before} -> {n_after})", depth=1, jump_kind="transition", expect="drawer shader count 1 -> 2") # VLM: the drawer visibly lists two or more shader entries now. vlm_assert("interaction_duplicate_adds_shader", "Does the navigation drawer's shader list show TWO or more shader " "entries (rows)?", depth=1, jump_kind="transition", tag="layout") # ══════════════════════════════════════════════════════════════════════════════ # 5) CRUD: New shader -> count 1 -> 2 AND editor swaps to the new template # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_new_shader_adds_and_swaps",)) def test_new_shader_adds_and_swaps(): clear_data() if not launch_editor(): record("interaction_new_shader_adds_and_swaps", False, "setup_failed: could not reach the editor", depth=1, jump_kind="value", expect="count 1 -> 2 and editor text changed") return before = editor_text() if not make_new_shader(): record("interaction_new_shader_adds_and_swaps", False, "feature_missing: no 'New shader' control", depth=1, jump_kind="value", expect="count 1 -> 2 and editor text changed") return after = editor_text() swapped = after != before and len(after) > 0 if not open_drawer_and_reach(): record("interaction_new_shader_adds_and_swaps", False, "setup_failed: could not open the drawer", depth=1, jump_kind="value", expect="count 1 -> 2 and editor text changed") return n_after = shader_count() ok = swapped and n_after == 2 record("interaction_new_shader_adds_and_swaps", ok, "" if ok else "behavior_wrong: New shader did not both add a row and " f"swap the editor (count -> {n_after}, editor changed={swapped})", depth=1, jump_kind="value", expect="count 1 -> 2 and editor text changed") # ══════════════════════════════════════════════════════════════════════════════ # 6) 3-step data sequence: Load sample "Circles" -> new shader + editor replaced # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_load_sample_circles", "interaction_load_sample_circles_vlm")) def test_load_sample_circles(): clear_data() if not launch_editor(): record("interaction_load_sample_circles", False, "setup_failed: could not reach the editor", depth=2, jump_kind="value", expect="editor replaced by sample source, count 1 -> 2") return before = editor_text() if not and_enter_load_sample(): record("interaction_load_sample_circles", False, "feature_missing: no Load sample path", depth=2, jump_kind="value", expect="editor replaced by sample source, count 1 -> 2") return if not tap_list_row("Circles"): record("interaction_load_sample_circles", False, "feature_missing: no 'Circles' sample row", depth=2, jump_kind="value", expect="editor replaced by sample source, count 1 -> 2") return wait_for_foreground() after = editor_text() swapped = after != before and len(after) > 0 if not open_drawer_and_reach(): record("interaction_load_sample_circles", False, "setup_failed: could not open the drawer", depth=2, jump_kind="value", expect="editor replaced by sample source, count 1 -> 2") return n_after = shader_count() ok = swapped and n_after == 2 record("interaction_load_sample_circles", ok, "" if ok else "behavior_wrong: Load sample did not replace the editor " f"and add a shader (count -> {n_after}, editor changed={swapped})", depth=2, jump_kind="value", expect="editor replaced by sample source, count 1 -> 2") # VLM: after loading, the code editor shows (colored) shader source code. vlm_assert("interaction_load_sample_circles", "Is the shader source in the code editor rendered with several " "distinct syntax-highlight colors (keywords/numbers in different " "colors), not a single flat color?", depth=2, jump_kind="value", tag="color") # ══════════════════════════════════════════════════════════════════════════════ # 7) SOLE-owned long-press: Rename shader writes the new title (data mutation) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_rename_via_longpress", "interaction_rename_via_longpress_vlm")) def test_rename_via_longpress(): clear_data() if not launch_editor(): record("interaction_rename_via_longpress", False, "setup_failed: could not reach the editor", depth=2, jump_kind="value", expect="drawer row titled 'kit_ren_A'") return # First prove the rename dialog renders (VLM), then complete the rename. field = and_enter_rename_dialog("Default") dialog_shown = field is not None vlm_assert("interaction_rename_via_longpress", "Is a dialog box titled 'Rename shader' shown, containing an " "editable text field and OK / Cancel buttons?", depth=2, jump_kind="value", tag="layout") if not dialog_shown: record("interaction_rename_via_longpress", False, "feature_missing: long-press did not open a Rename dialog", depth=2, jump_kind="value", expect="drawer row titled 'kit_ren_A'") return press_key("KEYCODE_MOVE_END") for _ in range(25): press_key(67) # clear the prefilled 'Default' settle("text") type_text(field, "kit_ren_A") ok_btn = node_by_id(ui(), "button1") # OK if ok_btn is not None: tap_node(ok_btn) settle("tap") settle("tap") if not open_drawer_and_reach(): record("interaction_rename_via_longpress", False, "setup_failed: could not reopen the drawer to verify", depth=2, jump_kind="value", expect="drawer row titled 'kit_ren_A'") return titles = shader_titles() ok = "kit_ren_A" in titles and "Default" not in titles record("interaction_rename_via_longpress", ok, "" if ok else f"behavior_wrong: rename not persisted (titles={titles})", depth=2, jump_kind="value", expect="drawer row titled 'kit_ren_A'") # ══════════════════════════════════════════════════════════════════════════════ # 8) Rename Cancel does NOT change the title # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_rename_cancel_noop",)) def test_rename_cancel_noop(): clear_data() if not launch_editor(): record("interaction_rename_cancel_noop", False, "setup_failed: could not reach the editor", depth=2, jump_kind="transition", expect="drawer row still 'Default' after Cancel") return field = and_enter_rename_dialog("Default") if field is None: record("interaction_rename_cancel_noop", False, "feature_missing: long-press did not open a Rename dialog", depth=2, jump_kind="transition", expect="drawer row still 'Default' after Cancel") return press_key("KEYCODE_MOVE_END") type_text(field, "SHOULD_NOT_STICK") cancel = node_by_id(ui(), "button2") # Cancel if cancel is None or not tap_node(cancel): record("interaction_rename_cancel_noop", False, "feature_missing: no Cancel button in the Rename dialog", depth=2, jump_kind="transition", expect="drawer row still 'Default' after Cancel") return settle("tap") settle("tap") if not open_drawer_and_reach(): record("interaction_rename_cancel_noop", False, "setup_failed: could not reopen the drawer to verify", depth=2, jump_kind="transition", expect="drawer row still 'Default' after Cancel") return titles = shader_titles() ok = "Default" in titles and "SHOULD_NOT_STICK" not in titles record("interaction_rename_cancel_noop", ok, "" if ok else f"behavior_wrong: Cancel changed the title (titles={titles})", depth=2, jump_kind="transition", expect="drawer row still 'Default' after Cancel") # ══════════════════════════════════════════════════════════════════════════════ # 9) Switch shaders via the drawer -> the editor reloads that shader's source # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_switch_shader_reloads_source",)) def test_switch_shader_reloads_source(): clear_data() if not launch_editor(): record("interaction_switch_shader_reloads_source", False, "setup_failed: could not reach the editor", depth=1, jump_kind="value", expect="editor source changes back to Default on switch") return default_src = editor_text() # Load "Circles" as a distinct 2nd shader so its source differs from Default. if not and_enter_load_sample() or not tap_list_row("Circles"): record("interaction_switch_shader_reloads_source", False, "setup_failed: could not create a second (Circles) shader", depth=1, jump_kind="value", expect="editor source changes back to Default on switch") return wait_for_foreground() circ_src = editor_text() if circ_src == default_src: record("interaction_switch_shader_reloads_source", False, "setup_failed: Circles source matched Default; cannot discriminate", depth=1, jump_kind="value", expect="editor source changes back to Default on switch") return if not open_drawer_and_reach(): record("interaction_switch_shader_reloads_source", False, "setup_failed: could not open the drawer", depth=1, jump_kind="value", expect="editor source changes back to Default on switch") return # Tap the "Default" row -> editor should reload the default source. default_row = None for n in ui(): if (n.get("resource-id", "").endswith("/shader_title") and n.get("text") == "Default" and "_center" in n): default_row = n break if default_row is None or not tap_node(default_row): record("interaction_switch_shader_reloads_source", False, "setup_failed: no 'Default' row to switch back to", depth=1, jump_kind="value", expect="editor source changes back to Default on switch") return settle("tap") settle("tap") back_src = editor_text() ok = (back_src != circ_src and "uniform float time" in back_src and "void main(void)" in back_src) record("interaction_switch_shader_reloads_source", ok, "" if ok else "behavior_wrong: switching rows did not reload the " "selected shader's source", depth=1, jump_kind="value", expect="editor source changes back to Default on switch") # ══════════════════════════════════════════════════════════════════════════════ # 10) MULTI-RECORD INTEGRITY: add 3, edit the middle, 1st & 3rd intact + ordered # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_multi_record_integrity",)) def test_multi_record_integrity(): clear_data() if not launch_editor(): record("interaction_multi_record_integrity", False, "setup_failed: could not reach the editor", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return # Build three shaders: Default + two "New shader"s. if not make_new_shader() or not make_new_shader(): record("interaction_multi_record_integrity", False, "feature_missing: could not create three shaders", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return if not open_drawer_and_reach(): record("interaction_multi_record_integrity", False, "setup_failed: could not open the drawer", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return start = shader_titles() if len(start) != 3: record("interaction_multi_record_integrity", False, f"feature_missing: expected 3 shaders, got {len(start)} ({start})", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return close_drawer() # Rename the three rows (top, middle, bottom) to stable markers. rename_row # opens its own drawer+dialog each time (depth via and_enter_rename_dialog) and # closes the drawer afterward. r1 = rename_row(start[0], "kit_A") r2 = rename_row(start[1], "kit_B") r3 = rename_row(start[2], "kit_C") if not (r1 and r2 and r3): record("interaction_multi_record_integrity", False, f"setup_failed: renames failed (A={r1} B={r2} C={r3})", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return if not open_drawer_and_reach(): record("interaction_multi_record_integrity", False, "setup_failed: could not verify the three renamed rows", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return seeded = shader_titles() seeded_ok = seeded == ["kit_A", "kit_B", "kit_C"] close_drawer() # Edit ONLY the middle record: kit_B -> kit_B2. if not rename_row("kit_B", "kit_B2"): record("interaction_multi_record_integrity", False, "behavior_wrong: could not edit the middle record", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return if not open_drawer_and_reach(): record("interaction_multi_record_integrity", False, "setup_failed: could not read back the final list", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") return final = shader_titles() # 1st and 3rd untouched AND still first/last; middle updated; old middle gone; # exactly three rows (a recreation that recreated one row fails here). ok = (seeded_ok and len(final) == 3 and final[0] == "kit_A" and final[-1] == "kit_C" and "kit_B2" in final and "kit_B" not in final) record("interaction_multi_record_integrity", ok, "" if ok else "behavior_wrong: multi-record integrity broke " f"(seeded={seeded}, final={final})", depth=2, jump_kind="value", expect="[kit_A, kit_B2, kit_C] with A first and C last") # ══════════════════════════════════════════════════════════════════════════════ # 11) PERSISTENCE across process death — the highest-value tests # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_duplicate_survives_kill",)) def test_duplicate_survives_process_death(): """Save-as-new, then force_stop + relaunch: the extra shader row must remain. An in-memory-only recreation cannot pass this.""" clear_data() if not launch_editor(): record("interaction_duplicate_survives_kill", False, "setup_failed: could not reach the editor", depth=1, jump_kind="value", expect="drawer still shows 2 shaders after relaunch") return if not make_duplicate(): record("interaction_duplicate_survives_kill", False, "feature_missing: no 'Save as new shader' control", depth=1, jump_kind="value", expect="drawer still shows 2 shaders after relaunch") return if not open_drawer_and_reach(): record("interaction_duplicate_survives_kill", False, "setup_failed: could not open the drawer before the kill", depth=1, jump_kind="value", expect="drawer still shows 2 shaders after relaunch") return n_before = shader_count() # Kill the process and relaunch through the portable editor launcher. force_stop() settle("key") if not launch_editor(): record("interaction_duplicate_survives_kill", False, "setup_failed: could not relaunch the editor after force-stop", depth=1, jump_kind="value", expect="drawer still shows 2 shaders after relaunch") return if not open_drawer_and_reach(): record("interaction_duplicate_survives_kill", False, "setup_failed: could not open the drawer after relaunch", depth=1, jump_kind="value", expect="drawer still shows 2 shaders after relaunch") return n_after = shader_count() ok = n_before == 2 and n_after == 2 record("interaction_duplicate_survives_kill", ok, "" if ok else "behavior_wrong: duplicated shader did not survive " f"process death (count before kill={n_before}, after={n_after})", depth=1, jump_kind="value", expect="drawer still shows 2 shaders after relaunch") @and_test(expects=("interaction_rename_survives_kill",)) def test_rename_survives_process_death(): """Rename Default -> kit_persist, force_stop + relaunch: the row keeps the new name. Proves the rename is a durable DB write, not a transient view label.""" clear_data() if not launch_editor(): record("interaction_rename_survives_kill", False, "setup_failed: could not reach the editor", depth=1, jump_kind="value", expect="drawer row 'kit_persist' after relaunch") return if not rename_row("Default", "kit_persist"): record("interaction_rename_survives_kill", False, "setup_failed: could not rename the shader before the kill", depth=1, jump_kind="value", expect="drawer row 'kit_persist' after relaunch") return force_stop() settle("key") if not launch_editor(): record("interaction_rename_survives_kill", False, "setup_failed: could not relaunch the editor after force-stop", depth=1, jump_kind="value", expect="drawer row 'kit_persist' after relaunch") return if not open_drawer_and_reach(): record("interaction_rename_survives_kill", False, "setup_failed: could not open the drawer after relaunch", depth=1, jump_kind="value", expect="drawer row 'kit_persist' after relaunch") return titles = shader_titles() ok = "kit_persist" in titles and "Default" not in titles record("interaction_rename_survives_kill", ok, "" if ok else "behavior_wrong: rename did not survive process death " f"(titles after relaunch={titles})", depth=1, jump_kind="value", expect="drawer row 'kit_persist' after relaunch") @and_test(expects=("interaction_edit_saved_survives_kill", "interaction_edit_saved_survives_kill_vlm")) def test_edit_saved_survives_process_death(): """Type a marker into the editor, EXPLICITLY Save shader (a hard force-stop kills the process before onPause auto-save flushes — verified on the original), then force_stop + relaunch: the marker is still in the source.""" clear_data() if not launch_editor(): record("interaction_edit_saved_survives_kill", False, "setup_failed: could not reach the editor", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") return ed = node_by_id(ui(), "editor") before = editor_text() absent_before = "//SAVE99" not in before if ed is None or not tap_node(ed): record("interaction_edit_saved_survives_kill", False, "setup_failed: could not focus the editor", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") return settle("keyboard") press_key("KEYCODE_MOVE_END") ed = node_by_id(ui(), "editor") or ed type_text(ed, "//SAVE99") typed = editor_text() if "//SAVE99" not in typed: record("interaction_edit_saved_survives_kill", False, "setup_failed: marker did not type into the editor", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") return # Explicit Save shader -> transient "Shader saved" toast (VLM below). if not open_menu(): record("interaction_edit_saved_survives_kill", False, "setup_failed: could not open the menu to Save", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") return save_btn = node_by_id(ui(), "save_shader") if save_btn is None: record("interaction_edit_saved_survives_kill", False, "feature_missing: no 'Save shader' control", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") return tap_node(save_btn) # The toast shows immediately and is transient; capture it before it fades. vlm_assert("interaction_edit_saved_survives_kill", "Is a small popup message that says 'Shader saved' (or similar) " "visible near the bottom of the screen?", depth=0, jump_kind="value", tag="content") settle("tap") force_stop() settle("key") if not launch_editor(): record("interaction_edit_saved_survives_kill", False, "setup_failed: could not relaunch the editor after force-stop", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") return after = editor_text() ok = absent_before and "//SAVE99" in after record("interaction_edit_saved_survives_kill", ok, "" if ok else "behavior_wrong: saved editor edit did not survive " "process death", depth=0, jump_kind="value", expect="editor still contains '//SAVE99' after relaunch") # ══════════════════════════════════════════════════════════════════════════════ # 12) Selected-row highlight (VLM only — a rendered background tint the tree does # not cleanly expose). Paired with the multi-shader data setup. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_selected_row_highlight_vlm",)) def test_selected_row_highlight_vlm(): clear_data() if not launch_editor(): record("interaction_selected_row_highlight_vlm", False, "setup_failed: could not reach the editor", depth=1, jump_kind="none", tag="color") return # Two shaders so one row can be the selected/highlighted one. if not make_duplicate(): record("interaction_selected_row_highlight_vlm", False, "feature_missing: could not create a second shader", depth=1, jump_kind="none", tag="color") return if not open_drawer_and_reach(): record("interaction_selected_row_highlight_vlm", False, "setup_failed: could not open the drawer", depth=1, jump_kind="none", tag="color") return vlm_assert("interaction_selected_row_highlight", "In the navigation drawer's list of shaders, is exactly ONE row " "visually highlighted or tinted with a different background color " "than the other row(s)?", depth=1, jump_kind="transition", tag="color") TESTS = [ test_add_uniform_inserts_text, test_add_uniform_date_vec4, test_extra_key_brace_insert, test_extra_key_paren_insert, test_type_into_editor, test_duplicate_adds_shader, test_new_shader_adds_and_swaps, test_load_sample_circles, test_rename_via_longpress, test_rename_cancel_noop, test_switch_shader_reloads_source, test_multi_record_integrity, test_duplicate_survives_process_death, test_rename_survives_process_death, test_edit_saved_survives_process_death, test_selected_row_highlight_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, "interaction")