Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 66 additions & 2 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ implement them:
means for `USAGE` and `BAD_REQUEST`. Neither is retryable as written: the
fix is a different command, or the same command against a different daemon.
`UNSUPPORTED_IN_GATEWAY_MODE` in particular is permanent, not provisional:
`nuke`, `cleanup`, `doctor`, `driver.passthrough` and `component install`
stay per-worker operations rather than waiting on some later fleet-wide
`nuke`, `cleanup`, `doctor`, `driver.passthrough`, `component install` and
`component list` stay per-worker operations rather than waiting on some later fleet-wide
version.
- `UNKNOWN_WORKER` takes `12`, the number the table already gives to "the
thing you named cannot be resolved" (`UNKNOWN_MODEL`, `NO_DRIVER`), because
Expand Down Expand Up @@ -1169,6 +1169,70 @@ The command takes no `--json`: its output is already JSON, so the flag is a
usage error (exit 2), as is a missing or extra argument or a platform other
than `ios` or `android`.

## `simlock component list [--platform <ios|android>]`

Lists every iOS simulator runtime and Android system image installed on the
machine, whoever installed it. Read it before you remove anything. Any
session may run it, an agent session included. It changes nothing.

```sh
simlock component list
simlock component list --platform android
```

The output is one JSON object on stdout:

```json
{
"components": [
{
"platform": "android",
"version": "35",
"variant": "google_apis/arm64-v8a",
"sizeBytes": 4201234567,
"installedBySimlock": true,
"installedAt": 1790864071200,
"devices": 2,
"foreignDevices": 0
},
{
"platform": "ios",
"version": "26.4",
"variant": "23E244",
"sizeBytes": 9103456789,
"installedBySimlock": false,
"devices": 1,
"foreignDevices": 3
}
]
}
```

Entries are ordered by platform, then version, then variant.

- `version` is the string `simlock catalog` lists under `runtimes`.
- `variant` tells two components of one version apart: the build of an iOS
runtime, or the tag and ABI of an Android image.
- `sizeBytes` is the disk the component takes. It is left out when it cannot
be read.
- `installedBySimlock` is `true` only for a component installed through
Simlock (`component install`, or a lease with `--allow-download`) that is
still the same one on disk. A component that was there before, or that was
deleted and installed again some other way, is `false`. `installedAt` is
when Simlock installed it.
- `devices` counts Simlock's own devices of this platform and version that
have not been deleted. Simlock does not track which variant a device uses,
so two variants of one version show the same count.
- `foreignDevices` counts the devices outside Simlock that use the
component: simulators in Xcode's default device set, or AVDs in your own
AVD home (`ANDROID_AVD_HOME`, or `~/.android/avd`). Simlock only reads
them.

A platform whose tools cannot answer is left out, and the other platform is
still listed. A gateway answers `UNSUPPORTED_IN_GATEWAY_MODE`; run the
command against the worker. A platform other than `ios` or `android`, or a
positional argument, is a usage error (exit 2).

## `simlock cleanup [--dry-run] [--rule <name>]`

Run the cleanup reconciliation immediately. `--dry-run` prints the actions
Expand Down
28 changes: 28 additions & 0 deletions docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,34 @@ const result = await admin.installComponent(
component share one download, and each gets its result. A dropped
connection does not stop the download; calling again joins it.

## What is installed: `listComponents`

`listComponents({ platform? })`, on either client, lists every iOS
simulator runtime and Android system image installed on the daemon's
machine, whoever installed it — the call behind `simlock component list`:

```ts
const { components } = await client.listComponents({ platform: "android" });
// [{ platform: "android", version: "35", variant: "google_apis/arm64-v8a",
// sizeBytes: 4201234567, installedBySimlock: true, installedAt: 1790864071200,
// devices: 2, foreignDevices: 0 }]
```

- Entries are ordered by platform, then version, then variant. Without
`platform`, both platforms are listed; a platform whose tools cannot
answer is left out.
- `version` is the string `getCatalog` lists under `runtimes`. `variant`
tells two components of one version apart: an iOS runtime's build, an
Android image's tag and ABI. `sizeBytes` is absent when it cannot be read.
- `installedBySimlock` is `true` only for a component Simlock installed that
is still the same one on disk; `installedAt` is when it did.
- `devices` counts Simlock's own devices of this platform and version that
have not been deleted; two variants of one version show the same count.
`foreignDevices` counts the devices outside Simlock that use the
component: simulators in Xcode's default device set, AVDs in the user's
own AVD home.
- A gateway rejects it with `UNSUPPORTED_IN_GATEWAY_MODE`.

## What machine answered: `getStatus().host`

`getStatus()` carries a `host` block beside `daemon`: the machine the daemon
Expand Down
56 changes: 48 additions & 8 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Three roles:

| Role | Can |
|---|---|
| `agent` | catalog, status, its own lease requests and leases, `exec` on its own lease |
| `agent` | catalog, status, installed components, its own lease requests and leases, `exec` on its own lease |
| `operator` | everything `agent` can, plus every other requester's leases/devices, the worker routes, event replay/stream, and releasing any lease |
| `worker` | open an uplink at [`/v1/uplink`](#get-v1uplink-websocket-upgrade), and nothing else |

Expand Down Expand Up @@ -116,8 +116,8 @@ Routes, status codes, and every other field are unchanged.
Gateway/worker fleet mode is purely additive on top of
that: the same routes answer identically whether the daemon behind them is a
worker or a **gateway** fronting a fleet of workers (except
`POST /v1/components/install`, which only a worker serves; a gateway answers
`501 UNSUPPORTED_IN_GATEWAY_MODE`), and what it adds are new
`POST /v1/components/install` and `GET /v1/components`, which only a worker
serves; a gateway answers `501 UNSUPPORTED_IN_GATEWAY_MODE`), and what it adds are new
routes (`/v1/uplink`, `/v1/workers*`, `POST /v1/leases/{id}/exec`), new
fields (`mode` on status, `workers[]`, `workerId`, `worker` on the lease),
and new error codes. Nothing existing changes shape, and a client that
Expand Down Expand Up @@ -691,6 +691,45 @@ runs joins it and gets its result; repeating it after it finished answers
`already-installed`. A lease request for the same component joins the same
download too.

### `GET /v1/components?platform=ios|android`

Role: `agent`. Lists every iOS simulator runtime and Android system image
installed on this machine, whoever installed it — the same answer as
`simlock component list`. It changes nothing. Without `platform`, both
platforms are listed.

```json
{
"components": [
{
"platform": "android",
"version": "35",
"variant": "google_apis/arm64-v8a",
"sizeBytes": 4201234567,
"installedBySimlock": true,
"installedAt": 1790864071200,
"devices": 2,
"foreignDevices": 0
}
]
}
```

Entries are ordered by platform, then version, then variant. `version` is
the string `GET /v1/catalog` lists under `runtimes`; `variant` tells two
components of one version apart (an iOS runtime's build, an Android image's
tag and ABI). `sizeBytes` is left out when it cannot be read.
`installedBySimlock` is `true` only for a component Simlock installed that is
still the same one on disk, and `installedAt` is when it did. `devices`
counts Simlock's own devices of this platform and version that have not been
deleted; two variants of one version show the same count. `foreignDevices`
counts the devices outside Simlock that use the component: simulators in
Xcode's default device set, AVDs in the user's own AVD home.

A platform whose tools cannot answer is left out. `400 BAD_REQUEST` for a
`platform` other than `ios` or `android`; `501 UNSUPPORTED_IN_GATEWAY_MODE`
from a gateway, which owns no components — ask the worker.

### `DELETE /v1/leases/{id}`

Role: `agent` (own lease); `operator` may release any lease.
Expand Down Expand Up @@ -919,7 +958,7 @@ Every failure is the same shape the daemon protocol uses:
| 404 | `UNKNOWN_WORKER` (`POST`/`DELETE /v1/workers/{id}/drain` naming a worker the gateway does not know), `UNKNOWN_LEASE_REQUEST` (unknown request id), `UNKNOWN_LEASE` (unknown lease id, expired/released, **or `GET /v1/leases/{id}`/`GET /v1/leases/{id}/events` naming another requester's lease** — see [`GET /v1/leases/{id}`](#get-v1leasesid)) |
| 409 | `REQUESTER_ALREADY_LEASED` (body names the existing lease id; fleet-wide on a gateway), `IDEMPOTENCY_CONFLICT` (an `Idempotency-Key` repeated with a different device), `REQUEST_NOT_CANCELLABLE` (body names the lease id if the request had already been granted), `WORKER_CONNECTED` (`DELETE /v1/workers/{id}` while its uplink is open) |
| 422 | `UNKNOWN_MODEL`, `RUNTIME_MISSING`, `NO_DRIVER`, `PASSTHROUGH_REFUSED` (a refused `exec` verb, a caller-supplied `--set`/`-P`, a bare `adb shell`), `UNKNOWN_PASSTHROUGH_TOOL` |
| 501 | `UNSUPPORTED_IN_GATEWAY_MODE` (an operation that acts on one machine, asked of a gateway: `POST /v1/components/install`) |
| 501 | `UNSUPPORTED_IN_GATEWAY_MODE` (an operation that acts on one machine, asked of a gateway: `POST /v1/components/install`, `GET /v1/components`) |
| 503 | `NO_CAPACITY` (only with `noWait: true`; response carries `Retry-After`), `WORKER_UNREACHABLE` (a gateway could not reach the worker holding this lease or request) |
| 504 | `EXEC_TIMEOUT` (a `device.exec` command outlived `exec.timeoutMs`), `DOWNLOAD_TIMEOUT` (a runtime download, waiting for another download included, outlived `downloads.timeoutMs`) |

Expand All @@ -933,15 +972,16 @@ behind this is not reachable right now" is the same answer in all four cases,
and a client with one retry rule for `transport` should not need a second one
because the unreachable thing happened to be a worker.

`UNSUPPORTED_IN_GATEWAY_MODE` comes from one route in this version,
`POST /v1/components/install` asked of a gateway — `nuke`, `cleanup`, and
`UNSUPPORTED_IN_GATEWAY_MODE` comes from two routes in this version,
`POST /v1/components/install` and `GET /v1/components` asked of a gateway —
`nuke`, `cleanup`, and
`doctor` are absent from the HTTP surface (see
[Not implemented](#not-implemented)), and the status is fixed so adding
`POST /v1/doctor` or `POST /v1/cleanup` later is additive rather than a fresh
decision. `501` is the honest status for it: this is not a temporary
condition to retry past, it is an operation this daemon will never perform,
and `nuke`/`cleanup`/`doctor`/`driver.passthrough`/component installs stay
per-worker permanently rather than pending some later fan-out.
and `nuke`/`cleanup`/`doctor`/`driver.passthrough`/component installs and
listings stay per-worker permanently rather than pending some later fan-out.

`EXEC_TIMEOUT`'s `504` is documented for completeness rather than for the
exec route: `POST /v1/leases/{id}/exec` has already answered `200` and begun
Expand Down
31 changes: 30 additions & 1 deletion docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ agent / console ──token auth──> │ HTTP frontend + unix socket
on HTTP — that is how agents reach it and what the uplink upgrades from — so
`http.enabled: false` in gateway mode fails the start rather than being
silently overridden. `nuke.run`, `cleanup.run`, `doctor.run`,
`driver.passthrough` and `component.install` answer
`driver.passthrough`, `component.install` and `component.list` answer
`UNSUPPORTED_IN_GATEWAY_MODE` permanently: they act on one machine's devices
or components, and stay per-worker. The lease lifecycle
(`lease.request`/`renew`/`release`/`cancel`/`release-all`) and `device.exec`
Expand Down Expand Up @@ -1443,6 +1443,35 @@ event. Neither transport stops the install when its client goes away; a
repeat joins it. A gateway answers `UNSUPPORTED_IN_GATEWAY_MODE`; relaying to
workers is a separate gateway operation.

The listing is `component.list` (ADR 0010 §8), an agent read with input
`{ platform? }`, behind `simlock component list`, `listComponents` on the
client and `GET /v1/components`. Each driver answers
`listComponents()`: one entry per installed component with its version, its
`variant` (the driver's own words, carried unread: the build on iOS, tag and
ABI on Android), its size when readable, its receipt from the same function
`findComponent` and `installComponent` use, and `foreignDevices`. It is
read-only, never downloads, and every process it starts is bounded, like
`listCatalog`. iOS reads `simctl runtime list -j` (iOS images only) and
counts devices per runtime in the default device set with an unscoped
`simctl list -j devices`, the one unscoped call besides the pre-root path's.
Android reads the installed images, sizes each directory with
`Filesystem.directorySize`, and counts AVDs in the user's own AVD home whose
`config.ini` names the image's directory. On both platforms a foreign-device
read that fails rejects the listing rather than undercount. Counting foreign devices is the
only place a driver looks at devices outside its root; it reads them and
never writes there (safety rule 1).

`ComponentInstaller.list(platform?)` merges each driver's listing with the
registry: `installedBySimlock` is true when a `ComponentRecord` of that
platform has a receipt equal (`sameReceipt`) to the entry's, and
`installedAt` is that record's time — the record is the only proof (ADR 0010
§5, safety rule 8). `devices` counts registry devices of that platform and
version in any state but `deleted`; the core cannot tell variants apart, so
two variants of one version show the same count. A driver whose listing
rejects is left out and logged, and the other platform is still listed.
Entries are ordered by platform, then version, then variant. A gateway
answers `UNSUPPORTED_IN_GATEWAY_MODE`.

## External APIs behind interfaces (ports)

Every external API the app touches gets its own type/interface (a *port*),
Expand Down
62 changes: 62 additions & 0 deletions e2e/component-list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, expect, it } from "vitest";

import { withDaemon } from "./helpers/index.js";

describe("simlock component list", () => {
it("lists a component installed with simlock component install as Simlock's, and one scripted as already present as not", async () => {
const env = await withDaemon();
await env.driverScript.set({
ios: {
availableOsVersions: ["18.4"],
componentSizes: { "18.4": 8_000_000_000, "19.0": 9_000_000_000 },
foreignDevices: { "18.4": 1 },
},
});

const install = await env.cli(["component", "install", "ios", "19.0"]);
expect(install.code, install.stderr).toBe(0);
const listed = await env.cli(["component", "list", "--platform", "ios"]);

expect(listed.code, listed.stderr).toBe(0);
expect(listed.json).toEqual({
components: [
{
devices: 0,
foreignDevices: 1,
installedBySimlock: false,
platform: "ios",
sizeBytes: 8_000_000_000,
version: "18.4",
},
{
devices: 0,
foreignDevices: 0,
installedAt: expect.any(Number),
installedBySimlock: true,
platform: "ios",
sizeBytes: 9_000_000_000,
version: "19.0",
},
],
});
});

it("answers an agent session", async () => {
const env = await withDaemon();
await env.driverScript.set({ ios: { availableOsVersions: ["18.4"] } });

// A credential the daemon rejects falls back to an agent session (with a notice).
const listed = await env.cli([
"--token",
"not-an-admin-credential",
"component",
"list",
"--platform",
"ios",
]);

expect(listed.code, listed.stderr).toBe(0);
expect(listed.stderr).toContain("connecting as agent");
expect(listed.json).toMatchObject({ components: [{ platform: "ios", version: "18.4" }] });
});
});
21 changes: 21 additions & 0 deletions e2e/fake-driver/fake-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type DeviceRequest,
type Driver,
type DriverCatalogEntry,
type DriverComponent,
type DriverDevice,
type DriverEstimate,
type DriverReality,
Expand Down Expand Up @@ -290,6 +291,26 @@ export class OutOfProcessFakeDriver implements Driver {
return { outcome: "installed", receipt, version: component };
}

/**
* One entry per available version, with the receipt `findComponent` reports for it; sizes and
* foreign devices come from `componentSizes` and `foreignDevices`.
*/
async listComponents(): Promise<readonly DriverComponent[]> {
const script = await this.#beforeCall("listComponents", []);
return this.#available(script).flatMap((version): DriverComponent[] => {
const found = this.#find(version, script);
if (found === undefined) return [];
const sizeBytes = script.componentSizes?.[version];
return [
{
...found,
foreignDevices: script.foreignDevices?.[version] ?? 0,
...(sizeBytes === undefined ? {} : { sizeBytes }),
},
];
});
}

#find(component: string, script: FakeDriverPlatformScript): InstalledComponent | undefined {
if (!this.#available(script).includes(component)) return undefined;
return {
Expand Down
5 changes: 5 additions & 0 deletions e2e/fake-driver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type FakeDriverOperation =
| "destroy"
| "listManaged"
| "listCatalog"
| "listComponents"
/** The root re-proof `doctor --purge-orphans` takes before its first destroy. */
| "revalidateRoot";

Expand Down Expand Up @@ -95,6 +96,10 @@ export interface FakeDriverPlatformScript {
* `failures.installComponent` makes it fail.
*/
readonly installProgress?: readonly number[];
/** What `listComponents` reports as each version's size in bytes; absent for one left out. */
readonly componentSizes?: Readonly<Record<string, number>>;
/** What `listComponents` reports as each version's foreign devices; 0 for one left out. */
readonly foreignDevices?: Readonly<Record<string, number>>;
readonly latencyMs?: Partial<Record<FakeDriverOperation, number>>;
readonly estimateMs?: Partial<Record<FakeDriverEstimateOperation, number>>;
readonly reclaimResult?: "ready" | "shutdown";
Expand Down
2 changes: 2 additions & 0 deletions src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type {
AnySimlockError,
CatalogGetInput,
CatalogGetOutput,
ComponentListInput,
ComponentListOutput,
CleanupRunInput,
CleanupRunOutput,
ComponentInstallInput,
Expand Down
Loading
Loading