# Shared by transcript-bench.sh and stream-bench.sh: the parts of driving # this app that both need and that neither should describe twice. # # Sourced, not run. It assumes android-env.sh has already been sourced, so # `ui-trace` and `adb` are this checkout's. # # **Nothing here presses a coordinate.** Every control is found by the name # it already carries for assistive technology, resolved from the screen at # the moment of the gesture (`ui-trace record --do "tap 'Save'"`). A # coordinate is a position measured once by hand, and anything that moves # the control -- a button added to the row, a font size, another device -- # makes the tap land on whatever now sits there; the bench then reports a # number that was never measured, which reads exactly like a result. That # is not hypothetical: both scripts pressed the render-report button at # `tap 723 205` until 2026-09-03, when it moved into the session settings # dialog. The check that none has crept back: # # grep -n "tap [0-9]" app/*.sh # The title of the session these benches open by default: whichever one the # server lists first, which is the most recently active. # # Asked of the server rather than taken from the screen, because a row has # no stable name of its own and "the first one" is a fact about the list # rather than about a position on it. Passing -s overrides it, and that is # the honest way to measure a particular session: the list is ordered by # last activity, so "the first row" is a different session at different # times of day. first_session_title() { ./ui-sandbox.sh api /sessions | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d[0]["title"] if d else "")' } # Restarts the app and opens the session called $1. open_session() { adb shell am force-stop com.example.aiapp adb shell am start -n com.example.aiapp/.MainActivity >/dev/null sleep 5 ui-trace record -d 6000 --do "tap '$1'" --do 'wait 3000' \ -o /tmp/bench-open.txt >/dev/null sleep 2 } # Copies the app's render report to the clipboard and the log, through the # session settings dialog it lives in. # # Pressed twice per run: once to empty the counters, and once at the end, # so what comes back covers exactly the work between the two. Closing the # dialog is part of it -- it covers the transcript, which is the thing the # gestures in between are meant to reach. copy_render_report() { ui-trace record -d 7000 \ --do "tap 'Session settings'" --do 'wait 1500' \ --do "tap 'Copy'" --do 'wait 800' \ --do "tap 'Close'" --do 'wait 800' \ -o "${1:-/tmp/bench-report.txt}" >/dev/null }