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
17 changes: 2 additions & 15 deletions e2e/event-history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ describe("event history", () => {
expect(stopped.code).toBe(0);
expect(grantOf(parseLines(stopped.stdout), leaseId)).toEqual(before);
expect(existsSync(env.socketPath)).toBe(false);
const status = await env.cli(["daemon", "status", "--json"]);
expect(status.json).toEqual({ status: "stopped" });
});

it("simlock events --since 1h after a daemon restart prints each event with the id it had before the restart", async () => {
Expand Down Expand Up @@ -141,21 +143,6 @@ describe("event history", () => {
expect(history.find((entry) => entry.event === "queue.changed")?.payload).toEqual({ depth: 0 });
});

it("prints the history with the daemon stopped, and the daemon stays stopped", async () => {
const env = await withDaemon();
await prepare(env);
const leaseId = await leaseDevice(env);
await stopDaemon(env);

const history = await env.cli(["events", "--since", "1h"]);

expect(history.code).toBe(0);
expect(grantOf(parseLines(history.stdout), leaseId)).toBeDefined();
expect(existsSync(env.socketPath)).toBe(false);
const status = await env.cli(["daemon", "status", "--json"]);
expect(status.json).toEqual({ status: "stopped" });
});

it("writes history.db and no events.jsonl in a fresh data directory, and leaves an events.jsonl placed there before the start byte-identical", async () => {
const fresh = await withDaemon();
const placed = await withDaemon({ mode: "auto" });
Expand Down
30 changes: 0 additions & 30 deletions e2e/fake-driver/device-data.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions e2e/physical-enrollment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,6 @@ describe("simlock device remove", () => {
}
});

it("from a non-interactive shell, with no --yes, unenrols the device", async () => {
const env = await startDaemon({ ios: { physicalDevices: [IPHONE] } });
const enrolled = await add(env, "ios", UDID);

const result = await env.cli(["device", "remove", UDID]);

expect(result.code, result.stderr).toBe(0);
expect((await rows(env)).find((row) => row.id === enrolled.id)?.state).toBe("deleted");
});

it("then device add writes a new record with a new registry ID and reenrolled false, and the old record stays deleted", async () => {
const env = await startDaemon({ ios: { physicalDevices: [IPHONE] } });
const first = await add(env, "ios", UDID);
Expand Down
143 changes: 64 additions & 79 deletions e2e/physical-leasing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,50 +257,70 @@ describe("a physical lease request: grant", () => {
expect(grant.device.spec).toMatchObject({ model: "iPhone 15 Pro", osVersion: "18.4" });
});

it('--os 18 with only an iPhone on 18.4.1 enrolled exits with UNKNOWN_MODEL at once, and its message names --os ">=18 <19"', async () => {
const env = await startWith({ ios: [IPHONE_1841] });
const accepted = await granted(env, physical("agent-range", "--os", ">=18 <19"));
expect(accepted.device.driverDeviceId).toBe(UDID_1841);
await release(env, accepted);

const refused = await env.cli(physical("agent-exact", "--os", "18", "--detach"), {
timeout: 15_000,
});

expect(refused.code, refused.stderr).toBe(12);
expect(refused.error?.code).toBe("UNKNOWN_MODEL");
expect(refused.error?.message).toContain('--os ">=18 <19"');
});

it('--os 18.4 with only an iPhone on 18.4.1 enrolled exits with UNKNOWN_MODEL at once, and its message names --os ">=18.4 <18.5"', async () => {
const env = await startWith({ ios: [IPHONE_1841] });
const accepted = await granted(env, physical("agent-range", "--os", ">=18.4 <18.5"));
expect(accepted.device.driverDeviceId).toBe(UDID_1841);
await release(env, accepted);

const refused = await env.cli(physical("agent-exact", "--os", "18.4", "--detach"), {
timeout: 15_000,
});

expect(refused.code, refused.stderr).toBe(12);
expect(refused.error?.code).toBe("UNKNOWN_MODEL");
expect(refused.error?.message).toContain('--os ">=18.4 <18.5"');
});

it("--os 18.4.1 with only an iPhone on 18.4 enrolled exits with UNKNOWN_MODEL at once, and its message names no range", async () => {
const env = await startWith({ ios: [IPHONE_A] });
const accepted = await granted(env, physical("agent-exact", "--os", "18.4"));
expect(accepted.device.driverDeviceId).toBe(UDID_A);
await release(env, accepted);

const refused = await env.cli(physical("agent-newer", "--os", "18.4.1", "--detach"), {
timeout: 15_000,
});

expect(refused.code, refused.stderr).toBe(12);
expect(refused.error?.code).toBe("UNKNOWN_MODEL");
expect(refused.error?.message).not.toMatch(/>=|<\d/);
});
it.each([
{
platform: "ios",
enrolled: { ios: [IPHONE_1841] },
driverDeviceId: UDID_1841,
accepted: ">=18 <19",
refused: "18",
range: ">=18 <19",
},
{
platform: "ios",
enrolled: { ios: [IPHONE_1841] },
driverDeviceId: UDID_1841,
accepted: ">=18.4 <18.5",
refused: "18.4",
range: ">=18.4 <18.5",
},
{
platform: "ios",
enrolled: { ios: [IPHONE_A] },
driverDeviceId: UDID_A,
accepted: "18.4",
refused: "18.4.1",
range: undefined,
},
{
platform: "android",
enrolled: { android: [PIXEL] },
driverDeviceId: SERIAL,
accepted: "34",
refused: "33",
range: undefined,
},
])(
"--os $refused on the only enrolled $platform device, which accepts --os $accepted, exits with UNKNOWN_MODEL at once, and its message names the --os range only for a partial iOS version",
async ({ platform, enrolled, driverDeviceId, accepted, refused, range }) => {
const env = await startWith(enrolled);
const leaseArgs = (agent: string, os: string): string[] => [
"lease",
"--platform",
platform,
"--physical",
"--os",
os,
"--agent-id",
agent,
];
const first = await granted(env, leaseArgs("agent-accepted", accepted));
expect(first.device.driverDeviceId).toBe(driverDeviceId);
await release(env, first);

const result = await env.cli([...leaseArgs("agent-refused", refused), "--detach"], {
timeout: 15_000,
});

expect(result.code, result.stderr).toBe(12);
expect(result.error?.code).toBe("UNKNOWN_MODEL");
if (range === undefined) {
expect(result.error?.message).not.toMatch(/>=|<\d/);
} else {
expect(result.error?.message).toContain(`--os "${range}"`);
}
},
);

it("--platform android --physical --os 34 is granted the phone on API 34", async () => {
const env = await startWith({ android: [PIXEL] });
Expand All @@ -321,41 +341,6 @@ describe("a physical lease request: grant", () => {
expect(grant.device.spec.osVersion).toBe("34");
});

it("--platform android --physical --os 33 with only a phone on API 34 enrolled exits with UNKNOWN_MODEL at once, and its message names no range", async () => {
const env = await startWith({ android: [PIXEL] });
const accepted = await granted(env, [
"lease",
"--platform",
"android",
"--physical",
"--os",
"34",
"--agent-id",
"agent-exact",
]);
expect(accepted.device.driverDeviceId).toBe(SERIAL);
await release(env, accepted);

const refused = await env.cli(
[
"lease",
"--platform",
"android",
"--physical",
"--os",
"33",
"--agent-id",
"agent-older",
"--detach",
],
{ timeout: 15_000 },
);

expect(refused.code, refused.stderr).toBe(12);
expect(refused.error?.code).toBe("UNKNOWN_MODEL");
expect(refused.error?.message).not.toMatch(/>=|<\d/);
});

it("the grant's environment is the fake driver's answer for that device: SIMLOCK_DEVICE_UDID on iOS, ANDROID_SERIAL and ANDROID_ADB_SERVER_PORT=5037 on Android", async () => {
const env = await startWith({ android: [PIXEL], ios: [IPHONE_A] });

Expand Down
2 changes: 1 addition & 1 deletion e2e/physical-presence-loss-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("a physical reclaim that fails while the device is gone makes it absent

expect(row?.state).toBe("quarantined");
expect(await payloadsOf(env, "device.purge-failed")).toContainEqual(
expect.objectContaining({ deviceId: LEASED.id }),
expect.objectContaining({ attemptedStrategy: "uninstall", deviceId: LEASED.id }),
);
expect(await payloadsOf(env, "device.quarantined")).toContainEqual(
expect.objectContaining({ deviceId: LEASED.id }),
Expand Down
17 changes: 0 additions & 17 deletions e2e/physical-reclaim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,6 @@ describe("a released physical device is reclaimed by uninstalling the apps enrol
});

describe("a physical reclaim that fails quarantines the device", () => {
const SLOW_RETRY = { warmPool: { quarantine: { retryBackoffMs: 60_000 } } };

it("a failed reclaim emits device.purge-failed with uninstall and leaves the device quarantined in simlock status", async () => {
const env = await startWith(LEASED, {
config: SLOW_RETRY,
leases: [HELD_LEASE(600_000)],
script: { failReclaim: true, installed: [...ENROLLED, ...AGENT_APPS] },
});

const released = await env.cli(["release", "lse_pheld"]);
expect(released.code, released.stderr).toBe(0);

const failed = await waitForEvent(env, "device.purge-failed");
expect(failed).toMatchObject({ attemptedStrategy: "uninstall", deviceId: LEASED.id });
await waitForState(env, LEASED.id, "quarantined");
});

it("a quarantine retry that succeeds makes the device ready with device.quarantine-recovered strategy uninstall and missingApps", async () => {
const env = await startWith(LEASED, {
config: { warmPool: { quarantine: { retryBackoffMs: 1_500 } } },
Expand Down
19 changes: 0 additions & 19 deletions e2e/slow-agent-device-gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,6 @@ function defineSuite(target: Target): void {
},
);

it(
"through the gateway, a screenshot saved as an artifact downloads to the agent's machine as a PNG",
{ timeout: 600_000 },
async () => {
const a = await agent("a");
ok(await open(a));
ok(await a.run(["install", "Appduct", target.app]));
ok(await a.run(["open", target.bundleId]));
const dir = await mkdtemp(join(tmpdir(), "simlock-ad-gw-artifact-"));
onTestFinished(() => rm(dir, { force: true, recursive: true }));
const png = join(dir, "artifact.png");
await expect(readFile(png)).rejects.toThrow();
ok(await a.run(["screenshot", png], FIRST_SNAPSHOT));
const bytes = await readFile(png);
expect(bytes.length).toBeGreaterThan(8);
expect(bytes.subarray(0, 8).toString("hex")).toBe("89504e470d0a1a0a");
},
);

it(
"with capabilities.agent-device.enabled unset on the gateway, its /v1/agent-device/health answers 404 where it answered something else while enabled",
{ timeout: 600_000 },
Expand Down
43 changes: 1 addition & 42 deletions e2e/slow-ios-physical.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execFile, spawn } from "node:child_process";
import { existsSync } from "node:fs";
import { access, mkdtemp, readFile, writeFile } from "node:fs/promises";
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
Expand Down Expand Up @@ -202,10 +202,6 @@ async function exitCodeOf(response: Response): Promise<{ code: number; body: str
return { body, code: (JSON.parse(data) as { exitCode: number }).exitCode };
}

async function errorCodeOf(response: Response): Promise<string> {
return ((await response.json()) as { error: { code: string } }).error.code;
}

describe.skipIf(process.platform !== "darwin" || missing !== undefined)(
missing === undefined
? "iOS physical phone (real devicectl)"
Expand Down Expand Up @@ -318,29 +314,6 @@ describe.skipIf(process.platform !== "darwin" || missing !== undefined)(
},
);

it(
"device.exec devicectl --json-output <path> list devices is refused and no file appears at <path>",
{ timeout: 5 * MINUTE },
async () => {
const daemon = await rig();
await enroll(daemon.env, udid);
const grant = await leasePhysical(daemon.env, "phone-lane-refuse");
const target = join(await mkdtemp(join(tmpdir(), "simlock-physical-")), "refused.json");

const refused = await exec(daemon, grant.lease.id, "phone-lane-refuse", [
"--json-output",
target,
"list",
"devices",
]);

expect(refused.status).toBe(422);
expect(await errorCodeOf(refused)).toBe("PASSTHROUGH_REFUSED");
await expect(access(target)).rejects.toMatchObject({ code: "ENOENT" });
await daemon.env.cli(["release", grant.lease.id]);
},
);

it(
"device.exec devicectl device process launch <bundle> -- -AppleLanguages (en) of the test app exits 0",
{ timeout: 10 * MINUTE },
Expand Down Expand Up @@ -378,20 +351,6 @@ describe.skipIf(process.platform !== "darwin" || missing !== undefined)(
},
);

it(
"the grant's environment carries SIMLOCK_DEVICE_UDID equal to the phone's UDID",
{ timeout: 5 * MINUTE },
async () => {
const { env } = await rig();
await enroll(env, udid);

const grant = await leasePhysical(env, "phone-lane-env");

expect(grant.environment["SIMLOCK_DEVICE_UDID"]).toBe(udid);
await env.cli(["release", grant.lease.id]);
},
);

it("ends with device remove, and removes the test app", { timeout: 5 * MINUTE }, async () => {
const bundle = await bundleIdOf(app);
const { env } = await rig();
Expand Down
Loading
Loading