@budaknyenyel/emu-lab
v0.1.0
Published
Leased Android emulator testing, CLI and MCP server
Readme
emu-lab
Android emulator testing with leased devices, cached builds, device-state controls and evidence-based failure classification. The package provides a Node 24 TypeScript library, CLI and tools-only MCP server. See the implementation plan for the full intended behavior and the API guide for in-process use.
The library, CLI and MCP server route operations through the shared core, which coordinates emulator leases and test execution.
flowchart LR
Library[Node library] --> Core[Core operations]
CLI[CLI] --> Core
MCP[MCP server] --> CLI
Core --> Scheduler[Lease scheduler]
Core --> Build[Build]
Core --> Runners[Device runners]
Core --> Classifier[Failure classifier]
Scheduler --> Emulator[Android emulator]
Runners --> EmulatorThe scheduler stores a state per device, including devices in a group lease. A lease remains active until release or until both its expiry and heartbeat deadlines have passed; heartbeat renews both deadlines.
stateDiagram-v2
[*] --> provisioning: reserve
provisioning --> active: provision and liveness succeed
provisioning --> quarantined: liveness fails or owner lost on recovery
provisioning --> [*]: provisioning fails and cleanup succeeds
active --> active: heartbeat
active --> cleaning: release or both deadlines passed
active --> quarantined: liveness fails or ownership unverified on recovery
cleaning --> [*]: verified cleanup succeeds
cleaning --> quarantined: ownership or cleanup cannot be verified
quarantined --> [*]: dead process, owner marker and free ports verifiedThe failure classifier evaluates rules in descending precedence and returns the first match. The default rules distinguish environment, app and test failures; no match leaves the classification unset.
flowchart TD
Input[Log, hierarchy, facts and artifacts] --> Rules[Rules in descending precedence]
Rules --> Rerun{Isolated rerun passed?}
Rerun -->|Yes| Flaky[Test: flaky]
Rerun -->|No| Env{Environment rule matches?}
Env -->|Yes| Environment[Environment: fail]
Env -->|No| AppCrash{App ANR or crash matches?}
AppCrash -->|Yes| App[App: fail]
AppCrash -->|No| TestRule{Reset or changed-copy rule matches?}
TestRule -->|Yes| Test[Test: fail]
TestRule -->|No| Assertion{App assertion rule matches?}
Assertion -->|Yes| App
Assertion -->|No| Unknown[Fail: classification unset]Install the published package with npm install @budaknyenyel/emu-lab, then run npx emu-lab --help or start emu-lab-mcp for MCP.
Install from source
Clone android-kit and emu-lab as sibling directories. In android-kit, run npm install && npm run build. In emu-lab, run npm install && npm run build. Android SDK tools, a compatible system image, JDK 21, hardware virtualization and Maestro 2.12.x are required for device workflows. JAVA_HOME must select JDK 21 for builds that target Java 21.
npx emu-lab doctor --json
npx emu-lab lab-status --json
npx emu-lab lease-device --profile software --json
npx emu-lab release-device --lease-id LEASE_ID --jsonOptions accept kebab-case flags; JSON objects and arrays can be passed as JSON strings. Each command returns the shared result envelope. Exit codes are 0 for pass, 1 for fail or flaky, and 2 for blocked, unsupported or error. Artifacts are stored below .android-kit/runs/<run-id>/emu-lab/. No telemetry is collected.
A generic MCP client can start the stdio server with an entry such as:
{
"mcpServers": {
"emu-lab": {
"command": "node",
"args": ["/path/to/emu-lab/dist/mcp/bin.js"]
}
}
}Optional project configuration is read from android-kit.yaml:
emuLab:
budget: 1
denySerials: []
allowInstall: false
keepDiagnostics: falseSet keepDiagnostics: true to retain redacted emulator boot diagnostics in the run artifacts. Output is withheld if the console authentication token cannot be read.
Never use a lease to control an independently owned emulator. Host GPU support varies with drivers and headless environments; select the software profile explicitly if host GPU is unavailable. Linux requires accessible KVM, Windows requires supported WHPX/AEHD virtualization, and macOS requires HVF. Emulator console authentication must remain enabled. Use synthetic data only.
The default uses the API 36 Google Play x86-64 image, 2 GiB RAM, four cores, headless mode and host GPU. On one Windows host, headless host-GPU boots reached the locale check in 249 seconds and ready in 158 seconds on a later run; a windowed boot reached the locale check in 434 seconds. These cold-boot observations are host- and load-dependent, not a benchmark. The software profile explicitly requests SwiftShader; headless: false enables a window. Before each boot the scheduler samples CPU utilization and blocks above maxCpuLoad (default 0.85), reporting an environment result rather than booting into an overloaded host.
