#!/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")