File size: 28,019 Bytes
c1c6a0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#!/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")