Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
449b0a0
test: allocate with physical: true leases an enrolled phone through t…
V3RON Oct 22, 2026
cbc7ac0
feat(agent-device): a physical allocate reaches the phone daemon thro…
V3RON Oct 22, 2026
08e9ea3
test: allocate with physical: true leases iOS phones by model and osV…
V3RON Oct 22, 2026
bd0af98
test: allocate with a physical that is not a boolean is refused malfo…
V3RON Oct 22, 2026
0c921c5
feat(agent-device): the front type-checks physical on the wire (#874)
V3RON Oct 22, 2026
1dfa012
test: simlock's refusal of a physical allocate reaches the agent with…
V3RON Oct 22, 2026
4bfe192
test: a physical allocate while the phone daemon is not running names…
V3RON Oct 22, 2026
263f45c
feat(agent-device): a phone lease answers with the phone daemon's rea…
V3RON Oct 22, 2026
c4715ea
test: later calls follow the lease to the daemon that allocated it (#…
V3RON Oct 22, 2026
3726701
test: non-RPC routes on a worker follow the lease header to the phone…
V3RON Oct 22, 2026
890bebd
test: simlock ending a phone lease releases it at the phone daemon (#…
V3RON Oct 22, 2026
df7eb55
feat(agent-device): both daemons' lease-end participants run for ever…
V3RON Oct 22, 2026
c4d9c86
test: a command on a phone lease naming another serial or udid is ref…
V3RON Oct 22, 2026
1688771
test: an ended phone lease is forgotten by the routed link (#874)
V3RON Oct 22, 2026
f7d3533
test: through a gateway a physical allocate, a later command and devi…
V3RON Oct 22, 2026
28cf16e
feat(agent-device): a relayed request reaches the daemon of the lease…
V3RON Oct 22, 2026
3dfe05a
test: a gateway adopts a live phone lease with the phone's address af…
V3RON Oct 22, 2026
6563074
feat(agent-device): the gateway adopts a phone lease at the phone's e…
V3RON Oct 22, 2026
cdb5dfb
test(e2e): agent-device leases a physical phone on the slow lane (#874)
V3RON Oct 22, 2026
be0a2b6
docs(agent-device): phones are leased with --physical through the pho…
V3RON Oct 22, 2026
baed6e7
refactor(agent-device): split the routed link's role lookup (#874)
V3RON Oct 22, 2026
239675f
docs(adr): list ADR 0041 before 0043 in the index (#874)
V3RON Oct 22, 2026
6ca2d20
test(agent-device): a virtual allocate whose address is its driver id…
V3RON Oct 22, 2026
3b9e666
test(agent-device): the header-routing title says the lease id picks …
V3RON Oct 22, 2026
f7e9bc2
merge origin/task/873
V3RON Oct 22, 2026
19ab1ff
fix(agent-device): a phone call drops the simulator daemon's instance…
V3RON Oct 22, 2026
11de40a
fix(e2e): an iPhone signs automatically with team and bundle ids; pro…
V3RON Oct 22, 2026
ede0889
fix(e2e): the physical-phone test sends a command the way the CLI doe…
V3RON Oct 22, 2026
90ae8a9
refactor(e2e): split the physical-phone test's helpers out so Fallow'…
V3RON Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 0023. agent-device is served by an optional edge module, and the simlock lease is the only clock

- **Status:** Accepted; §3–4 superseded in part by [ADR 0043](0043-physical-devices-reach-agent-device-through-a-second-daemon.md)
- **Status:** Accepted; §1 narrowed by 0026 for gateway mode; §3 narrowed by 0030 (no reap while turned off); §3–4 superseded in part by [ADR 0043](0043-physical-devices-reach-agent-device-through-a-second-daemon.md)
- **Date:** 2026-10-12
- **Issue:** [#466](https://github.com/callstackincubator/simlock/issues/466)
- **Supersedes:** nothing. Builds on [ADR 0020](0020-a-requester-may-choose-its-lease-id.md)
Expand Down
1 change: 1 addition & 0 deletions docs/internal/agent-rules/toolchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ The machine can run a line only if:
| Physical iOS | `uname -s` is `Darwin`; `SIMLOCK_PHYSICAL_IOS` is the UDID of an iPhone on USB (trusted, Developer Mode on, unlocked, Auto-Lock Never); `SIMLOCK_PHYSICAL_IOS_APP` is a `.app` signed for it. `/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" /Library/Developer/PrivateFrameworks/CoreDevice.framework/Resources/Info.plist` prints `642.` followed by a number (streaming a phone needs Xcode 27's CoreDevice; the framework is machine-wide and does not follow `xcode-select`). DeviceHub and Xcode are not running during the lane. The stream cases need the iPhone on iOS 27 or later; an older iPhone runs the refusal case instead. Run `scripts/slow-e2e.sh --physical e2e/slow-ios-physical.test.ts` |
| agent-device through simlock | `node -v` is 22.12.0 or later (agent-device's own minimum); the iOS check and `uname -m` is `arm64` (the fixture app is arm64 only), or the Android check; `SIMLOCK_E2E_AGENT_DEVICE` (in `.slow-lane.env`) is the absolute path of `bin/agent-device.mjs` in an install of the agent-device version `package.json` pins for `@agent-device/proxy` (`npm install -g agent-device@<version>`, or a checkout at tag `v<version>` built with `pnpm install && pnpm build && pnpm build:android`, the last building the Android snapshot helper); room for two devices: `node -p "os.totalmem() / 2**30"` prints at least 7 for iOS or 12 for Android (simlock's 4 GiB OS reserve plus two of its default 1.5 GiB iOS or 4 GiB Android per-device budgets). Run `scripts/slow-e2e.sh e2e/slow-agent-device.test.ts` or `scripts/slow-e2e.sh e2e/slow-agent-device-gateway.test.ts` |
| Physical Android | `command -v adb` finds it; `adb devices -l` lists `$SIMLOCK_PHYSICAL_ANDROID` on a USB transport (a `usb:` field) in state `device`; `SIMLOCK_PHYSICAL_ANDROID_APK` names an APK. Run `scripts/slow-e2e.sh --physical e2e/slow-android-physical.test.ts` |
| agent-device with a physical phone | the agent-device through simlock checks above (the Android or iOS one), and the Physical Android checks with `SIMLOCK_PHYSICAL_ANDROID`, or the Physical iOS checks with `SIMLOCK_PHYSICAL_IOS`; for iOS also `SIMLOCK_E2E_IOS_TEAM_ID` and `SIMLOCK_E2E_IOS_BUNDLE_ID` (in `.slow-lane.env`); set `SIMLOCK_E2E_IOS_PROVISIONING_PROFILE` and `SIMLOCK_E2E_IOS_SIGNING_IDENTITY` only for manual signing, which an Xcode-managed profile fails. Run `scripts/slow-e2e.sh --physical e2e/slow-agent-device-physical.test.ts` |
| Physical Android, a person at the phone | the Physical Android checks above, and `SIMLOCK_PHYSICAL_PERSON` is `1`. Run `scripts/slow-e2e.sh --physical-manual e2e/slow-android-physical-manual.test.ts` |
| Physical iOS, a person at the phone | the Physical iOS checks above, a passcode set on the phone (locking it then needs the passcode), and `SIMLOCK_PHYSICAL_PERSON` is `1`. Run `scripts/slow-e2e.sh --physical-manual e2e/slow-ios-physical-manual.test.ts` |

Expand Down
203 changes: 203 additions & 0 deletions e2e/slow-agent-device-physical.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { randomBytes } from "node:crypto";
import { existsSync } from "node:fs";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, beforeAll, describe, expect, it, onTestFinished } from "vitest";

import {
assertPinnedAgentDevice,
freeLoopbackPort,
listLeases,
newAgentToken,
waitForAgentDevice,
waitForFree,
withSharedDaemon,
type SharedTestEnv,
} from "./helpers/index.js";

const MINUTE = 60_000;
const PNG_MAGIC = "89504e470d0a1a0a";

type Platform = "android" | "ios";

const ANDROID_SERIAL = process.env["SIMLOCK_PHYSICAL_ANDROID"];
const IOS_UDID = process.env["SIMLOCK_PHYSICAL_IOS"];
// why: teamId and bundleId let Xcode sign the runner automatically; only a provisioning profile switches agent-device to manual signing (a signing identity alone does not), so each goes in only when set.
const IOS_SIGNING = {
teamId: process.env["SIMLOCK_E2E_IOS_TEAM_ID"],
bundleId: process.env["SIMLOCK_E2E_IOS_BUNDLE_ID"],
...(process.env["SIMLOCK_E2E_IOS_PROVISIONING_PROFILE"]
? { provisioningProfile: process.env["SIMLOCK_E2E_IOS_PROVISIONING_PROFILE"] }
: {}),
...(process.env["SIMLOCK_E2E_IOS_SIGNING_IDENTITY"]
? { signingIdentity: process.env["SIMLOCK_E2E_IOS_SIGNING_IDENTITY"] }
: {}),
} as const;

function unset(name: string, value: string | undefined): string | undefined {
return value === undefined || value === "" ? name : undefined;
}

const missing = {
android: unset("SIMLOCK_PHYSICAL_ANDROID", ANDROID_SERIAL),
ios:
unset("SIMLOCK_PHYSICAL_IOS", IOS_UDID) ??
unset("SIMLOCK_E2E_IOS_TEAM_ID", IOS_SIGNING.teamId) ??
unset("SIMLOCK_E2E_IOS_BUNDLE_ID", IOS_SIGNING.bundleId),
} as const;

interface RpcAnswer {
readonly result?: { readonly ok?: boolean; readonly data?: Record<string, unknown> };
readonly error?: { readonly message: string };
}

function deviceKeyOf(allocated: RpcAnswer): string | undefined {
const lease = allocated.result?.data?.["lease"] as { deviceKey?: string } | undefined;
return lease?.deviceKey;
}

function writtenPath(shot: RpcAnswer, requested: string): string {
const named = shot.result?.data?.["path"];
return existsSync(requested) || typeof named !== "string" ? requested : named;
}

function defineSuite(platform: Platform, id: string): void {
const tag = platform === "android" ? "Android" : "iOS";
const addressKey = platform === "android" ? "serial" : "udid";
describe.skipIf(missing[platform] !== undefined)(
missing[platform] === undefined
? `agent-device with a physical ${tag} phone (real agent-device)`
: `agent-device with a physical ${tag} phone (skipped: ${missing[platform]} is not set)`,
{ tags: ["slow", "physical", platform] },
() => {
let env: SharedTestEnv;
let secret: string;

// why: the agent-device CLI reads `/health` before any lease and sends its two instance ids on every RPC; a lease on the phone daemon must accept them.
const pins = async (): Promise<Record<string, string>> => {
const response = await fetch(`http://127.0.0.1:${env.httpPort}/v1/agent-device/health`, {
headers: { authorization: `Bearer ${secret}` },
});
const health = (await response.json()) as {
readonly instanceId?: string;
readonly upstream?: { readonly instanceId?: string };
};
return {
...(health.instanceId === undefined
? {}
: { "x-agent-device-instance": health.instanceId }),
...(health.upstream?.instanceId === undefined
? {}
: { "x-agent-device-upstream-instance": health.upstream.instanceId }),
};
};

const call = async (method: string, params: Record<string, unknown>): Promise<RpcAnswer> => {
const response = await fetch(`http://127.0.0.1:${env.httpPort}/v1/agent-device/rpc`, {
body: JSON.stringify({ id: 1, jsonrpc: "2.0", method, params }),
headers: {
authorization: `Bearer ${secret}`,
"content-type": "application/json",
...(await pins()),
},
method: "POST",
signal: AbortSignal.timeout(6 * MINUTE),
});
return (await response.json()) as RpcAnswer;
};

beforeAll(async () => {
const pinned = await assertPinnedAgentDevice(platform);
env = await withSharedDaemon({
configOverrides: {
capabilities: {
"agent-device": {
command: pinned,
enabled: true,
...(platform === "ios" ? { ios: IOS_SIGNING } : {}),
},
},
http: { enabled: true, host: "127.0.0.1", port: await freeLoopbackPort() },
},
driver: "real",
});
const token = await newAgentToken(env);
secret = token.secret;
await waitForAgentDevice(env, secret);
const added = await env.cli(["device", "add", "--platform", platform, id, "--json"], {
timeout: 2 * MINUTE,
});
expect(added.code, `device add failed: ${added.stderr}`).toBe(0);
}, 10 * MINUTE);

afterAll(async () => {
await env?.teardown();
}, 2 * MINUTE);

it(
`a raw agent_device.lease.allocate with physical: true and platform: "${platform}" is granted that ${addressKey}, a screenshot on the lease answers a PNG, and agent_device.lease.release releases the Simlock lease`,
{ timeout: 15 * MINUTE },
async () => {
const leaseId = randomBytes(16).toString("hex");
const scope = { clientId: "slow-lane", leaseProvider: "proxy", runId: "slow-lane" };

const allocated = await call("agent_device.lease.allocate", {
...scope,
leaseId,
physical: true,
platform,
ttlMs: 10 * MINUTE,
});

expect(allocated.error, JSON.stringify(allocated)).toBeUndefined();
expect(allocated.result?.ok).toBe(true);
const [lease] = await listLeases(env);
expect(lease?.id).toBe(leaseId);
const devices = (await env.cli(["list", "--devices"])).json as {
readonly id: string;
readonly driverDeviceId: string;
}[];
expect(devices.find((device) => device.id === lease?.deviceId)?.driverDeviceId).toBe(id);

// why: like the CLI, a command carries the scope the lease was allocated under plus the device key agent-device's reply named; without all of them agent-device refuses the lease's owner.
const deviceKey = deviceKeyOf(allocated);
const dir = await mkdtemp(join(tmpdir(), "simlock-ad-phone-"));
onTestFinished(() => rm(dir, { force: true, recursive: true }));
const png = join(dir, "shot.png");
// why: the CLI addresses the leased phone by its serial or udid on each command; with 26 devices known to agent-device none is picked for it.
const flags = { platform, [addressKey]: id };
const meta = { ...scope, deviceKey, leaseId };
const opened = await call("agent_device.command", {
command: "open",
flags,
meta,
positionals: [],
});
expect(opened.error, JSON.stringify(opened)).toBeUndefined();
const shot = await call("agent_device.command", {
command: "screenshot",
flags,
meta,
positionals: [png],
});
expect(shot.error, JSON.stringify(shot)).toBeUndefined();
expect((await readFile(writtenPath(shot, png))).subarray(0, 8).toString("hex")).toBe(
PNG_MAGIC,
);

const released = await call("agent_device.lease.release", {
...scope,
deviceKey,
leaseId,
});
expect(released.error, JSON.stringify(released)).toBeUndefined();
await waitForFree(env);
},
);
},
);
}

defineSuite("android", ANDROID_SERIAL ?? "");
defineSuite("ios", IOS_UDID ?? "");
Loading
Loading