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
34 changes: 31 additions & 3 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,11 @@ Android also lists `images`: every installed system image with its API
level (`runtime`), tag, and ABI. An image whose ABI the host cannot run
natively is listed too, with its ABI.

`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
from](#where-android-models-come-from).

A
platform whose SDK is missing (e.g. Android without `ANDROID_HOME` on a
non-macOS host, or iOS off macOS) is omitted rather than erroring the whole
Expand All @@ -1097,7 +1102,7 @@ with, its other names on the line below it, and then each image:
Platform: android
Runtimes: 34, 35 (default: 35)
Models:
My Tablet: 34, 35
My Tablet (custom): 34, 35
Pixel 8: 34, 35
Other names: pixel_8
Images (runtime, tag, ABI):
Expand All @@ -1111,14 +1116,35 @@ 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"]},
"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. The gateway does not
for a model, 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. The gateway does not
yet route by another name, so ask a gateway for a model by its name in
`models`.

### Where Android models come from

Simlock reads Android device models from two places and writes to neither:

- **Built-in profiles** ship with the Android SDK's `cmdline-tools`: the
ones `avdmanager list device` prints. A model newer than your
`cmdline-tools` is not there; update `cmdline-tools` to get it.
- **Custom profiles** are the ones you make with Android Studio's device
manager. Android Studio keeps them in `devices.xml` in your `.android`
directory. A custom profile exists only on the machine where it was made,
so in a fleet only the worker that has it can lease it. To add one, create
it with Android Studio's device manager on that machine.

When a name is in both, the built-in profile wins and the model is not
custom. If `devices.xml` cannot be read, the built-in models are still
listed. A custom model is marked `(custom)` in the human view of `simlock
catalog` and listed in `customModels` in `--json`.

## `simlock component install <ios|android> <version>`

Installs one iOS simulator runtime or Android system image, without leasing
Expand Down Expand Up @@ -1370,7 +1396,9 @@ operation **on a gateway**; against a worker they answer `UNKNOWN_REQUEST`
versions. Under each worker, one indented line per component install
waiting or running there, in the form `simlock status` prints. A worker the gateway cannot speak to shows `incompatible` with both
protocol ranges, which is what version skew looks like from here. `--json`
prints the raw worker views, which is what the console renders.
prints the raw worker views, which is what the console renders. Each
view's catalog carries that worker's own `customModels`, so this is where
you see which worker has a custom Android profile.
- `drain <worker-id>` / `undrain <worker-id>` — a drained worker keeps its
existing leases and receives no new dispatches: the way to take a machine
out of service without killing anyone's device. The flag is persisted by the
Expand Down
9 changes: 8 additions & 1 deletion docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ const { platforms } = await client.getCatalog({ platform: "ios" });
- `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.
- `customModels` lists the models that exist because of something on that
machine rather than the platform's tools: on Android, a profile made with
Android Studio's device manager and read from `devices.xml`. A built-in
profile with the same name wins, and that model is not custom. The field
is absent when there are none, and iOS never has it.
- `defaultRuntime` is the newest installed runtime, and is absent when none
is installed.
- The catalog lists only what is installed. It never lists a runtime the
Expand All @@ -219,7 +224,9 @@ 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 may be asked for by any name a worker lists for it, in
worker's own. 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.
`allowDownload` has no effect through a gateway: only installed runtimes
count.
Expand Down
13 changes: 12 additions & 1 deletion docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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.

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
from `devices.xml`; when a built-in profile has the same name, the built-in
one wins and the model is not custom. The field is absent when there are
none, and iOS never has it. On a gateway a model is listed when any worker
that lists it marks it custom; each worker's own list is in its catalog in
[`GET /v1/workers`](#worker-routes).

```json
{ "platforms": [ {
"platform": "ios",
Expand All @@ -255,6 +264,7 @@ it.
"defaultRuntime": "35",
"modelRuntimes": { "My Tablet": ["34", "35"], "Pixel 8": ["34", "35"] },
"modelAliases": { "Pixel 8": ["pixel_8"] },
"customModels": ["My Tablet"],
"images": [ { "runtime": "34", "tag": "default", "abi": "x86_64" },
{ "runtime": "35", "tag": "google_apis", "abi": "arm64-v8a" } ]
} ] }
Expand Down Expand Up @@ -827,7 +837,8 @@ none.

`catalog` is what that worker can lease, each model with the runtimes it
pairs with, and lists a newly installed component as soon as its install
ends. `host` is the worker's machine, the same block its own
ends. Its `customModels` are that worker's own, so this is where you see
which worker has a custom Android profile. `host` is the worker's machine, the same block its own
`GET /v1/status` reports, as of the gateway's last refresh: a tool installed
or upgraded on the worker shows here without a restart of either side.

Expand Down
9 changes: 7 additions & 2 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ 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,
and ABI, absent when no worker reports the field. Each worker's lists are
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
within the contract's bounds but their union may not be, so the gateway
cuts the sorted union to those bounds rather than answer with a catalog its
own clients would refuse. Routing still reads only
Expand All @@ -741,7 +743,10 @@ resolves. The same holds for names: the Android driver's
`DeviceProfileRegistry` owns the only matcher (first profile, in source
order, any of whose names equals the request ignoring case), and the
catalog's `modelAliases` are a profile's other names that the matcher sends
back to that profile. The iOS driver matches a device type's name only.
back to that profile. A listed model is in `customModels` when the profile
the matcher sends its name to is a `devices.xml` one, so the mark and the
resolution cannot disagree. The iOS driver matches a device type's name
only.

Worker business events are republished on the gateway's bus with `workerId`
added to the payload and land in the gateway's own ring buffer and event
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 @@ -395,6 +395,7 @@ export class OutOfProcessFakeDriver implements Driver {
return {
defaultRuntime: newestVersion(runtimes),
...(script.images === undefined ? {} : { images: [...script.images] }),
...(script.customModels === undefined ? {} : { customModels: [...script.customModels] }),
modelAliases: { ...script.modelAliases },
modelRuntimes: Object.fromEntries(
models.map((model) => [model, [...(script.modelRuntimes?.[model] ?? runtimes)]]),
Expand Down
2 changes: 2 additions & 0 deletions e2e/fake-driver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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 custom models; the field is absent unless set. */
readonly customModels?: readonly string[];
/** What `listCatalog` reports as installed images; the field is absent unless set. */
readonly images?: readonly {
readonly runtime: string;
Expand Down
56 changes: 56 additions & 0 deletions e2e/gateway-fleet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface WorkerView {
readonly models: readonly string[];
readonly modelRuntimes: Readonly<Record<string, readonly string[]>>;
readonly modelAliases: Readonly<Record<string, readonly string[]>>;
readonly customModels?: readonly string[];
readonly images?: readonly {
readonly runtime: string;
readonly tag: string;
Expand Down Expand Up @@ -374,6 +375,61 @@ describe("gateway fleet", () => {
]);
});

it("shows each worker's own custom models in the worker list, and marks a model custom in the catalog when any worker does", 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}` };
// Both workers list My Tablet; only worker-a has it as a custom profile.
await withDaemon({
configOverrides: { gateway: { ...uplink, label: "worker-a" } },
driverScript: {
android: {
availableOsVersions: ["35"],
customModels: ["My Tablet"],
knownModels: ["Pixel 8", "My Tablet"],
},
},
});
await withDaemon({
configOverrides: { gateway: { ...uplink, label: "worker-b" } },
driverScript: {
android: { availableOsVersions: ["35"], knownModels: ["Pixel 8", "My Tablet"] },
},
});

const workers = await waitForWorkers(
gateway,
(views) =>
views.length === 2 &&
views.every((view) => view.connection === "connected" && view.catalog.length > 0),
"both workers connected with their catalogs",
);
const androidOf = (label: string) =>
workers
.find((view) => view.label === label)
?.catalog.find((entry) => entry.platform === "android");
expect(androidOf("worker-a")?.customModels).toEqual(["My Tablet"]);
expect(androidOf("worker-b")?.models).toEqual(["Pixel 8", "My Tablet"]);
expect(androidOf("worker-b")).not.toHaveProperty("customModels");

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?.customModels).toEqual(["My Tablet"]);

const human = await gateway.cli(["catalog"]);
expect(human.code).toBe(0);
expect(human.stdout).toContain(" My Tablet (custom): 35");
expect(human.stdout).toContain(" Pixel 8: 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
36 changes: 36 additions & 0 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,42 @@ describe("CLI: catalog", () => {
].join("\n"),
);
});

it("prints (custom) after a custom model and not after a built-in one", async () => {
const output = outputCapture();
const environment = output.environmentWith({
connectAdmin: async () =>
fakeClient({
getCatalog: () =>
Promise.resolve({
platforms: [
{
customModels: ["My Tablet"],
defaultRuntime: "35",
modelAliases: {},
modelRuntimes: { "My Tablet": ["35"], "Pixel 8": ["35"] },
models: ["My Tablet", "Pixel 8"],
platform: "android",
runtimes: ["35"],
},
],
}),
}),
});

await expect(runCli(["catalog"], environment)).resolves.toBe(0);

expect(output.stdout).toBe(
[
"Platform: android",
" Runtimes: 35 (default: 35)",
" Models:",
" My Tablet (custom): 35",
" Pixel 8: 35",
"",
].join("\n"),
);
});
});

describe("CLI: component install (ADR 0010 §6)", () => {
Expand Down
4 changes: 3 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2146,14 +2146,16 @@ function formatCatalog(response: CatalogGetOutput): string {
// Each model with the runtimes it pairs with: a model and a runtime both listed for the
// platform are not necessarily leasable together.
// A model's other names follow it on a line of their own.
// A model that exists only because of something on that machine is marked `(custom)`.
const custom = new Set(entry.customModels ?? []);
const models = entry.models.flatMap((model) => {
const paired =
(Object.hasOwn(entry.modelRuntimes, model) ? entry.modelRuntimes[model] : undefined) ??
[];
const aliases =
(Object.hasOwn(entry.modelAliases, model) ? entry.modelAliases[model] : undefined) ?? [];
return [
` ${model}: ${paired.length > 0 ? paired.join(", ") : "(no paired runtime)"}`,
` ${model}${custom.has(model) ? " (custom)" : ""}: ${paired.length > 0 ? paired.join(", ") : "(no paired runtime)"}`,
...(aliases.length > 0 ? [` Other names: ${aliases.join(", ")}`] : []),
];
});
Expand Down
4 changes: 3 additions & 1 deletion src/contract/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ describe("operation input/output round trips", () => {
]);
});

it("catalog.get bounds every string and list in modelAliases and images", () => {
it("catalog.get bounds every string and list in modelAliases, customModels and images", () => {
const base = {
platform: "android",
models: ["Pixel 8"],
Expand All @@ -541,6 +541,8 @@ describe("operation input/output round trips", () => {
],
[{ modelAliases: { "Pixel 8": names(32) } }, { modelAliases: { "Pixel 8": names(33) } }],
[{ modelAliases: aliasedModels(4096) }, { modelAliases: aliasedModels(4097) }],
[{ customModels: ["x".repeat(256)] }, { customModels: ["x".repeat(257)] }],
[{ customModels: names(4096) }, { customModels: names(4097) }],
[
{ images: [{ ...image, runtime: "x".repeat(128) }] },
{ images: [{ ...image, runtime: "x".repeat(129) }] },
Expand Down
36 changes: 36 additions & 0 deletions src/contract/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { describe, expect, it } from "vitest";
import {
deviceRecordSchema,
fitHostFacts,
fitPlatformCatalog,
grantedDeviceSchema,
hostFactsSchema,
leaseGrantSchema,
platformCatalogSchema,
statusDeviceSchema,
} from "./schemas.js";

Expand Down Expand Up @@ -269,3 +271,37 @@ describe("fitHostFacts", () => {
expect(fitHostFacts(host)).toEqual(host);
});
});

describe("fitPlatformCatalog", () => {
const entry = (customModels: string[]) => ({
customModels,
defaultRuntime: "35",
modelAliases: {},
modelRuntimes: Object.fromEntries(customModels.map((model) => [model, ["35"]])),
models: customModels,
platform: "android" as const,
runtimes: ["35"],
});

it("stops customModels at its maximum, in an entry the schema accepts", () => {
const names = Array.from({ length: 4097 }, (_, index) => `m${index}`);

const fitted = fitPlatformCatalog(entry(names));

expect(fitted.customModels).toEqual(names.slice(0, 4096));
expect(() => platformCatalogSchema.parse(fitted)).not.toThrow();
});

it("leaves out customModels when no name fits", () => {
const fitted = fitPlatformCatalog(entry(["x".repeat(257)]));

expect(fitted).not.toHaveProperty("customModels");
expect(fitted.models).toEqual(["x".repeat(257)]);
});

it("leaves an entry that already fits as it is", () => {
const fits = entry(["My Tablet"]);

expect(fitPlatformCatalog(fits)).toEqual(fits);
});
});
Loading
Loading