mirror of
https://github.com/software-mansion/argent.git
synced 2026-09-14 19:27:14 +08:00
6e9e45c9f0
This pull request lets Argent drive a simulator or emulator another process is already running, attaching to its simulator-server rather than spawning a second one. A provider writes a JSON descriptor to `~/.argent/providers/` listing the devices it offers and the mechanisms Argent may use on each. They appear in `list-devices` with an `ext:` id and work with the existing tools. The file is re-read on every call, so a withdrawal or a narrowed grant applies immediately. `ios.additionalDeviceSets` (#600) already makes such a simulator reachable by UDID. What changes is ownership. `boot-device` and `stop-simulator-server` refuse these devices, anything the provider did not grant is refused with a message naming it and Argent uses only the endpoints its own simulator-server build serves. A grant binds to the device rather than to one of its names, so the real udid or serial is gated exactly like the `ext:` id. Android emulators are covered too and a device visible to both a provider and `adb`/`simctl` is listed once. The contract ships as `schemas/device-provider-v1.json`, validated by `argent providers check`, and is documented in `docs/reference/device-providers.mdx`. Includes unit tests and an e2e phase where the harness acts as its own provider. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for discovering and connecting to externally managed devices. * Added `argent providers` commands for listing, validating, publishing, withdrawing, and pruning providers. * Added provider-aware simulator, debugger, profiler, native tools, and device listings. * Added capability controls, endpoint validation, revocation handling, and provider-specific diagnostics. * Added automatic CLI discovery for provider integrations. * **Bug Fixes** * Improved service recovery and paused-runtime error reporting. * Improved simulator keyboard and paste command reliability. * **Documentation** * Documented provider descriptors, capabilities, lifecycle rules, and CLI usage. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
78 lines
3.4 KiB
Bash
78 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|
# Phase 90 — best-effort teardown of everything the run spun up.
|
|
# The sandbox dir itself is removed by run-e2e.sh (unless --keep).
|
|
|
|
run_phase() {
|
|
local P=cleanup
|
|
|
|
# An AVD the android tier booted is reaped here, not there: the RN tier drives
|
|
# the same serial after that tier ends. Runs before the stop-all below so the
|
|
# per-device call still has a service to stop.
|
|
if [ -n "${E2E_ANDROID_REAP_SERIAL:-}" ]; then
|
|
if server_running; then
|
|
assert_ok "$P" stop-simulator-server stop "{\"udid\":\"$E2E_ANDROID_REAP_SERIAL\"}"
|
|
else
|
|
skip "$P" stop-simulator-server stop "no reachable tool-server"
|
|
fi
|
|
# Nothing else shuts the emulator down: the tool-server only reaps devices
|
|
# Lens booted through its preview path, not ones boot-device started.
|
|
if command -v adb >/dev/null 2>&1; then
|
|
adb -s "$E2E_ANDROID_REAP_SERIAL" emu kill >/dev/null 2>&1 || true
|
|
info "sent 'emu kill' to $E2E_ANDROID_REAP_SERIAL"
|
|
else
|
|
warn "adb not on PATH: emulator $E2E_ANDROID_REAP_SERIAL left running"
|
|
fi
|
|
fi
|
|
|
|
# The unscoped `{}` is the machine-wide sweep across every device-owned
|
|
# namespace, and is right only here: the run's HOME is the sandbox, so the
|
|
# server it discovers is this run's own (see ensure_server's note) and the
|
|
# sweep cannot reach another agent's devices. Anywhere an agent talks to the
|
|
# shared install, pass `devices`.
|
|
if server_running; then
|
|
run_tool stop-all-simulator-servers '{}' >/dev/null 2>&1 && pass "$P" stop-all-simulator-servers teardown || skip "$P" stop-all-simulator-servers teardown "none running"
|
|
run_tool stop-metro '{}' >/dev/null 2>&1 && pass "$P" stop-metro teardown || skip "$P" stop-metro teardown "no metro"
|
|
else
|
|
skip "$P" stop-all-simulator-servers teardown "no reachable tool-server"
|
|
skip "$P" stop-metro teardown "no reachable tool-server"
|
|
fi
|
|
|
|
# Electron spawned by 40-chromium.
|
|
if [ -n "${E2E_ELECTRON_PID:-}" ] && kill -0 "$E2E_ELECTRON_PID" 2>/dev/null; then
|
|
kill "$E2E_ELECTRON_PID" 2>/dev/null || true
|
|
info "killed electron pid $E2E_ELECTRON_PID"
|
|
fi
|
|
|
|
# http server backing the Electron fixture.
|
|
if [ -n "${E2E_HTTP_PID:-}" ] && kill -0 "$E2E_HTTP_PID" 2>/dev/null; then
|
|
kill "$E2E_HTTP_PID" 2>/dev/null || true
|
|
fi
|
|
|
|
# Metro started by the RN tier.
|
|
if [ -n "${E2E_METRO_PID:-}" ] && kill -0 "$E2E_METRO_PID" 2>/dev/null; then
|
|
kill "$E2E_METRO_PID" 2>/dev/null || true
|
|
info "killed metro pid $E2E_METRO_PID"
|
|
fi
|
|
|
|
# Reap the fake provider from the device-provider tier: its own
|
|
# simulator-server and its descriptor. Argent deliberately never deletes
|
|
# another process's descriptor, so the harness — which IS that process here —
|
|
# has to.
|
|
if [ -n "${E2E_PROVIDER_SIM_PID:-}" ] && kill -0 "$E2E_PROVIDER_SIM_PID" 2>/dev/null; then
|
|
kill "$E2E_PROVIDER_SIM_PID" 2>/dev/null || true
|
|
info "killed provider pid $E2E_PROVIDER_SIM_PID"
|
|
fi
|
|
if [ -n "${E2E_PROVIDER_DESCRIPTOR:-}" ] && [ -f "$E2E_PROVIDER_DESCRIPTOR" ]; then
|
|
rm -f "$E2E_PROVIDER_DESCRIPTOR"
|
|
fi
|
|
|
|
# Confirm the private tool-server went down — this case is the run's only
|
|
# record that nothing was left behind.
|
|
argent_cli server stop >/dev/null 2>&1 && info "stopped private tool-server" || true
|
|
if server_running; then
|
|
fail "$P" harness teardown-complete "tool-server still answering after 'server stop'"
|
|
else
|
|
pass "$P" harness teardown-complete
|
|
fi
|
|
}
|