Skip to content
Closed
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
32 changes: 25 additions & 7 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ why its Android catalog looks thin, trimmed to one worker:
"runtimes": ["18.4", "26.0"],
"defaultRuntime": "26.0",
"modelRuntimes": {"iPhone 16": ["18.4"]},
"modelAliases": {}
"modelAliases": {},
"modelClasses": {"iPhone 16": "phone"}
},
{
"platform": "android",
Expand All @@ -921,6 +922,7 @@ why its Android catalog looks thin, trimmed to one worker:
"defaultRuntime": "18.0",
"modelRuntimes": {},
"modelAliases": {},
"modelClasses": {},
"images": [{"runtime": "18.0", "tag": "google_apis", "abi": "arm64-v8a"}]
}
],
Expand Down Expand Up @@ -1242,6 +1244,16 @@ level (`runtime`), tag, and ABI. An image whose ABI the host cannot run
natively is listed too, with its ABI. A tag listed here is what `simlock
lease --image-tag` accepts.

`modelClasses` gives, for a model, its class: `phone`, `tablet`, `watch`,
`tv`, `vision`, `auto` or `desktop`. On iOS the class comes from the device
type's product family: iPhone is `phone`, iPad is `tablet`, Apple Watch is
`watch`, Apple TV is `tv` and Apple Vision is `vision`. On Android it comes
from the device profile's tag: `android-tv` is `tv`, `android-wear` is
`watch`, an `android-automotive` tag is `auto` and `android-desktop` is
`desktop`; a profile with no tag, and a custom profile, is `phone`. A model
whose tools report no class, or one this list does not name, is still
listed and still leasable; it has no entry in `modelClasses`.

`customModels` lists the models that exist because of something on that
machine rather than the platform's tools. The field is absent when there are
none, and iOS never has it. See [Where Android models come
Expand All @@ -1256,16 +1268,19 @@ same way, unless `--platform` names it: then the command fails with that error.
downloads a runtime or system image, and lists only what is installed,
whatever `downloads.policy` says.

Human-oriented by default, one line per model with the runtimes it pairs
with, its other names on the line below it, and then each image:
Human-oriented by default, the models grouped under a line per class (in the
order `phone`, `tablet`, `watch`, `tv`, `vision`, `auto`, `desktop`, then
`(no class)` for a model with none), one line per model with the runtimes it
pairs with, its other names on the line below it, and then each image:

```text
Platform: android
Runtimes: 34, 35 (default: 35)
Models:
My Tablet (custom): 34, 35
Pixel 8: 34, 35
Other names: pixel_8
phone:
My Tablet (custom): 34, 35
Pixel 8: 34, 35
Other names: pixel_8
Images (runtime, tag, ABI):
34 default x86_64
35 google_apis arm64-v8a
Expand All @@ -1277,12 +1292,15 @@ Platform: android
{"platforms":[{"platform":"android","models":["My Tablet","Pixel 8"],"runtimes":["34","35"],"defaultRuntime":"35",
"modelRuntimes":{"My Tablet":["34","35"],"Pixel 8":["34","35"]},
"modelAliases":{"Pixel 8":["pixel_8"]},
"modelClasses":{"My Tablet":"phone","Pixel 8":"phone"},
"customModels":["My Tablet"],
"images":[{"runtime":"34","tag":"default","abi":"x86_64"},{"runtime":"35","tag":"google_apis","abi":"arm64-v8a"}]}]}
```

Against a gateway, `modelAliases` is the union of each worker's other names
for a model, and `images` the union of their images. A model is in
for a model, `modelClasses` the union of their classes (when two workers class
a model differently, the first worker in id order wins), and `images` the union
of their images. A model is in
`customModels` when any worker that lists it marks it custom;
`simlock worker list --json` shows which worker that is. A gateway accepts any
name a worker lists for a model, in any letter case, and sends that worker its
Expand Down
13 changes: 10 additions & 3 deletions docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ const { platforms } = await client.getCatalog({ platform: "ios" });
// runtimes: ["18.4", "26.0"],
// defaultRuntime: "26.0",
// modelRuntimes: { "iPhone 16": ["18.4", "26.0"], "iPhone XS": ["18.4"] },
// modelAliases: {} }]
// modelAliases: {},
// modelClasses: { "iPhone 16": "phone", "iPhone XS": "phone" } }]
```

- `models` and `runtimes` are what is installed. A model and a runtime that
Expand All @@ -255,6 +256,11 @@ const { platforms } = await client.getCatalog({ platform: "ios" });
it, in any letter case. Only models with another name appear. On Android
a built-in profile's AVD id is one (`{ "Pixel 8": ["pixel_8"] }`); iOS
has none.
- `modelClasses` maps a model to its class: `phone`, `tablet`, `watch`, `tv`,
`vision`, `auto` or `desktop`. On iOS it comes from the device type's
product family, on Android from the profile's tag, and a custom Android
profile is a `phone`. A model whose tools report no class, or one this list
does not name, has no entry; it is still listed and still leasable.
- `images` is on Android entries only: every installed system image as
`{ runtime, tag, abi }`, where `runtime` is a value from `runtimes`. An
image whose ABI the host cannot run natively is listed too.
Expand All @@ -274,8 +280,9 @@ Against a gateway the catalog is the union of the connected workers'. A
model is paired with a runtime when at least one worker pairs them, and
`modelWorkers` and `runtimeWorkers` say which workers have each model and
runtime. The gateway sends a request only to a worker that pairs the model
with the runtime. `modelAliases` and `images` are the unions of each
worker's own. A model is in `customModels` when any worker that lists it
with the runtime. `modelAliases`, `modelClasses` and `images` are the unions
of each worker's own; when two workers class a model differently, the first
worker in id order wins. A model is in `customModels` when any worker that lists it
marks it custom; each worker's own list is in its catalog on
`listWorkers()` from the admin client. A model may be asked for by any name a worker lists for it, in
any letter case, and the gateway sends that worker its own name for it.
Expand Down
17 changes: 15 additions & 2 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ for that platform has an `images` field. A gateway accepts any name a worker
lists for a model, in any letter case, and sends that worker its own name for
it.

Each entry also carries `modelClasses`: for a name in `models` whose tooling
reports one, its class, one of `phone`, `tablet`, `watch`, `tv`, `vision`,
`auto` or `desktop`. On iOS it comes from the device type's product family,
on Android from the device profile's tag, and a custom Android profile is a
`phone`. A model whose tools report no class, or one this API does not name,
is still listed and still leasable, and has no entry. On a gateway it is the
union over the connected workers; when two workers class a model differently,
the first worker in id order wins.

An entry may also carry `customModels`: the names from `models` that exist
because of something on that machine rather than the platform's tools. On
Android that is a profile made with Android Studio's device manager, read
Expand All @@ -294,14 +303,16 @@ that lists it marks it custom; each worker's own list is in its catalog in
"runtimes": ["18.4", "26.0"],
"defaultRuntime": "26.0",
"modelRuntimes": { "iPhone 16": ["18.4", "26.0"], "iPhone XS": ["18.4"] },
"modelAliases": {}
"modelAliases": {},
"modelClasses": { "iPhone 16": "phone", "iPhone XS": "phone" }
}, {
"platform": "android",
"models": ["My Tablet", "Pixel 8"],
"runtimes": ["34", "35"],
"defaultRuntime": "35",
"modelRuntimes": { "My Tablet": ["34", "35"], "Pixel 8": ["34", "35"] },
"modelAliases": { "Pixel 8": ["pixel_8"] },
"modelClasses": { "My Tablet": "phone", "Pixel 8": "phone" },
"customModels": ["My Tablet"],
"images": [ { "runtime": "34", "tag": "default", "abi": "x86_64" },
{ "runtime": "35", "tag": "google_apis", "abi": "arm64-v8a" } ]
Expand Down Expand Up @@ -1053,7 +1064,8 @@ simulated (hence the thin Android catalog), trimmed to one worker:
"runtimes": ["18.4", "26.0"],
"defaultRuntime": "26.0",
"modelRuntimes": {"iPhone 16": ["18.4"]},
"modelAliases": {}
"modelAliases": {},
"modelClasses": {"iPhone 16": "phone"}
},
{
"platform": "android",
Expand All @@ -1062,6 +1074,7 @@ simulated (hence the thin Android catalog), trimmed to one worker:
"defaultRuntime": "18.0",
"modelRuntimes": {},
"modelAliases": {},
"modelClasses": {},
"images": [{"runtime": "18.0", "tag": "google_apis", "abi": "arm64-v8a"}]
}
],
Expand Down
25 changes: 18 additions & 7 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ agent / console ──token auth──> │ HTTP frontend + unix socket
array of views and `daemon.mode: "gateway"`. `catalog.get` is the union of
the connected workers' catalogs, each model and runtime annotated with the
workers that have it, `modelRuntimes` per model the union of each
worker's own pairings, `modelAliases` the union per model, and `images`
the union by runtime, tag, and ABI (ADR 0008 §4). Worker events are republished on the gateway's bus
worker's own pairings, `modelAliases` the union per model, `modelClasses`
the union with the first worker in id order winning a model two classify
differently (ADR 0015 §3), and `images` the union by runtime, tag, and ABI
(ADR 0008 §4). Worker events are republished on the gateway's bus
with `workerId` added, so `simlock events --follow` against a gateway shows
the fleet.
- **What a gateway does not do.** It starts no drivers, validates no device
Expand Down Expand Up @@ -267,8 +269,9 @@ gateway's `worker.install-component` (ADR 0010 §7)
relays that operation to workers, so a worker without it must be
`incompatible` rather than fail in the middle of a relay. ADR 0014 gives every
event envelope an `id`, taking it to 10, and ADR 0009 makes `atRamBudget` a
required capacity field, taking it to 11. So the range both
sides advertise is `{min: 11, max: 11}`, an older client and a current daemon simply
required capacity field, taking it to 11, and ADR 0015 §3 makes the catalog's
`modelClasses` required, taking it to 12. So the range both
sides advertise is `{min: 12, max: 12}`, an older client and a current daemon simply
do not overlap, and `hello` fails with `PROTOCOL_VERSION_UNSUPPORTED` naming
both ranges. The same negotiation runs over a worker's uplink, which is why a
worker older than this shows up in a gateway's views as `incompatible`
Expand Down Expand Up @@ -829,7 +832,9 @@ annotated with the workers that have it. A model's `modelRuntimes` is the
union of what each connected worker pairs it with, never the cross product
of fleet models and fleet runtimes: one worker with the model and another
with the runtime is not a leasable pair. `modelAliases` is the union per
model, deduplicated ignoring case, and `images` the union by runtime, tag,
model, deduplicated ignoring case, `modelClasses` the union per model with
the first worker in id order winning a disagreement (a class a worker gives a
name it does not list is dropped), and `images` the union by runtime, tag,
and ABI, absent when no worker reports the field. `customModels` lists a
model when any worker that lists it marks it custom; a name a worker marks
but does not list is dropped. Each worker's lists are
Expand All @@ -852,7 +857,12 @@ back to that profile. A listed model is in `customModels` when the profile
the matcher sends its name to is a `devices.xml` one (parsed by Simlock, or
listed by `avdmanager` with `OEM : User`), so the mark and the resolution
cannot disagree. The iOS driver matches a device type's name
only. `DriverCatalog.listCatalog` leaves out and logs a driver whose catalog
only. Each driver also classes the models it lists (ADR 0015 §3): the iOS driver
from the device type's `productFamily`, the Android driver from the profile's
`Tag :` line (a `devices.xml` profile is a phone), each in one table inside its
own module; the core and the contract carry the class names and read nothing
from them, and a family or tag a table does not know lists no class and stays
leasable. `DriverCatalog.listCatalog` leaves out and logs a driver whose catalog
rejects when no platform is named, and fails with that driver's error when
its platform is named.

Expand Down Expand Up @@ -903,7 +913,8 @@ emits its own facts — `worker.connected`, `worker.disconnected`,
`{min: 8, max: 8}`, because a lease request chooses it, and ADR 0010 to
`{min: 9, max: 9}`, because the gateway is to relay `component.install` to workers, and
ADR 0014 to `{min: 10, max: 10}`, because every event envelope has an `id`, and
ADR 0009 to `{min: 11, max: 11}`, because `atRamBudget` is required; a
ADR 0009 to `{min: 11, max: 11}`, because `atRamBudget` is required, and
ADR 0015 to `{min: 12, max: 12}`, because `modelClasses` is required; a
worker on an older version is `incompatible` the same way. That is the ordinary upgrade path, not a failure mode:
upgrade the worker. An incompatible worker is marked `incompatible` in its
view with both ranges shown and is never dispatched to, and it is not
Expand Down
1 change: 1 addition & 0 deletions e2e/fake-driver/fake-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export class OutOfProcessFakeDriver implements Driver {
...(script.images === undefined ? {} : { images: [...script.images] }),
...(script.customModels === undefined ? {} : { customModels: [...script.customModels] }),
modelAliases: { ...script.modelAliases },
modelClasses: { ...script.modelClasses },
modelRuntimes: Object.fromEntries(
models.map((model) => [model, [...(script.modelRuntimes?.[model] ?? runtimes)]]),
),
Expand Down
11 changes: 11 additions & 0 deletions e2e/fake-driver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

export type FakeDriverPlatform = "ios" | "android";

export type FakeDriverDeviceClass =
| "phone"
| "tablet"
| "watch"
| "tv"
| "vision"
| "auto"
| "desktop";

export type FakeDriverOperation =
| "resolveSpec"
| "findComponent"
Expand Down Expand Up @@ -78,6 +87,8 @@ export interface FakeDriverPlatformScript {
readonly modelRuntimes?: Readonly<Record<string, readonly string[]>>;
/** What `listCatalog` reports as other names per model; none unless set. */
readonly modelAliases?: Readonly<Record<string, readonly string[]>>;
/** What `listCatalog` reports as each model's class; none unless set. */
readonly modelClasses?: Readonly<Record<string, FakeDriverDeviceClass>>;
/** What `listCatalog` reports as custom models; the field is absent unless set. */
readonly customModels?: readonly string[];
/**
Expand Down
51 changes: 51 additions & 0 deletions e2e/gateway-fleet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface WorkerView {
readonly modelRuntimes: Readonly<Record<string, readonly string[]>>;
readonly modelAliases: Readonly<Record<string, readonly string[]>>;
readonly customModels?: readonly string[];
readonly modelClasses?: Readonly<Record<string, string>>;
readonly images?: readonly {
readonly runtime: string;
readonly tag: string;
Expand Down Expand Up @@ -430,6 +431,56 @@ describe("gateway fleet", () => {
expect(human.stdout).toContain(" Pixel 8: 35");
});

it("carries the union of the workers' model classes in the gateway catalog, and prints each model under its class", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
configOverrides: { http: { host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
const minted = await gateway.cli(["token", "create", "--role", "worker"]);
const { secret } = minted.json as { secret: string };
const uplink = { token: secret, url: `ws://127.0.0.1:${port}` };
await withDaemon({
configOverrides: { gateway: { ...uplink, label: "worker-a" } },
driverScript: {
android: {
availableOsVersions: ["35"],
knownModels: ["Pixel 8"],
modelClasses: { "Pixel 8": "phone" },
},
},
});
await withDaemon({
configOverrides: { gateway: { ...uplink, label: "worker-b" } },
driverScript: {
android: {
availableOsVersions: ["35"],
knownModels: ["Television (1080p)", "Mystery"],
modelClasses: { "Television (1080p)": "tv" },
},
},
});
await waitForWorkers(
gateway,
(views) =>
views.length === 2 &&
views.every((view) => view.connection === "connected" && view.catalog.length > 0),
"both workers connected with their catalogs",
);

const catalog = await gateway.cli(["catalog", "--json"]);
expect(catalog.code).toBe(0);
const android = (catalog.json as { platforms: WorkerView["catalog"] }).platforms.find(
(entry) => entry.platform === "android",
);
expect(android?.modelClasses).toEqual({ "Pixel 8": "phone", "Television (1080p)": "tv" });

const human = await gateway.cli(["catalog"]);
expect(human.stdout).toContain(
" phone:\n Pixel 8: 35\n tv:\n Television (1080p): 35\n (no class):\n Mystery: 35",
);
});

it("gives a request with a mode that mode on either worker, and a request with none the default of the worker it landed on", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
Expand Down
7 changes: 7 additions & 0 deletions e2e/slow-android-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface AndroidCatalogOutput {
readonly models: readonly string[];
readonly runtimes: readonly string[];
readonly modelAliases: Readonly<Record<string, readonly string[]>>;
readonly modelClasses: Readonly<Record<string, string>>;
readonly images?: readonly { runtime: string; tag: string; abi: string }[];
}[];
}
Expand Down Expand Up @@ -75,6 +76,12 @@ function avdIdFromCatalog(output: AndroidCatalogOutput): string {
expect(existsSync(path), `listed image ${JSON.stringify(image)} is not installed`).toBe(true);
}

// avdmanager's tag classes the models: a stock Pixel is a phone, the stock TV profile a tv.
if (android.models.includes("Pixel 8")) expect(android.modelClasses["Pixel 8"]).toBe("phone");
if (android.models.includes("Television (1080p)")) {
expect(android.modelClasses["Television (1080p)"]).toBe("tv");
}

const aliases = android.models.flatMap((name) => android.modelAliases[name] ?? []);
expect(
aliases.length,
Expand Down
20 changes: 19 additions & 1 deletion e2e/slow-ios-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ async function expectSimctlPassthrough(env: TestEnv, udid: string): Promise<void
expect(refused.error).toMatchObject({ code: "USAGE" });
}

/** simctl's product family classes the models: every iPhone is a phone, every Apple Watch a watch. */
function expectProductFamilyClasses(
catalog: { readonly modelClasses: Readonly<Record<string, string>> } | undefined,
): void {
const classes = Object.entries(catalog?.modelClasses ?? {});
expect(classes.length, "simlock catalog classed no iOS model").toBeGreaterThan(0);
for (const [name, deviceClass] of classes) {
if (name.startsWith("iPhone ")) expect(deviceClass, name).toBe("phone");
if (name.startsWith("Apple Watch ")) expect(deviceClass, name).toBe("watch");
}
}

describe.skipIf(process.platform !== "darwin")(
"iOS smoke (real simctl)",
{ tags: ["slow", "ios"] },
Expand All @@ -67,7 +79,12 @@ describe.skipIf(process.platform !== "darwin")(
expect(catalog.code).toBe(0);
const platforms = (
catalog.json as {
platforms: { platform: string; models: string[]; runtimes: string[] }[];
platforms: {
platform: string;
models: string[];
runtimes: string[];
modelClasses: Record<string, string>;
}[];
}
).platforms;
const iosCatalog = platforms.find((platform) => platform.platform === "ios");
Expand All @@ -82,6 +99,7 @@ describe.skipIf(process.platform !== "darwin")(
"simlock catalog's runtimes must agree with real simctl",
).toContain(runtime);
}
expectProductFamilyClasses(iosCatalog);
const model = iosCatalog?.models[0] as string;

const lease = await env.cli(
Expand Down
Loading
Loading