---
name: testbed
description: "Use the testbed CLI to lease cloud Android phones, open human verification sessions, and run the acceptance case table for Raft app releases. Use when asked to smoke-test an APK, verify a build on a real device, hand a phone to a human verifier, or run release acceptance. Login is `testbed login` (managed Raft agents: PKCE through raft, no browser)."
---

# testbed — cloud phones and release acceptance

The testbed is the acceptance gate for Raft app releases: a warm pool of cloud Android
phones, human verification sessions on those phones, and an acceptance case table that
runs against an APK. Everything is driven by the `testbed` CLI; the Raft manifest only
publishes `agent-login`.

## Setup (once per seat)

```sh
npm i -g @botiverse/testbed-cli        # or: npx @botiverse/testbed-cli …
# non-root: npm config set prefix ~/.npm-global && export PATH="$HOME/.npm-global/bin:$PATH"
testbed login                          # managed Raft agent: no browser; human/CI: set TESTBED_TOKEN
testbed whoami                         # who the API thinks you are
```

`TESTBED_URL` selects the instance (default https://testbed.botiverse.build). Add `--json`
to any command to get the raw API body for parsing.

## Workflow 1 — run the acceptance table against a build

```sh
testbed cases                                           # the case table (id, tier, revision, title)
testbed run --all --apk <download-url> --release <id>   # legacy app/project selection; may be incompatible with mixed cases
testbed run <case-id...> --apk <download-url>           # a subset
testbed runs                                            # recent runs
testbed show <run-id>                                   # per-case verdicts, turns, evidence
```

To check a pinned Android emulator build, use the coordinate file for that build.

```sh
testbed preflight --all --coordinate-file build.json --json
testbed confirm <case-id> --coordinate-file build.json --receipt <ID.SHA256>
testbed show <ID> --json
```

Preflight lists the enabled cases for the selected project and app, with their
login mode or the reason they are ineligible. It creates zero runs. After reviewing
one case, pass its confirmation and the same build and run options to create it.
If the reply is lost, use the ID before the dot to read back the admission receipt
and the first attempt. Reuse the same confirmation only when dispatch is
`not_sent` and `can_resume` is true. If the reason is `SELECTION_CHANGED`,
run preflight again and review the updated case, workflow and inputs. An old
confirmation stays ineligible after a case or project change, even if the
previous settings are restored. For `unknown`,
reconcile the attempt with its workflow callback. A
`rejected` dispatch includes the provider HTTP status. An `accepted` dispatch
still requires installation, login and product evidence from the executor.

Release SOP rules (artin, 2026-09-04): the default 3-step smoke (login, channel list,
open a channel) is NOT a full smoke. A release smoke must enumerate the full applicable case set; `run --all` alone does not
resolve mixed platform, device and authentication requirements. Review each case and
use explicit strict coordinates (`testbed run <case-id> --coordinate-file PATH`) where
needed; never substitute an emulator for a required cloud device. A cell that was not
run is recorded as `NOT RUN` with the reason (hotfix exemption: `NOT RUN·hotfix 豁免`),
never left blank. Receipts bind `versionCode + SHA-256`, not just the version name.

## Workflow 2 — hand a phone to a human verifier

```sh
testbed verify start --ttl 30 --app-ref "1.11.0 (1110001)" \
  [--apk-key fast/<id> --apk-sha256 <hex>]   # pre-install an APK; key and sha go together
# prints the verify page URL — give it to the human
testbed verify accounts <session-id>          # QA accounts they may log in with
testbed verify login <session-id> --account <account-id>
testbed verify renew <session-id> --minutes 30
testbed verify reinstall <session-id> --apk-key fast/<id> --apk-sha256 <hex>
- `testbed verify logcat <session-id> [--out FILE]` — raw `logcat -d` of the session's device (creator, member, or operator); 1 MiB cap, credentials sanitized Worker-side. Use it the moment a verifier reports a bug, before the session ends.
testbed verify end <session-id>               # always end; the device is reclaimed
```

One verification session is live at a time; `start` answers 409 when another is live.
`show` on an ended session answers 410.

## Workflow 3 — drive a phone yourself over ADB

```sh
testbed pool                                  # free / leased
testbed acquire --ttl 20 --key-out ./adb.key  # lease; private key written 0600, never printed
adb connect <adb_endpoint>                    # from the acquire output
testbed renew <lease-id> --ttl 20
testbed diagnose-adb <lease-id> [--pubkey-sha256 <hex>]
testbed release <lease-id>                    # always release
```

Device safety (non-negotiable):
- Never paste `adb_private_key` into Raft messages, tasks, logs, or artifacts.
- Before connecting, derive the saved key's android_pubkey SHA-256 and require it to equal
  `adb_public_key_sha256` from the acquire response; on mismatch, release and do not connect.
- Release every lease. Devices in `reclaiming` / `reclaim_failed` are never yours.
- Cloud-phone screenshots can return a stale frame: to prove "nothing changed", the
  capture must include something that would have changed if it were live.

## Beds (Linux VMs on exe.dev)

A bed is a throwaway Linux VM the testbed brokers on exe.dev. Everything is `testbed bed …`; the Raft manifest advertises nothing for beds.

```bash
testbed bed provision --ttl 900 --spec '{"platform":"linux","labels":{"purpose":"probe"}}'   # → bed id, state ready when the VM is up
testbed bed list | testbed bed get <bed-id>
testbed bed round <bed-id> --argv '["uname","-a"]'            # one command round
testbed bed exec start <bed-id> --argv '["./long.sh"]'        # long job → job id; exec get/cancel
testbed bed collab grant <bed-id> --label me --public-key-file ~/.ssh/id_ed25519.pub   # SSH access; the key never leaves the file
testbed bed cleanup <bed-id>                                  # destroy; then `bed residue <bed-id>` proves zero provider residue
```
Rules: always `cleanup` what you `provision` (TTL is a backstop, not a plan); `residue` is the proof, not the destroy call; `--request-id` makes provision/round/exec/collab idempotent on retry; reports, retention and templates exist for evidence handling and are documented in `testbed bed --help`.

For a declarative agent-runtime Bed, add a `runtimeProfile` object to `--spec`.
It must use `testbed.runtime-profile.v1`, carry explicit `id`/`revision`, and
pin each selected `pi`, `codex`, `opencode`, or `builtin` runtime exactly.
`authRef` is an opaque exe.dev integration name, never a credential value, and
must match the sole `integrationRefs` item. The response reports the complete
managed set and one exclusive state per runtime: `ready`, `not_installed`,
`installed_needs_login`, or `probe_failed`. Only a successful native model-list
probe plus provider authority proof is `ready`; network/timeout is always
`probe_failed`. Use `--wait-ms` to bound automatic same-lineage reconciliation;
an unresolved outcome exits 2 and must not be reprovisioned under a new request
id. `ready` is the result of the last provision/reconcile probe, not continuous
health. Runtime-profile v1 measures managed runtime HOME roots without reading
file contents. The receipt lists observed auth-like relative paths with scope
`bed_home`, destruction `vm_destroy`, and terminal proof
`bed_tombstone_provider_absent`; an empty list means `none_observed`,
not "not scanned". Any runtime version-pin change must rerun this observation.
`vm_destroy` is eventual, not automatic proof: evidence holds and
cleanup-retry/incident keep the VM (and file) alive. Only a tombstone backed by
provider-absence readback proves destruction; an incident needs owner recovery.
## macOS VM (PVE VM130 lease)

One macOS VM on Proxmox, leased through the testbed; the Worker signs every adapter call with its own credential, so you never see the bridge, its token or a host command. Everything is `testbed pve …`; the manifest advertises nothing for it. `--purpose` is required on every call: while the provider is in quarantine the only accepted value is `task-9-universal-lease-v0.1-acceptance`.

```bash
P=task-9-universal-lease-v0.1-acceptance
testbed pve facts --purpose $P                                  # guest agent, os, baseline revision
testbed pve acquire --purpose $P --ttl 3600                     # → lease id + epoch (one active lease)
testbed pve status <lease-id> --epoch N --purpose $P            # the adapter's own view, not the Worker's
testbed pve exec <lease-id> --epoch N --purpose $P --argv '["uname","-a"]'
testbed pve put <lease-id> --epoch N --purpose $P --path /tmp/x --file ./x
testbed pve get <lease-id> --epoch N --purpose $P --path /tmp/x --out ./x.back
testbed pve release <lease-id> --epoch N --purpose $P           # ends the lease AND rolls back to baseline
```
Rules: `put` carries at most 15,722,496 bytes per file (just under 15 MiB: the adapter caps the whole request, data base64-encoded plus metadata, at 20 MiB; the Worker refuses larger requests with 413 before sending). TTL is 60..3600 s. `release` and `rollback` restore the baseline snapshot, so anything written after it is gone — copy out what you need first. Wrong owner/epoch/expired are typed refusals from the adapter, relayed verbatim. `--request-id` makes acquire/renew/exec/put/reboot/rollback/release idempotent on retry.

## Errors

**ADB says `unauthorized` on a fresh lease** — do NOT release yet (releasing destroys the evidence). The acquire JSON carries `adb_key_attested_at_activation: true` and `adb_key_attested_sha256`: the broker proved that key on the device when the lease activated. That is a point-in-time reading, not a live state. Three cells:

| acquire says | adb says | do |
|---|---|---|
| attested | connects | normal |
| attested | unauthorized | **step 0: `adb kill-server`, then reconnect.** The adb server reads `ADB_VENDOR_KEYS` only at startup; a server left over from a previous lease keeps offering the OLD key and reports `unauthorized` with a perfectly healthy device (2026-09-10, lease e78e6654). Skipping this step manufactures a convincing but false device-side diagnosis. Still unauthorized after a fresh server → the key changed after activation. Evidence first: (1) `testbed diagnose-adb <lease-id> --pubkey-sha256 <adb_key_attested_sha256>`, keep the JSON (before-repair); (2) `testbed repair-adb <lease-id>` (re-materializes + restarts adbd, lease unchanged) and retry; (3) still failing: diagnose-adb again (after-repair). Attach both JSONs before releasing |
| in_flight / no lease | — | do not connect; the key never materialized (the CLI keeps retrying with the same request id) |

`adb_pending` only says whether a public endpoint exists; it says nothing about the key. `adb_recovery` in the JSON repeats the recovery command.


- `401` → `testbed login` (agent) or check `TESTBED_TOKEN` (human/CI).
- `409 POOL_EXHAUSTED` / `ANOTHER_SESSION_LIVE` → wait or end/release what you hold.
- `410` on a verification session → it is over; start a new one.

## Reference

`GET /api/help` on the instance lists every command and the raw routes behind them.
Manifest action for Raft Agent Login: `agent-login` (the CLI performs it for you).
