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
1 change: 1 addition & 0 deletions apps/server/src/device/DeviceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface DeviceOperations {
{
readonly devices: ReadonlyArray<HostDevice>;
readonly detail: string | undefined;
readonly iosDiscoveryIncomplete?: boolean;
/** Some Android virtual devices could not be listed; the rest are. */
readonly androidDiscoveryIncomplete?: boolean;
},
Expand Down
13 changes: 8 additions & 5 deletions apps/server/src/device/DeviceHubOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type DeviceHostId,
DeviceOperationError,
type DevicePlatform,
type DevicePlatformAvailability,
} from "@t3tools/contracts";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
Expand Down Expand Up @@ -67,9 +68,7 @@ export const makeDeviceHubOperations = (options: {
readonly origin: string;
readonly http: HttpClient.HttpClient;
readonly run: DeviceHostReady["run"];
readonly iosAvailable: Effect.Effect<boolean>;
/** Whether to list AVDs, which the hub does not report until they boot. */
readonly androidAvailable: Effect.Effect<boolean>;
readonly platforms: Effect.Effect<ReadonlyArray<DevicePlatformAvailability>>;
}): DeviceOperations => {
const { hostId, origin, run } = options;
const httpClient = options.http.pipe(HttpClient.withScope);
Expand Down Expand Up @@ -127,11 +126,14 @@ export const makeDeviceHubOperations = (options: {
),
);
const details = warnings?.map((error) => error.message) ?? [];
if (yield* options.iosAvailable) {
const platforms = yield* options.platforms;
let iosDiscoveryIncomplete = false;
if (platforms.some((platform) => platform.platform === "ios" && platform.available)) {
// The hub hides simulators without usage timestamps, including every freshly created device.
const result = yield* run("xcrun", ["simctl", "list", "devices", "available", "--json"]);
const inventory = result.code === 0 ? decodeSimulators(result.stdout) : Option.none();
if (Option.isNone(inventory)) {
iosDiscoveryIncomplete = true;
details.push(
"Could not list iOS simulators (xcrun simctl list devices available --json). Discovered devices remain available.",
);
Expand All @@ -158,7 +160,7 @@ export const makeDeviceHubOperations = (options: {
}
}
let androidDiscoveryIncomplete = false;
if (yield* options.androidAvailable) {
if (platforms.some((platform) => platform.platform === "android" && platform.available)) {
const avds = yield* run("emulator", ["-list-avds"]);
// Discovered devices stay listed; the AVDs that could not be listed are a warning.
if (avds.code !== 0) {
Expand Down Expand Up @@ -186,6 +188,7 @@ export const makeDeviceHubOperations = (options: {
return {
devices,
detail: details.join("\n") || undefined,
iosDiscoveryIncomplete,
androidDiscoveryIncomplete,
};
}).pipe(Effect.withSpan("DeviceHubOperations.list"));
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/device/DeviceMultiHost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ it.effect("keeps hosts independent when serials collide and another host fails",
origin: `http://${id}`,
http,
run,
iosAvailable: Effect.succeed(false),
androidAvailable: Effect.succeed(true),
platforms: Effect.succeed([
{ platform: "ios", available: false },
{ platform: "android", available: true },
]),
}),
agentDevice: { baseUrl: `http://${id}`, token: "test", entryPath: "/agent-device" },
run,
Expand Down
Loading
Loading