Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2import {
3 DEFAULT_SERVER_SETTINGS,
4 DeviceBootError,
5 DeviceId,
6 DeviceOperationError,
7 LOCAL_DEVICE_HOST_ID,
8 ThreadId,
9 type DeviceSummary,
10 type ServerSettings as Settings,
11 type SshDeviceHostConfig,
12} from "@t3tools/contracts";
13import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
14import * as NodeServices from "@effect/platform-node/NodeServices";
15import * as NetService from "@t3tools/shared/Net";
16import * as Effect from "effect/Effect";
17import * as Exit from "effect/Exit";
18import * as Deferred from "effect/Deferred";
19import * as Fiber from "effect/Fiber";
20import * as FileSystem from "effect/FileSystem";
21import * as Layer from "effect/Layer";
22import * as Queue from "effect/Queue";
23import * as Ref from "effect/Ref";
24import * as Schema from "effect/Schema";
25import * as Sink from "effect/Sink";
26import * as Stream from "effect/Stream";
27import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
28import { HttpClient, HttpClientResponse } from "effect/http";
29import * as ServerConfig from "../config.ts";
30import * as ProcessRunner from "../processRunner.ts";
31import * as ServerSettings from "../serverSettings.ts";
32import * as DeviceHost from "./DeviceHost.ts";
33import { makeDeviceHubOperations } from "./DeviceHubOperations.ts";
34import { NodeRuntimeUnavailableError } from "@t3tools/shared/nodeRuntime";
35
36import * as DeviceService from "./DeviceService.ts";
37
38const decodeJson = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
39const decodeBootError = Schema.decodeUnknownSync(Schema.fromJsonString(DeviceBootError));
40const encodeBootError = Schema.encodeSync(Schema.fromJsonString(DeviceBootError));
41
42const fixture = Effect.fn("fixture")(function* (
43 onBoot: Effect.Effect<void> = Effect.void,
44 bootError?: string | { error?: string; errors?: Array<{ message: string; error?: string }> },
45 failListAfterShutdown = false,
46 runtimeFailure?:
47 | NodeRuntimeUnavailableError
48 | DeviceHost.DeviceHostError
49 | DeviceHost.AgentDeviceStartError,
50 inspectError = false,
51 installTool?: Parameters<typeof DeviceService.makeWithHosts>[3],
52 options: { readonly endsDevices?: boolean } = {},
53) {
54 const settings = yield* Ref.make(DEFAULT_SERVER_SETTINGS);
55 const starts: string[] = [];
56 const agentStarts: string[] = [];
57 const agentStops: string[] = [];
58 const requests: string[] = [];
59 const devices: Array<Omit<DeviceSummary, "hostId">> = [];
60 const discoveryErrors = yield* Ref.make<Array<{ message: string; error?: string }>>([]);
61 const androidAvailable = yield* Ref.make(true);
62 const encoderResult = yield* Ref.make({ code: 0, stdout: " V....D libx264", stderr: "" });
63 let booted = false;
64 let shutDown = false;
65 const http = HttpClient.make((request) =>
66 Effect.gen(function* () {
67 requests.push(request.url);
68 if (request.url.includes("/api/screenshot")) {
69 return HttpClientResponse.fromWeb(request, new Response(new Uint8Array([137, 80, 78, 71])));
70 }
71 if (request.url.endsWith("/shutdown")) {
72 shutDown = true;
73 booted = false;
74 return HttpClientResponse.fromWeb(request, Response.json({ ok: true }));
75 }
76 if (shutDown && failListAfterShutdown) {
77 return HttpClientResponse.fromWeb(request, new Response("Discovery busy", { status: 503 }));
78 }
79 if (request.url.endsWith("/boot")) {
80 yield* onBoot;
81 booted = true;
82 return HttpClientResponse.fromWeb(
83 request,
84 Response.json(
85 bootError
86 ? { ok: false, ...(typeof bootError === "string" ? { error: bootError } : bootError) }
87 : { ok: true, serial: "emulator-5554" },
88 ),
89 );
90 }
91 if (request.url.endsWith("/grid/api/start")) {
92 return HttpClientResponse.fromWeb(request, Response.json({ ok: true }));
93 }
94 return HttpClientResponse.fromWeb(
95 request,
96 Response.json({
97 errors: yield* Ref.get(discoveryErrors),
98 simulators: devices.filter((device) => device.platform === "ios"),
99 emulators: [
100 ...devices.filter((device) => device.platform === "android"),
101 ...(booted
102 ? [
103 {
104 id: "emulator-5554",
105 name: "Pixel_API_35",
106 platform: "android",
107 version: "Android 15",
108 booted: true,
109 physical: false,
110 },
111 ]
112 : []),
113 ],
114 }),
115 );
116 }),
117 );
118 const run = (command: string) =>
119 command === "emulator"
120 ? Effect.succeed({ code: 0, stdout: "Pixel_API_35\n", stderr: "" })
121 : Ref.get(encoderResult);
122 const ready: DeviceHost.DeviceHostReady = {
123 nodePath: process.execPath,
124 hub: { origin: "http://device.test" },
125 devices: {
126 ...makeDeviceHubOperations({
127 hostId: LOCAL_DEVICE_HOST_ID,
128 origin: "http://device.test",
129 http,
130 run,
131 androidAvailable: Ref.get(androidAvailable),
132 }),
133 ...(options.endsDevices ? { endsDevices: true } : {}),
134 },
135 helpers: { serveSimAxSettings: null, serveSimCli: null },
136 run,
137 };
138 const host: DeviceHost.DeviceHost["Service"] = {
139 ...(inspectError
140 ? {
141 inspect: Effect.fail(
142 new DeviceHost.DeviceHostError({
143 hostId: LOCAL_DEVICE_HOST_ID,
144 step: "probe",
145 cause: new Error("offline"),
146 }),
147 ),
148 }
149 : {}),
150 id: LOCAL_DEVICE_HOST_ID,
151 label: "This machine",
152 summary: Effect.succeed({
153 id: LOCAL_DEVICE_HOST_ID,
154 kind: "local",
155 label: "Test server",
156 platforms: [
157 { platform: "android", available: true },
158 { platform: "ios", available: true },
159 ],
160 hubInstalled: true,
161 agentDeviceInstalled: false,
162 }),
163 platformAvailability: (platform) => Effect.succeed({ platform, available: true }),
164 ensureReady: (onPhase) =>
165 Effect.gen(function* () {
166 if (runtimeFailure && runtimeFailure._tag !== "AgentDeviceStartError")
167 return yield* runtimeFailure;
168 starts.push("start");
169 yield* onPhase("installing", "Updating device hub from 0.9.0 to 0.10.1…");
170 return ready;
171 }),
172 ensureAgentReady: (onPhase) =>
173 Effect.gen(function* () {
174 if (runtimeFailure) return yield* runtimeFailure;
175 agentStarts.push("start");
176 yield* onPhase("starting");
177 return {
178 ...ready,
179 agentDevice: { baseUrl: "http://agent.test", token: "test", entryPath: "/agent" },
180 };
181 }),
182 current: Effect.succeed(null),
183 stopAgent: Effect.sync(() => {
184 agentStops.push("stop");
185 }),
186 stop: Effect.sync(() => {
187 starts.push("stop");
188 }),
189 };
190 const service = yield* DeviceService.makeWithHosts(
191 new Map([[host.id, host]]),
192 undefined,
193 undefined,
194 installTool,
195 ).pipe(
196 Effect.provide(NodeCrypto.layer),
197 Effect.provideService(DeviceHost.DeviceHost, host),
198 Effect.provideService(
199 ServerSettings.ServerSettingsService,
200 ServerSettings.ServerSettingsService.of({
201 updateProviderInstance: () => Effect.die("Unexpected provider mutation"),
202 withSettingsSnapshot: (use) => Effect.flatMap(Ref.get(settings), use),
203 start: Effect.void,
204 ready: Effect.void,
205 getSettings: Ref.get(settings),
206 updateSettings: (patch) =>
207 Ref.updateAndGet(settings, (current) => ({
208 ...current,
209 enableDeviceSupport: patch.enableDeviceSupport ?? current.enableDeviceSupport,
210 enableAgentDeviceAccess:
211 patch.enableAgentDeviceAccess ?? current.enableAgentDeviceAccess,
212 deviceOnboardingCompleted:
213 patch.deviceOnboardingCompleted ?? current.deviceOnboardingCompleted,
214 })),
215 streamChanges: Stream.empty,
216 subscribeChanges: Effect.succeed(Stream.empty),
217 }),
218 ),
219 );
220 // The host ending a device on its own, as EAS does at a session's limits.
221 const endDevice = () => {
222 booted = false;
223 };
224 return {
225 service,
226 starts,
227 agentStarts,
228 agentStops,
229 requests,
230 settings,
231 devices,
232 encoderResult,
233 discoveryErrors,
234 androidAvailable,
235 endDevice,
236 };
237});
238
239describe("device setup consent", () => {
240 it.effect("exposes daemon startup diagnostics through agent readiness and host status", () =>
241 Effect.gen(function* () {
242 const startupError = new DeviceHost.AgentDeviceStartError({
243 hostId: LOCAL_DEVICE_HOST_ID,
244 stateDir: "/test/device/agent-device",
245 exitCode: 1,
246 reason: "daemon_lock_not_directory",
247 cause: { stdout: "private startup diagnostics", code: 1 },
248 });
249 const { service, settings } = yield* fixture(Effect.void, undefined, false, startupError);
250 yield* Ref.update(settings, (current) => ({
251 ...current,
252 enableDeviceSupport: true,
253 enableAgentDeviceAccess: true,
254 }));
255 const error = yield* service.agentReadinessIfSupported().pipe(Effect.flip);
256 expect(error).toMatchObject({
257 _tag: "DeviceHostUnavailableError",
258 reason: startupError.message,
259 cause: startupError,
260 });
261 expect(error.message).toContain("daemon.lock is not a directory");
262 expect(error.message).not.toContain("private startup diagnostics");
263 expect((yield* service.state).hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({
264 status: "failed",
265 detail: startupError.message,
266 });
267 }).pipe(Effect.scoped),
268 );
269
270 it.effect("listing and provider startup do not start helpers before consent", () =>
271 Effect.gen(function* () {
272 const { service, starts, requests } = yield* fixture();
273 expect((yield* service.list).hostStatus).toBe("disabled");
274 expect(yield* service.readinessIfSupported()).toBeNull();
275 const readiness = yield* service.readiness().pipe(Effect.result);
276 expect(readiness._tag).toBe("Failure");
277 expect(starts).toEqual([]);
278 expect(requests).toEqual([]);
279 }).pipe(Effect.scoped),
280 );
281
282 it.effect(
283 "explicit setup discovers never-booted AVDs; disabling stops helpers and blocks agents",
284 () =>
285 Effect.gen(function* () {
286 const { service, starts, settings } = yield* fixture();
287 const state = yield* service.configure({ enabled: true });
288 expect((yield* Ref.get(settings)).enableDeviceSupport).toBe(true);
289 expect(state.devices.map((device) => [device.id, device.booted])).toEqual([
290 ["Pixel_API_35", false],
291 ]);
292 expect(starts).toEqual(["start"]);
293 const disabled = yield* service.configure({ enabled: false });
294 expect(disabled.hostStatus).toBe("disabled");
295 expect(disabled.devices).toEqual([]);
296 expect((yield* Ref.get(settings)).enableDeviceSupport).toBe(false);
297 expect(yield* service.readinessIfSupported()).toBeNull();
298 expect(starts).toEqual(["start", "stop"]);
299 }).pipe(Effect.scoped),
300 );
301
302 it.effect("boots a stopped Android AVD and uses its emulator serial without duplicating it", () =>
303 Effect.gen(function* () {
304 const { service, requests } = yield* fixture();
305 yield* service.configure({ enabled: true });
306 const session = yield* service.open({
307 threadId: ThreadId.make("thread-1"),
308 deviceId: "Pixel_API_35",
309 platform: "android",
310 });
311 expect(session.deviceId).toBe("emulator-5554");
312 expect(requests.filter((url) => url.endsWith("/boot"))).toHaveLength(1);
313 const state = yield* service.state;
314 expect(state.devices.map((device) => device.id)).toEqual(["emulator-5554"]);
315 expect(state.bootingDevices).toEqual([]);
316 }).pipe(Effect.scoped),
317 );
318
319 it.effect("blocks only emulator video until ffmpeg is usable, then allows retry", () =>
320 Effect.gen(function* () {
321 const { service, requests, devices, encoderResult } = yield* fixture();
322 devices.push(
323 {
324 id: DeviceId.make("physical-android"),
325 name: "Pixel",
326 platform: "android",
327 version: "Android 15",
328 booted: true,
329 physical: true,
330 },
331 {
332 id: DeviceId.make("ios-simulator"),
333 name: "iPhone",
334 platform: "ios",
335 version: "iOS 18",
336 booted: true,
337 physical: false,
338 },
339 );
340 yield* Ref.set(encoderResult, { code: 127, stdout: "", stderr: "spawn ffmpeg ENOENT" });
341 const state = yield* service.configure({ enabled: true });
342 expect(state.devices.map((device) => device.id)).toEqual([
343 "ios-simulator",
344 "physical-android",
345 "Pixel_API_35",
346 ]);
347 const threadId = ThreadId.make("emulator-video-readiness");
348 const physical = yield* service.open({
349 threadId,
350 deviceId: "physical-android",
351 platform: "android",
352 });
353 const ios = yield* service.open({ threadId, deviceId: "ios-simulator", platform: "ios" });
354 expect(physical.deviceId).toBe("physical-android");
355 expect(ios.deviceId).toBe("ios-simulator");
356
357 const openEmulator = service.open({
358 threadId,
359 deviceId: "Pixel_API_35",
360 platform: "android",
361 });
362 const missing = yield* openEmulator.pipe(Effect.flip);
363 expect(missing.message).toMatch(/ffmpeg/i);
364 expect(missing.message).toMatch(/emulator/i);
365 expect(requests.filter((url) => url.endsWith("/boot"))).toEqual([]);
366 expect((yield* service.state).sessions).toEqual([physical, ios]);
367 expect((yield* service.state).bootingDevices ?? []).toEqual([]);
368
369 yield* Ref.set(encoderResult, { code: 1, stdout: "", stderr: "cannot execute ffmpeg" });
370 expect((yield* openEmulator.pipe(Effect.flip)).message).toMatch(/ffmpeg/i);
371 yield* Ref.set(encoderResult, {
372 code: 0,
373 stdout: " V....D libx264rgb libx264 H.264 / AVC RGB (codec h264)",
374 stderr: "",
375 });
376 expect((yield* openEmulator.pipe(Effect.flip)).message).toMatch(/libx264/i);
377 expect(requests.filter((url) => url.endsWith("/boot"))).toEqual([]);
378 expect((yield* service.state).sessions).toEqual([physical, ios]);
379
380 devices.push({
381 id: DeviceId.make("emulator-5556"),
382 name: "Already_booted",
383 platform: "android",
384 version: "Android 15",
385 booted: true,
386 physical: false,
387 });
388 expect(
389 (yield* service
390 .open({ threadId, deviceId: "emulator-5556", platform: "android" })
391 .pipe(Effect.flip)).message,
392 ).toMatch(/libx264/i);
393
394 yield* Ref.set(encoderResult, { code: 0, stdout: " V....D libx264", stderr: "" });
395 const emulator = yield* openEmulator;
396 expect(emulator.deviceId).toBe("emulator-5554");
397 expect(requests.filter((url) => url.endsWith("/boot"))).toHaveLength(1);
398 }).pipe(Effect.scoped),
399 );
400
401 it.effect("installs agent support only after the separate agent permission", () =>
402 Effect.gen(function* () {
403 const { service, agentStarts, agentStops, settings } = yield* fixture();
404 yield* service.configure({ enabled: true });
405 expect(agentStarts).toEqual([]);
406 expect(yield* service.agentReadinessIfSupported()).toBeNull();
407
408 yield* service.configure({ agentAccessEnabled: true });
409 expect(agentStarts).toEqual(["start"]);
410 expect((yield* Ref.get(settings)).enableAgentDeviceAccess).toBe(true);
411 expect((yield* service.state).agentAccessEnabled).toBe(true);
412
413 yield* service.configure({ agentAccessEnabled: false, onboardingCompleted: true });
414 expect(agentStops).toEqual(["stop"]);
415 expect((yield* service.state).onboardingCompleted).toBe(true);
416 expect((yield* Ref.get(settings)).deviceOnboardingCompleted).toBe(true);
417 }).pipe(Effect.scoped),
418 );
419});
420
421it.effect("publishes boot progress and does not restore sessions after support is disabled", () =>
422 Effect.gen(function* () {
423 const started = yield* Deferred.make<void>();
424 const finish = yield* Deferred.make<void>();
425 const { service } = yield* fixture(
426 Deferred.succeed(started, undefined).pipe(Effect.andThen(Deferred.await(finish))),
427 );
428 yield* service.configure({ enabled: true });
429 const opening = yield* service
430 .open({ threadId: ThreadId.make("thread-1"), deviceId: "Pixel_API_35", platform: "android" })
431 .pipe(Effect.result, Effect.forkChild);
432 yield* Deferred.await(started);
433 expect((yield* service.state).bootingDevices?.map((device) => device.name)).toEqual([
434 "Pixel_API_35",
435 ]);
436 yield* service.configure({ enabled: false });
437 yield* Deferred.succeed(finish, undefined);
438 expect((yield* Fiber.join(opening))._tag).toBe("Failure");
439 const state = yield* service.state;
440 expect(state.hostStatus).toBe("disabled");
441 expect(state.devices).toEqual([]);
442 expect(state.sessions).toEqual([]);
443 expect(state.bootingDevices).toEqual([]);
444 }).pipe(Effect.scoped),
445);
446
447it.effect.each([
448 { case: "drops it on a host that ends devices itself", endsDevices: true, kept: 0 },
449 {
450 case: "keeps it on a host that can miss a device for one listing",
451 endsDevices: false,
452 kept: 1,
453 },
454])("when a host stops listing a session's device, $case", ({ endsDevices, kept }) =>
455 Effect.gen(function* () {
456 const { service, endDevice } = yield* fixture(
457 Effect.void,
458 undefined,
459 false,
460 undefined,
461 false,
462 undefined,
463 { endsDevices },
464 );
465 yield* service.configure({ enabled: true });
466 const threadId = ThreadId.make("ended-by-host");
467 yield* service.open({ threadId, deviceId: "Pixel_API_35", platform: "android" });
468 expect((yield* service.state).sessions.map((session) => session.deviceId)).toEqual([
469 "emulator-5554",
470 ]);
471 endDevice();
472 yield* service.list;
473 expect((yield* service.state).sessions).toHaveLength(kept);
474 }).pipe(Effect.scoped),
475);
476
477describe("device discovery after server restart", () => {
478 it.effect("captures an explicit device before any client lists devices", () =>
479 Effect.gen(function* () {
480 const { service, settings, requests } = yield* fixture();
481 yield* Ref.update(settings, (current) => ({ ...current, enableDeviceSupport: true }));
482 expect((yield* service.state).devices).toEqual([]);
483 const capture = yield* service.screenshot({ deviceId: DeviceId.make("Pixel_API_35") });
484 expect(capture.device.id).toBe("Pixel_API_35");
485 expect(Array.from(capture.png)).toEqual([137, 80, 78, 71]);
486 expect(requests.some((url) => url.endsWith("/api/devices"))).toBe(true);
487 }).pipe(Effect.scoped),
488 );
489});
490
491const missingPlistMessage =
492 "[apple-utils] Failed to read CoreSimulator plist at /Users/test/Library/Developer/CoreSimulator/Devices/deleted-simulator/device.plist:";
493
494it.effect("keeps other discovery warnings and clears them when only a deleted plist remains", () =>
495 Effect.gen(function* () {
496 const { service, discoveryErrors } = yield* fixture();
497 const missing = {
498 message: missingPlistMessage,
499 error: "Error: ENOENT: no such file or directory",
500 };
501 yield* Ref.set(discoveryErrors, [missing, { message: "Android discovery failed." }]);
502 const initial = yield* service.configure({ enabled: true });
503 expect(initial.hostStatusDetail).toBe("Android discovery failed.");
504 yield* Ref.set(discoveryErrors, [missing]);
505 const refreshed = yield* service.list;
506 expect(refreshed.hostStatusDetail).toBeUndefined();
507 expect(refreshed.hostStatuses.local?.detail).toBeUndefined();
508 }).pipe(Effect.scoped),
509);
510
511it.effect("hides Android discovery failures when the host has no Android SDK", () =>
512 Effect.gen(function* () {
513 const { service, discoveryErrors, androidAvailable } = yield* fixture();
514 const avdmanagerFailure = { message: "[android-utils] Failed to run `avdmanager list avd`:" };
515 yield* Ref.set(discoveryErrors, [avdmanagerFailure, { message: "iOS discovery failed." }]);
516 yield* Ref.set(androidAvailable, false);
517 const withoutSdk = yield* service.configure({ enabled: true });
518 expect(withoutSdk.hostStatusDetail).toBe("iOS discovery failed.");
519 yield* Ref.set(androidAvailable, true);
520 const withSdk = yield* service.list;
521 expect(withSdk.hostStatusDetail).toBe(`${avdmanagerFailure.message}\niOS discovery failed.`);
522 }).pipe(Effect.scoped),
523);
524
525// The hub reports `error` as a util.inspect of Node's exec error.
526const simctlMessage = "[apple-utils] Failed to run `xcrun simctl list devices --json`:";
527const simctlCause =
528 "An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=60): Unable to connect to CoreSimulatorService [xcrun shim fail mode]";
529const simctlError = `Error: Command failed: xcrun simctl list devices --json
530${simctlCause}
531
532 at genericNodeError (node:internal/errors:986:15)
533 at wrappedFn (node:internal/errors:540:14)
534 at ChildProcess.exithandler (node:child_process:417:12)
535 at ChildProcess._handle.onexit (node:internal/child_process:335:5) {
536 code: 1,
537 killed: false,
538 signal: null,
539 cmd: 'xcrun simctl list devices --json',
540 stdout: '',
541 stderr: '${simctlCause}\\n'
542}`;
543const avdmanager = "/Users/test/Library/Android/sdk/cmdline-tools/latest/bin/avdmanager";
544const avdmanagerError = `Error: spawn ${avdmanager} ENOENT
545 at ChildProcess._handle.onexit (node:internal/child_process:316:19)
546 at onErrorNT (node:internal/child_process:524:16) {
547 errno: -2,
548 code: 'ENOENT',
549 syscall: 'spawn ${avdmanager}',
550 path: '${avdmanager}',
551 spawnargs: [ 'list', 'avd' ],
552 cmd: '${avdmanager} list avd',
553 stdout: '',
554 stderr: ''
555}`;
556
557it.effect("keeps the cause from the hub's error in discovery warnings, without the stack", () =>
558 Effect.gen(function* () {
559 const { service, discoveryErrors } = yield* fixture();
560 yield* Ref.set(discoveryErrors, [
561 { message: simctlMessage, error: simctlError },
562 { message: "[android-utils] Failed to run `avdmanager list avd`:", error: avdmanagerError },
563 ]);
564 const state = yield* service.configure({ enabled: true });
565 expect(state.hostStatusDetail).toBe(
566 [
567 `${simctlMessage} Error: Command failed: xcrun simctl list devices --json ${simctlCause}`,
568 `[android-utils] Failed to run \`avdmanager list avd\`: Error: spawn ${avdmanager} ENOENT`,
569 ].join("\n"),
570 );
571 expect(state.hostStatusDetail).not.toContain(" at ");
572 expect(state.hostStatusDetail).not.toContain("stderr:");
573 }).pipe(Effect.scoped),
574);
575
576it.effect.each([
577 {
578 diagnostic: "Insufficient disk space at /private/user/path",
579 reason: "disk_space",
580 message: "not enough free disk space",
581 },
582 {
583 diagnostic: "Timed out spawning /private/user/command",
584 reason: "timeout",
585 message: "did not become ready in time",
586 },
587 {
588 diagnostic:
589 "The emulator process exited with code 1.\nTry manually: emulator -avd Pixel_API_35",
590 reason: "launch_failed",
591 message: "could not start",
592 },
593] as const)("normalizes boot failure: $reason", ({ diagnostic, message }) =>
594 Effect.gen(function* () {
595 const { service } = yield* fixture(Effect.void, diagnostic);
596 yield* service.configure({ enabled: true });
597 const error = yield* service
598 .open({
599 threadId: ThreadId.make("boot-failure"),
600 deviceId: "Pixel_API_35",
601 platform: "android",
602 })
603 .pipe(Effect.flip);
604 expect(error._tag).toBe("DeviceBootError");
605 expect(error.message).toContain(message);
606 expect(error.message).toContain(diagnostic);
607 expect((yield* service.state).bootingDevices).toEqual([]);
608 }).pipe(Effect.scoped),
609);
610
611// regression: #22012 report Android emulator boot failures
612it.effect("includes nested hub boot diagnostics and bounds them to 2,000 characters", () =>
613 Effect.gen(function* () {
614 const diagnostic = "Error: emulator binary missing\n" + "diagnostic output\n".repeat(200);
615 const { service } = yield* fixture(Effect.void, {
616 error: "Failed to spawn emulator",
617 errors: [{ message: "Failed to launch emulator binary", error: diagnostic }],
618 });
619 yield* service.configure({ enabled: true });
620 const error = yield* service
621 .open({
622 threadId: ThreadId.make("nested-boot-failure"),
623 deviceId: "Pixel_API_35",
624 platform: "android",
625 })
626 .pipe(Effect.flip);
627 expect(error._tag).toBe("DeviceBootError");
628 if (error._tag !== "DeviceBootError") return;
629 const expected = `Failed to spawn emulator\n\nFailed to launch emulator binary\n\n${diagnostic}`;
630 expect(error.diagnostics).toBe(`${expected.slice(0, 1_999)}…`);
631 expect(error.diagnostics).toHaveLength(2_000);
632 expect(error.message).toContain(error.diagnostics);
633 const roundTrip = decodeBootError(encodeBootError(error));
634 expect(roundTrip.message).toBe(error.message);
635 expect((yield* service.state).bootingDevices).toEqual([]);
636 }).pipe(Effect.scoped),
637);
638
639it.effect("keeps shutdown successful when subsequent discovery fails", () =>
640 Effect.gen(function* () {
641 const { service } = yield* fixture(Effect.void, undefined, true);
642 yield* service.configure({ enabled: true });
643 const threadId = ThreadId.make("shutdown-refresh");
644 const session = yield* service.open({
645 threadId,
646 deviceId: "Pixel_API_35",
647 platform: "android",
648 });
649 yield* service.close({ threadId, deviceId: session.deviceId, shutdown: true });
650 const state = yield* service.state;
651 expect(state.sessions).toEqual([]);
652 expect(state.devices.find((device) => device.id === session.deviceId)?.booted).toBe(false);
653 }).pipe(Effect.scoped),
654);
655
656it.effect.each(["shutdown", "close"] as const)(
657 "%s releases iOS capture so reopening uses a fresh session",
658 (operation) =>
659 Effect.gen(function* () {
660 const deviceId = DeviceId.make("11111111-1111-1111-1111-111111111111");
661 const threadId = ThreadId.make("capture-recovery");
662 let booted = true;
663 let capture: number | null = null;
664 let generation = 0;
665 const http = HttpClient.make((request) =>
666 Effect.sync(() => {
667 const path = new URL(request.url).pathname;
668 if (path === "/api/devices") {
669 return HttpClientResponse.fromWeb(
670 request,
671 Response.json({
672 emulators: [],
673 simulators: [
674 {
675 id: deviceId,
676 name: "iPhone",
677 platform: "ios",
678 version: "26",
679 physical: false,
680 booted,
681 },
682 ],
683 }),
684 );
685 }
686 if (path === "/vendor/serve-sim/grid/api/start") capture ??= ++generation;
687 else if (path === "/vendor/serve-sim/grid/api/shutdown") {
688 if (request.body._tag !== "Uint8Array") throw new Error("Missing shutdown body");
689 expect(decodeJson(new TextDecoder().decode(request.body.body))).toEqual({
690 udid: deviceId,
691 });
692 capture = null;
693 booted = false;
694 } else if (path === "/api/devices/shutdown") {
695 // This route powers off without releasing serve-sim's cached capture.
696 booted = false;
697 } else if (path === "/api/devices/boot") booted = true;
698 else throw new Error(`Unexpected hub path: ${path}`);
699 return HttpClientResponse.fromWeb(request, Response.json({ ok: true, id: deviceId }));
700 }),
701 );
702 const run = () => Effect.succeed({ code: 0, stdout: "", stderr: "" });
703 const ready: DeviceHost.DeviceHostReady = {
704 nodePath: process.execPath,
705 hub: { origin: "http://device.test" },
706 devices: makeDeviceHubOperations({
707 hostId: LOCAL_DEVICE_HOST_ID,
708 origin: "http://device.test",
709 http,
710 run,
711 androidAvailable: Effect.succeed(true),
712 }),
713 helpers: { serveSimAxSettings: null, serveSimCli: null },
714 run,
715 };
716 const host: DeviceHost.DeviceHost["Service"] = {
717 id: LOCAL_DEVICE_HOST_ID,
718 label: "This machine",
719 summary: Effect.succeed({
720 id: LOCAL_DEVICE_HOST_ID,
721 kind: "local",
722 label: "Simulator host",
723 platforms: [{ platform: "ios", available: true }],
724 hubInstalled: true,
725 agentDeviceInstalled: false,
726 }),
727 platformAvailability: (platform) => Effect.succeed({ platform, available: true }),
728 ensureReady: () => Effect.succeed(ready),
729 ensureAgentReady: () => Effect.die("Agent access is not used in this test"),
730 current: Effect.succeed(ready),
731 stopAgent: Effect.void,
732 stop: Effect.void,
733 };
734 const service = yield* DeviceService.makeWithHosts(new Map([[host.id, host]])).pipe(
735 Effect.provide(NodeCrypto.layer),
736 );
737 const input = { threadId, deviceId, platform: "ios" as const };
738 yield* service.open(input);
739 expect(capture).toBe(1);
740 if (operation === "shutdown") yield* service.shutdown(input);
741 else yield* service.close({ threadId, deviceId, shutdown: true });
742 expect(capture).toBeNull();
743 expect((yield* service.state).sessions).toEqual([]);
744 yield* service.open(input);
745 expect(capture).toBe(2);
746 expect((yield* service.state).sessions).toHaveLength(1);
747 }).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true })), Effect.scoped),
748);
749
750it.effect.each([
751 { hubReports: "off", outcome: "succeeds" },
752 { hubReports: "booted", outcome: "fails" },
753 { hubReports: "missing", outcome: "fails" },
754] as const)(
755 "iOS shutdown $outcome when serve-sim rejects it and the hub reports the simulator $hubReports",
756 ({ hubReports, outcome }) =>
757 Effect.gen(function* () {
758 const deviceId = DeviceId.make("22222222-2222-2222-2222-222222222222");
759 const paths: string[] = [];
760 let listed: "booted" | "off" | "missing" = "booted";
761 const http = HttpClient.make((request) =>
762 Effect.sync(() => {
763 const path = new URL(request.url).pathname;
764 paths.push(path);
765 if (path === "/api/devices") {
766 return HttpClientResponse.fromWeb(
767 request,
768 Response.json({
769 emulators: [],
770 simulators:
771 listed === "missing"
772 ? []
773 : [
774 {
775 id: deviceId,
776 name: "iPhone",
777 platform: "ios",
778 version: "26",
779 physical: false,
780 booted: listed === "booted",
781 },
782 ],
783 errors: listed === "missing" ? [{ message: "simctl list failed" }] : [],
784 }),
785 );
786 }
787 if (path === "/vendor/serve-sim/grid/api/shutdown") {
788 // serve-sim runs `simctl shutdown` bare and returns its failure as-is.
789 listed = hubReports;
790 return HttpClientResponse.fromWeb(
791 request,
792 Response.json(
793 { ok: false, error: "Unable to shutdown device in current state: Shutdown" },
794 { status: 500 },
795 ),
796 );
797 }
798 throw new Error(`Unexpected hub path: ${path}`);
799 }),
800 );
801 const run = () => Effect.succeed({ code: 0, stdout: "", stderr: "" });
802 const ready: DeviceHost.DeviceHostReady = {
803 nodePath: process.execPath,
804 hub: { origin: "http://device.test" },
805 devices: makeDeviceHubOperations({
806 hostId: LOCAL_DEVICE_HOST_ID,
807 origin: "http://device.test",
808 http,
809 run,
810 androidAvailable: Effect.succeed(true),
811 }),
812 helpers: { serveSimAxSettings: null, serveSimCli: null },
813 run,
814 };
815 const host: DeviceHost.DeviceHost["Service"] = {
816 id: LOCAL_DEVICE_HOST_ID,
817 label: "This machine",
818 summary: Effect.succeed({
819 id: LOCAL_DEVICE_HOST_ID,
820 kind: "local",
821 label: "Simulator host",
822 platforms: [{ platform: "ios", available: true }],
823 hubInstalled: true,
824 agentDeviceInstalled: false,
825 }),
826 platformAvailability: (platform) => Effect.succeed({ platform, available: true }),
827 ensureReady: () => Effect.succeed(ready),
828 ensureAgentReady: () => Effect.die("Agent access is not used in this test"),
829 current: Effect.succeed(ready),
830 stopAgent: Effect.void,
831 stop: Effect.void,
832 };
833 const service = yield* DeviceService.makeWithHosts(new Map([[host.id, host]])).pipe(
834 Effect.provide(NodeCrypto.layer),
835 );
836 yield* service.list;
837 const exit = yield* Effect.exit(service.shutdown({ deviceId, platform: "ios" }));
838 expect(paths.filter((path) => path.endsWith("shutdown"))).toEqual([
839 "/vendor/serve-sim/grid/api/shutdown",
840 ]);
841 if (outcome === "succeeds") {
842 expect(Exit.isSuccess(exit)).toBe(true);
843 expect(
844 (yield* service.state).devices.find((device) => device.id === deviceId)?.booted,
845 ).toBe(false);
846 } else {
847 expect(Exit.isFailure(exit)).toBe(true);
848 expect(
849 (yield* service.state).devices.find((device) => device.id === deviceId)?.booted,
850 ).toBe(true);
851 }
852 }).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true })), Effect.scoped),
853);
854
855it.effect.each([LOCAL_DEVICE_HOST_ID, "ssh-fixture"])(
856 "retains hub inventory on %s when AVD enumeration fails and recovers on retry",
857 (hostId) =>
858 Effect.gen(function* () {
859 let enumeration = { code: 1, stdout: "private stdout", stderr: "private stderr" };
860 const run = () => Effect.sync(() => enumeration);
861 const hubDevices = [
862 { id: "iphone", name: "iPhone", platform: "ios", physical: false },
863 { id: "phone", name: "Pixel", platform: "android", physical: true },
864 { id: "emulator-5554", name: "Running_AVD", platform: "android", physical: false },
865 ].map((device) => ({ ...device, booted: true, version: "test" }));
866 const http = HttpClient.make((request) =>
867 Effect.succeed(
868 HttpClientResponse.fromWeb(
869 request,
870 Response.json({ simulators: hubDevices.slice(0, 1), emulators: hubDevices.slice(1) }),
871 ),
872 ),
873 );
874 const ready: DeviceHost.DeviceHostReady = {
875 nodePath: process.execPath,
876 hub: { origin: "http://device.test" },
877 devices: makeDeviceHubOperations({
878 hostId,
879 origin: "http://device.test",
880 http,
881 run,
882 androidAvailable: Effect.succeed(true),
883 }),
884 helpers: { serveSimAxSettings: null, serveSimCli: null },
885 run,
886 };
887 const host: DeviceHost.DeviceHost["Service"] = {
888 id: hostId,
889 label: "Test device host",
890 summary: Effect.succeed({
891 id: hostId,
892 kind: hostId === LOCAL_DEVICE_HOST_ID ? "local" : "ssh",
893 label: "Test device host",
894 platforms: [{ platform: "android", available: true }],
895 hubInstalled: true,
896 agentDeviceInstalled: false,
897 }),
898 platformAvailability: (platform) => Effect.succeed({ platform, available: true }),
899 ensureReady: () => Effect.succeed(ready),
900 ensureAgentReady: () => Effect.die("Agent access is not used in this test"),
901 current: Effect.succeed(ready),
902 stop: Effect.void,
903 stopAgent: Effect.void,
904 };
905 const service = yield* DeviceService.makeWithHosts(new Map([[hostId, host]])).pipe(
906 Effect.provide(NodeCrypto.layer),
907 Effect.provideService(HttpClient.HttpClient, http),
908 );
909
910 const incomplete = yield* service.list;
911 expect(incomplete.devices).toEqual(hubDevices.map((device) => ({ ...device, hostId })));
912 expect(incomplete.hostStatuses[hostId]).toEqual({
913 status: "ready",
914 androidDiscoveryIncomplete: true,
915 detail:
916 "Could not list Android virtual devices (emulator -list-avds, exit code 1). Discovered devices remain available.",
917 });
918 if (hostId === LOCAL_DEVICE_HOST_ID) {
919 expect(incomplete.hostStatusDetail).toBe(incomplete.hostStatuses[hostId]?.detail);
920 }
921
922 enumeration = { code: 0, stdout: "Running_AVD\r\nStopped_AVD\nStopped_AVD\n", stderr: "" };
923 const recovered = yield* service.retryHost(hostId);
924 expect(recovered.devices).toEqual([
925 ...hubDevices.map((device) => ({ ...device, hostId })),
926 {
927 hostId,
928 id: "Stopped_AVD",
929 name: "Stopped_AVD",
930 platform: "android",
931 version: "Android",
932 booted: false,
933 physical: false,
934 },
935 ]);
936 expect(recovered.hostStatuses[hostId]).toEqual({ status: "ready" });
937 if (hostId === LOCAL_DEVICE_HOST_ID) expect(recovered.hostStatusDetail).toBeUndefined();
938 }).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true })), Effect.scoped),
939);
940
941it.effect("retry keeps device and agent consent unchanged", () =>
942 Effect.gen(function* () {
943 const { service, starts, agentStarts } = yield* fixture();
944 yield* service.retryHost(LOCAL_DEVICE_HOST_ID);
945 expect(starts).toEqual([]);
946 expect(agentStarts).toEqual([]);
947 yield* service.configure({ enabled: true });
948 yield* service.retryHost(LOCAL_DEVICE_HOST_ID);
949 expect(agentStarts).toEqual([]);
950 yield* service.configure({ agentAccessEnabled: true });
951 const before = agentStarts.length;
952 yield* service.retryHost(LOCAL_DEVICE_HOST_ID);
953 expect(agentStarts.length).toBe(before + 1);
954 }).pipe(Effect.scoped),
955);
956
957it.effect("failed read-only discovery preserves lifecycle status and installed inventory", () =>
958 Effect.gen(function* () {
959 const { service, starts } = yield* fixture(Effect.void, undefined, false, undefined, true);
960 const state = yield* service.inspect;
961 expect(state.supportsToolInspection).toBe(true);
962 expect(state.hostStatus).toBe("disabled");
963 expect(state.hosts[0]?.hubInstalled).toBe(true);
964 expect(state.hosts[0]?.toolInspectionError).toContain("Reconnect the host");
965 expect(starts).toEqual([]);
966 }).pipe(Effect.scoped),
967);
968
969it.effect(
970 "manual updates install only the selected tool without enabling access or starting helpers",
971 () =>
972 Effect.gen(function* () {
973 const installed: string[] = [];
974 const { service, starts, agentStarts, requests } = yield* fixture(
975 Effect.void,
976 undefined,
977 false,
978 undefined,
979 false,
980 (tool) =>
981 Effect.sync(() => {
982 installed.push(tool);
983 }),
984 );
985 const before = yield* service.state;
986 const state = yield* service.updateTool("agent");
987 expect(installed).toEqual(["agent"]);
988 expect(state.supportsToolUpdate).toBe(true);
989 expect(state.hostStatus).toBe(before.hostStatus);
990 expect(state.agentAccessEnabled).toBe(before.agentAccessEnabled);
991 expect(state.revision).toBeGreaterThan(before.revision);
992 expect(starts).toEqual([]);
993 expect(agentStarts).toEqual([]);
994 expect(requests).toEqual([]);
995 yield* service.updateTool("hub");
996 expect(installed).toEqual(["agent", "hub"]);
997 }).pipe(Effect.scoped),
998);
999
1000it.effect("failed manual installation leaves lifecycle state unchanged and can be retried", () =>
1001 Effect.gen(function* () {
1002 let attempts = 0;
1003 const { service, starts, agentStarts } = yield* fixture(
1004 Effect.void,
1005 undefined,
1006 false,
1007 undefined,
1008 false,
1009 () =>
1010 Effect.suspend(() =>
1011 ++attempts === 1
1012 ? Effect.fail(
1013 new DeviceOperationError({
1014 operation: "update device tool",
1015 reason: "command_failed",
1016 cause: new Error("offline"),
1017 }),
1018 )
1019 : Effect.void,
1020 ),
1021 );
1022 const before = yield* service.state;
1023 const result = yield* service.updateTool("agent").pipe(Effect.result);
1024 expect(result._tag).toBe("Failure");
1025 expect(yield* service.state).toEqual(before);
1026 yield* service.updateTool("agent");
1027 expect(attempts).toBe(2);
1028 expect(starts).toEqual([]);
1029 expect(agentStarts).toEqual([]);
1030 }).pipe(Effect.scoped),
1031);
1032
1033it.effect("reconciles SSH host settings without publishing no-op changes", () =>
1034 Effect.gen(function* () {
1035 const fs = yield* FileSystem.FileSystem;
1036 const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-device-reconcile-" });
1037 const settings = yield* ServerSettings.ServerSettingsService;
1038 // Each change is acknowledged after reconciliation consumed it, so no-ops are observable.
1039 const changes = yield* Queue.unbounded<{ value: Settings; done: Deferred.Deferred<void> }>();
1040 const removedFiles: string[] = [];
1041 const localHost: DeviceHost.DeviceHost["Service"] = {
1042 id: LOCAL_DEVICE_HOST_ID,
1043 label: "This machine",
1044 summary: Effect.succeed({
1045 id: LOCAL_DEVICE_HOST_ID,
1046 label: "Local",
1047 kind: "local",
1048 platforms: [],
1049 hubInstalled: false,
1050 agentDeviceInstalled: false,
1051 }),
1052 platformAvailability: (platform) => Effect.succeed({ platform, available: false }),
1053 current: Effect.succeed(null),
1054 ensureReady: () => Effect.die("Unexpected device launch"),
1055 ensureAgentReady: () => Effect.die("Unexpected agent launch"),
1056 stop: Effect.void,
1057 stopAgent: Effect.void,
1058 };
1059 const service = yield* DeviceService.make.pipe(
1060 Effect.provideService(DeviceHost.DeviceHost, localHost),
1061 Effect.provideService(ServerSettings.ServerSettingsService, {
1062 ...settings,
1063 subscribeChanges: Effect.succeed(
1064 Stream.fromQueue(changes).pipe(
1065 Stream.flatMap(({ value, done }) =>
1066 Stream.make(value).pipe(
1067 Stream.concat(
1068 Stream.fromEffect(Deferred.succeed(done, undefined)).pipe(Stream.drain),
1069 ),
1070 ),
1071 ),
1072 ),
1073 ),
1074 }),
1075 Effect.provideService(
1076 FileSystem.FileSystem,
1077 FileSystem.makeNoop({
1078 remove: (file) => Effect.sync(() => void removedFiles.push(file)),
1079 }),
1080 ),
1081 Effect.provideService(ProcessRunner.ProcessRunner, {
1082 run: () => Effect.die("Unexpected helper launch"),
1083 }),
1084 Effect.provideService(
1085 HttpClient.HttpClient,
1086 HttpClient.make(() => Effect.die("Unexpected HTTP request")),
1087 ),
1088 Effect.provideService(
1089 ChildProcessSpawner.ChildProcessSpawner,
1090 ChildProcessSpawner.make(() =>
1091 Effect.succeed(
1092 ChildProcessSpawner.makeHandle({
1093 pid: ChildProcessSpawner.ProcessId(123),
1094 stdout: Stream.make(new TextEncoder().encode("hostname 192.0.2.1\nport 22\n")),
1095 stderr: Stream.empty,
1096 all: Stream.empty,
1097 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
1098 isRunning: Effect.succeed(false),
1099 kill: () => Effect.void,
1100 stdin: Sink.drain,
1101 getInputFd: () => Sink.drain,
1102 getOutputFd: () => Stream.empty,
1103 unref: Effect.succeed(Effect.void),
1104 }),
1105 ),
1106 ),
1107 ),
1108 Effect.provide(Layer.mergeAll(ServerConfig.layerTest(baseDir, baseDir), NetService.layer)),
1109 );
1110 const update = Effect.fnUntraced(function* (deviceHosts: ReadonlyArray<SshDeviceHostConfig>) {
1111 const value = yield* settings.updateSettings({ deviceHosts: [...deviceHosts] });
1112 const done = yield* Deferred.make<void>();
1113 yield* Queue.offer(changes, { value, done });
1114 yield* Deferred.await(done);
1115 return yield* service.state;
1116 });
1117
1118 const initial = yield* service.state;
1119 expect(yield* update([])).toEqual(initial);
1120
1121 const host: SshDeviceHostConfig = {
1122 kind: "ssh",
1123 id: "remote",
1124 label: "Remote",
1125 target: "remote-fixture",
1126 };
1127 const added = yield* update([host]);
1128 expect(added.hosts.map((entry) => entry.id)).toEqual([LOCAL_DEVICE_HOST_ID, host.id]);
1129 expect(yield* update([{ ...host }])).toEqual(added);
1130
1131 yield* service.setHostStatus(host.id, { status: "failed", detail: "stale" });
1132 const removed = yield* update([]);
1133 expect(removed.hosts.map((entry) => entry.id)).toEqual([LOCAL_DEVICE_HOST_ID]);
1134 expect(removed.hostStatuses[host.id]).toBeUndefined();
1135 expect(removedFiles).toHaveLength(1);
1136 }).pipe(
1137 Effect.scoped,
1138 Effect.provide(Layer.mergeAll(ServerSettings.layerTest(), NodeServices.layer)),
1139 ),
1140);
1141
1142it.effect("a failed tool update reports npm's exit code but not its output", () =>
1143 Effect.gen(function* () {
1144 const host: DeviceHost.DeviceHost["Service"] = {
1145 id: LOCAL_DEVICE_HOST_ID,
1146 label: "This machine",
1147 summary: Effect.succeed({
1148 id: LOCAL_DEVICE_HOST_ID,
1149 kind: "local",
1150 label: "Test server",
1151 platforms: [],
1152 hubInstalled: false,
1153 agentDeviceInstalled: false,
1154 }),
1155 platformAvailability: (platform) => Effect.succeed({ platform, available: false }),
1156 ensureReady: () => Effect.die("Updating a tool does not start the hub"),
1157 ensureAgentReady: () => Effect.die("Updating a tool does not start the agent"),
1158 current: Effect.succeed(null),
1159 stopAgent: Effect.void,
1160 stop: Effect.void,
1161 };
1162 const npmFailure = {
1163 code: ChildProcessSpawner.ExitCode(243),
1164 stdout: "",
1165 stderr: "npm error EACCES https://private:credential@registry.example.test/expo-device-hub",
1166 timedOut: false,
1167 stdoutTruncated: false,
1168 stderrTruncated: false,
1169 stdoutInvalidUtf8: false,
1170 stderrInvalidUtf8: false,
1171 };
1172 const service = yield* DeviceService.make.pipe(
1173 Effect.provideService(DeviceHost.DeviceHost, host),
1174 Effect.provideService(ProcessRunner.ProcessRunner, {
1175 run: () => Effect.succeed(npmFailure),
1176 }),
1177 Effect.provideService(
1178 HttpClient.HttpClient,
1179 HttpClient.make(() => Effect.die("Updating a tool makes no hub requests")),
1180 ),
1181 );
1182
1183 const error = yield* service.updateTool("hub").pipe(Effect.flip);
1184 expect(error).toMatchObject({
1185 _tag: "DeviceOperationError",
1186 reason: "command_failed",
1187 exitCode: 243,
1188 });
1189 expect(error.message).toBe(
1190 "Device update device tool failed: The device command failed (exit code 243).",
1191 );
1192 }).pipe(
1193 Effect.provide(
1194 Layer.mergeAll(
1195 ServerSettings.layerTest({ enableDeviceSupport: true }),
1196 ServerConfig.layerTest(process.cwd(), { prefix: "t3-device-update-" }),
1197 NodeCrypto.layer,
1198 NetService.layer,
1199 ).pipe(Layer.provideMerge(NodeServices.layer)),
1200 ),
1201 Effect.scoped,
1202 ),
1203);