Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 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
c267dac
test: a user runs simlock rotate <orientation> and sees Rotated lease…
leonardoxr Oct 31, 2026
adb10f2
feat(cli): simlock rotate turns the holder's only lease (#1108)
leonardoxr Oct 31, 2026
8972aca
test: --lease names the lease to rotate before or after the orientati…
leonardoxr Oct 31, 2026
fa9b7cf
feat(cli): simlock rotate --lease names the lease (#1108)
leonardoxr Oct 31, 2026
17858cd
test: simlock rotate takes aliases, refuses unknown names and ambiguo…
leonardoxr Oct 31, 2026
9f1396f
test: an MCP client calls rotate_device {orientation} and the held le…
leonardoxr Oct 31, 2026
bc1a869
feat(mcp): rotate_device turns the session's held lease (#1108)
leonardoxr Oct 31, 2026
a8dda2f
test: rotate_device answers NO_LEASE, BAD_REQUEST and the daemon's re…
leonardoxr Oct 31, 2026
77edefa
test: simlock instructions lists simlock rotate and rotate_device (#1…
leonardoxr Oct 31, 2026
eae80be
test: a socket whose write fails closes 1013 while the daemon keeps r…
leonardoxr Oct 31, 2026
6d6c5ea
feat(instructions): simlock instructions lists simlock rotate and rot…
leonardoxr Oct 31, 2026
e5bb97b
test: simlock rotate --help and the root usage name the command (#1108)
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
8c98b94
feat(cli): simlock rotate --help, the root usage, the CLI reference a…
leonardoxr Oct 31, 2026
18735fc
Merge remote-tracking branch 'origin/task/1107' into task/1108
leonardoxr Oct 31, 2026
7603ff6
fix: the website's MCP summaries say six tools; rotate_device's alias…
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
de2bc7b
Merge remote-tracking branch 'origin/task/1107' into task/1108
leonardoxr Oct 31, 2026
33b7b53
test: pin rotate's agent role, client close and the rotate_device inp…
leonardoxr Oct 31, 2026
dedafb1
test: drop a leftover debug assertion from the MCP smoke table (#1108)
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
54dd125
Merge branch 'task/1107' into task/1108
V3RON Oct 31, 2026
aea4fb3
docs(cli): list simlock rotate in the CLI reference's command table (…
V3RON Oct 31, 2026
fbfc5a7
test(cli): prove simlock rotate through a gateway with --gateway (#1108)
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
562e8d5
Merge branch 'fix-1107' into fix-1108
V3RON Oct 31, 2026
153ebd3
Merge remote-tracking branch 'origin/main' into up-1108
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
43 changes: 24 additions & 19 deletions src/cli/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,26 @@ Surface: [cli.mdx](../../website/src/content/docs/docs/reference/cli.mdx) — ev

## Files

| File | Role |
| ---------------- | ------------------------------------------------------------------------------------------------- |
| `index.ts` | `runCli`: the global `--token`, `--gateway` and `--local`, the command lookup, the error boundary |
| `tree.ts` | The command tree — each node names the module that implements it |
| `environment.ts` | `buildCliEnvironment`: the ports a command may reach, from the ports it is handed |
| `types.ts` | `CliEnvironment` and its ports — types only, so routing loads no code |
| `errors.ts` | The error → code/exit mapping |
| `usage-error.ts` | `UsageError` and `withHelpHint`, the help pointer's one wording |
| `connect.ts` | `connectDaemonClient`: credential order, the admin session, the notice |
| `args.ts` | `commandArgs` / `requiredPositional` / `subcommandOrUsage` / `writeResult` |
| `commands/*.ts` | One module per command, `run(argv, context)`; loaded by the tree on a hit |
| `format.ts` | The human renderers for `status`, `worker list`, `daemon start`, etc. |
| `duration.ts` | `parseDuration` for `--ttl`-style flags |
| `termination.ts` | The signals and parent-exit wait a held lease blocks on |
| `log-file.ts` | `readLogFile`: `daemon.log` plus a rotated generation |
| `stdio.ts` | `readPipedStdin`: a piped stdin for `simctl`/`adb`, read to EOF |
| `passthrough.ts` | `spawnPassthrough`: runs a resolved simctl/adb command, stdio inherited |
| `follow-log.ts` | `followLog`: `daemon logs --follow` across rotations |
| `main.ts` | The bin; sets `process.exitCode` |
| File | Role |
| ----------------- | ------------------------------------------------------------------------------------------------- |
| `index.ts` | `runCli`: the global `--token`, `--gateway` and `--local`, the command lookup, the error boundary |
| `tree.ts` | The command tree — each node names the module that implements it |
| `environment.ts` | `buildCliEnvironment`: the ports a command may reach, from the ports it is handed |
| `types.ts` | `CliEnvironment` and its ports — types only, so routing loads no code |
| `errors.ts` | The error → code/exit mapping |
| `usage-error.ts` | `UsageError` and `withHelpHint`, the help pointer's one wording |
| `connect.ts` | `connectDaemonClient`: credential order, the admin session, the notice |
| `args.ts` | `commandArgs` / `requiredPositional` / `subcommandOrUsage` / `writeResult` |
| `commands/*.ts` | One module per command, `run(argv, context)`; loaded by the tree on a hit |
| `format.ts` | The human renderers for `status`, `worker list`, `daemon start`, etc. |
| `duration.ts` | `parseDuration` for `--ttl`-style flags |
| `termination.ts` | The signals and parent-exit wait a held lease blocks on |
| `log-file.ts` | `readLogFile`: `daemon.log` plus a rotated generation |
| `stdio.ts` | `readPipedStdin`: a piped stdin for `simctl`/`adb`, read to EOF |
| `remote-lease.ts` | `resolveRemoteLeaseId`: the requester's only lease, shared by `simctl`/`adb` and `rotate` |
| `passthrough.ts` | `spawnPassthrough`: runs a resolved simctl/adb command, stdio inherited |
| `follow-log.ts` | `followLog`: `daemon logs --follow` across rotations |
| `main.ts` | The bin; sets `process.exitCode` |

`format.ts`, `duration.ts` and `termination.ts` are reached only from a command module, and
`follow-log.ts` and `passthrough.ts` only from a dynamic import inside `environment.ts`.
Expand Down Expand Up @@ -89,6 +90,10 @@ Surface: [cli.mdx](../../website/src/content/docs/docs/reference/cli.mdx) — ev
fills the lease's device in and refuses another (ADR 0047). A piped stdin is
read to EOF first; output chunks go to stdout and stderr.
`PASSTHROUGH_REFUSED` and `UNKNOWN_PASSTHROUGH_TOOL` become usage errors (exit 2).
5a. **`simlock rotate <orientation> [--lease <id>]`** — `parseOrientation` (contract) spells the
orientation, an unknown one is a usage error (exit 2); the lease is `--lease` (anywhere on the line)
or the requester's only lease (`resolveRemoteLeaseId`); `device.rotate` answers, and the line printed
is `Rotated lease <id> to <orientation>` from the answer. Worker or gateway alike.
6. **`simlock events --follow`** — subscribe, then replay, then print buffered pushes not
already replayed (by `eventKey`). `--since` without `--follow` never launches a daemon;
with none running it reads `history.db` itself (read-only; no file is empty, an unreadable
Expand Down
23 changes: 1 addition & 22 deletions src/cli/commands/passthrough.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SimlockAdminClient } from "../../admin/index.js";
import { asUsageIfRefused, UsageError } from "../errors.js";
import { resolveRemoteLeaseId } from "../remote-lease.js";
import { connectDaemonClient } from "../connect.js";
import type { CommandContext } from "../tree.js";

Expand Down Expand Up @@ -103,26 +104,4 @@ function extractLeaseFlag(args: readonly string[]): {
return { leaseFlag, rest: args.slice(index) };
}

async function resolveRemoteLeaseId(
client: SimlockAdminClient,
environment: CommandContext["environment"],
): Promise<string> {
const { leases } = await client.listLeases();
const own =
client.role === "admin"
? leases.filter((lease) => lease.requesterId === environment.requesterId)
: leases;
if (own.length === 0) {
throw new UsageError(
`No lease is held by ${environment.requesterId}: run \`simlock lease\` first, or set SIMLOCK_AGENT_ID to the id that holds it`,
);
}
if (own.length > 1) {
throw new UsageError(
`${environment.requesterId} holds more than one lease (${own.map((lease) => lease.id).join(", ")}); pass --lease <id> to name the device you mean`,
);
}
return (own[0] as { readonly id: string }).id;
}

export { run };
40 changes: 40 additions & 0 deletions src/cli/commands/rotate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { parseOrientation } from "../../contract/index.js";
import { commandArgs, requiredPositional, UsageError } from "../args.js";
import { connectDaemonClient } from "../connect.js";
import { resolveRemoteLeaseId } from "../remote-lease.js";
import type { CommandContext } from "../tree.js";

async function run(
argv: readonly string[],
{ environment, token }: CommandContext,
): Promise<number> {
const { help, lease, positionals } = commandArgs(argv, {
help: { type: "boolean", short: "h" },
lease: { type: "string" },
});
if (help) {
environment.stdout.write(
"Usage: simlock rotate <portrait|portrait-upside-down|landscape-left|landscape-right> [--lease <id>]\n",
);
return 0;
}
const parsed = parseOrientation(requiredPositional(positionals, "orientation"));
if (!parsed.ok) throw new UsageError(parsed.message);
const client = await connectDaemonClient(environment, token);
try {
const leaseId =
typeof lease === "string" ? lease : await resolveRemoteLeaseId(client, environment);
const requesterId = client.role === "admin" ? environment.requesterId : undefined;
const rotated = await client.rotate(
leaseId,
parsed.orientation,
requesterId === undefined ? undefined : { requesterId },
);
environment.stdout.write(`Rotated lease ${rotated.leaseId} to ${rotated.orientation}\n`);
return 0;
} finally {
await client.close();
}
}

export { run };
179 changes: 179 additions & 0 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10674,3 +10674,182 @@ describe("simlock worker update", () => {
}
});
});

describe("simlock rotate", () => {
const heldLease = {
deviceId: "dev_1",
grantedAt: 0,
id: "lse_mine",
lastRenewedAt: 0,
idChosenByRequester: false,
ownerId: "some-other-principal",
requesterId: "test-requester",
ttlDeadline: 60_000,
ttlMs: 60_000,
};

const two = [heldLease, { ...heldLease, deviceId: "dev_2", id: "lse_other" }];

async function rotateWith(
argv: readonly string[],
leases: readonly (typeof heldLease)[],
role: "admin" | "agent" = "admin",
daemonHome?: { role: "gateway"; dataDirectory: string; gatewayPresent: true },
) {
const output = outputCapture();
const rotations: unknown[] = [];
let closes = 0;
const exitCode = await runCli(
argv,
output.environmentWith({
...(daemonHome === undefined ? {} : { daemonHome }),
connectAdmin: async () =>
fakeClient({
role,
close: () => {
closes += 1;
return Promise.resolve();
},
listLeases: () => Promise.resolve({ leases: [...leases] }),
rotate: (leaseId, orientation, options) => {
rotations.push({ leaseId, orientation, options });
return Promise.resolve({ leaseId: `${leaseId}_answered`, orientation });
},
}),
}),
);
return { closes: () => closes, exitCode, output, rotations };
}

it("a user runs simlock rotate <orientation> [--lease <id>], on a worker or with --gateway, and sees Rotated lease <id> to <orientation>, or a usage error", async () => {
const only = await rotateWith(["rotate", "landscape-left"], [heldLease]);
expect(only.exitCode).toBe(0);
expect(only.rotations).toEqual([
{
leaseId: "lse_mine",
orientation: "landscape_left",
options: { requesterId: "test-requester" },
},
]);
expect(only.output.stdout).toBe("Rotated lease lse_mine_answered to landscape_left\n");
expect(only.closes()).toBe(1);

const asAgent = await rotateWith(["rotate", "landscape-left"], [heldLease], "agent");
expect(asAgent.exitCode).toBe(0);
expect(asAgent.rotations).toEqual([
{ leaseId: "lse_mine", orientation: "landscape_left", options: undefined },
]);

const gateway = {
role: "gateway",
dataDirectory: "/simlock/gateway",
gatewayPresent: true,
} as const;
for (const argv of [
["--gateway", "rotate", "landscape-left"],
["rotate", "landscape-left", "--gateway"],
]) {
const throughGateway = await rotateWith(argv, [heldLease], "agent", gateway);
expect(throughGateway.exitCode, argv.join(" ")).toBe(0);
expect(throughGateway.rotations, argv.join(" ")).toEqual([
{ leaseId: "lse_mine", orientation: "landscape_left", options: undefined },
]);
expect(throughGateway.output.stdout, argv.join(" ")).toBe(
"Rotated lease lse_mine_answered to landscape_left\n",
);
}

for (const argv of [
["rotate", "--lease", "lse_other", "left"],
["rotate", "left", "--lease", "lse_other"],
["rotate", "left", "--lease=lse_other"],
]) {
const named = await rotateWith(argv, two);
expect(named.exitCode).toBe(0);
expect(named.rotations).toEqual([
{
leaseId: "lse_other",
orientation: "landscape_left",
options: { requesterId: "test-requester" },
},
]);
}

for (const [spelling, orientation] of [
["LEFT", "landscape_left"],
[" left ", "landscape_left"],
["upside-down", "portrait_upside_down"],
]) {
const spelled = await rotateWith(["rotate", spelling as string], [heldLease]);
expect(spelled.exitCode).toBe(0);
expect(spelled.output.stdout).toBe(`Rotated lease lse_mine_answered to ${orientation}\n`);
}

const refusals: [readonly string[], readonly (typeof heldLease)[], RegExp][] = [
[["rotate", "sideways"], [heldLease], /^Unknown orientation sideways; use portrait,/],
[["rotate", "auto"], [heldLease], /^Unknown orientation auto;/],
[["rotate", "landscapeLeft"], [heldLease], /^Unknown orientation landscapeLeft;/],
[["rotate"], [heldLease], /^Expected orientation/],
[["rotate", "left"], [], /test-requester/],
[["rotate", "left"], two, /lse_mine.*lse_other.*--lease <id>/s],
];
for (const [argv, leases, message] of refusals) {
const refused = await rotateWith(argv, leases);
expect(refused.exitCode).toBe(2);
expect(refused.rotations).toEqual([]);
expect(JSON.parse(refused.output.stderr.trim().split("\n").at(-1) ?? "")).toEqual({
error: { code: "USAGE", message: expect.stringMatching(message) },
});
}

const unsupported = outputCapture();
let unsupportedCloses = 0;
await expect(
runCli(
["rotate", "left", "--lease", "lse_android"],
unsupported.environmentWith({
connectAdmin: async () =>
fakeClient({
close: () => {
unsupportedCloses += 1;
return Promise.resolve();
},
rotate: () =>
Promise.reject(
new SimlockError(
"ROTATION_UNSUPPORTED",
"domain",
"Lease lse_android is on an Android emulator; only an iOS simulator can be rotated",
{
class: "emulator",
leaseId: "lse_android",
physical: false,
platform: "android",
},
),
),
}),
}),
),
).resolves.toBe(12);
expect(JSON.parse(unsupported.stderr.trim().split("\n").at(-1) ?? "")).toEqual({
error: {
code: "ROTATION_UNSUPPORTED",
message:
"Lease lse_android is on an Android emulator; only an iOS simulator can be rotated",
},
});
expect(unsupported.stdout).toBe("");
expect(unsupportedCloses).toBe(1);

const help = await rotateWith(["rotate", "--help"], [heldLease]);
expect(help.exitCode).toBe(0);
expect(help.output.stdout).toBe(
"Usage: simlock rotate <portrait|portrait-upside-down|landscape-left|landscape-right> [--lease <id>]\n",
);
expect(help.rotations).toEqual([]);
const listing = outputCapture();
await runCli(["--help"], listing.environmentWith());
expect(listing.stdout).toContain(" rotate <orientation> [--lease <id>]");
});
});
3 changes: 3 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Commands:
device add --platform <ios|android> <id> [--json]
Enrol a physical device plugged into this host
device remove <id> [--json] Forget an enrolled physical device; the device is untouched
rotate <orientation> [--lease <id>]
Turn the leased iOS simulator: portrait, portrait-upside-down,
landscape-left or landscape-right
simctl <args...> Run xcrun simctl against Simlock's iOS device set
adb <args...> Run adb against Simlock's adb server
mcp Start the stdio MCP server
Expand Down
25 changes: 25 additions & 0 deletions src/cli/remote-lease.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { SimlockAdminClient } from "../admin/index.js";
import { UsageError } from "./errors.js";
import type { CommandContext } from "./tree.js";

export async function resolveRemoteLeaseId(
client: SimlockAdminClient,
environment: CommandContext["environment"],
): Promise<string> {
const { leases } = await client.listLeases();
const own =
client.role === "admin"
? leases.filter((lease) => lease.requesterId === environment.requesterId)
: leases;
if (own.length === 0) {
throw new UsageError(
`No lease is held by ${environment.requesterId}: run \`simlock lease\` first, or set SIMLOCK_AGENT_ID to the id that holds it`,
);
}
if (own.length > 1) {
throw new UsageError(
`${environment.requesterId} holds more than one lease (${own.map((lease) => lease.id).join(", ")}); pass --lease <id> to name the device you mean`,
);
}
return (own[0] as { readonly id: string }).id;
}
1 change: 1 addition & 0 deletions src/cli/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const COMMANDS: readonly CommandNode[] = [
},
{ name: "simctl", load: () => import("./commands/passthrough.js") },
{ name: "adb", load: () => import("./commands/passthrough.js") },
{ name: "rotate", load: () => import("./commands/rotate.js") },
{ name: "mcp", load: () => import("./commands/mcp.js") },
{ name: "instructions", load: () => import("./commands/instructions.js") },
{ name: "setup", load: () => import("./commands/setup.js") },
Expand Down
2 changes: 2 additions & 0 deletions src/instructions/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TOOL_NAMES = [
"release_simulator",
"lease_status",
"run_on_device",
"rotate_device",
];

const REQUIRED: Readonly<Record<(typeof HEADINGS)[number], readonly string[]>> = {
Expand Down Expand Up @@ -99,6 +100,7 @@ const REQUIRED: Readonly<Record<(typeof HEADINGS)[number], readonly string[]>> =
...REFUSED_ADB_SEQUENCES.map(({ sequence }) => `\`simlock adb ${sequence.join(" ")}\``),
"`simlock adb` refuses any option before the subcommand other than `-s`, `-t`, `-d` or `-e`",
"`simlock adb shell`",
"`simlock rotate <orientation>`",
...[
ERROR_TABLE.QUEUE_TIMEOUT.cliExitCode,
ERROR_TABLE.NO_CAPACITY.cliExitCode,
Expand Down
Loading
Loading