Skip to content

Commit d18352e

Browse files
feat(web): set up EAS Simulator hosts in Settings (#21846)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent aee25ac commit d18352e

13 files changed

Lines changed: 639 additions & 3 deletions

File tree

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const RPC_REQUIRED_SCOPES = {
195195
[WS_METHODS.subscribeDiscoveredLocalServers]: AuthOrchestrationReadScope,
196196
[WS_METHODS.deviceConfigure]: AuthSettingsWriteScope,
197197
[WS_METHODS.deviceTestHost]: AuthSettingsWriteScope,
198+
[WS_METHODS.deviceEasAccount]: AuthSettingsWriteScope,
198199
[WS_METHODS.deviceList]: AuthOrchestrationReadScope,
199200
[WS_METHODS.deviceOpen]: AuthOrchestrationOperateScope,
200201
[WS_METHODS.deviceClose]: AuthOrchestrationOperateScope,

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
type DeviceSession,
1818
type DeviceShutdownInput,
1919
type DeviceSummary,
20+
type DeviceEasAccount,
21+
DeviceEasAccountError,
22+
type DeviceEasAccountInput,
2023
type DeviceHostConfig,
2124
type EasDeviceHostConfig,
2225
type SshDeviceHostConfig,
@@ -46,6 +49,7 @@ import * as Scope from "effect/Scope";
4649
import * as Semaphore from "effect/Semaphore";
4750
import * as Stream from "effect/Stream";
4851
import * as SynchronizedRef from "effect/SynchronizedRef";
52+
import * as HttpClient from "effect/http/HttpClient";
4953

5054
import * as ServerSettings from "../serverSettings.ts";
5155
import { isLocalSshDeviceHost, remoteSshDeviceHosts } from "./localSshDeviceHost.ts";
@@ -55,6 +59,7 @@ import * as ProcessRunner from "../processRunner.ts";
5559
import * as DeviceHost from "./DeviceHost.ts";
5660
import * as SshDeviceHost from "./SshDeviceHost.ts";
5761
import * as EasDeviceHost from "./EasDeviceHost.ts";
62+
import { makeExpoApi, resolveExpoCredential } from "./ExpoApi.ts";
5863
import * as Exit from "effect/Exit";
5964
import * as LocalDeviceHost from "./LocalDeviceHost.ts";
6065

@@ -103,6 +108,10 @@ export class DeviceService extends Context.Service<
103108
readonly testHost: (
104109
config: SshDeviceHostConfig,
105110
) => Effect.Effect<DeviceHostSummary, DeviceError>;
111+
/** Who an Expo credential signs in as and which EAS projects it can run sessions under. */
112+
readonly easAccount: (
113+
input: DeviceEasAccountInput,
114+
) => Effect.Effect<DeviceEasAccount, DeviceEasAccountError>;
106115
/**
107116
* The agent-device flags that reach the device: its config and session,
108117
* and the id agent-device selects it by, which can differ from its id here.
@@ -199,6 +208,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
199208
supportsHostRetry: true,
200209
supportsToolUpdate: installTool !== undefined,
201210
supportsToolInspection: true,
211+
supportsEasHosts: true,
202212
hosts: initialHosts,
203213
hostStatus: initialSettings.enabled ? "idle" : "disabled",
204214
hostStatuses: {},
@@ -810,6 +820,12 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
810820
),
811821
retryHost,
812822
inspect,
823+
easAccount: () =>
824+
Effect.fail(
825+
new DeviceEasAccountError({
826+
reason: "EAS accounts are unavailable in this device service.",
827+
}),
828+
),
813829
agentCli: Effect.fail(
814830
new DeviceHostUnavailableError({
815831
hostId: LOCAL_DEVICE_HOST_ID,
@@ -1083,8 +1099,38 @@ export const make = Effect.gen(function* () {
10831099
concurrency: 4,
10841100
}),
10851101
);
1102+
const easAccount: DeviceService["Service"]["easAccount"] = Effect.fn("DeviceService.easAccount")(
1103+
function* (input) {
1104+
const saved =
1105+
input.hostId === undefined
1106+
? ""
1107+
: ((yield* settings.getSettings).easDeviceHosts.find((host) => host.id === input.hostId)
1108+
?.accessToken ?? "");
1109+
const credential = yield* resolveExpoCredential(input.accessToken ?? saved);
1110+
const viewer = yield* makeExpoApi(yield* HttpClient.HttpClient, credential).viewer;
1111+
return { signedInAs: viewer.name, credentialSource: credential.source, apps: viewer.apps };
1112+
},
1113+
Effect.provide(easContext),
1114+
// Only bounded text reaches the browser: the credential errors' own
1115+
// guidance, or a category for what Expo answered, never Expo's text.
1116+
Effect.mapError(
1117+
(cause) =>
1118+
new DeviceEasAccountError({
1119+
reason:
1120+
cause._tag === "ExpoApiError"
1121+
? cause.status === 401 || cause.status === 403
1122+
? `Expo rejected the credential (HTTP ${cause.status}).`
1123+
: cause.rejected
1124+
? "Expo refused the account check."
1125+
: "Could not complete the Expo account check."
1126+
: cause.message,
1127+
}),
1128+
),
1129+
);
1130+
10861131
return {
10871132
...service,
1133+
easAccount,
10881134
agentCli: resolveNodeExecutable("Device automation").pipe(
10891135
Effect.andThen(ensureAgentDevice(config.baseDir)),
10901136
Effect.provideService(FileSystem.FileSystem, fs),

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const RPC_AGGREGATES = {
199199
[WS_METHODS.subscribeDiscoveredLocalServers]: "preview",
200200
[WS_METHODS.deviceConfigure]: "device",
201201
[WS_METHODS.deviceTestHost]: "device",
202+
[WS_METHODS.deviceEasAccount]: "device",
202203
[WS_METHODS.deviceList]: "device",
203204
[WS_METHODS.deviceOpen]: "device",
204205
[WS_METHODS.deviceClose]: "device",

‎apps/server/src/ws.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,7 @@ export const layerWsRpc = (
29042904
[WS_METHODS.subscribePreviewEvents]: (_input) => previewManager.events,
29052905
[WS_METHODS.deviceConfigure]: (input) => deviceService.configure(input),
29062906
[WS_METHODS.deviceTestHost]: (input) => deviceService.testHost(input),
2907+
[WS_METHODS.deviceEasAccount]: (input) => deviceService.easAccount(input),
29072908
[WS_METHODS.deviceList]: (input) =>
29082909
input.inspectOnly && !input.updateTool
29092910
? deviceService.inspect

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,48 @@ describe("device setup guidance", () => {
6363
expect(platformSetupStatus(state, "android").message).toBe("Android Emulator is missing.");
6464
});
6565

66+
it("names an EAS host instead of local tooling when only the cloud can run iOS", () => {
67+
const state = deviceState({
68+
hostStatus: "idle",
69+
hostStatuses: { eas: { status: "ready" } },
70+
hosts: [
71+
{
72+
...deviceState().hosts[0]!,
73+
platforms: [
74+
{ platform: "ios", available: false, reason: "Xcode was not found." },
75+
{ platform: "android", available: false, reason: "No SDK." },
76+
],
77+
},
78+
{
79+
id: "eas",
80+
kind: "eas",
81+
label: "EAS Simulator",
82+
hubInstalled: true,
83+
agentDeviceInstalled: true,
84+
platforms: [
85+
{ platform: "ios", available: true },
86+
{ platform: "android", available: false, reason: "Not supported yet." },
87+
],
88+
},
89+
],
90+
devices: [
91+
{
92+
hostId: "eas",
93+
id: "eas-ios",
94+
platform: "ios",
95+
name: "iPhone (EAS Simulator)",
96+
version: "Cloud",
97+
booted: false,
98+
physical: false,
99+
},
100+
],
101+
});
102+
expect(platformSetupStatus(state, "ios")).toEqual({
103+
ready: true,
104+
message: "EAS Simulator starts iOS Simulators in the cloud with EAS Simulator.",
105+
});
106+
});
107+
66108
it("counts a remote device host when this machine has no simulator tooling", () => {
67109
const state = deviceState({
68110
hostStatus: "idle",

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
117117
return {
118118
ready: true,
119119
message:
120-
platform === "ios"
121-
? `Xcode and iOS Simulator are available${location}.`
122-
: `The Android SDK and Emulator are available${location}.`,
120+
remoteHost?.kind === "eas"
121+
? `${remoteHost.label} starts iOS Simulators in the cloud with EAS Simulator.`
122+
: platform === "ios"
123+
? `Xcode and iOS Simulator are available${location}.`
124+
: `The Android SDK and Emulator are available${location}.`,
123125
};
124126
}
125127

0 commit comments

Comments
 (0)