Datasets:
File size: 23,411 Bytes
41dfd8d | 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 | #!/usr/bin/env python3
"""STRUCTURE lane — TimePlanner (day-planner).
Owns two things only:
(1) the GATE — the app launches, is foreground, and its top-level surfaces
exist (main Compose container + top bar + 3-tab bottom nav). jump_kind="none".
(2) tree-SHAPE deltas — a user interaction that changes the view tree's SHAPE
(a class of widget appears/disappears, an empty->populated list, a section
of cards appears). Recorded as jump_kind="transition" with a before/after
count or surface-set delta, and reversed to assert it restores.
No content-string equality (text lane), no checked/selected assertions (states
lane), no computed values (computation lane), no reach-by-jump-alone (navigation
lane). Everything asserted here was OBSERVED on the running original.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
# ── Onboarding: after clear_data() (only then) a notification-permission dialog
# appears with "Allow"/"Don't allow" (curly apostrophe). It is on-screen so ui()
# sees it. No-op after a plain restart_app(). Call after every launch. ──────────
def dismiss_onboarding():
for _ in range(2):
nodes = ui()
btn = next((n for n in nodes
if (n.get("text") or "") in ("Allow", "Don't allow", "Don’t allow")),
None)
if not btn:
return
tap_node(btn)
def _has(nodes, label):
return find_node_ci(nodes, label) is not None
def _home_ready(nodes):
"""TimePlanner Home is up iff the 'Schedule' top-bar title is present."""
return _has(nodes, "Schedule")
def _ensure_home(max_tries=10):
"""Drive the GUI until TimePlanner's Home is showing.
The .debug build bundles LeakCanary, which registers a SECOND launcher alias
in the SAME package; after a data wipe `monkey LAUNCHER` sometimes opens the
LeakCanary screen instead of the app, and monkey then STAYS on that alias
(a plain relaunch re-opens LeakCanary). The portable break is a hard reset —
HOME, force-stop, relaunch — which clears the task so the launcher re-resolves;
empirically this lands on the app within a couple of tries. Nothing here writes
a component/package literal: LeakCanary is detected only by its on-screen text.
Returns True once Home ('Schedule') is confirmed on a settled dump."""
for _ in range(max_tries):
dismiss_onboarding() # onboarding dialog IS the app -> Home
nodes = ui()
if _home_ready(nodes):
# A Compose recomposition/animation can leave the very next dump blank,
# so confirm Home on a SETTLED re-dump before handing control back.
for _ in range(3):
settle("launch")
if _home_ready(ui()):
return True
continue
# LeakCanary, the system launcher, or a blank frame: hard-reset the task.
home()
settle("key")
force_stop()
settle("key")
launch_app()
wait_for_foreground()
return _home_ready(ui())
def _clickable_ancestor(nodes, node):
"""Compose leaf labels are not themselves clickable; the tappable card is an
ancestor View whose bounds enclose the leaf. Return the smallest clickable
node containing `node`'s centre (else the node itself)."""
if not node or "_center" not in node:
return node
cx, cy = node["_center"]
best, best_area = None, None
for n in nodes:
if n.get("clickable") != "true" or "_bounds" not in n:
continue
x1, y1, x2, y2 = n["_bounds"]
if x1 <= cx <= x2 and y1 <= cy <= y2:
area = (x2 - x1) * (y2 - y1)
if best_area is None or area < best_area:
best, best_area = n, area
return best or node
def _fresh_empty_home():
"""Guaranteed clean entry point: wipe data, launch, clear onboarding and any
LeakCanary launcher. The day then has no schedule -> the empty-state block
('Nothing planned yet' + 'Plan now') is showing. Returns True iff Home is up."""
clear_data()
launch_app()
wait_for_foreground()
return _ensure_home()
def _restart_home():
"""Restart (data intact) and confirm Home — used where the empty state is not
required. Still routed through the LeakCanary recovery."""
restart_app()
wait_for_foreground()
return _ensure_home()
# ── depth-family helpers (naming BACKS a declared depth>=1; the taps are mine) ──
def and_enter_editor(nodes):
"""Home -> Editor by tapping the free-slot 'Unassigned' add-row. Confirms the
Editor surface (its 'Save' button appears). Counts one surface."""
row = find_node_ci(nodes, "Unassigned") or find_node_ci(nodes, "Add a task")
if not row:
return False
if not tap_node(_clickable_ancestor(nodes, row)):
return False
if not _has(ui(), "Save"):
return False
and_enter("editor")
return True
def and_enter_category_sheet(nodes):
"""Editor -> Category bottom sheet by tapping the Category card. Confirms the
sheet (its 'Select' button appears). Counts one surface."""
lbl = find_node_ci(nodes, "Category")
if not lbl:
return False
if not tap_node(_clickable_ancestor(nodes, lbl)):
return False
if not _has(ui(), "Select"):
return False
and_enter("category_sheet")
return True
def and_enter_settings(nodes):
"""Home -> Settings via the bottom-nav 'Settings' tab. Counts one surface."""
if not tap_text(nodes, "Settings"):
return False
if not _has(ui(), "Appearance"):
return False
and_enter("settings")
return True
def and_enter_analytics(nodes):
"""Home -> Analytics via the bottom-nav 'Analytics' tab. Counts one surface."""
if not tap_text(nodes, "Analytics"):
return False
if not _has(ui(), "Planning stats"):
return False
and_enter("analytics")
return True
def and_enter_overview(nodes):
"""Home -> Overview via the top-bar grid icon (desc 'Overview'). Counts one
surface (its 'Schedules' section header appears)."""
grid = find_node(nodes, content_desc="Overview")
if not grid or not tap_node(grid):
return False
if not _has(ui(), "Schedules"):
return False
and_enter("overview")
return True
# ══════════════════════════════════════════════════════════════════════════════
# GATE (jump_kind="none", depth=0) — kept to <=30% of the file
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("structure_gate_launch", "structure_gate_home_layout_vlm"))
def test_gate_launch():
"""App launches, reaches foreground, and its top-level Compose container
exists. A dead process or a blank Activity fails this."""
ok_home = _fresh_empty_home()
nodes = ui()
container = bool(find_by_class(nodes, "ComposeView")
or find_by_class(nodes, "FrameLayout"))
ok = bool(ok_home and container)
record("structure_gate_launch", ok,
"" if ok else "setup_failed: app did not reach the foreground with a "
"top-level Compose container",
depth=0, jump_kind="none")
vlm_assert("structure_gate_home_layout",
"Is this a day-planner Home screen: a top app bar with a title, a "
"date row with left/right chevron arrows, and a bottom navigation "
"bar? Answer YES only if that overall schedule-screen layout is "
"visible.",
RESULTS_DIR, expect="YES", depth=0, jump_kind="none", tag="layout")
@and_test(expects=("structure_gate_home_topbar",))
def test_gate_home_topbar():
"""Top-bar host: title 'Schedule' plus the menu + overview icon buttons (by
content-desc, not internal id)."""
_fresh_empty_home()
nodes = ui()
menu = find_node(nodes, content_desc="Open menu") is not None
overview = find_node(nodes, content_desc="Overview") is not None
if not (menu and overview): # top bar may still be composing; re-read
settle("launch")
nodes = ui()
menu = find_node(nodes, content_desc="Open menu") is not None
overview = find_node(nodes, content_desc="Overview") is not None
title = _has(nodes, "Schedule")
ok = bool(title and menu and overview)
record("structure_gate_home_topbar", ok,
"" if ok else "feature_missing: home top-bar host (Schedule title + "
"Open menu + Overview icons) not all present",
depth=0, jump_kind="none")
@and_test(expects=("structure_bottom_nav_three_tabs",
"structure_bottom_nav_layout_vlm"))
def test_bottom_nav_three_tabs():
"""Bottom-nav host has exactly the 3 tab labels Home / Analytics / Settings —
the shape of the navigation container."""
_fresh_empty_home()
nodes = ui()
labels = [t for t in ("Home", "Analytics", "Settings") if _has(nodes, t)]
ok = len(labels) == 3
record("structure_bottom_nav_three_tabs", ok,
"" if ok else f"feature_missing: expected 3 bottom-nav tabs "
f"(Home/Analytics/Settings), found {labels}",
depth=0, jump_kind="none")
vlm_assert("structure_bottom_nav_layout",
"Is there a bottom navigation bar containing exactly 3 icon+label "
"items, evenly spaced across the bottom edge of the screen?",
RESULTS_DIR, expect="YES", depth=0, jump_kind="none", tag="position")
# ══════════════════════════════════════════════════════════════════════════════
# SHAPE DELTAS (jump_kind="transition") — the bulk of the file
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("structure_home_empty_to_planned",
"structure_empty_state_layout_vlm"))
def test_home_empty_to_planned():
"""Empty day -> tap 'Plan now' -> the tree gains a schedule free-slot row
('Unassigned') and the empty-state block ('Nothing planned yet' + 'Plan now')
disappears. Reversed by wiping back to the empty day."""
_fresh_empty_home()
before = ui()
empty_present = _has(before, "Nothing planned yet") and _has(before, "Plan now")
b_show = and_showing(before)
# capture the empty-state layout before we leave it (only if it is really up)
vlm_assert("structure_empty_state_layout",
"Does the centre of the screen show a single large placeholder "
"icon with a short line of text under it and one outlined button "
"below that (an empty-state), rather than a list of rows?",
RESULTS_DIR, expect="YES", depth=0, jump_kind="none", tag="position")
tapped = tap_text(before, "Plan now")
after = ui()
row_appeared = _has(after, "Unassigned")
empty_gone = not _has(after, "Nothing planned yet")
fwd_ok = bool(empty_present and tapped and row_appeared and empty_gone
and surface_changed(b_show, and_showing(after)))
# reverse: a fresh wipe returns to the empty-state shape
_fresh_empty_home()
restored = _has(ui(), "Plan now")
ok = fwd_ok and restored
record("structure_home_empty_to_planned", ok,
"" if ok else "behavior_wrong: 'Plan now' did not replace the "
"empty-state block with a schedule row (or it did not "
"restore on a clean day)",
depth=0, jump_kind="transition",
expect="empty-state (Nothing planned yet + Plan now) -> free-slot row "
"'Unassigned' appears in-place; restored to empty-state on data wipe")
@and_test(expects=("structure_editor_field_cards",
"structure_editor_cards_layout_vlm",
"structure_editor_priority_segmented_vlm"))
def test_editor_field_cards():
"""Opening the Editor adds a whole class of field controls that Home never
shows: the 'Priority'/'Statistics' labels, 2 toggle switches, and the Note
EditText. Reversed with BACK -> those controls are gone again on Home."""
_fresh_empty_home()
tap_text(ui(), "Plan now")
home = ui()
home_switches = len([n for n in home if n.get("checkable") == "true"])
home_edits = len(find_by_class(home, "EditText"))
home_priority = _has(home, "Priority") and _has(home, "Statistics")
entered = and_enter_editor(home)
ed = ui()
ed_switches = len([n for n in ed if n.get("checkable") == "true"])
ed_edits = len(find_by_class(ed, "EditText"))
ed_fields = (_has(ed, "Category") and _has(ed, "Priority")
and _has(ed, "Statistics") and _has(ed, "Save"))
fwd_ok = bool(entered and not home_priority and home_switches == 0
and ed_fields and ed_switches == 2 and ed_edits == home_edits + 1)
vlm_assert("structure_editor_cards_layout",
"Is the main area a vertically stacked list of rounded rectangular "
"field cards (a form), with a Cancel and a Save button at the "
"bottom?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="layout")
vlm_assert("structure_editor_priority_segmented",
"Is there a horizontal segmented control divided into exactly 3 "
"side-by-side options labelled Standard, Medium and Max?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="shape")
and_back()
back_home = ui()
restored = (not _has(back_home, "Priority")
and len([n for n in back_home if n.get("checkable") == "true"]) == 0)
ok = fwd_ok and restored
record("structure_editor_field_cards", ok,
"" if ok else "behavior_wrong: Editor did not add the field-card "
"controls (2 switches + Note EditText + Priority) over "
"Home, or they did not disappear on BACK",
depth=1, jump_kind="transition",
expect="switch count 0->2 and EditText +1 and Priority/Statistics "
"appear on opening Editor; restored to 0 switches on BACK")
@and_test(expects=("structure_category_sheet_radios",
"structure_category_sheet_position_vlm"))
def test_category_sheet_radios():
"""From the Editor, opening the Category bottom sheet adds a class of widget
the Editor never has: RadioButton rows (0 -> 5) plus a 'Select' button.
Reversed by dismissing the sheet -> RadioButton count back to 0."""
_fresh_empty_home()
tap_text(ui(), "Plan now")
if not and_enter_editor(ui()):
record("structure_category_sheet_radios", False,
"setup_failed: could not open the Editor to reach the Category "
"sheet", depth=2, jump_kind="transition",
expect="RadioButton count 0->5 on opening the Category sheet")
record("structure_category_sheet_position_vlm", False,
"setup_failed: could not open the Editor", depth=2,
jump_kind="transition", tag="position")
return
ed = ui()
ed_radios = len(find_by_class(ed, "RadioButton"))
opened = and_enter_category_sheet(ed)
sheet = ui()
sheet_radios = len(find_by_class(sheet, "RadioButton"))
has_select = _has(sheet, "Select")
fwd_ok = bool(opened and ed_radios == 0 and sheet_radios == 5 and has_select)
vlm_assert("structure_category_sheet_position",
"Is a bottom sheet panel overlaid on the lower part of the screen "
"(its top edge is below the middle, sliding up from the bottom) "
"showing a scrollable list of selectable category rows?",
RESULTS_DIR, expect="YES", depth=2, jump_kind="transition",
tag="position")
# reverse: dismiss via Cancel (safe) -> back on the Editor, no radios
if not tap_text(ui(), "Cancel"):
and_back()
restored = len(find_by_class(ui(), "RadioButton")) == 0
ok = fwd_ok and restored
record("structure_category_sheet_radios", ok,
"" if ok else "behavior_wrong: Category sheet did not add 5 "
"RadioButton rows over the Editor (or they did not "
"clear on dismiss)",
depth=2, jump_kind="transition",
expect="RadioButton count 0->5 (+Select button) on opening the "
"Category sheet; restored to 0 on Cancel")
@and_test(expects=("structure_settings_sections",
"structure_settings_color_swatches_vlm",
"structure_settings_theme_segmented_vlm"))
def test_settings_sections():
"""The Settings root has a distinct section shape: the section headers
Appearance / Interface / Security plus 2 toggle switches — none of which the
Home schedule shows. Reversed by returning to Home via its bottom-nav tab."""
_fresh_empty_home()
home = ui()
home_sections = _has(home, "Appearance") or _has(home, "Interface")
entered = and_enter_settings(home)
s = ui()
headers = [h for h in ("Appearance", "Interface", "Security") if _has(s, h)]
s_switches = len([n for n in s if n.get("checkable") == "true"])
fwd_ok = bool(entered and not home_sections and len(headers) == 3
and s_switches >= 2 and not _has(s, "Nothing planned yet"))
vlm_assert("structure_settings_color_swatches",
"Under a 'Color' label, is there a horizontal row of exactly 4 "
"coloured swatch tiles side by side, in distinct colours "
"(reddish, purple, indigo and blue)?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="color")
vlm_assert("structure_settings_theme_segmented",
"Under a 'Theme' label, is there a horizontal segmented control "
"with 3 options (Light, System, Dark) where one option is "
"highlighted with a filled/tinted background?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="shape")
# reverse
tap_text(ui(), "Home")
restored = _has(ui(), "Schedule")
ok = fwd_ok and restored
record("structure_settings_sections", ok,
"" if ok else "behavior_wrong: Settings did not show the 3 section "
"headers + >=2 switches, or Home tab did not restore",
depth=1, jump_kind="transition",
expect="Settings adds section headers Appearance/Interface/Security "
"+ >=2 switches over Home; restored to Schedule on Home tab")
@and_test(expects=("structure_analytics_tab_switch",
"structure_analytics_donut_vlm",
"structure_analytics_heatmap_vlm"))
def test_analytics_tab_switch():
"""Analytics Time tab shows 'Planning stats' (heatmap) + 'Category stats'
(donut). Switching to the Workload tab REMOVES the 'Planning stats' block —
a tree-shape delta. Reversed by switching back to the Time tab."""
_fresh_empty_home()
entered = and_enter_analytics(ui())
time_tab = ui()
time_ok = _has(time_tab, "Planning stats") and _has(time_tab, "Category stats")
b_show = and_showing(time_tab)
vlm_assert("structure_analytics_donut",
"Under 'Category stats', is there a circular ring / donut (pie) "
"chart with a hole in the centre and a number in the middle?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="shape")
vlm_assert("structure_analytics_heatmap",
"Under 'Planning stats', is there a grid of small squares arranged "
"in rows and columns (a calendar heatmap), with weekday labels like "
"Mon/Wed/Fri along the left?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="none", tag="layout")
wl = find_node(time_tab, content_desc="Workload") or find_node_ci(time_tab, "Workload")
switched = tap_node(wl) if wl else False
workload = ui()
planning_gone = not _has(workload, "Planning stats")
fwd_ok = bool(entered and time_ok and switched and planning_gone
and surface_changed(b_show, and_showing(workload)))
# reverse: back to Time tab -> Planning stats returns
tm = find_node(ui(), content_desc="Time") or find_node_ci(ui(), "Time")
if tm:
tap_node(tm)
restored = _has(ui(), "Planning stats")
ok = fwd_ok and restored
record("structure_analytics_tab_switch", ok,
"" if ok else "behavior_wrong: Workload tab did not remove the "
"'Planning stats' block (or Time tab did not restore it)",
depth=1, jump_kind="transition",
expect="'Planning stats' block present on Time tab, removed on Workload "
"tab, restored on Time tab")
@and_test(expects=("structure_overview_shape",))
def test_overview_shape():
"""The Overview screen (top-bar grid icon) has a shape Home lacks: it gains
ProgressBar widgets plus the 'Schedules' / 'Current task' section headers, and
the Home empty-state ('Plan now') disappears. Reversed with BACK to Home."""
_fresh_empty_home()
home = ui()
home_bars = len(find_by_class(home, "ProgressBar"))
home_sched_header = _has(home, "Schedules")
entered = and_enter_overview(home)
ov = ui()
ov_bars = len(find_by_class(ov, "ProgressBar"))
ov_headers = _has(ov, "Schedules") and _has(ov, "Current task")
plan_gone = not _has(ov, "Plan now")
fwd_ok = bool(entered and not home_sched_header and ov_headers
and ov_bars > home_bars and plan_gone)
and_back()
restored = _has(ui(), "Schedule")
ok = fwd_ok and restored
record("structure_overview_shape", ok,
"" if ok else "behavior_wrong: Overview did not add ProgressBar + "
"Schedules/Current task sections over Home (or BACK did "
"not restore Home)",
depth=1, jump_kind="transition",
expect="Overview adds ProgressBar widgets + Schedules/Current task "
"headers over Home; restored to Schedule on BACK")
TESTS = [
test_gate_launch,
test_gate_home_topbar,
test_bottom_nav_three_tabs,
test_home_empty_to_planned,
test_editor_field_cards,
test_category_sheet_radios,
test_settings_sections,
test_analytics_tab_switch,
test_overview_shape,
]
if __name__ == "__main__":
if not device_online():
print("[structure] DEVICE OFFLINE — the adb tunnel appears to be down; "
"records will read setup_failed rather than app defects.")
run_suite(TESTS, "structure")
|