#!/usr/bin/env python3 """STRUCTURE-lane suite for EasyNotes (Jetpack Compose notes app). This lane owns exactly two things: 1. THE GATE — the app launches, is foreground, and its top-level surfaces exist (Home = Search + Settings + New Note; an editor surface; the Settings list). These are jump_kind="none" and kept a small minority of the file. 2. TREE-SHAPE DELTAS — an interaction that changes the SHAPE of the view tree: a new class of widget appears, a dropdown/overlay adds a window layer, a top-bar region swaps its children. Recorded via surface_changed() or a numeric widget-class count delta, as jump_kind="transition", and reversed to assert restoration. Everything else (the TEXT of an element, a checked/selected value, a computed count, exact reachability naming) is CEDED to the other lanes. Compose quirks honoured (see recon.md): widgets carry no stable resource-id and no Switch/Button subclass; there is NO ViewGroup in the tree (the container is a FrameLayout / ComposeView). Switches are android.view.View with checkable="true". The '&' in "Colors & Styles" arrives HTML-escaped as "Colors & Styles", so that row is tapped via its subtitle. The dump is stale mid-animation — re-ui() after every state change. VLM ORDERING RULE followed throughout: every vlm_assert is taken while the CHANGED surface is still on screen — i.e. AFTER the trigger but BEFORE the reversal step — otherwise the screenshot would show the restored (Home) surface. """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,E402 # ── local helpers (NOT kit re-implementations — thin, app-specific glue) ──────── def _text_contains(nodes, needle): """Case-insensitive substring match on text OR content-desc. Needed because the kit's find_node_ci is EXACT and "Colors & Styles" is stored escaped as "Colors & Styles" in the raw dump.""" n = needle.strip().lower() for node in nodes: blob = (node.get("text", "") + " " + node.get("content-desc", "")).lower() if n in blob: return node return None def _n_checkable(nodes): """Count switch-like widgets: Compose renders them as checkable Views.""" return len(find_nodes(nodes, checkable=True)) def _home_container(nodes): """The top-level Compose host / main container on Home. Compose has no ViewGroup, so accept the FrameLayout root or the ComposeView.""" return (find_by_class(nodes, "FrameLayout") or find_by_class(nodes, "ComposeView")) def and_enter_editor(): """Navigate Home -> Edit (New Note FAB) and count one surface. Backs a declared depth>=1 for editor-shape tests.""" ok, _note = and_enter_surface(ui(), content_desc="New Note") return ok def and_enter_settings(): """Navigate Home -> Settings list and count one surface.""" ok, _note = and_enter_surface(ui(), content_desc="Settings") return ok def and_enter_preview_of(title): """Navigate Home -> Preview of the named card and count one surface.""" card = find_node_ci(ui(), title) or _text_contains(ui(), title) if not card: return False before = and_showing() if not tap_node(card): return False after = and_showing() if not surface_changed(before, after): return False and_enter("preview") return True def and_enter_colors(): """Navigate Settings -> Colors & Styles (tapped via its subtitle, because the title contains an escaped '&') and count one surface.""" row = _text_contains(ui(), "Themes") # "Themes • Size • Font" if not row: return False before = and_showing() if not tap_node(row): return False after = and_showing() if not surface_changed(before, after): return False and_enter("colors") return True def _seed_note(name="Groceries", body="Milk Eggs Bread"): """Create one note through the GUI so card/preview/selection tests have a subject. Returns True on success. Leaves the app on Home.""" tap_node(find_node(ui(), content_desc="New Note")) ets = find_by_class(ui(), "EditText") if len(ets) < 2: return False type_text(ets[0], name) ets = find_by_class(ui(), "EditText") type_text(ets[1], body) hide_keyboard() done = find_node(ui(), content_desc="Done") if done: tap_node(done) return bool(find_node_ci(ui(), name) or _text_contains(ui(), name)) # ══════════════════════════════════════════════════════════════════════════════ # GATE (jump_kind="none", depth=0) — kept a minority of the file # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("structure_gate_launch", "structure_gate_home_vlm")) def test_gate_launch(): """Home launches, is foreground, and shows its three discriminating top-level controls (Search, Settings, New Note) inside a main container.""" restart_app() ok_fg = wait_for_foreground() nodes = ui() container = bool(_home_container(nodes)) has_search = bool(find_node(nodes, content_desc="Search")) has_settings = bool(find_node(nodes, content_desc="Settings")) has_fab = bool(find_node(nodes, content_desc="New Note")) ok = ok_fg and container and has_search and has_settings and has_fab record("structure_gate_launch", bool(ok), "" if ok else ("setup_failed: app did not reach a Home surface with a " f"container+Search+Settings+New Note (fg={ok_fg}, " f"container={container}, search={has_search}, " f"settings={has_settings}, fab={has_fab})"), depth=0, jump_kind="none", expect="Home shows a main container + Search + Settings + New Note") vlm_assert("structure_gate_home", "Is there a rounded search bar spanning nearly the full width " "across the TOP of the screen, and a filled dark pill-shaped " "button in the BOTTOM-RIGHT corner?", RESULTS_DIR, depth=0, jump_kind="none", tag="position") @and_test(expects=("structure_gate_empty_placeholder", "structure_gate_empty_vlm")) def test_gate_empty_state(): """A virgin install (no notes) shows the empty-state placeholder region: a placeholder icon plus its caption exist as top-level elements.""" clear_data() restart_app() ok_fg = wait_for_foreground() nodes = ui() icon = bool(find_node(nodes, content_desc="Placeholder icon")) caption = bool(find_node_ci(nodes, "No created notes.")) ok = ok_fg and (icon or caption) record("structure_gate_empty_placeholder", bool(ok), "" if ok else "feature_missing: empty-state placeholder region absent", depth=0, jump_kind="none", expect="Empty Home shows a placeholder icon + caption") vlm_assert("structure_gate_empty", "Is there a single small icon centered horizontally in the MIDDLE " "of an otherwise blank screen, with one short line of grey caption " "text directly BELOW it, and no note cards anywhere?", RESULTS_DIR, depth=0, jump_kind="none", tag="position") @and_test(expects=("structure_gate_editor_exists",)) def test_gate_editor_surface_exists(): """The note-editor surface exists: opening New Note yields a surface with two EditText fields plus Back+Done controls (structural existence of the editor, not its content).""" clear_data() restart_app() wait_for_foreground() entered = and_enter_editor() nodes = ui() n_edit = len(find_by_class(nodes, "EditText")) has_done = bool(find_node(nodes, content_desc="Done")) has_back = bool(find_node(nodes, content_desc="Back")) ok = entered and n_edit >= 2 and has_done and has_back record("structure_gate_editor_exists", bool(ok), "" if ok else ("feature_missing: editor surface lacks 2 EditText + " f"Done + Back (edits={n_edit}, done={has_done}, " f"back={has_back})"), depth=1, jump_kind="none", expect="Editor surface has 2 EditText fields + Back + Done") # ══════════════════════════════════════════════════════════════════════════════ # SHAPE DELTAS (jump_kind="transition", mandatory expect=, reversed to restore) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("structure_editor_replaces_home", "structure_editor_vlm")) def test_new_note_changes_tree_shape(): """Tapping New Note materially changes the tree SHAPE (editor surface replaces Home); pressing Back restores the Home shape.""" clear_data() restart_app() wait_for_foreground() before = and_showing(ui()) entered = and_enter_editor() after = and_showing(ui()) changed = surface_changed(before, after) # VLM while the editor surface is STILL on screen (before the reversal) vlm_assert("structure_editor", "Below the top bar, are there two separate rounded-corner boxes " "stacked vertically — a SHORT box at the top labelled 'Name' and a " "much TALLER box below it labelled 'Description'?", RESULTS_DIR, depth=1, jump_kind="transition", tag="shape") # reverse: leave the editor, Home shape must come back and_back() restored = surface_changed(after, and_showing(ui())) ok = entered and changed and restored record("structure_editor_replaces_home", bool(ok), "" if ok else ("behavior_wrong: opening/closing the editor did not " f"change then restore the tree shape (changed={changed}, " f"restored={restored})"), depth=1, jump_kind="transition", expect="Home surface -> editor surface on New Note, restored on Back") @and_test(expects=("structure_editor_toggle_pill_vlm",)) def test_editor_toggle_pill_centered(): """The Edit/Preview toggle pill is centered in the editor top bar (purely a rendered-layout fact, VLM-only).""" clear_data() restart_app() wait_for_foreground() entered = and_enter_editor() if not entered: record("structure_editor_toggle_pill_vlm", False, "setup_failed: could not open the editor", depth=1, jump_kind="transition", expect="Edit/Preview pill centered in the top bar", tag="position") return vlm_assert("structure_editor_toggle_pill", "In the top bar, is there a small rounded pill containing two icons " "(a pencil and an eye) positioned in the horizontal CENTER, with a " "single icon at the far left and a single icon at the far right of " "the same bar?", RESULTS_DIR, depth=1, jump_kind="transition", tag="position") @and_test(expects=("structure_markdown_toolbar_appears", "structure_markdown_toolbar_vlm")) def test_description_focus_reveals_toolbar(): """Focusing the Description field ADDS the markdown-toolbar row (a new class of icon buttons: Bullet List / Checkbox / Insert Image, plus Undo/Redo) — a shape delta. Dismissing focus removes it again.""" clear_data() restart_app() wait_for_foreground() entered = and_enter_editor() before = and_showing(ui()) had_toolbar_before = bool(find_node(ui(), content_desc="Bullet List")) # focus the Description field (second EditText, the tall one) ets = find_by_class(ui(), "EditText") focused_ok = False if len(ets) >= 2: focused_ok = tap_node(ets[1]) settle("keyboard") after = and_showing(ui()) has_toolbar = bool(find_node(ui(), content_desc="Bullet List")) changed = surface_changed(before, after) # VLM while the toolbar row is STILL on screen (before we blur it away) vlm_assert("structure_markdown_toolbar", "Is there a single horizontal ROW of small evenly-spaced icon " "buttons stretched across the width of the screen, sitting just " "ABOVE the on-screen keyboard?", RESULTS_DIR, depth=1, jump_kind="transition", tag="layout") # reverse: dismiss the keyboard/focus -> toolbar should disappear hide_keyboard() gone = not bool(find_node(ui(), content_desc="Bullet List")) ok = (entered and focused_ok and not had_toolbar_before and has_toolbar and changed and gone) record("structure_markdown_toolbar_appears", bool(ok), "" if ok else ("behavior_wrong: markdown toolbar did not appear on " f"Description focus and vanish on blur " f"(before={had_toolbar_before}, after={has_toolbar}, " f"changed={changed}, gone={gone})"), depth=1, jump_kind="transition", expect="Bullet List/Checkbox/Insert Image toolbar row appears on " "Description focus, removed on blur") @and_test(expects=("structure_selection_bar_swaps", "structure_selection_bar_vlm")) def test_long_press_swaps_top_bar(): """Long-pressing a note card swaps the Home top bar's SHAPE: the Search+Settings region is replaced by a selection bar (Close / Pin / Delete). Closing it restores the Home top bar.""" clear_data() restart_app() wait_for_foreground() if not _seed_note(): record("structure_selection_bar_swaps", False, "setup_failed: could not seed a note to long-press", depth=0, jump_kind="transition", expect="Search/Settings top bar -> Close/Pin/Delete selection bar") record("structure_selection_bar_vlm", False, "setup_failed: could not seed a note to long-press", depth=0, jump_kind="none", tag="position") return home = ui() before = and_showing(home) had_search = bool(find_node(home, content_desc="Search")) card = find_node_ci(home, "Groceries") or _text_contains(home, "Groceries") pressed = long_press(card) if card else False sel = ui() after = and_showing(sel) has_close = bool(find_node(sel, content_desc="Close")) has_delete = bool(find_node(sel, content_desc="Delete")) search_gone = not bool(find_node(sel, content_desc="Search")) changed = surface_changed(before, after) # VLM while the selection bar is STILL on screen (before Close) vlm_assert("structure_selection_bar", "Is the top bar now showing a close (X) icon next to a number at " "the far LEFT, and two action icons (a pin and a trash/delete " "icon) grouped at the far RIGHT of the same bar?", RESULTS_DIR, depth=0, jump_kind="none", tag="position") # reverse: Close exits selection, Home top bar returns close = find_node(ui(), content_desc="Close") if close: tap_node(close) restored = bool(find_node(ui(), content_desc="Search")) ok = (pressed and had_search and has_close and has_delete and search_gone and changed and restored) record("structure_selection_bar_swaps", bool(ok), "" if ok else ("behavior_wrong: long-press did not swap the top bar to a " f"selection bar and back (close={has_close}, " f"delete={has_delete}, search_gone={search_gone}, " f"changed={changed}, restored={restored})"), depth=0, jump_kind="transition", expect="Search/Settings top bar -> Close/Pin/Delete selection bar, " "restored on Close") @and_test(expects=("structure_selection_highlight_vlm",)) def test_selected_card_highlight(): """A selected card gains a highlighted (accent) border — a rendered property invisible to the dump, so VLM-only.""" clear_data() restart_app() wait_for_foreground() if not _seed_note(): record("structure_selection_highlight_vlm", False, "setup_failed: could not seed a note", depth=0, jump_kind="none", tag="color") return card = find_node_ci(ui(), "Groceries") or _text_contains(ui(), "Groceries") if not (card and long_press(card)): record("structure_selection_highlight_vlm", False, "setup_failed: could not enter selection mode", depth=0, jump_kind="none", tag="color") return vlm_assert("structure_selection_highlight", "Does the single note card near the top of the screen have a " "visible colored (blue/dark) OUTLINE border drawn around all four " "of its edges?", RESULTS_DIR, depth=0, jump_kind="none", tag="color") @and_test(expects=("structure_more_menu_overlay", "structure_more_menu_vlm")) def test_more_menu_adds_overlay(): """Opening the More menu in Preview adds a dropdown overlay layer (Delete / Pinned / Copy / Information appear on top of the note) — a shape delta. BACK dismisses the overlay and restores the Preview shape.""" clear_data() restart_app() wait_for_foreground() if not _seed_note(): record("structure_more_menu_overlay", False, "setup_failed: could not seed a note", depth=1, jump_kind="transition", expect="More dropdown overlay adds Copy/Information/Pinned rows") record("structure_more_menu_vlm", False, "setup_failed: could not seed a note", depth=1, jump_kind="none", tag="position") return entered = and_enter_preview_of("Groceries") pv = ui() before = and_showing(pv) info = find_node(pv, content_desc="Info") tapped = tap_node(info) if info else False mn = ui() after = and_showing(mn) # count NON-destructive menu items appearing (avoid keying on "Delete" text) appeared = sum(bool(find_node_ci(mn, t)) for t in ("Copy", "Information", "Pinned")) changed = surface_changed(before, after) # VLM while the dropdown overlay is STILL on screen (before we dismiss it) vlm_assert("structure_more_menu", "Is there a small rectangular pop-up menu floating over the " "top-RIGHT area of the screen, containing a vertical stack of rows " "where each row has an icon on the left and a short text label to " "its right?", RESULTS_DIR, depth=1, jump_kind="none", tag="position") # reverse: dismiss the dropdown back() settle("tap") restored = surface_changed(after, and_showing(ui())) ok = entered and tapped and appeared >= 3 and changed and restored record("structure_more_menu_overlay", bool(ok), "" if ok else ("behavior_wrong: More menu did not add a dropdown overlay " f"and dismiss it (appeared={appeared}/3, changed={changed}, " f"restored={restored})"), depth=1, jump_kind="transition", expect="More dropdown overlay adds Copy/Information/Pinned rows, " "dismissed on BACK") @and_test(expects=("structure_search_trailing_swap",)) def test_search_swaps_trailing_control(): """Typing into the Search bar changes the top-bar SHAPE: the trailing Settings gear is replaced by a Clear (X) control. Clearing restores the gear.""" clear_data() restart_app() wait_for_foreground() if not _seed_note(): record("structure_search_trailing_swap", False, "setup_failed: could not seed a note", depth=0, jump_kind="transition", expect="Settings gear -> Clear control while a query is present") return home = ui() before = and_showing(home) had_gear = bool(find_node(home, content_desc="Settings")) sb = find_by_class(home, "EditText") typed = False if sb: typed = type_text(sb[0], "zzqqzz") after = and_showing(ui()) has_clear = bool(find_node(ui(), content_desc="Clear")) gear_gone = not bool(find_node(ui(), content_desc="Settings")) changed = surface_changed(before, after) # reverse: tap Clear -> gear returns clr = find_node(ui(), content_desc="Clear") if clr: tap_node(clr) hide_keyboard() restored = bool(find_node(ui(), content_desc="Settings")) ok = (typed and had_gear and has_clear and gear_gone and changed and restored) record("structure_search_trailing_swap", bool(ok), "" if ok else ("behavior_wrong: search input did not swap the trailing " f"gear for a Clear control and back (clear={has_clear}, " f"gear_gone={gear_gone}, changed={changed}, " f"restored={restored})"), depth=0, jump_kind="transition", expect="Settings gear -> Clear (X) while a query is present, restored " "when cleared") @and_test(expects=("structure_settings_list_exists", "structure_settings_list_vlm")) def test_settings_list_shape(): """Navigating Home -> Settings replaces Home with a Settings surface that contains multiple section rows (structural: >=6 named section containers).""" clear_data() restart_app() wait_for_foreground() before = and_showing(ui()) entered = and_enter_settings() st = ui() after = and_showing(st) sections = sum(bool(_text_contains(st, s)) for s in ("Support", "Behavior", "Language", "Backup", "Privacy", "Tools", "About")) home_gone = not bool(find_node(st, content_desc="Search")) changed = surface_changed(before, after) ok = entered and sections >= 6 and home_gone and changed record("structure_settings_list_exists", bool(ok), "" if ok else ("feature_missing: Settings surface lacks >=6 section rows " f"or Home did not leave (sections={sections}, " f"home_gone={home_gone}, changed={changed})"), depth=1, jump_kind="transition", expect="Settings surface shows >=6 section rows, Home surface gone") vlm_assert("structure_settings_list", "Is the screen a vertical LIST of rounded rectangular section " "cards stacked top-to-bottom, each row with a title text on the " "left and a circular icon on the right?", RESULTS_DIR, depth=1, jump_kind="transition", tag="layout") @and_test(expects=("structure_colors_adds_switches", "structure_colors_switches_vlm")) def test_colors_screen_adds_switches(): """DEPTH-2 shape delta: Home -> Settings (0 switch widgets in the list) -> Colors & Styles reveals a class of switch widgets (>=5 checkable Views). The Settings list itself has none, so the delta is real and attributable to entering Colors.""" clear_data() restart_app() wait_for_foreground() entered_settings = and_enter_settings() # depth 1 st = ui() switches_on_list = _n_checkable(st) entered_colors = and_enter_colors() # depth 2 col = ui() switches_on_colors = _n_checkable(col) left_settings = not bool(_text_contains(col, "Screen Protection")) delta_ok = switches_on_list == 0 and switches_on_colors >= 5 ok = entered_settings and entered_colors and delta_ok and left_settings record("structure_colors_adds_switches", bool(ok), "" if ok else ("behavior_wrong: Colors screen did not add a class of " f"switch widgets over the Settings list " f"(list={switches_on_list}, colors={switches_on_colors}, " f"left_settings={left_settings})"), depth=2, jump_kind="transition", expect="Settings list has 0 switches; Colors & Styles surface has >=5 " "checkable switch widgets") vlm_assert("structure_colors_switches", "Are there multiple settings rows each with a small toggle SWITCH " "control aligned along the RIGHT edge of the screen?", RESULTS_DIR, depth=2, jump_kind="transition", tag="position") @and_test(expects=("structure_behavior_adds_switches",)) def test_behavior_screen_adds_switches(): """DEPTH-2 shape delta on a DIFFERENT settings subscreen: Behavior reveals its own class of switch widgets (>=5 checkable Views) that the Settings list lacks.""" clear_data() restart_app() wait_for_foreground() entered_settings = and_enter_settings() # depth 1 st = ui() switches_on_list = _n_checkable(st) row = _text_contains(st, "Support • Images") # Behavior subtitle entered_behavior = False if row: before = and_showing(st) if tap_node(row) and surface_changed(before, and_showing(ui())): and_enter("behavior") # depth 2 entered_behavior = True beh = ui() switches_on_behavior = _n_checkable(beh) delta_ok = switches_on_list == 0 and switches_on_behavior >= 5 ok = entered_settings and entered_behavior and delta_ok record("structure_behavior_adds_switches", bool(ok), "" if ok else ("behavior_wrong: Behavior screen did not add a class of " f"switch widgets over the Settings list " f"(list={switches_on_list}, behavior={switches_on_behavior})"), depth=2, jump_kind="transition", expect="Settings list has 0 switches; Behavior surface has >=5 " "checkable switch widgets") @and_test(expects=("structure_settings_scroll_vlm",)) def test_settings_grouped_layout_vlm(): """The Settings list groups its section cards with a distinct highlighted Support banner on top — a rendered grouping fact (VLM-only, layout).""" clear_data() restart_app() wait_for_foreground() entered = and_enter_settings() if not entered: record("structure_settings_scroll_vlm", False, "setup_failed: could not open Settings", depth=1, jump_kind="none", tag="layout") return vlm_assert("structure_settings_scroll", "At the TOP of the settings list, is there a single wide banner " "card that is visually distinct (darker / gradient filled) from " "the plain light-grey section cards listed below it?", RESULTS_DIR, depth=1, jump_kind="none", tag="layout") # ── suite ─────────────────────────────────────────────────────────────────────── TESTS = [ test_gate_launch, test_gate_empty_state, test_gate_editor_surface_exists, test_new_note_changes_tree_shape, test_editor_toggle_pill_centered, test_description_focus_reveals_toolbar, test_long_press_swaps_top_bar, test_selected_card_highlight, test_more_menu_adds_overlay, test_search_swaps_trailing_control, test_settings_list_shape, test_colors_screen_adds_switches, test_behavior_screen_adds_switches, test_settings_grouped_layout_vlm, ] if __name__ == "__main__": run_suite(TESTS, "structure")