File size: 27,782 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
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
#!/usr/bin/env python3
"""COMPUTATION lane — Urik Keyboard (com.urik.keyboard).

This app is a soft-keyboard + settings app: there is NO calculator. Its
deterministic input -> output surfaces are:
  1. ListPreference dialogs: pick an option -> the row's `summary` becomes EXACTLY
     that option's label (Suggestion Count, Key Size, Key Label Size, Cursor Speed,
     Space Bar Size, Keyboard Layout, Long Press Punctuation, Long Press Duration).
  2. Vibration Strength SeekBar: tap a position on the bar -> the `seekbar_value`
     label shows the corresponding number (observed deterministic: far-left -> "6",
     far-right -> "250", centre -> "128").
  3. test_field EditText: type a string -> the field's `text` equals exactly that.

Every expected value below was REPRODUCED LIVE on the original app (see _explore*).
All tests are jump_kind="value" with a specific `expect`, depth=2 (Settings ->
fragment -> [dialog]), and restore any mutated preference to keep the baseline clean.
"""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import *  # noqa: F403


# ── local helpers (READ-ONLY kit; these only orchestrate kit calls) ─────────────

def summary_for(nodes, title_text):
    """The `summary` TextView that sits directly under the row whose title == title_text.

    Preference rows are (title TextView / summary TextView) pairs; we pick the
    summary whose center-y is closest to (and not far above) the located title.
    Returns (title_node, summary_node) — either may be None.
    """
    tn = find_node(nodes, text=title_text)
    if not tn or "_center" not in tn:
        return None, None
    ty = tn["_center"][1]
    cands = [n for n in nodes
             if n.get("resource-id", "").endswith("summary") and "_center" in n]
    below = [n for n in cands if n["_center"][1] >= ty - 5]
    if not below:
        return tn, None
    best = min(below, key=lambda n: abs(n["_center"][1] - ty))
    return tn, best


def summary_text(nodes, title_text):
    _tn, sm = summary_for(nodes, title_text)
    return (sm.get("text", "").strip() if sm else "")


def open_settings():
    """restart_app() -> tap 'Open Settings' -> return the settings-list nodes."""
    restart_app()
    wait_for_foreground()
    tap_text(ui(), "Open Settings")


def and_enter_fragment(row_text):
    """Open a settings fragment by its row title (exact text, then ci fallback).

    Names in the and_enter_* family, so it backs the depth>=1 declaration.
    Returns (ok, note).
    """
    nodes = ui()
    n = find_node(nodes, text=row_text) or find_node_ci(nodes, row_text)
    if not n:
        return False, f"setup_failed: settings row {row_text!r} not found"
    if not tap_node(n):
        return False, f"setup_failed: settings row {row_text!r} not tappable"
    and_enter(row_text)
    return True, ""


def and_enter_layout_fragment():
    """Open the 'Layout & Input' fragment. Its row text is the LITERAL
    'Layout & Input' (uiautomator does not unescape &); fall back to the
    unique summary 'Number row, space bar size'."""
    nodes = ui()
    row = (find_node(nodes, text="Layout & Input")
           or find_node(nodes, text="Number row, space bar size"))
    if not row:
        return False, "setup_failed: 'Layout & Input' row not found"
    if not tap_node(row):
        return False, "setup_failed: 'Layout & Input' row not tappable"
    and_enter("Layout & Input")
    return True, ""


def and_enter_dialog(pref_title, scroll=False):
    """Scroll (optional) to a ListPreference row, tap it to open its dialog.

    Counts as one more surface (the dialog). Returns (ok, note).
    """
    if scroll and not find_node(ui(), text=pref_title):
        scroll_into_view(pref_title)
    pn = find_node(ui(), text=pref_title)
    if not pn:
        return False, f"setup_failed: preference {pref_title!r} not found"
    before = and_showing()
    if not tap_node(pn):
        return False, f"setup_failed: preference {pref_title!r} not tappable"
    after = and_showing()
    if not surface_changed(before, after):
        return False, f"behavior_wrong: no dialog appeared for {pref_title!r}"
    and_enter(f"{pref_title} dialog")
    return True, ""


def pick_option(pick):
    """Tap a dialog option (CheckedTextView) by its exact label."""
    return tap_text(ui(), pick)


def restore_listpref(pref_title, restore_label, scroll=False):
    """Best-effort restore of a ListPreference to its original label. Never fails
    the test — restoration is cleanup, not the assertion."""
    try:
        if scroll and not find_node(ui(), text=pref_title):
            scroll_into_view(pref_title)
        pn = find_node(ui(), text=pref_title)
        if pn and tap_node(pn):
            tap_text(ui(), restore_label)
    except Exception:
        pass


def seek_value(nodes):
    n = node_by_id(nodes, "seekbar_value")
    return (n.get("text", "").strip() if n else "")


def tap_seekbar_fraction(frac):
    """Tap the Vibration Strength SeekBar at a horizontal fraction of its width.

    Coordinate is DERIVED from the seekbar node's own bounds (never a literal).
    Returns the new seekbar_value text, or "" if the bar was not found.
    """
    bar = node_by_id(ui(), "seekbar")
    if not bar or "_bounds" not in bar:
        return "", False
    x1, y1, x2, y2 = bar["_bounds"]
    tx = int(x1 + (x2 - x1) * frac)
    ty = (y1 + y2) // 2
    tap(tx, ty)
    return seek_value(ui()), True


def test_field(nodes):
    """The fragment's bottom 'Test changes' EditText (id test_field)."""
    n = node_by_id(nodes, "test_field")
    if n:
        return n
    ets = find_by_class(nodes, "EditText")
    return ets[-1] if ets else None


# ══════════════════════════════════════════════════════════════════════════════
# (1) ListPreference: pick option -> summary becomes EXACTLY that label
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("computation_suggestion_count_2", "computation_suggestion_count_dialog_vlm"))
def test_suggestion_count_2():
    """Suggestion Count: pick '2' in the dialog -> row summary becomes '2'
    (observed). Positive/negative: '2' is ABSENT as the summary before, PRESENT
    after. VLM: the dialog is a rendered radio list. Restore to '3' at the end."""
    name = "computation_suggestion_count_2"
    exp = "2"
    open_settings()
    ok, note = and_enter_fragment("Auto-Correct Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary '2'")
        return
    before = summary_text(ui(), "Suggestion Count")   # observed "3"
    okd, noted = and_enter_dialog("Suggestion Count")
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary '2'")
        return
    # VLM while the dialog is up: a rendered radio/checkmark option list.
    vlm_assert("computation_suggestion_count_dialog",
               "Is a dialog shown containing a vertical list of selectable options "
               "each preceded by a round radio-button circle (one filled/selected)?",
               RESULTS_DIR, tag="shape")
    pick_option("2")
    got = summary_text(ui(), "Suggestion Count")
    ok = (got == exp) and (before != exp)
    record(name, ok,
           "" if ok else f"behavior_wrong: summary {got!r} after picking '2' "
                         f"(before {before!r}), expected '2'",
           depth=2, jump_kind="value", expect="Suggestion Count summary == '2'")
    restore_listpref("Suggestion Count", "3")


@and_test(expects=("computation_suggestion_count_1",))
def test_suggestion_count_1():
    """Suggestion Count: pick '1' -> summary becomes '1' (observed). Restore '3'."""
    name = "computation_suggestion_count_1"
    open_settings()
    ok, note = and_enter_fragment("Auto-Correct Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary '1'")
        return
    before = summary_text(ui(), "Suggestion Count")
    okd, noted = and_enter_dialog("Suggestion Count")
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary '1'")
        return
    pick_option("1")
    got = summary_text(ui(), "Suggestion Count")
    ok = (got == "1") and (before != "1")
    record(name, ok,
           "" if ok else f"behavior_wrong: summary {got!r} after picking '1' "
                         f"(before {before!r}), expected '1'",
           depth=2, jump_kind="value", expect="Suggestion Count summary == '1'")
    restore_listpref("Suggestion Count", "3")


@and_test(expects=("computation_key_size_large",))
def test_key_size_large():
    """Key Size: options Small/Medium/Large/Extra Large (Medium selected). Pick
    'Large' -> summary becomes 'Large' (observed). Restore 'Medium'."""
    name = "computation_key_size_large"
    open_settings()
    ok, note = and_enter_fragment("Appearance")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'Large'")
        return
    before = summary_text(ui(), "Key Size")   # observed "Medium"
    okd, noted = and_enter_dialog("Key Size")
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'Large'")
        return
    pick_option("Large")
    got = summary_text(ui(), "Key Size")
    ok = (got == "Large") and (before != "Large")
    record(name, ok,
           "" if ok else f"behavior_wrong: Key Size summary {got!r} after picking "
                         f"'Large' (before {before!r}), expected 'Large'",
           depth=2, jump_kind="value", expect="Key Size summary == 'Large'")
    restore_listpref("Key Size", "Medium")


@and_test(expects=("computation_key_label_size_large",))
def test_key_label_size_large():
    """Key Label Size: options Small/Medium/Large (Medium selected). Pick 'Large'
    -> summary becomes 'Large' (observed). Restore 'Medium'."""
    name = "computation_key_label_size_large"
    open_settings()
    ok, note = and_enter_fragment("Appearance")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'Large'")
        return
    before = summary_text(ui(), "Key Label Size")
    okd, noted = and_enter_dialog("Key Label Size")
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'Large'")
        return
    pick_option("Large")
    got = summary_text(ui(), "Key Label Size")
    ok = (got == "Large") and (before != "Large")
    record(name, ok,
           "" if ok else f"behavior_wrong: Key Label Size summary {got!r} after "
                         f"picking 'Large' (before {before!r}), expected 'Large'",
           depth=2, jump_kind="value", expect="Key Label Size summary == 'Large'")
    restore_listpref("Key Label Size", "Medium")


@and_test(expects=("computation_cursor_speed_fast",))
def test_cursor_speed_fast():
    """Cursor Speed: options Slow/Medium/Fast/Very Fast (Medium selected). Pick
    'Fast' -> summary becomes 'Fast' (observed). Row needs scrolling. Restore 'Medium'."""
    name = "computation_cursor_speed_fast"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'Fast'")
        return
    scroll_into_view("Cursor Speed")
    before = summary_text(ui(), "Cursor Speed")
    okd, noted = and_enter_dialog("Cursor Speed", scroll=True)
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'Fast'")
        return
    pick_option("Fast")
    got = summary_text(ui(), "Cursor Speed")
    ok = (got == "Fast") and (before != "Fast")
    record(name, ok,
           "" if ok else f"behavior_wrong: Cursor Speed summary {got!r} after "
                         f"picking 'Fast' (before {before!r}), expected 'Fast'",
           depth=2, jump_kind="value", expect="Cursor Speed summary == 'Fast'")
    restore_listpref("Cursor Speed", "Medium", scroll=True)


@and_test(expects=("computation_long_press_punctuation_spacebar",))
def test_long_press_punctuation_spacebar():
    """Long Press Punctuation: options Off/Spacebar/Period Key (Period Key selected).
    Pick 'Spacebar' -> summary becomes 'Spacebar' (observed). Restore 'Period Key'."""
    name = "computation_long_press_punctuation_spacebar"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'Spacebar'")
        return
    scroll_into_view("Long Press Punctuation")
    before = summary_text(ui(), "Long Press Punctuation")   # observed "Period Key"
    okd, noted = and_enter_dialog("Long Press Punctuation", scroll=True)
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'Spacebar'")
        return
    pick_option("Spacebar")
    got = summary_text(ui(), "Long Press Punctuation")
    ok = (got == "Spacebar") and (before != "Spacebar")
    record(name, ok,
           "" if ok else f"behavior_wrong: Long Press Punctuation summary {got!r} "
                         f"after picking 'Spacebar' (before {before!r}), expected 'Spacebar'",
           depth=2, jump_kind="value", expect="Long Press Punctuation summary == 'Spacebar'")
    restore_listpref("Long Press Punctuation", "Period Key", scroll=True)


@and_test(expects=("computation_long_press_duration_long",))
def test_long_press_duration_long():
    """Long Press Duration: options Short/Medium/Long (Medium selected). Pick
    'Long' -> summary becomes 'Long' (observed). Restore 'Medium'."""
    name = "computation_long_press_duration_long"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'Long'")
        return
    scroll_into_view("Long Press Duration")
    before = summary_text(ui(), "Long Press Duration")
    okd, noted = and_enter_dialog("Long Press Duration", scroll=True)
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'Long'")
        return
    pick_option("Long")
    got = summary_text(ui(), "Long Press Duration")
    ok = (got == "Long") and (before != "Long")
    record(name, ok,
           "" if ok else f"behavior_wrong: Long Press Duration summary {got!r} after "
                         f"picking 'Long' (before {before!r}), expected 'Long'",
           depth=2, jump_kind="value", expect="Long Press Duration summary == 'Long'")
    restore_listpref("Long Press Duration", "Medium", scroll=True)


@and_test(expects=("computation_space_bar_size_wide",))
def test_space_bar_size_wide():
    """Space Bar Size (Layout & Input): options Compact/Standard/Wide (Standard
    selected). Pick 'Wide' -> summary becomes 'Wide' (observed). Restore 'Standard'."""
    name = "computation_space_bar_size_wide"
    open_settings()
    ok, note = and_enter_layout_fragment()
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'Wide'")
        return
    if not find_node(ui(), text="Space Bar Size"):
        scroll_into_view("Space Bar Size")
    before = summary_text(ui(), "Space Bar Size")   # observed "Standard"
    okd, noted = and_enter_dialog("Space Bar Size", scroll=True)
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'Wide'")
        return
    pick_option("Wide")
    got = summary_text(ui(), "Space Bar Size")
    ok = (got == "Wide") and (before != "Wide")
    record(name, ok,
           "" if ok else f"behavior_wrong: Space Bar Size summary {got!r} after "
                         f"picking 'Wide' (before {before!r}), expected 'Wide'",
           depth=2, jump_kind="value", expect="Space Bar Size summary == 'Wide'")
    restore_listpref("Space Bar Size", "Standard", scroll=True)


@and_test(expects=("computation_keyboard_layout_qwertz", "computation_keyboard_layout_dialog_vlm"))
def test_keyboard_layout_qwertz():
    """Keyboard Layout (Layout & Input): default summary 'Default (Language Layout)'.
    Options include QWERTY/AZERTY/QWERTZ/Dvorak/... Pick 'QWERTZ' -> summary becomes
    EXACTLY 'QWERTZ' (observed verbatim). VLM: the dialog is a rendered option list.
    Restore to 'Default (Language Layout)'."""
    name = "computation_keyboard_layout_qwertz"
    open_settings()
    ok, note = and_enter_layout_fragment()
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="summary 'QWERTZ'")
        return
    before = summary_text(ui(), "Keyboard Layout")   # observed "Default (Language Layout)"
    okd, noted = and_enter_dialog("Keyboard Layout")
    if not okd:
        record(name, False, noted, depth=2, jump_kind="value", expect="summary 'QWERTZ'")
        return
    vlm_assert("computation_keyboard_layout_dialog",
               "Is a dialog shown listing multiple keyboard-layout choices (such as "
               "QWERTY / QWERTZ / AZERTY) as a vertical list of selectable rows?",
               RESULTS_DIR, tag="shape")
    pick_option("QWERTZ")
    got = summary_text(ui(), "Keyboard Layout")
    ok = (got == "QWERTZ") and (before != "QWERTZ")
    record(name, ok,
           "" if ok else f"behavior_wrong: Keyboard Layout summary {got!r} after "
                         f"picking 'QWERTZ' (before {before!r}), expected 'QWERTZ'",
           depth=2, jump_kind="value", expect="Keyboard Layout summary == 'QWERTZ'")
    restore_listpref("Keyboard Layout", "Default (Language Layout)")


# ══════════════════════════════════════════════════════════════════════════════
# (2) Vibration Strength SeekBar: tap a position -> numeric label (deterministic)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("computation_vibration_seekbar_min",
                   "computation_vibration_seekbar_min_vlm"))
def test_vibration_seekbar_min():
    """Vibration Strength SeekBar (min 1, max 255, starts at 128). Tapping the far
    LEFT (2% of the bar width) deterministically sets seekbar_value to '6'
    (reproduced 3x). Positive/negative: value is '128' before, '6' after. VLM: the
    thumb visibly sits at the left end. Restore toward 128 (centre tap -> 128)."""
    name = "computation_vibration_seekbar_min"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="seekbar_value '6'")
        return
    if not scroll_into_view("Vibration Strength"):
        record(name, False, "setup_failed: 'Vibration Strength' not reached",
               depth=2, jump_kind="value", expect="seekbar_value '6'")
        return
    and_enter("Vibration Strength seekbar")
    before = seek_value(ui())          # observed "128"
    got, found = tap_seekbar_fraction(0.02)
    if not found:
        record(name, False, "setup_failed: seekbar node not found",
               depth=2, jump_kind="value", expect="seekbar_value '6'")
        return
    # VLM: thumb pushed to the far-left after the tap.
    vlm_assert("computation_vibration_seekbar_min",
               "Is the slider (SeekBar) thumb positioned at the far-LEFT end of the "
               "Vibration Strength track, near the start of the bar?",
               RESULTS_DIR, tag="position")
    ok = (got == "6") and (before == "128")
    record(name, ok,
           "" if ok else f"behavior_wrong: seekbar_value {got!r} after far-left tap "
                         f"(before {before!r}), expected '6'",
           depth=2, jump_kind="value", expect="seekbar_value == '6' (far-left tap)")
    tap_seekbar_fraction(0.5)          # restore toward centre (-> 128)


@and_test(expects=("computation_vibration_seekbar_max",
                   "computation_vibration_seekbar_max_vlm"))
def test_vibration_seekbar_max():
    """Tapping the far RIGHT (98% of the bar width) deterministically sets
    seekbar_value to '250' (reproduced 3x). Positive/negative: '250' absent before,
    present after. VLM: the thumb visibly sits at the right end. Restore toward 128."""
    name = "computation_vibration_seekbar_max"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="seekbar_value '250'")
        return
    if not scroll_into_view("Vibration Strength"):
        record(name, False, "setup_failed: 'Vibration Strength' not reached",
               depth=2, jump_kind="value", expect="seekbar_value '250'")
        return
    and_enter("Vibration Strength seekbar")
    before = seek_value(ui())
    got, found = tap_seekbar_fraction(0.98)
    if not found:
        record(name, False, "setup_failed: seekbar node not found",
               depth=2, jump_kind="value", expect="seekbar_value '250'")
        return
    vlm_assert("computation_vibration_seekbar_max",
               "Is the slider (SeekBar) thumb positioned at the far-RIGHT end of the "
               "Vibration Strength track, near the end of the bar?",
               RESULTS_DIR, tag="position")
    ok = (got == "250") and (before != "250")
    record(name, ok,
           "" if ok else f"behavior_wrong: seekbar_value {got!r} after far-right tap "
                         f"(before {before!r}), expected '250'",
           depth=2, jump_kind="value", expect="seekbar_value == '250' (far-right tap)")
    tap_seekbar_fraction(0.5)          # restore toward centre (-> 128)


@and_test(expects=("computation_vibration_seekbar_center",))
def test_vibration_seekbar_center():
    """Tapping the CENTRE (50% of the bar width) deterministically sets
    seekbar_value to '128' (reproduced 3x; also the default). Verify by first
    driving it to the far-left ('6') then a centre tap returns it to '128' —
    so the assertion is a specific set->read, not merely 'unchanged'."""
    name = "computation_vibration_seekbar_center"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect="seekbar_value '128'")
        return
    if not scroll_into_view("Vibration Strength"):
        record(name, False, "setup_failed: 'Vibration Strength' not reached",
               depth=2, jump_kind="value", expect="seekbar_value '128'")
        return
    and_enter("Vibration Strength seekbar")
    low, found = tap_seekbar_fraction(0.02)      # drive down to '6' first
    if not found:
        record(name, False, "setup_failed: seekbar node not found",
               depth=2, jump_kind="value", expect="seekbar_value '128'")
        return
    got, _ = tap_seekbar_fraction(0.5)           # centre -> back to '128'
    ok = (low == "6") and (got == "128")
    record(name, ok,
           "" if ok else f"behavior_wrong: centre tap gave {got!r} (from {low!r}), "
                         f"expected '128'",
           depth=2, jump_kind="value", expect="seekbar_value == '128' (centre tap)")


# ══════════════════════════════════════════════════════════════════════════════
# (3) test_field EditText echo: type a string -> field text equals it exactly
#     (different fragments from the interaction lane; distinct markers)
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("computation_test_field_echo_typing",
                   "computation_test_field_echo_typing_vlm"))
def test_test_field_echo_typing():
    """Typing Behavior fragment's bottom test_field: type 'kbdcompute7' -> the
    field's text equals exactly 'kbdcompute7' (observed). VLM: the typed text is
    rendered in the field."""
    name = "computation_test_field_echo_typing"
    marker = "kbdcompute7"
    open_settings()
    ok, note = and_enter_fragment("Typing Behavior Settings")
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect=f"field == {marker!r}")
        return
    tf = test_field(ui())
    if not tf:
        record(name, False, "feature_missing: no test_field EditText",
               depth=2, jump_kind="value", expect=f"field == {marker!r}")
        return
    if not type_text(tf, marker):
        record(name, False, "setup_failed: could not type into test_field",
               depth=2, jump_kind="value", expect=f"field == {marker!r}")
        return
    got = (node_by_id(ui(), "test_field") or {}).get("text", "")
    ok = got.strip() == marker
    # VLM: the field visibly renders the typed characters.
    vlm_assert("computation_test_field_echo_typing",
               f"Does the 'Test changes' input field at the bottom visibly display "
               f"the typed text '{marker}'?",
               RESULTS_DIR, tag="content")
    record(name, ok,
           "" if ok else f"behavior_wrong: test_field held {got!r}, expected {marker!r}",
           depth=2, jump_kind="value", expect=f"test_field text == {marker!r}")


@and_test(expects=("computation_test_field_echo_layout",))
def test_test_field_echo_layout():
    """Layout & Input fragment's bottom test_field: type 'kbdlayout9' -> the
    field's text equals exactly 'kbdlayout9' (observed)."""
    name = "computation_test_field_echo_layout"
    marker = "kbdlayout9"
    open_settings()
    ok, note = and_enter_layout_fragment()
    if not ok:
        record(name, False, note, depth=1, jump_kind="value", expect=f"field == {marker!r}")
        return
    tf = test_field(ui())
    if not tf:
        record(name, False, "feature_missing: no test_field EditText",
               depth=2, jump_kind="value", expect=f"field == {marker!r}")
        return
    if not type_text(tf, marker):
        record(name, False, "setup_failed: could not type into test_field",
               depth=2, jump_kind="value", expect=f"field == {marker!r}")
        return
    got = (node_by_id(ui(), "test_field") or {}).get("text", "")
    ok = got.strip() == marker
    record(name, ok,
           "" if ok else f"behavior_wrong: test_field held {got!r}, expected {marker!r}",
           depth=2, jump_kind="value", expect=f"test_field text == {marker!r}")


TESTS = [
    # ListPreference pick -> summary
    test_suggestion_count_2,
    test_suggestion_count_1,
    test_key_size_large,
    test_key_label_size_large,
    test_cursor_speed_fast,
    test_long_press_punctuation_spacebar,
    test_long_press_duration_long,
    test_space_bar_size_wide,
    test_keyboard_layout_qwertz,
    # SeekBar set -> value
    test_vibration_seekbar_min,
    test_vibration_seekbar_max,
    test_vibration_seekbar_center,
    # test_field echo
    test_test_field_echo_typing,
    test_test_field_echo_layout,
]

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