File size: 27,057 Bytes
d292518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""COMPUTATION lane — FlorisBoard.

Core function of this app is the KEYBOARD: tap key(s) -> the exact resulting
characters land in the in-app preview EditText, whose `text` attribute is the
dump-readable OUTPUT. Every rule test here is a single-purpose input->output
`value` assertion (jump_kind="value"), reached at depth=0 (the preview field is
same-activity, opened by tapping the bottom "Try out your setup" bar). Longer
multi-step data sequences and long-press hint digits belong to the interaction
lane; single keys / short "type this, read it back" strings are ours.

The keys themselves are drawn on a Compose CANVAS (no key nodes in the dump), so
what the keyboard RENDERS is observable only through the VLM — that is why this
lane carries a large VLM share (8 questions), all about opaque rendered keys.

Every coordinate is derived from get_screen_info() fractions (recon.md's
CALIBRATED, char-verified QWERTY map); NOTHING is a pixel/package/serial literal.
"""
import os
import sys

os.environ.setdefault("ADB_PATH", "/opt/android/platform-tools/adb")
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import *  # noqa: F403,E402


# ── Local matchers (kit has no startswith/ampersand helper) ─────────────────────
def find_node_startswith(nodes, prefix):
    p = prefix.lower()
    for n in nodes:
        if n.get("text", "").lower().startswith(p):
            return n
    return None


# ── Keyboard geometry — recon.md's calibrated map, all fractions of the screen ──
# ROW1 "qwertyuiop"  y=0.705  x = 0.05 + 0.90*(i/9)   i=0..9
# ROW2 "asdfghjkl"   y=0.795  x = 0.09 + 0.82*(i/8)   i=0..8
# ROW3 "zxcvbnm"     y=0.855  x = 0.18 + 0.64*(i/6)   i=0..6
# SPACE-ROW y=0.915 : ?123 .08  comma .24  emoji .35  space .50  period .76  enter .92
# SHIFT y=0.855 x=0.08 ; BACKSPACE y=0.855 x=0.92
# Symbols layout (after ?123) reuses the ROW1 x-map (10 keys):
#   digits row  y=0.705 -> 1234567890
#   symbol row  y=0.795 -> @ # $ _ & - + ( ) /
_ROWS = {
    1: (0.705, 0.05, 0.90, 9),
    2: (0.795, 0.09, 0.82, 8),
    3: (0.855, 0.18, 0.64, 6),
}
_SPACE_ROW_Y = 0.915
_SPACE_ROW_X = {
    "?123": 0.08, "comma": 0.24, "emoji": 0.35,
    "space": 0.50, "period": 0.76, "enter": 0.92,
}
_SHIFT_X, _BKSP_X, _MODKEY_Y = 0.08, 0.92, 0.855
_ROW1_XSPAN = (0.05, 0.90, 9)   # x-map shared by the symbols digit + symbol rows


def _wh():
    s = get_screen_info()
    return s["width"], s["height"]


def tap_key(row_idx, col_idx):
    """Tap the alpha-layout key at (row 1..3, column) by fraction of the screen."""
    w, h = _wh()
    y_frac, x0, span, denom = _ROWS[row_idx]
    tap(int((x0 + span * (col_idx / denom)) * w), int(y_frac * h))


def tap_space_key(name):
    """Tap a bottom-row key by name (?123 / comma / emoji / space / period / enter)."""
    w, h = _wh()
    tap(int(_SPACE_ROW_X[name] * w), int(_SPACE_ROW_Y * h))


def tap_shift():
    w, h = _wh()
    tap(int(_SHIFT_X * w), int(_MODKEY_Y * h))


def tap_backspace():
    w, h = _wh()
    tap(int(_BKSP_X * w), int(_MODKEY_Y * h))


def tap_symbol_col(col_idx, y_frac):
    """Tap a symbols-layout key at column col_idx on the row at y_frac
    (0.705 = digit row, 0.795 = symbol row), using the ROW1 x-map."""
    w, h = _wh()
    x0, span, denom = _ROW1_XSPAN
    tap(int((x0 + span * (col_idx / denom)) * w), int(y_frac * h))


# ── Preview-keyboard lifecycle (recon helper, hardened for the fresh-emulator
#    first-run flow: an unconfigured install boots into a Subtype editor that has
#    no "Try out your setup" bar until a subtype is saved) ─────────────────────
def _ensure_home_or_settings(nodes):
    """If the first-run subtype editor is up (no 'Try out' bar), pick the English
    preset and Save so a settings screen with the preview bar appears."""
    if find_node_ci(nodes, "Try out your setup"):
        return nodes
    if (find_node_startswith(nodes, "Suggested subtype")
            or find_node_ci(nodes, "Primary language")):
        preset = find_node_ci(nodes, "English (United States)")
        if preset:
            tap_node(preset)
            settle("tap")
        save = find_node_ci(ui(), "Save")
        if save:
            tap_node(save)
            settle("launch")
            settle("launch")
    return ui()


def open_preview_keyboard():
    """Fresh app, reach a screen with the preview bar, focus it, wait for the IME
    window to animate in. Returns True when the keyboard is up."""
    restart_app()
    wait_for_foreground()
    settle("launch")
    nodes = _ensure_home_or_settings(ui())
    bar = find_node_ci(nodes, "Try out your setup")
    if not bar:
        return False
    tap_node(bar)
    settle("launch")
    settle("launch")   # IME window animates in
    return True


def preview_field_text():
    """The current text of the preview EditText (the keyboard's OUTPUT)."""
    for n in ui():
        if n.get("class", "").endswith("EditText"):
            return n.get("text", "")
    return None


def clear_field(max_deletes=48):
    """The preview text PERSISTS across restarts, so every test must start from a
    virgin field. Backspace until empty. Clearing also drops the first-letter
    auto-capitalisation, so a subsequent word types verbatim (verified)."""
    for _ in range(max_deletes):
        if (preview_field_text() or "") == "":
            return True
        tap_backspace()
    return (preview_field_text() or "") == ""


def fresh_preview():
    """open + clear; returns True only when the field is up and empty."""
    if not open_preview_keyboard():
        return False
    return clear_field()


def to_symbols_verified():
    """Switch to the symbols layout and PROVE it took: FlorisBoard reverts to the
    alpha layout when the field empties, and the ?123 switch is race-prone, so we
    tap ?123, then probe digit-column 0 (must yield '1'), retrying once. Leaves the
    field empty and the symbols layout active. Returns True on success."""
    for _ in range(3):
        tap_space_key("?123")
        settle("tap")
        settle("tap")
        before = preview_field_text() or ""
        tap_symbol_col(0, 0.705)          # digit col0 -> '1' iff symbols is active
        after = preview_field_text() or ""
        got = after[len(before):] if after.startswith(before) else after
        tap_backspace()                   # remove the probe char
        if got == "1":
            return (preview_field_text() or "") == before
        clear_field()
    return False


# ══════════════════════════════════════════════════════════════════════════════
# Full letter rows -> exact strings
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_type_row1", "computation_type_row1_vlm"))
def test_type_row1():
    if not fresh_preview():
        record("computation_type_row1", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="qwertyuiop")
    else:
        for i in range(10):
            tap_key(1, i)
        got = preview_field_text() or ""
        ok = got == "qwertyuiop"
        record("computation_type_row1", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected 'qwertyuiop'",
               depth=0, jump_kind="value", expect="qwertyuiop")
    vlm_assert("computation_type_row1",
               "Does the on-screen keyboard render a QWERTY letter layout, with a "
               "top row of letters starting q, w, e, r, t on the left?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_type_row2",))
def test_type_row2():
    if not fresh_preview():
        record("computation_type_row2", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="asdfghjkl")
        return
    for i in range(9):
        tap_key(2, i)
    got = preview_field_text() or ""
    ok = got == "asdfghjkl"
    record("computation_type_row2", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'asdfghjkl'",
           depth=0, jump_kind="value", expect="asdfghjkl")


@and_test(expects=("computation_type_row3",))
def test_type_row3():
    if not fresh_preview():
        record("computation_type_row3", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="zxcvbnm")
        return
    for i in range(7):
        tap_key(3, i)
    got = preview_field_text() or ""
    ok = got == "zxcvbnm"
    record("computation_type_row3", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'zxcvbnm'",
           depth=0, jump_kind="value", expect="zxcvbnm")


# ══════════════════════════════════════════════════════════════════════════════
# Words -> exact strings (cleared field -> no auto-cap; verified verbatim)
# ══════════════════════════════════════════════════════════════════════════════
# Letter -> (row, col) from the verified QWERTY map.
_L = {
    "q": (1, 0), "w": (1, 1), "e": (1, 2), "r": (1, 3), "t": (1, 4),
    "y": (1, 5), "u": (1, 6), "i": (1, 7), "o": (1, 8), "p": (1, 9),
    "a": (2, 0), "s": (2, 1), "d": (2, 2), "f": (2, 3), "g": (2, 4),
    "h": (2, 5), "j": (2, 6), "k": (2, 7), "l": (2, 8),
    "z": (3, 0), "x": (3, 1), "c": (3, 2), "v": (3, 3), "b": (3, 4),
    "n": (3, 5), "m": (3, 6),
}


def _type_word(word):
    for ch in word:
        r, c = _L[ch]
        tap_key(r, c)


@and_test(expects=("computation_word_hello", "computation_word_hello_vlm"))
def test_word_hello():
    if not fresh_preview():
        record("computation_word_hello", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="hello")
    else:
        _type_word("hello")
        got = preview_field_text() or ""
        ok = got == "hello"
        record("computation_word_hello", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected 'hello'",
               depth=0, jump_kind="value", expect="hello")
    vlm_assert("computation_word_hello",
               "Is typed text visible in the preview text field located directly "
               "above the on-screen keyboard?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_word_floris",))
def test_word_floris():
    if not fresh_preview():
        record("computation_word_floris", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="floris")
        return
    _type_word("floris")
    got = preview_field_text() or ""
    ok = got == "floris"
    record("computation_word_floris", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'floris'",
           depth=0, jump_kind="value", expect="floris")


@and_test(expects=("computation_word_keyboard",))
def test_word_keyboard():
    if not fresh_preview():
        record("computation_word_keyboard", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="keyboard")
        return
    _type_word("keyboard")
    got = preview_field_text() or ""
    ok = got == "keyboard"
    record("computation_word_keyboard", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'keyboard'",
           depth=0, jump_kind="value", expect="keyboard")


# ══════════════════════════════════════════════════════════════════════════════
# Single-key values
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_key_a",))
def test_key_a():
    if not fresh_preview():
        record("computation_key_a", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="a")
        return
    tap_key(2, 0)                       # 'a'
    got = preview_field_text() or ""
    ok = got == "a"
    record("computation_key_a", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'a'",
           depth=0, jump_kind="value", expect="a")


@and_test(expects=("computation_key_m",))
def test_key_m():
    if not fresh_preview():
        record("computation_key_m", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="m")
        return
    tap_key(3, 6)                       # 'm'
    got = preview_field_text() or ""
    ok = got == "m"
    record("computation_key_m", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'm'",
           depth=0, jump_kind="value", expect="m")


@and_test(expects=("computation_key_p",))
def test_key_p():
    if not fresh_preview():
        record("computation_key_p", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="p")
        return
    tap_key(1, 9)                       # 'p'  (rightmost of the top row)
    got = preview_field_text() or ""
    ok = got == "p"
    record("computation_key_p", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'p'",
           depth=0, jump_kind="value", expect="p")


# ══════════════════════════════════════════════════════════════════════════════
# shift + letter -> uppercase
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_shift_a", "computation_shift_a_vlm"))
def test_shift_a():
    if not fresh_preview():
        record("computation_shift_a", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="A")
    else:
        tap_shift()
        tap_key(2, 0)                   # 'a' -> 'A'
        got = preview_field_text() or ""
        ok = got == "A"
        record("computation_shift_a", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected 'A'",
               depth=0, jump_kind="value", expect="A")
    # Capture the SHIFTED keyboard rendering for the VLM.
    if fresh_preview():
        tap_shift()
    vlm_assert("computation_shift_a",
               "After the shift key is pressed, are the letter keys on the "
               "keyboard rendered as UPPERCASE letters (A, S, D, F ...)?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_shift_g",))
def test_shift_g():
    if not fresh_preview():
        record("computation_shift_g", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="G")
        return
    tap_shift()
    tap_key(2, 4)                       # 'g' -> 'G'
    got = preview_field_text() or ""
    ok = got == "G"
    record("computation_shift_g", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected 'G'",
           depth=0, jump_kind="value", expect="G")


# ══════════════════════════════════════════════════════════════════════════════
# Symbols layout: digit values
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_symbol_digit_5", "computation_symbol_digit_5_vlm"))
def test_symbol_digit_5():
    if not fresh_preview() or not to_symbols_verified():
        record("computation_symbol_digit_5", False,
               "setup_failed: could not reach the symbols layout",
               depth=0, jump_kind="value", expect="5")
    else:
        tap_symbol_col(4, 0.705)        # digit-row col4 -> '5'
        got = preview_field_text() or ""
        ok = got == "5"
        record("computation_symbol_digit_5", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected '5'",
               depth=0, jump_kind="value", expect="5")
    # Capture the symbols layout digit row for the VLM.
    if fresh_preview():
        to_symbols_verified()
    vlm_assert("computation_symbol_digit_5",
               "Does the keyboard's top row show the digits 1 2 3 4 5 6 7 8 9 0 "
               "in order from left to right?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_symbol_digit_0",))
def test_symbol_digit_0():
    if not fresh_preview() or not to_symbols_verified():
        record("computation_symbol_digit_0", False,
               "setup_failed: could not reach the symbols layout",
               depth=0, jump_kind="value", expect="0")
        return
    tap_symbol_col(9, 0.705)            # digit-row col9 -> '0'
    got = preview_field_text() or ""
    ok = got == "0"
    record("computation_symbol_digit_0", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected '0'",
           depth=0, jump_kind="value", expect="0")


@and_test(expects=("computation_symbol_digit_1",))
def test_symbol_digit_1():
    if not fresh_preview() or not to_symbols_verified():
        record("computation_symbol_digit_1", False,
               "setup_failed: could not reach the symbols layout",
               depth=0, jump_kind="value", expect="1")
        return
    tap_symbol_col(0, 0.705)            # digit-row col0 -> '1'
    got = preview_field_text() or ""
    ok = got == "1"
    record("computation_symbol_digit_1", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected '1'",
           depth=0, jump_kind="value", expect="1")


# ══════════════════════════════════════════════════════════════════════════════
# Symbols layout: symbol-char values
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_symbol_at", "computation_symbol_at_vlm"))
def test_symbol_at():
    if not fresh_preview() or not to_symbols_verified():
        record("computation_symbol_at", False,
               "setup_failed: could not reach the symbols layout",
               depth=0, jump_kind="value", expect="@")
    else:
        tap_symbol_col(0, 0.795)        # symbol-row col0 -> '@'
        got = preview_field_text() or ""
        ok = got == "@"
        record("computation_symbol_at", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected '@'",
               depth=0, jump_kind="value", expect="@")
    if fresh_preview():
        to_symbols_verified()
    vlm_assert("computation_symbol_at",
               "In the symbols layout, are symbol keys such as @ , # and $ "
               "rendered on the keyboard?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_symbol_hash",))
def test_symbol_hash():
    if not fresh_preview() or not to_symbols_verified():
        record("computation_symbol_hash", False,
               "setup_failed: could not reach the symbols layout",
               depth=0, jump_kind="value", expect="#")
        return
    tap_symbol_col(1, 0.795)            # symbol-row col1 -> '#'
    got = preview_field_text() or ""
    ok = got == "#"
    record("computation_symbol_hash", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected '#'",
           depth=0, jump_kind="value", expect="#")


@and_test(expects=("computation_symbol_dollar",))
def test_symbol_dollar():
    if not fresh_preview() or not to_symbols_verified():
        record("computation_symbol_dollar", False,
               "setup_failed: could not reach the symbols layout",
               depth=0, jump_kind="value", expect="$")
        return
    tap_symbol_col(2, 0.795)            # symbol-row col2 -> '$'
    got = preview_field_text() or ""
    ok = got == "$"
    record("computation_symbol_dollar", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected '$'",
           depth=0, jump_kind="value", expect="$")


# ══════════════════════════════════════════════════════════════════════════════
# Space, backspace, comma, period (single-purpose value checks)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_space_between",
                   "computation_space_between_vlm"))
def test_space_between():
    if not fresh_preview():
        record("computation_space_between", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="a b")
    else:
        tap_key(2, 0)                   # 'a'
        tap_space_key("space")          # ' '
        tap_key(3, 4)                   # 'b'
        got = preview_field_text() or ""
        ok = got == "a b"
        record("computation_space_between", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected 'a b'",
               depth=0, jump_kind="value", expect="a b")
    vlm_assert("computation_space_between",
               "Does the bottom row of the keyboard contain a wide space bar in "
               "the middle and a return/enter key (a checkmark) at the right, "
               "with a ?123 key at the left?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_backspace", "computation_backspace_vlm"))
def test_backspace():
    if not fresh_preview():
        record("computation_backspace", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect="a (after deleting b of 'ab')")
    else:
        tap_key(2, 0)                   # 'a'
        tap_key(3, 4)                   # 'b'  -> field is "ab"
        tap_backspace()                 # delete 'b' -> "a"
        got = preview_field_text() or ""
        ok = got == "a"
        record("computation_backspace", ok,
               "" if ok else f"behavior_wrong: got {got!r}, expected 'a'",
               depth=0, jump_kind="value", expect="a")
    # Capture the alpha layout for the mod-key rendering question.
    fresh_preview()
    vlm_assert("computation_backspace",
               "Does the keyboard have a shift key (up-arrow) at the bottom-left "
               "of the letters and a backspace/delete key (an X in an arrow) at "
               "the bottom-right of the letters?",
               RESULTS_DIR, tag="content")


@and_test(expects=("computation_comma",))
def test_comma():
    if not fresh_preview():
        record("computation_comma", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect=",")
        return
    tap_space_key("comma")              # ',' (period overlaps space bar; comma verified)
    got = preview_field_text() or ""
    ok = got == ","
    record("computation_comma", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected ','",
           depth=0, jump_kind="value", expect=",")


@and_test(expects=("computation_period",))
def test_period():
    if not fresh_preview():
        record("computation_period", False,
               "setup_failed: could not open/clear preview keyboard",
               depth=0, jump_kind="value", expect=".")
        return
    tap_space_key("period")            # '.'
    got = preview_field_text() or ""
    ok = got == "."
    record("computation_period", ok,
           "" if ok else f"behavior_wrong: got {got!r}, expected '.'",
           depth=0, jump_kind="value", expect=".")


# ══════════════════════════════════════════════════════════════════════════════
# One more VLM: the alpha layout carries hinted numbers on its top row.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("computation_hinted_numbers_vlm",))
def test_hinted_numbers_vlm():
    fresh_preview()                    # default alpha layout
    vlm_assert("computation_hinted_numbers",
               "On the top letter row of the keyboard, is each letter key marked "
               "with a small hint digit in its upper corner (1 on q, 2 on w, and "
               "so on)?",
               RESULTS_DIR, tag="content")


TESTS = [
    test_type_row1,
    test_type_row2,
    test_type_row3,
    test_word_hello,
    test_word_floris,
    test_word_keyboard,
    test_key_a,
    test_key_m,
    test_key_p,
    test_shift_a,
    test_shift_g,
    test_symbol_digit_5,
    test_symbol_digit_0,
    test_symbol_digit_1,
    test_symbol_at,
    test_symbol_hash,
    test_symbol_dollar,
    test_space_between,
    test_backspace,
    test_comma,
    test_period,
    test_hinted_numbers_vlm,
]

if __name__ == "__main__":
    if not device_online():
        print("Device not reachable — aborting.")
        sys.exit(1)
    run_suite(TESTS, "computation")