File size: 30,624 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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
"""STRUCTURE module for openScale — the GATE + tree-SHAPE deltas.

This lane owns exactly two things:
  1. The gate: the app launches and its top-level Overview surface exists
     (main container + the drawer/nav host "Open menu"). jump_kind="none", depth 0.
  2. Tree-SHAPE deltas: an interaction changes the *shape* of the view tree
     (node counts / a new region/surface appears), asserted by surface_changed /
     a node-count delta — never by content strings, checked-state, values, focus,
     or reachability-as-content (those belong to other lanes).

A new surface appearing is itself a tree-SHAPE change, so surface-crossing
records here are jump_kind="transition" (not "reach"): every test relaunches the
app for isolation, and a "reach" that includes a relaunch is not honest
navigation. depth>=1 claims are backed by file-local and_enter_* helpers.

Every test opens its own entry point via restart_app()/clear_data(); nothing
depends on a previous test. VLM budget for this file: 8 vlm_assert records,
spent on genuinely visual LAYOUT facts that a blank screen would fail.
"""

import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import *          # noqa: F403,F401


# ─────────────────────────────────────────────────────────────────────────────
# Shared navigation helpers. Each one performs a real navigation AND calls
# and_enter(...) so that any depth>=1 claim is backed for the depth auditor.
# ─────────────────────────────────────────────────────────────────────────────

def _create_user():
    """From a virgin Overview ("No User Active"), create a minimal user so the
    core UI (New Measurement etc.) becomes reachable. Returns True on success.
    Follows the recon recipe: type Name + Height=180 into the first two
    EditTexts sorted by y, then tap the top-right Save Button directly (no
    hide_keyboard(), which would BACK out of the form and lose the entry)."""
    au = find_node_ci(ui(), "Add User")
    if not au:
        return False
    tap_node(au); settle("tap")
    ets = sorted(find_by_class(ui(), "EditText"),
                 key=lambda n: n.get("_bounds", [0, 0, 0, 0])[1])
    if len(ets) < 2:
        return False
    type_text(ets[0], "Tester")
    ets = sorted(find_by_class(ui(), "EditText"),
                 key=lambda n: n.get("_bounds", [0, 0, 0, 0])[1])
    type_text(ets[1], "180")
    # Save = the single clickable Button in the top-right of the TopAppBar
    # (has no content-desc on the User form), located by position.
    nodes = ui()
    save = [n for n in nodes
            if n.get("_bounds") and n["_bounds"][0] > 800 and n["_bounds"][1] < 300
            and n.get("clickable") == "true"]
    if not save:
        return False
    tap_node(save[0]); settle("tap"); settle("tap")
    return find_node_ci(ui(), "Add Measurement") is not None


def _set_dialog_value(val):
    """PROVEN-RELIABLE numeric entry (recon recipe, used verbatim). A
    NumberInputDialog must already be open. Clears the appended default, then
    types one char at a time. Returns the field's resulting text so the caller
    can verify it == str(val)."""
    c = find_node_ci(ui(), "Clear")
    if c:
        tap_node(c); settle("keyboard")
    ets = find_by_class(ui(), "EditText")
    if not ets:
        return ""
    tap_node(ets[0]); settle("keyboard"); settle("keyboard")
    for ch in str(val):
        adb_shell("input", "text", ch); settle("text")
    settle("text")
    ets = find_by_class(ui(), "EditText")
    return ets[0].get("text", "") if ets else ""


def and_enter_measurement():
    """Overview (user exists) → New Measurement. Backs depth>=1."""
    add = find_node(ui(), content_desc="Add new measurement")
    if not add:
        return False
    tap_node(add); settle("tap"); settle("tap")
    ok = find_node(ui(), content_desc="Save measurement") is not None
    if ok:
        and_enter("measurement")
    return ok


def and_enter_settings():
    """Overview → (drawer) → Settings. Backs depth>=1."""
    om = find_node(ui(), content_desc="Open menu")
    if not om:
        return False
    tap_node(om); settle("tap")
    st = find_node_ci(ui(), "Settings")
    if not st:
        return False
    tap_node(st); settle("tap"); settle("tap")
    ok = find_node(ui(), text="Settings") is not None
    if ok:
        and_enter("settings")
    return ok


def and_enter_charts():
    """Overview → (drawer) → Charts. Backs depth>=1."""
    om = find_node(ui(), content_desc="Open menu")
    if not om:
        return False
    tap_node(om); settle("tap")
    ch = find_node_ci(ui(), "Charts")
    if not ch:
        return False
    tap_node(ch); settle("tap"); settle("tap")
    ok = find_node(ui(), text="Charts") is not None
    if ok:
        and_enter("charts")
    return ok


def and_enter_edit_dialog():
    """New Measurement → tap "Edit Weight" → NumberInputDialog. Backs depth>=2
    (caller must already be on New Measurement, i.e. one and_enter deep)."""
    ew = find_node(ui(), content_desc="Edit Weight")
    if not ew:
        return False
    tap_node(ew); settle("tap"); settle("tap")
    ok = find_node_ci(ui(), "Clear") is not None
    if ok:
        and_enter("edit_dialog")
    return ok


def _save_weight_measurement(val="80"):
    """From New Measurement (already open): set Weight=val via the reliable
    recipe and confirm with OK — which CLOSES the dialog itself (no Back), so we
    remain on New Measurement — then tap Save. openScale's Save auto-navigates
    back to Overview. Returns True iff the field held the value AND a populated
    Overview (per-entry Edit/Delete controls) is showing."""
    ew = find_node(ui(), content_desc="Edit Weight")
    if not ew:
        return False
    tap_node(ew); settle("tap"); settle("tap")
    if find_node_ci(ui(), "Clear") is None:
        return False
    got = _set_dialog_value(val)
    ok = find_node_ci(ui(), "OK")
    if ok:
        tap_node(ok); settle("tap")            # OK dismisses the dialog
    save = find_node(ui(), content_desc="Save measurement")
    if not save or got != str(val):            # value not held -> no value row
        return False
    tap_node(save); settle("tap"); settle("tap")
    nodes = ui()
    return any(n.get("content-desc", "").startswith("Edit measurement from ")
               for n in nodes)


# ─────────────────────────────────────────────────────────────────────────────
# (1) THE GATE — the only legitimate jump_kind="none" existence records.
# ─────────────────────────────────────────────────────────────────────────────

@and_test(expects=("structure_gate_launch",))
def test_gate_launch():
    """App launches and reaches the foreground with a real view tree."""
    and_reset_depth()
    clear_data()
    restart_app()
    fg = wait_for_foreground()
    nodes = ui()
    # A live Compose surface always has a top-level container + several Views.
    container = bool(find_by_class(nodes, "FrameLayout")
                     or find_by_class(nodes, "ViewGroup"))
    ok = bool(fg) and container and len(nodes) >= 5
    record("structure_gate_launch", ok,
           "" if ok else "setup_failed: app did not reach the foreground with a view tree",
           depth=0, jump_kind="none")


@and_test(expects=("structure_gate_overview_surface",))
def test_gate_overview_surface():
    """The top-level Overview surface exists: its TopAppBar nav host
    ("Open menu") plus the Overview title and the empty-state entry point.
    Existence of the app's home surface — the gate. jump_kind="none"."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    nodes = ui()
    nav_host = find_node(nodes, content_desc="Open menu")          # drawer host
    title = find_node(nodes, text="Overview")                      # screen title
    entry = find_node_ci(nodes, "Add User")                        # empty-state CTA
    ok = bool(nav_host) and bool(title) and bool(entry)
    record("structure_gate_overview_surface", ok,
           "" if ok else "feature_missing: Overview surface / nav host absent",
           depth=0, jump_kind="none")


# ─────────────────────────────────────────────────────────────────────────────
# (2) TREE-SHAPE DELTAS.  A new surface appearing == a shape change => transition.
# ─────────────────────────────────────────────────────────────────────────────

@and_test(expects=("structure_drawer_shape",))
def test_drawer_shape_delta():
    """Opening the navigation drawer changes the tree SHAPE materially (a whole
    side-sheet of menu Views is added), and closing it restores the shape.
    Asserted as a surface delta, not by naming any drawer label. depth=1."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    before = and_showing(ui())
    om = find_node(ui(), content_desc="Open menu")
    if not om:
        record("structure_drawer_shape", False,
               "feature_missing: no 'Open menu' nav host to open the drawer",
               depth=1, jump_kind="transition",
               expect="drawer side-sheet Views added, restored on close")
        return
    tap_node(om); settle("tap")
    opened_nodes = ui()
    opened = and_showing(opened_nodes)
    grew = surface_changed(before, opened)                 # shape changed materially
    and_enter("drawer")
    # Reverse: close the drawer and assert the added shape is gone.
    close = find_node(opened_nodes, content_desc="Close navigation menu")
    restored_gone = False
    if close:
        tap_node(close); settle("tap")
        restored = and_showing(ui())
        restored_gone = surface_changed(opened, restored)
        and_back()
    ok = grew and restored_gone
    record("structure_drawer_shape", ok,
           "" if ok else "behavior_wrong: drawer did not add/restore a shape delta",
           depth=1, jump_kind="transition",
           expect="drawer open adds side-sheet Views (Δ>=2); close restores shape")


@and_test(expects=("structure_settings_row_count",))
def test_settings_row_count():
    """The Settings screen is a menu list whose ROW COUNT is a shape fact:
    the seven top-level setting rows are present, and reaching Settings adds the
    'General' row that was not on Overview (surface shape change). depth=1,
    backed by and_enter_settings."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    before = and_showing(ui())
    if not and_enter_settings():
        record("structure_settings_row_count", False,
               "setup_failed: could not navigate to Settings",
               depth=1, jump_kind="transition",
               expect="Settings list has 7 rows; 'General' row newly appeared")
        return
    after_nodes = ui()
    after = and_showing(after_nodes)
    appeared = surface_changed(before, after) and find_node_ci(after_nodes, "General")
    rows = ["General", "User", "Measurement Types", "Bluetooth",
            "Chart", "Data Management", "About"]
    n_rows = sum(1 for r in rows if find_node_ci(after_nodes, r))
    ok = bool(appeared) and n_rows == 7
    record("structure_settings_row_count", ok,
           "" if ok else f"behavior_wrong: expected 7 setting rows, saw {n_rows}",
           depth=1, jump_kind="transition",
           expect="Settings list has 7 rows (General..About); surface shape changed")


@and_test(expects=("structure_new_measurement_rows",))
def test_new_measurement_row_count():
    """The New Measurement screen is a LONG vertical list of metric rows; its
    editable-row COUNT is a shape fact (nodes whose content-desc starts with
    "Edit " number nine, "Increase " nine). Requires a user, then navigates
    Overview→New Measurement (and_enter_measurement backs depth=1)."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not _create_user():
        record("structure_new_measurement_rows", False,
               "setup_failed: could not create the prerequisite user",
               depth=1, jump_kind="transition",
               expect="New Measurement list has 9 'Edit X' + 9 'Increase X' rows")
        return
    before = and_showing(ui())
    if not and_enter_measurement():
        record("structure_new_measurement_rows", False,
               "setup_failed: could not open New Measurement",
               depth=1, jump_kind="transition",
               expect="New Measurement list has 9 'Edit X' + 9 'Increase X' rows")
        return
    nodes = ui()
    after = and_showing(nodes)
    grew = surface_changed(before, after)
    edit_rows = [n for n in nodes if n.get("content-desc", "").startswith("Edit ")]
    inc_rows = [n for n in nodes if n.get("content-desc", "").startswith("Increase ")]
    ok = grew and len(edit_rows) == 9 and len(inc_rows) == 9
    record("structure_new_measurement_rows", ok,
           "" if ok else f"behavior_wrong: expected 9 Edit + 9 Increase rows, "
                         f"saw {len(edit_rows)} / {len(inc_rows)}",
           depth=1, jump_kind="transition",
           expect="New Measurement list has 9 'Edit X' + 9 'Increase X' metric rows")


@and_test(expects=("structure_edit_dialog_shape",))
def test_edit_dialog_shape_delta():
    """Opening the Edit-Weight NumberInputDialog changes tree SHAPE: an EditText
    (0→1) plus the Clear/Cancel/OK button layer appear; cancelling restores the
    shape (EditText back to 0). depth=2 (Overview→New Measurement→dialog),
    backed by and_enter_measurement + and_enter_edit_dialog."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not _create_user() or not and_enter_measurement():
        record("structure_edit_dialog_shape", False,
               "setup_failed: could not reach New Measurement",
               depth=2, jump_kind="transition",
               expect="dialog adds EditText 0->1 + Clear/Cancel/OK; cancel restores")
        return
    before_nodes = ui()
    before = and_showing(before_nodes)
    et_before = len(find_by_class(before_nodes, "EditText"))
    if not and_enter_edit_dialog():
        record("structure_edit_dialog_shape", False,
               "feature_missing: Edit Weight did not open a NumberInputDialog",
               depth=2, jump_kind="transition",
               expect="dialog adds EditText 0->1 + Clear/Cancel/OK; cancel restores")
        return
    dlg_nodes = ui()
    dlg = and_showing(dlg_nodes)
    et_dlg = len(find_by_class(dlg_nodes, "EditText"))
    buttons_appeared = all(find_node_ci(dlg_nodes, b) for b in ("Clear", "Cancel", "OK"))
    grew = surface_changed(before, dlg) and et_dlg == et_before + 1 and buttons_appeared
    # Reverse: Cancel closes the dialog and removes the added shape.
    restored_ok = False
    cancel = find_node_ci(dlg_nodes, "Cancel")
    if cancel:
        tap_node(cancel); settle("tap")
        r_nodes = ui()
        restored_ok = (len(find_by_class(r_nodes, "EditText")) == et_before
                       and find_node_ci(r_nodes, "Clear") is None)
        and_back()
    ok = grew and restored_ok
    record("structure_edit_dialog_shape", ok,
           "" if ok else "behavior_wrong: dialog shape delta / restore not observed",
           depth=2, jump_kind="transition",
           expect="Edit Weight: EditText 0->1 + Clear/Cancel/OK appear; Cancel restores")


@and_test(expects=("structure_charts_surface",))
def test_charts_surface():
    """Charts is a distinct top-level surface: navigating to it makes the Charts
    title + its 'Time range' / 'Filter chart data' controls appear (a surface
    shape change) while the Overview empty-state entry disappears. depth=1
    (and_enter_charts)."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    before = and_showing(ui())
    if not and_enter_charts():
        record("structure_charts_surface", False,
               "setup_failed: could not navigate to Charts",
               depth=1, jump_kind="transition",
               expect="Charts surface appears (title + chart controls)")
        return
    nodes = ui()
    after = and_showing(nodes)
    grew = surface_changed(before, after)
    controls = bool(find_node(nodes, content_desc="Time range icon")
                    or find_node(nodes, content_desc="Filter chart data"))
    title = bool(find_node(nodes, text="Charts"))
    ok = grew and controls and title
    record("structure_charts_surface", ok,
           "" if ok else "behavior_wrong: Charts surface / its controls did not appear",
           depth=1, jump_kind="transition",
           expect="Charts title + chart controls appeared; surface shape changed")


@and_test(expects=("structure_overview_populated_shape",))
def test_overview_populated_shape():
    """Empty→populated Overview is a shape delta: after creating the first
    measurement the empty-state card ("No Measurements Yet") is replaced by an
    entry card region that adds per-entry edit/delete controls. Asserted as a
    surface delta plus the new per-entry controls appearing (a shape fact, not
    the value text). depth=1 (created a measurement via and_enter_measurement).
    NOTE: openScale's Save auto-navigates back to Overview — do NOT press Back."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not _create_user():
        record("structure_overview_populated_shape", False,
               "setup_failed: could not create the prerequisite user",
               depth=1, jump_kind="transition",
               expect="empty Overview -> populated entry card (edit/delete controls appear)")
        return
    empty = and_showing(ui())                       # "No Measurements Yet" state
    had_empty = find_node_ci(ui(), "Add Measurement") is not None
    if not and_enter_measurement():
        record("structure_overview_populated_shape", False,
               "setup_failed: could not open New Measurement",
               depth=1, jump_kind="transition",
               expect="empty Overview -> populated entry card (edit/delete controls appear)")
        return
    save = find_node(ui(), content_desc="Save measurement")
    if not save:
        record("structure_overview_populated_shape", False,
               "feature_missing: no 'Save measurement' action",
               depth=1, jump_kind="transition",
               expect="empty Overview -> populated entry card (edit/delete controls appear)")
        return
    tap_node(save); settle("tap"); settle("tap")   # lands on Overview automatically
    pop_nodes = ui()
    populated = and_showing(pop_nodes)
    grew = surface_changed(empty, populated)
    # A populated Overview adds per-entry controls; match by content-desc PREFIX
    # so no date literal is baked in (shape fact, not content).
    entry_ctrls = [n for n in pop_nodes
                   if n.get("content-desc", "").startswith("Edit measurement from ")
                   or n.get("content-desc", "").startswith("Delete measurement from ")]
    empty_gone = find_node_ci(pop_nodes, "Add Measurement") is None
    ok = had_empty and grew and len(entry_ctrls) >= 1 and empty_gone
    record("structure_overview_populated_shape", ok,
           "" if ok else "behavior_wrong: empty->populated Overview shape delta not observed",
           depth=1, jump_kind="transition",
           expect="empty-state card replaced by entry card; per-entry edit/delete controls appear")


# ─────────────────────────────────────────────────────────────────────────────
# (3) VLM — 8 records on genuinely visual LAYOUT facts (spatial arrangement is
#     unreadable from the dump). Each asks about a SPECIFIC rendered property a
#     blank/dead screen would fail; expect="YES". Surface-crossing VLM records
#     are jump_kind="transition" and backed by and_enter_* helpers. Setup-failed
#     fallbacks carry an expect so no transition record is left without one.
# ─────────────────────────────────────────────────────────────────────────────

@and_test(expects=("structure_gate_card_vlm",))
def test_gate_card_layout_vlm():
    """Overview empty state renders a single centered rounded card with an icon
    above stacked text and a filled pill button — a specific layout."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    vlm_assert("structure_gate_card",
               "Is there a single rounded card centered in the middle of the "
               "screen containing an icon above two lines of text and a filled "
               "pill-shaped button near its bottom?",
               RESULTS_DIR, expect="YES", depth=0, jump_kind="none", tag="layout")


@and_test(expects=("structure_drawer_sidesheet_vlm",))
def test_drawer_sidesheet_position_vlm():
    """The drawer is a side sheet anchored to the LEFT edge, with a colored
    header/logo at top and a vertical stack of menu items below it, while the
    right part of the screen is dimmed."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    om = find_node(ui(), content_desc="Open menu")
    tap_node(om); settle("tap")
    and_enter("drawer")
    vlm_assert("structure_drawer_sidesheet",
               "Is a navigation drawer panel occupying the LEFT side of the "
               "screen, with a colored header at the top and a vertical list of "
               "menu items below it, while the right edge of the screen is dimmed?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="position")


@and_test(expects=("structure_measure_list_vlm",))
def test_new_measurement_list_layout_vlm():
    """New Measurement shows a vertical list of labelled rows, each with a
    circular colored icon at the left edge — a distinctive layout."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not (_create_user() and and_enter_measurement()):
        record("structure_measure_list_vlm", False,
               "setup_failed: could not reach New Measurement for VLM",
               depth=1, jump_kind="transition", tag="layout",
               expect="New Measurement vertical row list with left circular icons")
        return
    vlm_assert("structure_measure_list",
               "Is this a vertically scrolling list where each row has a "
               "circular colored icon at its left edge followed by a metric "
               "label, stacked one row per metric?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="layout")


@and_test(expects=("structure_measure_icon_vlm",))
def test_new_measurement_icon_shape_vlm():
    """Each metric row's leading icon is a filled CIRCLE (round colored badge),
    not a square or bare glyph — a shape fact."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not (_create_user() and and_enter_measurement()):
        record("structure_measure_icon_vlm", False,
               "setup_failed: could not reach New Measurement for VLM",
               depth=1, jump_kind="transition", tag="shape",
               expect="metric rows have round colored leading icons")
        return
    vlm_assert("structure_measure_icon",
               "At the left edge of the metric rows, are the icons round "
               "(circular) colored badges rather than square tiles or plain "
               "black glyphs with no background?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="shape")


@and_test(expects=("structure_measure_steppers_vlm",))
def test_new_measurement_steppers_position_vlm():
    """Editable metric rows show up/down stepper arrows and a pencil edit icon
    aligned to the RIGHT edge of each row — a position fact."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not (_create_user() and and_enter_measurement()):
        record("structure_measure_steppers_vlm", False,
               "setup_failed: could not reach New Measurement for VLM",
               depth=1, jump_kind="transition", tag="position",
               expect="right-aligned up/down steppers + pencil per metric row")
        return
    vlm_assert("structure_measure_steppers",
               "On the right-hand side of the metric rows, are there stacked "
               "up and down arrow buttons next to a pencil (edit) icon, aligned "
               "to the right edge of each row?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="position")


@and_test(expects=("structure_settings_list_vlm",))
def test_settings_list_layout_vlm():
    """Settings renders a single-column vertical list of menu rows, each a
    leading glyph icon followed by its label, evenly spaced top-to-bottom."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not and_enter_settings():
        record("structure_settings_list_vlm", False,
               "setup_failed: could not reach Settings for VLM",
               depth=1, jump_kind="transition", tag="layout",
               expect="Settings single-column icon+label row list")
        return
    vlm_assert("structure_settings_list",
               "Is this a single-column vertical list of menu rows, each row an "
               "icon on the left followed by a text label, stacked and evenly "
               "spaced down the screen?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="layout")


@and_test(expects=("structure_chart_area_vlm",))
def test_charts_graph_area_vlm():
    """The Charts screen renders a graph/plot area (canvas — never in the view
    tree). A blank screen or a plain list would fail this. shape fact."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not (_create_user() and and_enter_measurement()):
        record("structure_chart_area_vlm", False,
               "setup_failed: could not create data for Charts VLM",
               depth=1, jump_kind="transition", tag="shape",
               expect="Charts screen shows a chart/graph plotting area")
        return
    # Save a measurement so the chart has a datapoint, then open Charts.
    save = find_node(ui(), content_desc="Save measurement")
    if save:
        tap_node(save); settle("tap"); settle("tap")   # lands back on Overview
    and_reset_depth()
    if not and_enter_charts():
        record("structure_chart_area_vlm", False,
               "setup_failed: could not reach Charts for VLM",
               depth=1, jump_kind="transition", tag="shape",
               expect="Charts screen shows a chart/graph plotting area")
        return
    vlm_assert("structure_chart_area",
               "Below the top toolbar, is there a chart/graph plotting area "
               "(with an axis line or gridlines / plotted region) rather than "
               "only text rows or an empty blank space?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="shape")


@and_test(expects=("structure_entry_card_vlm",))
def test_overview_entry_card_layout_vlm():
    """A populated Overview groups one measurement into a rounded entry card:
    a date heading at top with trash+pencil icons on the right, and metric rows
    (circular icon + label + value) below — a specific grouped layout. A Weight
    value is entered first so the card actually renders value rows."""
    and_reset_depth()
    clear_data()
    restart_app(); wait_for_foreground()
    if not (_create_user() and and_enter_measurement()):
        record("structure_entry_card_vlm", False,
               "setup_failed: could not reach New Measurement for VLM",
               depth=1, jump_kind="transition", tag="layout",
               expect="populated Overview entry card groups date + value rows")
        return
    if not _save_weight_measurement("80"):
        record("structure_entry_card_vlm", False,
               "setup_failed: could not save a valued measurement for the card VLM",
               depth=1, jump_kind="transition", tag="layout",
               expect="populated Overview entry card groups date + value rows")
        return
    vlm_assert("structure_entry_card",
               "Is there a rounded card that groups a date heading at its top "
               "(with small trash and pencil icons on the top-right) above one "
               "or more metric rows, each row a circular icon with a label on "
               "the left and a value on the right?",
               RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="layout")


# ─────────────────────────────────────────────────────────────────────────────

TESTS = [
    test_gate_launch,
    test_gate_overview_surface,
    test_drawer_shape_delta,
    test_settings_row_count,
    test_new_measurement_row_count,
    test_edit_dialog_shape_delta,
    test_charts_surface,
    test_overview_populated_shape,
    test_gate_card_layout_vlm,
    test_drawer_sidesheet_position_vlm,
    test_new_measurement_list_layout_vlm,
    test_new_measurement_icon_shape_vlm,
    test_new_measurement_steppers_position_vlm,
    test_settings_list_layout_vlm,
    test_charts_graph_area_vlm,
    test_overview_entry_card_layout_vlm,
]

if __name__ == "__main__":
    run_suite(TESTS, "structure")