diff --git a/src/agent-device/edge-request-rules.test.ts b/src/agent-device/edge-request-rules.test.ts index b2ca5ff4a..479190475 100644 --- a/src/agent-device/edge-request-rules.test.ts +++ b/src/agent-device/edge-request-rules.test.ts @@ -289,6 +289,28 @@ describe("the agent-device front's request rules", () => { expect(reached()).toBe(1); }); + it("`--device` naming the leased phone's own model, which the catalog does not list, reaches the phone daemon as `serial` of the phone, with no `device`", async () => { + const rig = await setUpWithPhone({ phoneModel: "SM-S911U" }); + await granted(rig, 1, { physical: true, platform: "android" }); + const snapshots = () => + rig.phone + .rpcRequests("agent_device.command") + .filter((request) => request.params?.["command"] === "snapshot"); + + await runCommand(rig, "snapshot", 1, { flags: { device: "sm-s911u" } }); + + const sent = snapshots(); + expect(sent).toHaveLength(1); + const flags = flagsOf(sent[0]?.params ?? {}); + expect(flags["serial"]).toBe(phoneSerial); + expect(flags).not.toHaveProperty("device"); + await refused( + rig, + () => runCommand(rig, "snapshot", 1, { flags: { device: "SM-S918U" } }), + simlockPicks, + ); + }); + it("`--device` with the leased device's id, and its name with `_` for a space, extra spaces and other letter case, are forwarded unchanged", async () => { const rig: Rig = await setUp(); rig.fake.nameDeviceInNextReply({ name: "Sim Lock Phone" }); diff --git a/src/agent-device/front/request-rules.ts b/src/agent-device/front/request-rules.ts index 4d52a7d24..958ff4188 100644 --- a/src/agent-device/front/request-rules.ts +++ b/src/agent-device/front/request-rules.ts @@ -175,6 +175,8 @@ function ruleDeviceSet(unit: Unit): void { async function namesLeasedModel(check: Check, leased: TokenDevice, name: string): Promise { if (leased.platform === undefined || leased.model === undefined) return false; + // why: an enrolled phone's model need not be in the virtual catalog, and the lease already fixes the device, so its own model names it. + if (name.toLowerCase() === leased.model.toLowerCase()) return true; try { const { platforms } = await check.context.dispatch( "catalog.get", diff --git a/src/agent-device/test-edge.ts b/src/agent-device/test-edge.ts index 6e3f318ca..72bbbcba2 100644 --- a/src/agent-device/test-edge.ts +++ b/src/agent-device/test-edge.ts @@ -20,7 +20,10 @@ import { export const phoneSerial = "R58Y61A60HN"; // why: one Android driver serving a virtual Pixel 8 and an enrolled, present phone, so a test can lease either through the same worker. -export async function setUpWithPhone(options: SetUpOptions = {}): Promise { +export async function setUpWithPhone({ + phoneModel = "Pixel 8", + ...options +}: SetUpOptions & { readonly phoneModel?: string } = {}): Promise { const rig = await setUp({ ...options, drivers: (clock) => [ @@ -31,7 +34,7 @@ export async function setUpWithPhone(options: SetUpOptions = {}): Promise { knownModels: ["Pixel 8"], modelClasses: { "Pixel 8": "phone" }, physicalDevices: [ - { class: "phone", ids: [phoneSerial], model: "Pixel 8", osVersion: "15" }, + { class: "phone", ids: [phoneSerial], model: phoneModel, osVersion: "15" }, ], platform: "android", }), diff --git a/website/src/content/docs/docs/using-devices/agent-device.mdx b/website/src/content/docs/docs/using-devices/agent-device.mdx index 0a66425b4..94046169a 100644 --- a/website/src/content/docs/docs/using-devices/agent-device.mdx +++ b/website/src/content/docs/docs/using-devices/agent-device.mdx @@ -148,7 +148,7 @@ If every matching device is taken, `open` waits up to 330 seconds, then fails wi - **`close` gives the device back.** Simlock ends the lease and deletes the device; the next agent gets a new one. - **`install` sends the app from your machine.** agent-device uploads it. A path on the worker is refused. - **`devices` lists only your devices**, and nothing before `open`. -- **Simlock picks the device.** Do not pass `--udid` or `--serial`. Simlock answers `boot` on a leased device itself; its `id` is the device's UDID on iOS or serial on Android. The agent-device `leaseId` is the Simlock lease id, usable with `/v1/leases//…`. +- **Simlock picks the device.** Do not pass `--udid` or `--serial`. After `open`, `--device` may name only the leased device: its name, its model in any letter case (an enrolled phone's model too, even when the catalog does not list it), or a catalog alias of that model. `test --device` takes only the names or ids of devices you hold. Simlock answers `boot` on a leased device itself; its `id` is the device's UDID on iOS or serial on Android. The agent-device `leaseId` is the Simlock lease id, usable with `/v1/leases//…`. - **A `batch`** can nest at most 8 levels deep and hold at most 1000 steps in all. - **`orientation` on an iPhone or iPad simulator** (not a foldable iPhone Duo) is done by Simlock, and replies `Rotation requested: landscape-left (unconfirmed)`: it was sent, but nothing confirms it happened. Use `portrait`, `portrait-upside-down`, `landscape-left` or `landscape-right`, or `upside-down`, `left` and `right`. On every other device, and as a `batch` step, agent-device rotates as it normally does. @@ -239,7 +239,7 @@ Sign-in errors (`UNAUTHENTICATED`, `FORBIDDEN`) and errors from outside Simlock, | `refused: name --platform ios or android` | Pass `--platform` to `open`. | | `refused: boot names no lease; open a device first` | Run `open` before `boot`. | | `refused: this lease has ended; open a device` | Run `open` again. | -| `refused: simlock picks the device` | Drop `--udid`, `--serial` or a `--device` that names another device. | +| `refused: simlock picks the device` | Drop `--udid`, `--serial` or a `--device` that names another device. The leased device's name or model is accepted, except by `test`, which takes names and ids only. | | `refused: simlock chooses the device set; run disconnect, then connect proxy without --ios-simulator-device-set` | Do as the message says. | | `refused: send the app from your machine as an upload` | Give `install` a path on your machine. | | `No active proxy device lease for this session; run open first.` | The session has no lease, often because parallel agents share one session. Set `AGENT_DEVICE_SESSION` per agent, then `open`. |