Files
software-mansion__argent/packages/tool-server/test/device-info.test.ts
Mateusz Aliyev 6e9e45c9f0 feat: attach to devices offered by external providers (#735)
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 -->
2026-09-04 22:02:57 +02:00

100 lines
3.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { nativeIdPlatform } from "@argent/device-providers";
import {
classifyDevice,
isAndroidEmulatorSerial,
isIosPhysicalDevice,
resolveDevice,
} from "../src/utils/device-info";
describe("classifyDevice", () => {
it("classifies iOS simulator UUIDs as ios", () => {
expect(classifyDevice("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA")).toBe("ios");
expect(classifyDevice("01234567-89ab-cdef-0123-456789abcdef")).toBe("ios");
});
it("treats non-UUID ids as android", () => {
expect(classifyDevice("emulator-5554")).toBe("android");
expect(classifyDevice("HT82A0203045")).toBe("android");
});
it("classifies amazon-prefixed serials as vega", () => {
expect(classifyDevice("amazon-4a27df03c9777152")).toBe("vega");
});
/**
* `argent providers check` cannot reach this classifier, so it asks
* `nativeIdPlatform` in the contract package instead. The two have to give
* one answer or the check would pass a descriptor the tool-server drops. This
* holds it to that for every id a provider may declare, which is every id
* without one of the prefixes above.
*/
it.each([
"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
"01234567-89ab-cdef-0123-456789abcdef",
"00008110-000978540290401E",
"emulator-5554",
"HT82A0203045",
"192.168.1.5:5555",
])("agrees with the contract's nativeIdPlatform on %s", (nativeId) => {
expect(classifyDevice(nativeId)).toBe(nativeIdPlatform(nativeId));
});
});
describe("resolveDevice", () => {
it("returns ios+simulator for a UUID", () => {
const d = resolveDevice("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA");
expect(d.platform).toBe("ios");
expect(d.kind).toBe("simulator");
expect(d.id).toBe("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA");
});
it("returns android+emulator for an emulator serial", () => {
const d = resolveDevice("emulator-5554");
expect(d.platform).toBe("android");
expect(d.kind).toBe("emulator");
});
it("returns android+device for a physical phone's USB serial", () => {
const d = resolveDevice("HT82A0203045");
expect(d.platform).toBe("android");
expect(d.kind).toBe("device");
});
it("returns android+device for a wireless-adb ip:port serial", () => {
const d = resolveDevice("192.168.1.5:5555");
expect(d.platform).toBe("android");
expect(d.kind).toBe("device");
});
it("returns vega+vvd for an amazon- serial (v1 supports the Virtual Device only)", () => {
const d = resolveDevice("amazon-4a27df03c9777152");
expect(d.platform).toBe("vega");
expect(d.kind).toBe("vvd");
});
});
describe("isIosPhysicalDevice", () => {
it("is true for a physical iPhone UDID", () => {
expect(isIosPhysicalDevice(resolveDevice("00008110-000978540290401E"))).toBe(true);
});
it("is false for an iOS simulator", () => {
expect(isIosPhysicalDevice(resolveDevice("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"))).toBe(false);
});
it("is false for physical Android hardware (kind 'device' too, the bare-kind hazard)", () => {
const android = resolveDevice("HT82A0203045");
expect(android.kind).toBe("device");
expect(isIosPhysicalDevice(android)).toBe(false);
});
});
describe("isAndroidEmulatorSerial", () => {
it("is true only for emulator-* serials", () => {
expect(isAndroidEmulatorSerial("emulator-5554")).toBe(true);
expect(isAndroidEmulatorSerial("HT82A0203045")).toBe(false);
expect(isAndroidEmulatorSerial("192.168.1.5:5555")).toBe(false);
});
});