Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d1f74bc
test: a holder's rotate of its iOS-simulator lease answers and sends …
leonardoxr Oct 31, 2026
a42ade3
feat(daemon): device.rotate turns a leased simulator through its devi…
leonardoxr Oct 31, 2026
fe1c197
test: a caller rotates a lease it may not touch, or names a bad orien…
leonardoxr Oct 31, 2026
2f1ebec
feat(contract): device.rotate is authorized like device.exec (#1107)
leonardoxr Oct 31, 2026
e54e3f2
test: a holder rotates a lease not on an iOS phone or tablet simulato…
leonardoxr Oct 31, 2026
18acbd7
feat(daemon): device.rotate refuses a lease not on an iOS phone or ta…
leonardoxr Oct 31, 2026
642a392
test: a holder rotates when the helper cannot start or the write fail…
leonardoxr Oct 31, 2026
770e4f0
feat(daemon): device.rotate answers INPUT_UNAVAILABLE with the reason…
leonardoxr Oct 31, 2026
50dac1b
test: an input socket opened after a rotate's helper closed gets a fr…
leonardoxr Oct 31, 2026
22b171d
feat(daemon): one device input per lease, shared by the input module'…
leonardoxr Oct 31, 2026
736d3ba
test: a client program calls client.rotate(leaseId, orientation) and …
leonardoxr Oct 31, 2026
e778c34
feat(client): client.rotate turns a lease's simulator through device.…
leonardoxr Oct 31, 2026
a4d9f18
test: an agent calls POST /v1/leases/{id}/rotate on a worker and thro…
leonardoxr Oct 31, 2026
0dc922c
feat(http): POST /v1/leases/{id}/rotate on a worker and through a gat…
leonardoxr Oct 31, 2026
6f2f973
docs: rotate over HTTP and its two error codes (#1107)
leonardoxr Oct 31, 2026
d8d222b
test: the alias parser maps a spelling to an orientation or the unkno…
leonardoxr Oct 31, 2026
4bae4e7
feat(contract): parseOrientation maps an alias to an orientation or t…
leonardoxr Oct 31, 2026
c6834bc
test: the gateway coordinator forwards device.rotate and names the ca…
leonardoxr Oct 31, 2026
eae80be
test: a socket whose write fails closes 1013 while the daemon keeps r…
leonardoxr Oct 31, 2026
aced7b4
test: fold the coordinator's rotate case into the HTTP gateway test t…
leonardoxr Oct 31, 2026
0844848
chore: name how the coordinator's rotate is reached for Fallow (#1107)
leonardoxr Oct 31, 2026
7aa86a7
fix(gateway): name the caller's lease id in every worker error, and p…
leonardoxr Oct 31, 2026
6382188
docs: list POST /v1/leases/{id}/rotate and device.rotate in the manua…
leonardoxr Oct 31, 2026
44ba688
fix(modules): reserve the rotate lease sub-route for the core route (…
V3RON Oct 31, 2026
b90d8f4
test(contract): prove device.rotate's input bounds and strict keys (#…
V3RON Oct 31, 2026
f4f1484
test(gateway): prove gateway.execTimeoutMs bounds a forwarded device.…
V3RON Oct 31, 2026
84bf37d
test(daemon): drop the failed-open case device-rotate's e2e test alre…
V3RON Oct 31, 2026
b8643d1
chore(gateway): drop the Fallow suppression the rotate timeout test m…
V3RON Oct 31, 2026
9aff689
Merge remote-tracking branch 'origin/main' into fix-1107
V3RON Oct 31, 2026
283a63e
fix(contract): bump the protocol to 68, since main took 67 (#1107)
V3RON Oct 31, 2026
e0329c0
Merge remote-tracking branch 'origin/main' into fix-1107
V3RON Oct 31, 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
1 change: 1 addition & 0 deletions .agents/scripts/protocol-bump-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const NOT_SHAPES = new Set([
"index.ts",
"console-url.ts",
"duration.ts",
"orientation.ts",
"os-range.ts",
"version-order.ts",
]);
Expand Down
2 changes: 2 additions & 0 deletions src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type {
DeviceUnhealthyPush,
ExecInput,
ExecOutput,
RotateInput,
RotateOutput,
DeviceOutputChunk,
ExecOptions,
DoctorReport,
Expand Down
1 change: 1 addition & 0 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8279,6 +8279,7 @@ function fakeClient(overrides: Partial<SimlockAdminClient> = {}): SimlockAdminCl
requestLease: (_input, _options) => Promise.resolve(grant),
resolvePassthrough: () => Promise.resolve({ args: [], command: "adb", env: {} }),
exec: () => Promise.resolve({ exitCode: 0 }),
rotate: (leaseId, orientation) => Promise.resolve({ leaseId, orientation }),
cancelLease: () => Promise.resolve({ result: "not-found" }),
renewLease: () => Promise.resolve(grant.lease as LeaseRecord),
releaseLease: (input) => Promise.resolve({ leaseId: input.leaseId }),
Expand Down
2 changes: 2 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type {
DeviceUnhealthyPush,
ExecInput,
ExecOutput,
RotateInput,
RotateOutput,
DeviceOutputChunk,
ExecOptions,
DoctorReport,
Expand Down
7 changes: 4 additions & 3 deletions src/contract/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Imported by: daemon, gateway, simlock-client, every frontend, core, leasing, his
| `os-range.ts` | OS constraint grammar: parse, `satisfies`, `compareVersions` |
| `version-order.ts` | `isNewerVersion(candidate, running)`: the one "newer" rule (semver order) every update surface shares; the console imports it by this path, not the index (the index carries zod) |
| `duration.ts` | `parseDurationMs`, for the CLI and HTTP |
| `orientation.ts` | `INPUT_ORIENTATIONS`, `parseOrientation` (the aliases a spelling maps to an orientation or the unknown message), `isRotatableModel`, `modelFamily`; no wire shape |
| `relay.ts` | Bounded relay ids, channel ids, headers |
| `console-url.ts` | The console address `status.get` reports |

Expand All @@ -33,7 +34,7 @@ park on readiness (all but `status.get`) → handler → parse output.
every operation but `daemon.stop`, which `DaemonServer` answers.

- `agent`: `catalog.get`, `status.get`, `component.list`, `lease.request`, `lease.cancel`,
`lease.renew`, `lease.release`, `lease.list`, `lease.get`, `driver.passthrough`, `device.exec`,
`lease.renew`, `lease.release`, `lease.list`, `lease.get`, `driver.passthrough`, `device.exec`, `device.rotate`,
`doctor.run` without `fix` or `purgeOrphans`.
- `admin`: every other operation (`list.get`, `config.get`, `inbox.get`, `daemon.stop`, `events.*`,
`token.*`, `worker.*`, `component.install`, `device.add`, `relay.request`, ...).
Expand All @@ -45,7 +46,7 @@ every operation but `daemon.stop`, which `DaemonServer` answers.

- `lease.renew`, `lease.release` — `ownsLease`: admin, or `ownerId` = principal.
- `lease.cancel` — admin, or the pending request's owner = principal.
- `device.exec` — agent: owns the lease and names no `requesterId`. Admin: the lease's
- `device.exec`, `device.rotate` — agent: owns the lease and names no `requesterId`. Admin: the lease's
requester = `requesterId` (default: principal).

Three identities:
Expand All @@ -57,7 +58,7 @@ Three identities:

## Protocol version

- `PROTOCOL_VERSION_RANGE` in `protocol.ts` holds it, now `{ min: 67, max: 67 }`. `DAEMON_PROTOCOL_VERSION` (`src/daemon-protocol/`) is its `max`.
- `PROTOCOL_VERSION_RANGE` in `protocol.ts` holds it, now `{ min: 68, max: 68 }`. `DAEMON_PROTOCOL_VERSION` (`src/daemon-protocol/`) is its `max`.
- Every change to a contract shape bumps it by one in the same PR. Move `min` too, unless
a compatibility path stays side by side. `.agents/scripts/protocol-bump-check.mjs` checks
it on push and in CI; it counts every file here as a shape but tests, `index.ts` and the
Expand Down
20 changes: 20 additions & 0 deletions src/contract/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ export interface ErrorDetailsMap {
PASSTHROUGH_REFUSED: { readonly tool: string };
UNKNOWN_PASSTHROUGH_TOOL: { readonly tool: string };
EXEC_TIMEOUT: Record<string, never>;
/** why: `device.rotate` on a lease that is not on an iOS phone or tablet simulator; `class` is the physical class, the simulator's model family, or `emulator`. */
ROTATION_UNSUPPORTED: {
readonly leaseId: string;
readonly platform: Platform;
readonly physical: boolean;
readonly class: string;
};
/** why: `device.rotate` could not reach the lease's input helper; `reason` is the driver's text, cut to 200 characters. */
INPUT_UNAVAILABLE: { readonly leaseId: string; readonly reason: string };
DOCTOR_UNAVAILABLE: Record<string, never>;
HISTORY_NOT_KEPT: { readonly oldestTs: number };
HISTORY_UNAVAILABLE: Record<string, never>;
Expand Down Expand Up @@ -193,6 +202,8 @@ const CODES_WITH_DECLARED_DETAILS_BY_CODE: Record<CodeWithDeclaredDetails, true>
DOWNLOADS_DISABLED: true,
COMPONENT_IN_USE: true,
UNKNOWN_LEASE: true,
ROTATION_UNSUPPORTED: true,
INPUT_UNAVAILABLE: true,
DEVICE_NOT_ENROLLABLE: true,
DEVICE_BUSY: true,
UNKNOWN_DEVICE: true,
Expand Down Expand Up @@ -344,6 +355,15 @@ export const ERROR_TABLE: { readonly [Code in SimlockErrorCode]: ErrorTableEntry
// out of time" outcome (`QUEUE_TIMEOUT`) already uses -- so a script branching on "timed
// out" does not need a second number for the second kind of wait.
EXEC_TIMEOUT: { code: "EXEC_TIMEOUT", kind: "domain", cliExitCode: 10, httpStatus: 504 },
// why: a fact about the lease's device, as `RUNTIME_MISSING` is about the host: 422 and 12.
ROTATION_UNSUPPORTED: {
code: "ROTATION_UNSUPPORTED",
kind: "domain",
cliExitCode: 12,
httpStatus: 422,
},
// why: the helper that takes the touch is down, like `DOCTOR_UNAVAILABLE`: 503 and 1.
INPUT_UNAVAILABLE: { code: "INPUT_UNAVAILABLE", kind: "domain", cliExitCode: 1, httpStatus: 503 },
DOWNLOAD_TIMEOUT: {
code: "DOWNLOAD_TIMEOUT",
kind: "domain",
Expand Down
1 change: 1 addition & 0 deletions src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./console-url.js";
export * from "./duration.js";
export * from "./errors.js";
export * from "./operations.js";
export * from "./orientation.js";
export * from "./os-range.js";
export * from "./protocol.js";
export * from "./pushes.js";
Expand Down
40 changes: 40 additions & 0 deletions src/contract/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const ROLE_MATRIX: ReadonlyArray<{
input: { args: ["devices"], leaseId: "lease_1", tool: "adb" },
role: "agent",
},
{
name: "device.rotate",
input: { leaseId: "lease_1", orientation: "landscape_left" },
role: "agent",
},
{ name: "identity.get", input: {}, role: "agent" },
{ name: "token.list", input: {}, role: "admin" },
{ name: "token.revoke", input: { id: "tok_1" }, role: "admin" },
Expand Down Expand Up @@ -138,6 +143,11 @@ const EFFECT_MATRIX: ReadonlyArray<{
input: { args: ["devices"], leaseId: "lease_1", tool: "adb" },
effect: "write",
},
{
name: "device.rotate",
input: { leaseId: "lease_1", orientation: "landscape_left" },
effect: "write",
},
{ name: "identity.get", input: {}, effect: "read" },
{ name: "token.list", input: {}, effect: "read" },
{ name: "token.revoke", input: { id: "tok_1" }, effect: "write" },
Expand Down Expand Up @@ -1149,6 +1159,36 @@ describe("operation input/output round trips", () => {
expect(OPERATIONS["device.exec"].output.parse({ exitCode: 0 })).toEqual({ exitCode: 0 });
});

it("device.rotate: accepts a leaseId and requesterId of 1 to 256 characters and each orientation, and refuses an empty or 257-character one, another orientation or an unknown key", () => {
const parse = (input: object) => OPERATIONS["device.rotate"].input.parse(input);
const base = { leaseId: "lse_1", orientation: "portrait" };

for (const orientation of [
"portrait",
"portrait_upside_down",
"landscape_left",
"landscape_right",
]) {
expect(parse({ ...base, orientation })).toEqual({ ...base, orientation });
}
expect(parse({ ...base, leaseId: "x".repeat(256), requesterId: "y".repeat(256) })).toEqual({
...base,
leaseId: "x".repeat(256),
requesterId: "y".repeat(256),
});

for (const refused of [
{ ...base, leaseId: "" },
{ ...base, leaseId: "x".repeat(257) },
{ ...base, requesterId: "" },
{ ...base, requesterId: "y".repeat(257) },
{ ...base, orientation: "upside_down" },
{ ...base, angle: 90 },
]) {
expect(() => parse(refused)).toThrow();
}
});

it("the output push carries a frame id, a stream, and a chunk", () => {
expect(PUSH_SCHEMAS.output.parse({ chunk: "hello", requestId: 7, stream: "stdout" })).toEqual({
chunk: "hello",
Expand Down
48 changes: 38 additions & 10 deletions src/contract/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EVENTS_PAGE_WITH_SINCE_MESSAGE,
eventsPageWithoutSince,
} from "./events-page.js";
import { INPUT_ORIENTATIONS } from "./orientation.js";
import { parseOsConstraint } from "./os-range.js";
import { relayChannelSchema, relayHeadersSchema, relayIdSchema } from "./relay.js";
import { ownsLease, type AuthorizeContext, type Role } from "./roles.js";
Expand Down Expand Up @@ -485,16 +486,7 @@ export const deviceExec = defineOperation({
* authorized, the same convention `ownsLease` uses, so the handler's own `UNKNOWN_LEASE`
* surfaces instead of a misleading `FORBIDDEN`.
*/
authorize: (input, context) => {
if (context.role !== "admin") {
if (input.requesterId !== undefined) return false;
const ownerId = context.ownerId(input.leaseId);
return ownerId === undefined || ownerId === context.principal;
}
const requesterId = input.requesterId ?? context.principal;
const leaseRequesterId = context.leaseRequesterId(input.leaseId);
return leaseRequesterId === undefined || leaseRequesterId === requesterId;
},
authorize: authorizeOneLeaseCall,
});

/**
Expand Down Expand Up @@ -1074,6 +1066,41 @@ const identityGet = defineOperation({
}),
});

/**
* why: `device.exec`'s and `device.rotate`'s one rule, so a gateway's admin session is held to the lease's requester on both.
*/
function authorizeOneLeaseCall(
input: { readonly leaseId: string; readonly requesterId?: string | undefined },
context: AuthorizeContext,
): boolean {
if (context.role !== "admin") {
if (input.requesterId !== undefined) return false;
const ownerId = context.ownerId(input.leaseId);
return ownerId === undefined || ownerId === context.principal;
}
const requesterId = input.requesterId ?? context.principal;
const leaseRequesterId = context.leaseRequesterId(input.leaseId);
return leaseRequesterId === undefined || leaseRequesterId === requesterId;
}

/**
* why: turns a leased iOS phone or tablet simulator, through the lease's device input, whether or not the input module is on.
*/
const deviceRotate = defineOperation({
name: "device.rotate",
role: "agent",
effect: "write",
input: z
.object({
leaseId: z.string().min(1).max(256),
orientation: z.enum(INPUT_ORIENTATIONS),
requesterId: z.string().min(1).max(256).optional(),
})
.strict(),
output: z.object({ leaseId: z.string().max(256), orientation: z.enum(INPUT_ORIENTATIONS) }),
authorize: authorizeOneLeaseCall,
});

export const OPERATIONS = {
"identity.get": identityGet,
"catalog.get": catalogGet,
Expand All @@ -1086,6 +1113,7 @@ export const OPERATIONS = {
"lease.get": leaseGet,
"driver.passthrough": driverPassthrough,
"device.exec": deviceExec,
"device.rotate": deviceRotate,
"doctor.run": doctorRun,
"lease.release-all": leaseReleaseAll,
"list.get": listGet,
Expand Down
33 changes: 33 additions & 0 deletions src/contract/orientation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";

import { parseOrientation } from "./orientation.js";

// why: a parser with many spellings, each a row; it has no surface above it that lists them.
describe("parseOrientation", () => {
it("maps a spelling to an orientation, ignoring case and surrounding space, or to the unknown message", () => {
const accepted: readonly (readonly [string, string])[] = [
["landscape_left", "landscape_left"],
["landscape-left", "landscape_left"],
["LEFT", "landscape_left"],
[" Left ", "landscape_left"],
["landscape_right", "landscape_right"],
["landscape-right", "landscape_right"],
["right", "landscape_right"],
["portrait_upside_down", "portrait_upside_down"],
["portrait-upside-down", "portrait_upside_down"],
["upside-down", "portrait_upside_down"],
["portrait", "portrait"],
["PORTRAIT", "portrait"],
];
for (const [spelling, orientation] of accepted) {
expect(parseOrientation(spelling), spelling).toEqual({ ok: true, orientation });
}

for (const spelling of ["auto", "landscapeLeft", "", " ", "up", "landscape"]) {
expect(parseOrientation(spelling), JSON.stringify(spelling)).toEqual({
message: `Unknown orientation ${spelling}; use portrait, portrait-upside-down, landscape-left or landscape-right`,
ok: false,
});
}
});
});
58 changes: 58 additions & 0 deletions src/contract/orientation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// why: the four names a rotate takes over the contract and the input socket's `0x07` frame.
export const INPUT_ORIENTATIONS = [
"portrait",
"portrait_upside_down",
"landscape_left",
"landscape_right",
] as const;

export type ModelFamily = "phone" | "tablet" | "tv" | "watch" | "vision" | "unknown";

const MODEL_FAMILY_PREFIXES: readonly (readonly [string, ModelFamily])[] = [
["iPhone", "phone"],
["iPad", "tablet"],
["Apple TV", "tv"],
["Apple Watch", "watch"],
["Apple Vision", "vision"],
];

// why: every model the iOS driver lists starts with its product family's name, and the device record keeps only the model.
export function modelFamily(model: string): ModelFamily {
return MODEL_FAMILY_PREFIXES.find(([prefix]) => model.startsWith(prefix))?.[1] ?? "unknown";
}

export function isRotatableModel(model: string): boolean {
const family = modelFamily(model);
return family === "phone" || family === "tablet";
}

export type Orientation = (typeof INPUT_ORIENTATIONS)[number];

export type OrientationParse =
| { readonly ok: true; readonly orientation: Orientation }
| { readonly ok: false; readonly message: string };

// why: the spellings `parseOrientation` accepts for a caller that takes more than the four names; HTTP and the client take only the four names.
const ALIASES: Readonly<Record<string, Orientation>> = {
"landscape-left": "landscape_left",
"landscape-right": "landscape_right",
landscape_left: "landscape_left",
landscape_right: "landscape_right",
left: "landscape_left",
portrait: "portrait",
"portrait-upside-down": "portrait_upside_down",
portrait_upside_down: "portrait_upside_down",
right: "landscape_right",
"upside-down": "portrait_upside_down",
};

export function parseOrientation(input: string): OrientationParse {
const orientation = Object.hasOwn(ALIASES, input.trim().toLowerCase())
? ALIASES[input.trim().toLowerCase()]
: undefined;
if (orientation !== undefined) return { ok: true, orientation };
return {
message: `Unknown orientation ${input}; use portrait, portrait-upside-down, landscape-left or landscape-right`,
ok: false,
};
}
2 changes: 1 addition & 1 deletion src/contract/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ProtocolRange {
const protocolRangeSchema = z.object({ min: z.number().int(), max: z.number().int() });

/** Widen only once a second version is kept alive side by side with the first; a bump that leaves no shim behind moves both ends. */
export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 67, max: 67 };
export const PROTOCOL_VERSION_RANGE: ProtocolRange = { min: 68, max: 68 };

const LEGACY_DAEMON_PROTOCOL_VERSION = 2;

Expand Down
13 changes: 12 additions & 1 deletion src/core/fake-device-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ class FakeDeviceInput implements DeviceInput {
readonly #failedListeners = new Set<(error: Error) => void>();
#config: InputScreenConfig;

// why: a test sets this to make every write fail and the input report it through `onFailed`, as a helper whose pipe broke does.
sendFailure: Error | undefined;

constructor(config: InputScreenConfig) {
this.#config = config;
}

send(message: InputMessage): void {
send(message: InputMessage): Promise<void> {
if (this.sendFailure !== undefined) {
this.fail(this.sendFailure);
return Promise.reject(this.sendFailure);
}
this.sent.push(message);
return Promise.resolve();
}

onConfig(listener: (config: InputScreenConfig) => void): () => void {
Expand Down Expand Up @@ -56,6 +64,8 @@ export class FakeInputFactory implements DeviceInputFactory {
failWith: Error | undefined;
// why: a test sets this to hold every open until it resolves, to end a lease while a socket is still opening.
gate: Promise<void> | undefined;
// why: a test sets this to make the writes of the inputs it opens next fail.
sendFailure: Error | undefined;
opens = 0;

constructor(private readonly config: InputScreenConfig) {}
Expand All @@ -65,6 +75,7 @@ export class FakeInputFactory implements DeviceInputFactory {
await this.gate;
if (this.failWith !== undefined) throw this.failWith;
const input = new FakeDeviceInput(this.config);
input.sendFailure = this.sendFailure;
this.opened.push(input);
return input;
}
Expand Down
Loading
Loading