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
7 changes: 3 additions & 4 deletions e2e/component-install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { describe, expect, it } from "vitest";
import {
type CliResult,
events,
freeLoopbackPort,
type TestEnv,
waitFor,
withDaemon,
withHttpDaemon,
} from "./helpers/index.js";

const MISSING = ["lease", "--platform", "ios", "--device", "iPhone 16", "--os", "19.0"] as const;
Expand Down Expand Up @@ -263,10 +263,9 @@ interface HttpDaemon {
}

async function httpDaemon(): Promise<HttpDaemon> {
const port = await freeLoopbackPort();
const env = await withDaemon({
const { env, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { enabled: true, host: "127.0.0.1", port } },
});
}));
const baseUrl = `http://127.0.0.1:${port}`;
await waitFor(
async () => {
Expand Down
12 changes: 5 additions & 7 deletions e2e/console-serving.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, withDaemon, type TestEnv } from "./helpers/index.js";
import { type TestEnv, waitFor, withDaemon, withHttpDaemon } from "./helpers/index.js";

/**
* The daemon serves the built web console at `/` whenever HTTP is enabled, at the address
Expand Down Expand Up @@ -33,10 +33,9 @@ async function fetchWhenListening(url: string): Promise<Response> {

describe("the web console", () => {
it("GET / answers the console page when HTTP is enabled", async () => {
const port = await freeLoopbackPort();
const worker = await withDaemon({
const { env: worker, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { enabled: true, host: "127.0.0.1", port } },
});
}));

const url = await consoleUrl(worker);
expect(url).toBe(`http://127.0.0.1:${port}/`);
Expand All @@ -58,11 +57,10 @@ describe("the web console", () => {
});

it("a gateway serves the console page at the address simlock status prints", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { enabled: true, host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));

const url = await consoleUrl(gateway);
expect(url).toBe(`http://127.0.0.1:${port}/`);
Expand Down
7 changes: 3 additions & 4 deletions e2e/contract-surface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
import { OPERATIONS, type OperationName } from "../src/contract/index.js";
import { NodeIpcTransport } from "../src/ports/index.js";
import { SimlockWire, WireCallError } from "../src/simlock-client/wire.js";
import { freeLoopbackPort, withDaemon } from "./helpers/index.js";
import { withDaemon, withHttpDaemon } from "./helpers/index.js";
import type { TestEnv } from "./helpers/env.js";

/**
Expand Down Expand Up @@ -106,11 +106,10 @@ describe("contract surface", () => {
// its input before deciding anything, so even the ones a gateway answers
// `UNSUPPORTED_IN_GATEWAY_MODE` reject an unparseable payload with `BAD_REQUEST` first.
// Anything that came back `UNKNOWN_REQUEST` here would be an operation a gateway forgot.
const port = await freeLoopbackPort();
const env = await withDaemon({
const { env } = await withHttpDaemon((port) => ({
configOverrides: { http: { host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));
expect((await env.startDaemon()).code).toBe(0);

expect(await sweep(env)).toEqual(
Expand Down
12 changes: 5 additions & 7 deletions e2e/gateway-component-install.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, withDaemon, type TestEnv } from "./helpers/index.js";
import { type TestEnv, waitFor, withDaemon, withHttpDaemon } from "./helpers/index.js";

interface WorkerView {
readonly id: string;
Expand Down Expand Up @@ -44,11 +44,10 @@ async function androidRuntimeWorkers(gateway: TestEnv, runtime: string): Promise

describe("simlock component install through a gateway", () => {
it("asks every worker, shows the install in worker list while it runs, reports each by id, refuses on the worker set to never, the gateway's catalog lists the component for the one that installed it, and an agent token gets 403 over HTTP", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { enabled: true, host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));
const minted = await gateway.cli(["token", "create", "--role", "worker"]);
expect(minted.code, minted.stderr).toBe(0);
const { secret } = minted.json as { secret: string };
Expand Down Expand Up @@ -150,11 +149,10 @@ describe("simlock component install through a gateway", () => {
});

it("refuses component install with no worker flag on a gateway with exit 2, telling the operator to name workers", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway } = await withHttpDaemon((port) => ({
configOverrides: { http: { host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));

const result = await gateway.cli(["component", "install", "ios", "26.4"]);

Expand Down
7 changes: 3 additions & 4 deletions e2e/gateway-event-relay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { join } from "node:path";

import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, withDaemon } from "./helpers/index.js";
import { waitFor, withDaemon, withHttpDaemon } from "./helpers/index.js";
import type { RecordedEvent } from "./helpers/events.js";

/**
Expand All @@ -15,11 +15,10 @@ import type { RecordedEvent } from "./helpers/events.js";
*/

async function gatewayWithWorker() {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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 worker = await withDaemon({
Expand Down
7 changes: 3 additions & 4 deletions e2e/gateway-fast-fail.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, withDaemon } from "./helpers/index.js";
import { waitFor, withDaemon, withHttpDaemon } from "./helpers/index.js";
import type { CliResult, TestEnv } from "./helpers/index.js";
import type { FakeDriverScript } from "./fake-driver/types.js";

Expand All @@ -26,12 +26,11 @@ interface WorkerView {
}

async function startGateway() {
const port = await freeLoopbackPort();
// `driver: "none"`: a gateway starts no drivers (ADR 0005 §2).
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { enabled: true, host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));
const minted = await gateway.cli(["token", "create", "--role", "worker"]);
expect(minted.code, minted.stderr).toBe(0);
const { secret } = minted.json as { secret: string };
Expand Down
47 changes: 19 additions & 28 deletions e2e/gateway-fleet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, waitForDeviceState, withDaemon } from "./helpers/index.js";
import { waitFor, waitForDeviceState, withDaemon, withHttpDaemon } from "./helpers/index.js";
import type { TestEnv } from "./helpers/env.js";

/**
Expand Down Expand Up @@ -132,13 +132,12 @@ function expectSameView(

describe("gateway fleet", () => {
it("two workers join, status aggregates them, a kill disconnects one, drain flags the other", async () => {
const port = await freeLoopbackPort();
// `driver: "none"`: a gateway starts no drivers and warns about every worker-only key in
// its config (ADR 0005 §2), so it gets no fake-driver wiring and no capacity seeding.
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));

// 1. The gateway mints a join token. `--role worker` is what makes it a join token and
// nothing else: it opens an uplink and no `/v1` route.
Expand Down Expand Up @@ -280,11 +279,10 @@ describe("gateway fleet", () => {
});

it("shows each worker's own pairings, other names, and images in the worker list and their union in the catalog", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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}` };
Expand Down Expand Up @@ -397,11 +395,10 @@ 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({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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}` };
Expand Down Expand Up @@ -452,11 +449,10 @@ describe("gateway fleet", () => {
});

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({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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}` };
Expand Down Expand Up @@ -529,11 +525,10 @@ describe("gateway fleet", () => {
});

it("grants --device 'iphone 16 pro' and --device pixel_7 through a gateway by the worker's own names", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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 };
// The fake driver resolves model names exactly, so a grant proves the gateway sent the
Expand Down Expand Up @@ -577,11 +572,10 @@ describe("gateway fleet", () => {
});

it("grants an Android --class phone request on the worker holding a warm Pixel, not on one with free capacity", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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 pixels = {
Expand Down Expand Up @@ -654,11 +648,10 @@ describe("gateway fleet", () => {
});

it("grants --class phone with --os '>=18' through a gateway on a worker whose runtime is in the range, and nothing else", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
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 join = (label: string, osVersion: string) =>
Expand Down Expand Up @@ -702,11 +695,10 @@ describe("gateway fleet", () => {
});

it("refuses an uplink whose token is not a worker join token", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));
// An operator token is a real credential that opens no uplink (ADR 0005 §25). The worker
// keeps retrying at its backoff cap rather than giving up, so what this asserts is the
// gateway's side: it never becomes a worker.
Expand Down Expand Up @@ -736,11 +728,10 @@ describe("gateway fleet", () => {
});

it("through a gateway, a caller-chosen lease ID comes back with no worker prefix, renews and releases by that ID, and a second request for it is LEASE_ID_TAKEN", async () => {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: { http: { host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));
const { secret } = (await gateway.cli(["token", "create", "--role", "worker"])).json as {
secret: string;
};
Expand Down
7 changes: 3 additions & 4 deletions e2e/gateway-lease-limit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";

import type { FakeDriverScript } from "./fake-driver/types.js";
import { freeLoopbackPort, waitFor, withDaemon } from "./helpers/index.js";
import { waitFor, withDaemon, withHttpDaemon } from "./helpers/index.js";
import type { CliResult, TestEnv } from "./helpers/index.js";

const FAST = { timeout: 20_000 };
Expand All @@ -11,15 +11,14 @@ const IPHONE_16: FakeDriverScript = {
const TWO_DEVICES = { limits: { maxRunning: 2, ios: { maxDevices: 2, maxRunning: 2 } } };

async function startGateway(maxPerRequester: number) {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
configOverrides: {
http: { enabled: true, host: "127.0.0.1", port },
lease: { maxPerRequester },
mode: "gateway",
},
driver: "none",
});
}));
const minted = await gateway.cli(["token", "create", "--role", "worker"]);
expect(minted.code, minted.stderr).toBe(0);
const { secret } = minted.json as { secret: string };
Expand Down
11 changes: 5 additions & 6 deletions e2e/gateway-physical-routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { describe, expect, it } from "vitest";
import type { CliBackgroundHandle } from "./helpers/cli.js";
import type { FakeDriverPlatformScript, ScriptedPhysicalDevice } from "./fake-driver/types.js";
import {
freeLoopbackPort,
type CliResult,
type TestEnv,
waitFor,
waitForDeviceState,
withDaemon,
type CliResult,
type TestEnv,
withHttpDaemon,
} from "./helpers/index.js";

const FAST = { timeout: 20_000 };
Expand Down Expand Up @@ -70,12 +70,11 @@ interface Fleet {
}

async function startFleet(specs: readonly WorkerSpec[]): Promise<Fleet> {
const port = await freeLoopbackPort();
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
agentId: "fleet-agent",
configOverrides: { http: { enabled: true, host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));
const minted = await gateway.cli(["token", "create", "--role", "worker"]);
expect(minted.code, minted.stderr).toBe(0);
const { secret } = minted.json as { secret: string };
Expand Down
7 changes: 3 additions & 4 deletions e2e/gateway-smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { freeLoopbackPort, waitFor, withDaemon, type TestEnv } from "./helpers/index.js";
import { type TestEnv, waitFor, withDaemon, withHttpDaemon } from "./helpers/index.js";

/**
* ADR 0005's happy path, over real transports: a real gateway process, real worker processes
Expand Down Expand Up @@ -59,14 +59,13 @@ interface Fleet {
* these tests are about.
*/
async function startFleet(specs: readonly WorkerSpec[], agentId: string): Promise<Fleet> {
const port = await freeLoopbackPort();
// `driver: "none"`: a gateway starts no drivers and warns about every worker-only key in its
// config (ADR 0005 §2), so it gets no fake-driver wiring and no capacity seeding.
const gateway = await withDaemon({
const { env: gateway, port } = await withHttpDaemon((port) => ({
agentId,
configOverrides: { http: { enabled: true, host: "127.0.0.1", port }, mode: "gateway" },
driver: "none",
});
}));

const minted = await gateway.cli(["token", "create", "--role", "worker"]);
expect(minted.code).toBe(0);
Expand Down
Loading
Loading