# Terminal clear proof

Compare base [f1efcfb494](https://github.com/pingdotgg/t3code/commit/f1efcfb4948542237f6e2ceb5389de9e23f9baea) and head [5192732701](https://github.com/pingdotgg/t3code/commit/519273270179633afba4c0e261540ce86d2c735d). All data is synthetic. Web is Chromium, 1280 x 800, light theme. Mobile is a pooled Pixel 9, Android API 36, 1080 x 2424, light theme, with the software keyboard.

## Web

Save terminal-clear-split-controls.e2e.ts in scripts/scenarios of current main. Run vp i, then:

    T3CODE_DEV_SEED=0 vp run scenarios:prove scripts/scenarios/terminal-clear-split-controls.e2e.ts --base f1efcfb4948542237f6e2ceb5389de9e23f9baea --head 519273270179633afba4c0e261540ce86d2c735d --upload-command "ghdrop upload"

The single test seeds a project and Replay thread, launches a real raw-mode PTY program, emits the OSC opener, clears through a second-client RPC while the drawer stays open, completes the title, captures, then closes/reopens the drawer and captures again. It repeats with CSI containing LF before Clear and `m` afterwards. The text assertions copy from the real terminal canvas. Base displays progressready-title / mready-csi; head displays ready-title / ready-csi, at the top row.

## Android

Run the server and Metro from each commit's own checkout, using separate fresh T3 homes, T3CODE_DEV_SEED=0, and no copied database. Prepare/install the dev client using vp run mobile:install android --prepare and --session. Pair through the repository's pair-client.sh, and seed each server using proof-seed.ts (save under scripts/scenarios). Set T3_SCENARIO_APP_DIR to the app checkout when the seed helper is run from the runner checkout.

Open the seeded thread, tap Terminal, Open new terminal. Set a synthetic prompt with `export PS1='demo $ '; clear`, press Enter. Swipe the terminal toolbar left until Clear is at the left edge. Save the mobile Python drivers outside the checkout. Their session and output prefix are arguments; run them from the runner checkout.

    python3 mobile-title-driver.py SESSION OUTPUT_PREFIX

This types the reported printf command, presses Enter, waits 1.5 seconds, taps the actual Clear key at (90,1460), and records the result. Base displays progressready; head displays ready.

## Real queued-exit and drain race

Save proof-inspector.mjs under scripts/scenarios. On each server separately, while port 9229 is free, start:

    node scripts/scenarios/proof-inspector.mjs T3_HOME install

Wait for ARMED, then send an ordinary shell command. The debugger briefly stops at the real output publication boundary, installs a subscriber that waits on output containing HOLD, then resumes. It never changes process events, session status, parser state, drain flags or the queue. It simulates a slow subscriber; every output and exit comes from the real shell and PTY.

    python3 mobile-race-driver.py SESSION T3_HOME SERVER_ORIGIN scripts/scenarios/proof-inspector.mjs OUTPUT_PREFIX

The driver runs `printf 'HOLD-one\n'; sleep 8; printf 'HOLD-two\n'; sleep 8; exit 42`. It clears during the first blocked publication, then waits for subsequent output and the genuine exit to queue. It clears again and releases the subscribers. State snapshots are read-only through the inspector. Base starts a second concurrent drain (two blocked subscribers), drops exit 42, and leaves the terminal marked running. Head retains one drain, keeps exit 42, delivers it on release, and automatically returns the mobile app to the thread. race-transcript.txt contains only the sanitized runtime observations.

## Text fallback

Save proof-mobile-runtime.mjs and proof-terminal-rpc.ts under scripts/scenarios. Before opening a new terminal, run:

    PROOF_METRO_ORIGIN=DEVICE_REACHABLE_METRO_ORIGIN node scripts/scenarios/proof-mobile-runtime.mjs METRO_PORT

This uses Hermes CDP to make the optional native-view adapter report no native view/output. No source files, parser, output reducer or fallback renderer are modified. The real app shows "Native terminal unavailable. Using text fallback.". The exact advertised Metro origin is required for its debugger websocket.

Open a new shell. Set `export PS1='demo $ '; bind 'set enable-bracketed-paste off'`. Empty the fallback input, show the keyboard, then run:

    python3 mobile-fallback-driver.py SESSION T3_HOME SERVER_ORIGIN THREAD_ID scripts/scenarios/proof-terminal-rpc.ts OUTPUT_PREFIX

This sends the same printf command through a second-client RPC, clears during its pause, and records the actual fallback. Base displays progressready; head displays ready. Restore the adapter afterwards:

    PROOF_METRO_ORIGIN=DEVICE_REACHABLE_METRO_ORIGIN node scripts/scenarios/proof-mobile-runtime.mjs METRO_PORT '__proofRestoreTerminal(); true'

The native Android comparison uses the real Clear key; the supplementary fallback comparison uses RPC Clear. Release the device and stop only the server and Metro processes started for this proof.
