Skip to content

Commit e067776

Browse files
author
PR Batch Tester
committed
fix(devices): keep setup guidance specific to each platform
1 parent ea82262 commit e067776

4 files changed

Lines changed: 52 additions & 29 deletions

File tree

‎apps/server/src/device/DeviceHubOperations.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { DeviceHostReady, DeviceOperations, HostDevice } from "./DeviceHost
1414

1515
const BOOT_TIMEOUT = Duration.minutes(3);
1616
const SCREENSHOT_TIMEOUT = Duration.seconds(20);
17-
// Outlasts a hub-side 30 s simctl timeout, so the hub's own explanation can arrive first.
17+
// Allow the proposed upstream 30 s simctl timeout to report its cause first.
1818
const LIST_TIMEOUT_SECONDS = 40;
1919
// simctl could not list simulators at all, so the hub's empty iOS list says nothing.
2020
const SIMULATOR_LIST_FAILED =

‎apps/server/src/device/DeviceService.test.ts‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ const discoveryFixture = Effect.fn("discoveryFixture")(function* () {
912912
? { simulators: [], emulators: [] }
913913
: {
914914
simulators: [],
915-
emulators: hubDevices.slice(1),
915+
emulators: [],
916916
errors: [
917917
{
918918
message: "[apple-utils] Failed to run `xcrun simctl list devices --json`:",
@@ -975,7 +975,7 @@ it.effect(
975975

976976
hub.mode = "simctl_failed";
977977
const failed = yield* service.list;
978-
expect(failed.devices).toEqual(listed);
978+
expect(failed.devices).toEqual(listed.filter((device) => device.platform === "ios"));
979979
expect(failed.hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({
980980
status: "ready",
981981
detail: "[apple-utils] Failed to run `xcrun simctl list devices --json`:",
@@ -988,30 +988,27 @@ it.effect(
988988
}).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true })), Effect.scoped),
989989
);
990990

991-
it.effect(
992-
"waits past the hub's own simctl timeout and keeps devices when the hub never answers",
993-
() =>
994-
Effect.gen(function* () {
995-
const { service, hub, listed } = yield* discoveryFixture();
996-
yield* service.list;
991+
it.effect("keeps devices with a warning when the hub never answers within 40 seconds", () =>
992+
Effect.gen(function* () {
993+
const { service, hub, listed } = yield* discoveryFixture();
994+
yield* service.list;
997995

998-
hub.mode = "hung";
999-
const listing = yield* service.list.pipe(Effect.forkScoped);
1000-
yield* Deferred.await(hub.requested);
1001-
yield* TestClock.adjust("40 seconds");
1002-
const timedOut = yield* Fiber.join(listing);
1003-
expect(timedOut.devices).toEqual(listed);
1004-
expect(timedOut.hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({
1005-
status: "ready",
1006-
detail:
1007-
"The device hub did not answer within 40 seconds. Devices found earlier stay listed.",
1008-
});
996+
hub.mode = "hung";
997+
const listing = yield* service.list.pipe(Effect.forkScoped);
998+
yield* Deferred.await(hub.requested);
999+
yield* TestClock.adjust("40 seconds");
1000+
const timedOut = yield* Fiber.join(listing);
1001+
expect(timedOut.devices).toEqual(listed);
1002+
expect(timedOut.hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({
1003+
status: "ready",
1004+
detail: "The device hub did not answer within 40 seconds. Devices found earlier stay listed.",
1005+
});
10091006

1010-
hub.mode = "listed";
1011-
const recovered = yield* service.list;
1012-
expect(recovered.devices).toEqual(listed);
1013-
expect(recovered.hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({ status: "ready" });
1014-
}).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true })), Effect.scoped),
1007+
hub.mode = "listed";
1008+
const recovered = yield* service.list;
1009+
expect(recovered.devices).toEqual(listed);
1010+
expect(recovered.hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({ status: "ready" });
1011+
}).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true })), Effect.scoped),
10151012
);
10161013

10171014
it.effect("retry keeps device and agent consent unchanged", () =>

‎apps/web/src/components/device/DeviceSetup.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,26 @@ describe("device setup guidance", () => {
5757
ready: false,
5858
message: "No iOS devices were listed because device discovery reported a problem.",
5959
});
60+
expect(platformSetupStatus(failed, "android").message).toContain("Device Manager");
61+
const androidFailure = deviceState({
62+
hostStatuses: {
63+
local: { status: "ready", detail: "[android-utils] Failed to run `avdmanager list avd`:" },
64+
},
65+
});
66+
expect(platformSetupStatus(androidFailure, "ios").message).toContain("Xcode Settings");
67+
expect(platformSetupStatus(androidFailure, "android").message).toContain("discovery reported");
6068
expect(platformSetupStatus(deviceState(), "ios").message).toContain("Xcode Settings");
6169
});
6270

71+
it("reports an unanswered hub for either platform", () => {
72+
const state = deviceState({
73+
hostStatusDetail:
74+
"The device hub did not answer within 40 seconds. Devices found earlier stay listed.",
75+
});
76+
expect(platformSetupStatus(state, "ios").message).toContain("discovery reported");
77+
expect(platformSetupStatus(state, "android").message).toContain("discovery reported");
78+
});
79+
6380
it("counts a remote device host when this machine has no simulator tooling", () => {
6481
const state = deviceState({
6582
hostStatus: "idle",

‎apps/web/src/components/device/DeviceSetup.tsx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,20 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
103103
(host.kind === "local" && state.hostStatus === "ready"),
104104
);
105105
if (readyHosts.length > 0 && !hasDevices) {
106+
const diagnosticPrefix = platform === "ios" ? "[apple-utils] " : "[android-utils] ";
106107
if (
107-
readyHosts.some(
108-
(host) =>
109-
state.hostStatuses[host.id]?.detail || (host.kind === "local" && state.hostStatusDetail),
110-
)
108+
readyHosts.some((host) => {
109+
const detail =
110+
state.hostStatuses[host.id]?.detail ??
111+
(host.kind === "local" ? state.hostStatusDetail : undefined);
112+
return detail
113+
?.split("\n")
114+
.some(
115+
(line) =>
116+
line.startsWith(diagnosticPrefix) ||
117+
line.startsWith("The device hub did not answer within "),
118+
);
119+
})
111120
) {
112121
return {
113122
ready: false,

0 commit comments

Comments
 (0)