Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

EasDeviceHost.test.ts

569 lines24.8 KB

1import { describe, expect, it } from "@effect/vitest";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import type { EasDeviceHostConfig } from "@t3tools/contracts";
4import * as HostProcess from "@t3tools/shared/HostProcess";
5import * as Deferred from "effect/Deferred";
6import * as Effect from "effect/Effect";
7import * as Fiber from "effect/Fiber";
8import * as Exit from "effect/Exit";
9import * as FileSystem from "effect/FileSystem";
10import * as Layer from "effect/Layer";
11import * as Path from "effect/Path";
12import * as Scope from "effect/Scope";
13import * as TestClock from "effect/testing/TestClock";
14import { HttpClient, HttpClientResponse } from "effect/http";
15​
16import * as ServerConfig from "../config.ts";
17import * as ProcessRunner from "../processRunner.ts";
18import * as EasDeviceHost from "./EasDeviceHost.ts";
19​
20const APP_ID = "d763fcb8-d37c-41ea-a773-b54a0ab4a454";
21​
22const config = (overrides: Partial<EasDeviceHostConfig> = {}): EasDeviceHostConfig => ({
23 kind: "eas",
24 id: "eas",
25 label: "EAS Simulator",
26 appId: APP_ID,
27 accessToken: "expo-token",
28 maxSessionMinutes: 25,
29 idleMinutes: 5,
30 maxConcurrentSessions: 2,
31 ...overrides,
32});
33​
34interface Gate {
35 readonly requested: Deferred.Deferred<void>;
36 readonly release: Deferred.Deferred<void>;
38const makeGate = Effect.all({
39 requested: Deferred.make<void>(),
40 release: Deferred.make<void>(),
41});
42​
43/** Expo's API and one session's preview host, recording what was asked of them. */
44const fakeExpo = (
45 options: {
46 readonly status?: () => string;
47 readonly failCreate?: boolean;
48 /** Expo answers the create with GraphQL errors: a refusal. */
49 readonly rejectCreate?: boolean;
50 readonly failStop?: () => boolean;
51 readonly failList?: () => boolean;
52 readonly active?: ReadonlyArray<{ id: string; status: string; name: string }>;
53 readonly previewGate?: Gate;
54 readonly createGate?: Gate;
55 /** Holds the first session read it answers with a gate. */
56 readonly sessionGate?: () => Gate | undefined;
57 readonly activeIncludesCreated?: boolean;
58 readonly failPreview?: boolean;
59 readonly omitCreatedFromActive?: boolean;
60 } = {},
61) => {
62 const calls: Array<{ operation: string; variables: Record<string, unknown> }> = [];
63 let created = 0;
64 let createdName = "";
65 const previews: string[] = [];
66 let previewFails = options.failPreview ?? false;
67 let createFails = options.failCreate ?? false;
68 let sessionGated = false;
69 const http = HttpClient.make((request) =>
70 Effect.gen(function* () {
71 const url = new URL(request.url);
72 if (url.origin === "https://preview.test") {
73 previews.push(`${url.pathname}${url.search}`);
74 expect(request.headers.authorization).toBe("Bearer preview-token");
75 if (options.previewGate) {
76 yield* Deferred.succeed(options.previewGate.requested, undefined);
77 yield* Deferred.await(options.previewGate.release);
78 }
79 if (previewFails) {
80 return HttpClientResponse.fromWeb(request, new Response("bad gateway", { status: 502 }));
81 }
82 if (url.pathname.endsWith("/api/screenshot")) {
83 return HttpClientResponse.fromWeb(request, new Response(Uint8Array.of(137, 80, 78, 71)));
84 }
85 return HttpClientResponse.fromWeb(
86 request,
87 Response.json(
88 url.pathname === "/vendor/serve-emu/api"
89 ? { serial: "emulator-5554" }
90 : { device: "UDID-1" },
91 ),
92 );
93 }
94 const body =
95 request.body._tag === "Uint8Array"
96 ? (JSON.parse(new TextDecoder().decode(request.body.body)) as {
97 query: string;
98 variables: Record<string, { name?: string } & Record<string, unknown>>;
99 })
100 : { query: "", variables: {} };
101 expect(request.headers.authorization).toBe("Bearer expo-token");
102 const operation = /(?:query|mutation) (\w+)/.exec(body.query)?.[1] ?? "unknown";
103 calls.push({ operation, variables: body.variables });
104 if (operation === "T3CreateEasSimulatorSession") {
105 createdName = body.variables.input?.name ?? "";
106 if (options.createGate) {
107 yield* Deferred.succeed(options.createGate.requested, undefined);
108 yield* Deferred.await(options.createGate.release);
109 }
110 if (createFails)
111 return HttpClientResponse.fromWeb(request, new Response("bad gateway", { status: 502 }));
112 if (options.rejectCreate)
113 return HttpClientResponse.fromWeb(
114 request,
115 Response.json({ errors: [{ message: "Not allowed" }] }),
116 );
117 }
118 if (operation === "T3StopEasSimulatorSession" && options.failStop?.()) {
119 return HttpClientResponse.fromWeb(request, new Response("bad gateway", { status: 502 }));
120 }
121 if (operation === "T3ActiveEasSimulatorSessions" && options.failList?.()) {
122 return HttpClientResponse.fromWeb(request, new Response("bad gateway", { status: 502 }));
123 }
124 const sessionGate =
125 operation === "T3EasSimulatorSession" ? options.sessionGate?.() : undefined;
126 if (sessionGate && !sessionGated) {
127 sessionGated = true;
128 yield* Deferred.succeed(sessionGate.requested, undefined);
129 yield* Deferred.await(sessionGate.release);
130 }
131 const data =
132 operation === "T3EasSimulatorAvailability"
133 ? {
134 app: {
135 byId: {
136 ownerAccount: {
137 name: "pingdotgg",
138 accountFeatureGates: { "device-run-sessions": true },
139 },
140 },
141 },
142 }
143 : operation === "T3CreateEasSimulatorSession"
144 ? { deviceRunSession: { createDeviceRunSession: { id: `session-${++created}` } } }
145 : operation === "T3ActiveEasSimulatorSessions"
146 ? {
147 app: {
148 byId: {
149 deviceRunSessionsPaginated: {
150 edges: [
151 ...(options.omitCreatedFromActive
152 ? []
153 : [{ node: { id: "orphan", status: "NEW", name: createdName } }]),
154 {
155 node: {
156 id: "someone-else",
157 status: "IN_PROGRESS",
158 name: "T3 Code · EAS Simulator · 000000",
159 },
160 },
161 ...(options.active ?? []).map((node) => ({ node })),
162 ...(options.activeIncludesCreated && created > 0
163 ? [
164 {
165 node: {
166 id: `session-${created}`,
167 status: "STARTING",
168 name: createdName,
169 },
170 },
171 ]
172 : []),
173 ],
174 },
175 },
176 },
177 }
178 : operation === "T3EasSimulatorSession"
179 ? {
180 deviceRunSessions: {
181 byId: {
182 id: body.variables.id,
183 status: options.status?.() ?? "IN_PROGRESS",
184 remoteConfig: {
185 __typename: "AgentDeviceRunSessionRemoteConfig",
186 agentDeviceRemoteSessionUrl: "https://agent.test",
187 agentDeviceRemoteSessionToken: "agent-token",
188 webPreviewToken: "preview-token",
189 previewApiUrl: "https://preview.test?token=preview-token",
190 },
191 },
192 },
193 }
194 : {
195 deviceRunSession: {
196 ensureDeviceRunSessionStopped: { id: body.variables.id, status: "STOPPED" },
197 },
198 };
199 return HttpClientResponse.fromWeb(request, Response.json({ data }));
200 }),
201 );
202 const named = (operation: string) => calls.filter((call) => call.operation === operation);
203 const stopped = () => named("T3StopEasSimulatorSession").map((call) => call.variables.id);
204 const allowPreview = () => {
205 previewFails = false;
206 };
207 const allowCreate = () => {
208 createFails = false;
209 };
210 return { http, named, stopped, allowPreview, allowCreate, previews };
211};
212​
213const layer = Layer.mergeAll(
214 ProcessRunner.layer,
215 ServerConfig.layerTest(process.cwd(), { prefix: "t3-eas-host-" }),
216).pipe(Layer.provideMerge(NodeServices.layer));
217​
218const makeHost = (
219 expo: ReturnType<typeof fakeExpo>,
220 hostConfig: EasDeviceHostConfig,
221 scope: Scope.Scope,
222) =>
223 EasDeviceHost.make(hostConfig).pipe(
224 Effect.provideService(HttpClient.HttpClient, expo.http),
225 Effect.provideService(Scope.Scope, scope),
226 );
227​
228describe("EAS Simulator host", () => {
229 it.effect("starts a bounded session and routes its stream and agent to that session", () =>
230 Effect.gen(function* () {
231 const expo = fakeExpo();
232 const scope = yield* Scope.make();
233 const host = yield* makeHost(expo, config(), scope);
234 const ready = yield* host.ensureReady(() => Effect.void);
235 const catalog = (yield* ready.devices.list).devices;
236 expect(catalog.map((device) => [device.id, device.booted])).toEqual([
237 ["eas-ios", false],
238 ["eas-android", false],
239 ]);
240​
241 expect(yield* ready.devices.boot(catalog[0]!)).toBe("session-1");
242 expect(expo.named("T3CreateEasSimulatorSession")[0]?.variables.input).toMatchObject({
243 appId: APP_ID,
244 platform: "IOS",
245 type: "AGENT_DEVICE",
246 maxRunTimeMinutes: 25,
247 maxIdleTimeMinutes: 5,
248 });
249 const listed = (yield* ready.devices.list).devices;
250 expect(listed.find((device) => device.id === "session-1")?.booted).toBe(true);
251 expect(yield* ready.devices.agentEndpoint!("session-1")).toEqual({
252 baseUrl: "https://agent.test",
253 token: "agent-token",
254 agentDeviceId: "UDID-1",
255 });
256​
257 const routed = yield* ready.upstream!(
258 "/vendor/serve-sim/helper/session-1/webrtc/offer",
259 new URLSearchParams("hostId=eas"),
260 );
261 expect(routed).toEqual({
262 url: "https://preview.test/helper/UDID-1/webrtc/offer?hostId=eas",
263 headers: { authorization: "Bearer preview-token" },
264 protocols: ["serve-sim.token.preview-token"],
265 });
266 expect(
267 yield* ready.upstream!(
268 "/vendor/serve-sim/helper/ws",
269 new URLSearchParams("device=session-1"),
270 ),
271 ).toMatchObject({ url: "https://preview.test/helper/ws?device=UDID-1" });
272 expect(yield* ready.upstream!("/vendor/serve-emu/ws", new URLSearchParams())).toBeNull();
273 expect(
274 yield* ready.upstream!("/vendor/serve-sim/helper/%E0/config", new URLSearchParams()),
275 ).toBeNull();
276​
277 yield* Scope.close(scope, Exit.void);
278 expect(expo.named("T3StopEasSimulatorSession").map((call) => call.variables.id)).toEqual([
279 "session-1",
280 ]);
281 }).pipe(Effect.scoped, Effect.provide(layer)),
282 );
283​
284 it.effect("runs an Android session through serve-emu beside an iOS one", () =>
285 Effect.gen(function* () {
286 const expo = fakeExpo();
287 const scope = yield* Scope.make();
288 const host = yield* makeHost(expo, config(), scope);
289 expect(yield* host.platformAvailability("android")).toEqual({
290 platform: "android",
291 available: true,
292 });
293 const ready = yield* host.ensureReady(() => Effect.void);
294 const [ios, android] = (yield* ready.devices.list).devices;
295 expect(yield* ready.devices.boot(ios!)).toBe("session-1");
296 expect(yield* ready.devices.boot(android!)).toBe("session-2");
297 expect(expo.named("T3CreateEasSimulatorSession")[1]?.variables.input).toMatchObject({
298 platform: "ANDROID",
299 });
300 const running = (yield* ready.devices.list).devices.find(
301 (device) => device.id === "session-2",
302 );
303 expect(running).toMatchObject({ platform: "android", booted: true });
304​
305 expect(yield* ready.devices.agentEndpoint!("session-2")).toMatchObject({
306 agentDeviceId: "emulator-5554",
307 });
308 expect(Array.from(yield* ready.devices.screenshot(running!))).toEqual([137, 80, 78, 71]);
309 expect(expo.previews.slice(-2)).toEqual([
310 "/vendor/serve-emu/api",
311 "/vendor/serve-emu/api/screenshot?device=emulator-5554",
312 ]);
313 expect(
314 yield* ready.upstream!(
315 "/vendor/serve-emu/webrtc/offer",
316 new URLSearchParams("device=session-2&hostId=eas"),
317 ),
318 ).toEqual({
319 url: "https://preview.test/vendor/serve-emu/webrtc/offer?device=emulator-5554&hostId=eas",
320 headers: { authorization: "Bearer preview-token" },
321 protocols: ["serve-emu.token.preview-token"],
322 });
323 // Each session answers only on its own platform's stream.
324 expect(
325 yield* ready.upstream!("/vendor/serve-emu/api", new URLSearchParams("device=session-1")),
326 ).toBeNull();
327 expect(
328 yield* ready.upstream!("/vendor/serve-sim/api", new URLSearchParams("device=session-2")),
329 ).toBeNull();
330 }).pipe(Effect.scoped, Effect.provide(layer)),
331 );
332​
333 it.effect("refuses to start past its session limit", () =>
334 Effect.gen(function* () {
335 const expo = fakeExpo();
336 const host = yield* makeHost(expo, config({ maxConcurrentSessions: 1 }), yield* Scope.make());
337 const ready = yield* host.ensureReady(() => Effect.void);
338 const [catalogDevice] = (yield* ready.devices.list).devices;
339 yield* ready.devices.boot(catalogDevice!);
340 const refused = yield* ready.devices.boot(catalogDevice!).pipe(Effect.flip);
341 expect(refused.message).toBe(
342 "EAS Simulator is unavailable: EAS Simulator is limited to 1 running session. Close one in the Device panel first.",
343 );
344 expect(expo.named("T3CreateEasSimulatorSession")).toHaveLength(1);
345 }).pipe(Effect.scoped, Effect.provide(layer)),
346 );
347​
348 it.effect("tells concurrent sessions apart although EAS gives each the same UDID", () =>
349 Effect.gen(function* () {
350 const expo = fakeExpo();
351 const scope = yield* Scope.make();
352 const host = yield* makeHost(expo, config({ maxConcurrentSessions: 2 }), scope);
353 const ready = yield* host.ensureReady(() => Effect.void);
354 const [catalogDevice] = (yield* ready.devices.list).devices;
355 expect(yield* ready.devices.boot(catalogDevice!)).toBe("session-1");
356 expect(yield* ready.devices.boot(catalogDevice!)).toBe("session-2");
357 expect((yield* ready.devices.list).devices.map((device) => device.id)).toEqual([
358 "eas-ios",
359 "eas-android",
360 "session-1",
361 "session-2",
362 ]);
363 expect(
364 yield* ready.upstream!(
365 "/vendor/serve-sim/api",
366 new URLSearchParams("device=session-2&hostId=eas"),
367 ),
368 ).toMatchObject({ url: "https://preview.test/api?device=UDID-1&hostId=eas" });
369​
370 yield* ready.devices.shutdown({ id: "session-1", platform: "ios" });
371 expect(expo.stopped()).toEqual(["session-1"]);
372 expect((yield* ready.devices.list).devices.map((device) => device.id)).toEqual([
373 "eas-ios",
374 "eas-android",
375 "session-2",
376 ]);
377 yield* Scope.close(scope, Exit.void);
378 expect(expo.stopped()).toEqual(["session-1", "session-2"]);
379 }).pipe(Effect.scoped, Effect.provide(layer)),
380 );
381​
382 it.effect(
383 "keeps a refused create's record for the reaper without counting it after a restart",
384 () =>
385 Effect.gen(function* () {
386 const fs = yield* FileSystem.FileSystem;
387 const path = yield* Path.Path;
388 const server = yield* ServerConfig.ServerConfig;
389 const ledger = path.join(server.stateDir, "device", "eas", "eas.json");
390 // Expo refuses the create and lists nothing.
391 const expo = fakeExpo({ rejectCreate: true, omitCreatedFromActive: true });
392 const first = yield* Scope.make();
393 const host = yield* makeHost(expo, config({ maxConcurrentSessions: 1 }), first);
394 const ready = yield* host.ensureReady(() => Effect.void);
395 const [catalogDevice] = (yield* ready.devices.list).devices;
396 yield* ready.devices.boot(catalogDevice!).pipe(Effect.flip);
397 const entries = JSON.parse(yield* fs.readFileString(ledger)) as Array<{
398 refused?: boolean;
399 }>;
400 expect(entries.map((entry) => entry.refused)).toEqual([true]);
401 yield* Scope.close(first, Exit.void);
402 // A later server cannot even list the app: the record must not hold a slot.
403 const later = fakeExpo({ failList: () => true });
404 const restarted = yield* makeHost(
405 later,
406 config({ maxConcurrentSessions: 1 }),
407 yield* Scope.make(),
408 );
409 const readyAgain = yield* restarted.ensureReady(() => Effect.void);
410 const [device] = (yield* readyAgain.devices.list).devices;
411 expect(yield* readyAgain.devices.boot(device!)).toBe("session-1");
412 }).pipe(Effect.scoped, Effect.provide(layer)),
413 );
414​
415 it.effect(
416 "does not sweep a replacement's session from a listing in flight when its scope closes",
417 () =>
418 Effect.gen(function* () {
419 const gate = yield* makeGate;
420 let armed = false;
421 const expo = fakeExpo({ sessionGate: () => (armed ? gate : undefined) });
422 const first = yield* Scope.make();
423 const old = yield* makeHost(expo, config(), first);
424 const oldReady = yield* old.ensureReady(() => Effect.void);
425 const [catalogDevice] = (yield* oldReady.devices.list).devices;
426 expect(yield* oldReady.devices.boot(catalogDevice!)).toBe("session-1");
427 // Long enough that the listing reads the session's status and a sweep is due.
428 yield* TestClock.adjust("2 minutes");
429 armed = true;
430 const listing = yield* oldReady.devices.list.pipe(Effect.forkChild);
431 yield* Deferred.await(gate.requested);
432 // Settings saved while the old listing waits on Expo.
433 yield* Scope.close(first, Exit.void);
434 const replacement = yield* makeHost(expo, config(), yield* Scope.make());
435 const ready = yield* replacement.ensureReady(() => Effect.void);
436 const [device] = (yield* ready.devices.list).devices;
437 expect(yield* ready.devices.boot(device!)).toBe("session-2");
438 yield* Deferred.succeed(gate.release, undefined);
439 yield* Fiber.join(listing);
440 expect(expo.stopped()).toEqual(["session-1"]);
441 }).pipe(Effect.scoped, Effect.provide(layer)),
442 );
443​
444 it.effect("stops the session a refused create made anyway", () =>
445 Effect.gen(function* () {
446 // Expo refuses the create but lists a session by its name.
447 const expo = fakeExpo({ rejectCreate: true });
448 const host = yield* makeHost(expo, config({ maxConcurrentSessions: 1 }), yield* Scope.make());
449 const ready = yield* host.ensureReady(() => Effect.void);
450 const [catalogDevice] = (yield* ready.devices.list).devices;
451 const failure = yield* ready.devices.boot(catalogDevice!).pipe(Effect.flip);
452 expect(failure.message).toContain("Not allowed");
453 expect(expo.stopped()).toEqual(["orphan"]);
454 }).pipe(Effect.scoped, Effect.provide(layer)),
455 );
456​
457 it.effect("records a session before creating it and refuses to start without the record", () =>
458 Effect.gen(function* () {
459 const fs = yield* FileSystem.FileSystem;
460 const path = yield* Path.Path;
461 const server = yield* ServerConfig.ServerConfig;
462 // A directory where the ledger file should be: it can be neither read nor written.
463 yield* fs.makeDirectory(path.join(server.stateDir, "device", "eas", "eas.json"), {
464 recursive: true,
465 });
466 const expo = fakeExpo();
467 const host = yield* makeHost(expo, config(), yield* Scope.make());
468 const ready = yield* host.ensureReady(() => Effect.void);
469 const [catalogDevice] = (yield* ready.devices.list).devices;
470 const failure = yield* ready.devices.boot(catalogDevice!).pipe(Effect.flip);
471 expect(failure.message).toContain("could not be read");
472 expect(expo.named("T3CreateEasSimulatorSession")).toHaveLength(0);
473 }).pipe(Effect.scoped, Effect.provide(layer)),
474 );
475​
476 it.effect("keeps a session it could not stop counted, listed, and retried", () =>
477 Effect.gen(function* () {
478 let stopFails = true;
479 const expo = fakeExpo({ failStop: () => stopFails });
480 const host = yield* makeHost(expo, config({ maxConcurrentSessions: 1 }), yield* Scope.make());
481 const ready = yield* host.ensureReady(() => Effect.void);
482 const [catalogDevice] = (yield* ready.devices.list).devices;
483 yield* ready.devices.boot(catalogDevice!);
484 yield* ready.devices.shutdown({ id: "session-1", platform: "ios" }).pipe(Effect.flip);
485 expect((yield* ready.devices.list).devices.map((device) => device.id)).toContain("session-1");
486 const refused = yield* ready.devices.boot(catalogDevice!).pipe(Effect.flip);
487 expect(refused.message).toContain("limited to 1 running session");
488 stopFails = false;
489 yield* ready.devices.list;
490 expect((yield* ready.devices.list).devices.map((device) => device.id)).toEqual([
491 "eas-ios",
492 "eas-android",
493 ]);
494 expect(expo.stopped().filter((id) => id === "session-1").length).toBeGreaterThanOrEqual(2);
495 }).pipe(Effect.scoped, Effect.provide(layer)),
496 );
497​
498 it.effect("lets go of a stopping session Expo has ended although its stop keeps failing", () =>
499 Effect.gen(function* () {
500 let status = "IN_PROGRESS";
501 const expo = fakeExpo({ failStop: () => true, status: () => status });
502 const host = yield* makeHost(expo, config({ maxConcurrentSessions: 1 }), yield* Scope.make());
503 const ready = yield* host.ensureReady(() => Effect.void);
504 const [catalogDevice] = (yield* ready.devices.list).devices;
505 yield* ready.devices.boot(catalogDevice!);
506 yield* ready.devices.shutdown({ id: "session-1", platform: "ios" }).pipe(Effect.flip);
507 expect((yield* ready.devices.list).devices.map((device) => device.id)).toContain("session-1");
508 // Expo ended it by itself: the stop keeps failing, but the status says so.
509 status = "STOPPED";
510 expect((yield* ready.devices.list).devices.map((device) => device.id)).toEqual([
511 "eas-ios",
512 "eas-android",
513 ]);
514 status = "IN_PROGRESS";
515 expect(yield* ready.devices.boot(catalogDevice!)).toBe("session-2");
516 }).pipe(Effect.scoped, Effect.provide(layer)),
517 );
518​
519 it.effect("asks for an EAS project before starting anything when none can be found", () =>
520 Effect.gen(function* () {
521 const expo = fakeExpo();
522 const host = yield* makeHost(expo, config({ appId: undefined }), yield* Scope.make());
523 const ready = yield* host.ensureReady(() => Effect.void);
524 const [catalogDevice] = (yield* ready.devices.list).devices;
525 const failure = yield* ready.devices.boot(catalogDevice!).pipe(Effect.flip);
526 expect(failure.message).toContain("Choose one for this host in Settings");
527 expect(expo.named("T3CreateEasSimulatorSession")).toHaveLength(0);
528 }).pipe(Effect.scoped, Effect.provide(layer)),
529 );
530​
531 it.effect("reports iOS unavailable on a server with no Expo credential", () =>
532 Effect.gen(function* () {
533 const fs = yield* FileSystem.FileSystem;
534 const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-expo-home-" });
535 const host = yield* makeHost(
536 fakeExpo(),
537 config({ accessToken: "" }),
538 yield* Scope.make(),
539 ).pipe(
540 Effect.provideService(HostProcess.HomeDirectory, home),
541 Effect.provideService(HostProcess.Environment, {}),
542 );
543 const [ios] = (yield* host.summary).platforms;
544 expect(ios).toMatchObject({ platform: "ios", available: false });
545 expect(ios?.reason).toContain("No Expo credential on the server");
546 }).pipe(Effect.scoped, Effect.provide(layer)),
547 );
548​
549 it.effect("stops a session that is still starting when the host stops", () =>
550 Effect.gen(function* () {
551 const previewGate = yield* makeGate;
552 const expo = fakeExpo({ previewGate });
553 const host = yield* makeHost(expo, config(), yield* Scope.make());
554 const ready = yield* host.ensureReady(() => Effect.void);
555 const [catalogDevice] = (yield* ready.devices.list).devices;
556 const booting = yield* ready.devices.boot(catalogDevice!).pipe(Effect.forkChild);
557 yield* Deferred.await(previewGate.requested);
558 // Never released: stopping must not wait for the session to become ready.
559 yield* host.stop;
560 expect(expo.stopped()).toEqual(["session-1"]);
561 const failure = yield* Fiber.join(booting).pipe(Effect.flip);
562 expect(failure.message).toContain("was stopped while the session started");
563 expect((yield* ready.devices.list).devices.map((device) => device.id)).toEqual([
564 "eas-ios",
565 "eas-android",
566 ]);
567 }).pipe(Effect.scoped, Effect.provide(layer)),
568 );
569});