Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import {
4 DeviceHostUnavailableError,
5 DeviceId,
6 EnvironmentId,
7 ProviderInstanceId,
8 ThreadId,
9} from "@t3tools/contracts";
10import * as Effect from "effect/Effect";
11import * as Layer from "effect/Layer";
12import * as Option from "effect/Option";
13import { McpSchema, McpServer } from "effect/ai";
14
15import * as ServerConfig from "../config.ts";
16import * as DeviceService from "../device/DeviceService.ts";
17import * as ProjectService from "../project/ProjectService.ts";
18import * as McpHttpServer from "./McpHttpServer.ts";
19import * as McpInvocationContext from "./McpInvocationContext.ts";
20import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts";
21
22const environmentId = EnvironmentId.make("environment-device-test");
23const threadId = ThreadId.make("thread-device-test");
24const invocation = (capabilities: ReadonlyArray<McpInvocationContext.McpCapability>) => ({
25 environmentId,
26 requestNamespace: "provider-session-device-test",
27 thread: {
28 threadId,
29 providerSessionId: "provider-session-device-test",
30 providerInstanceId: ProviderInstanceId.make("codex"),
31 },
32 client: undefined,
33 capabilities: new Set(capabilities),
34 issuedAt: 1,
35});
36const client = McpSchema.McpServerClient.of({
37 clientId: 1,
38 clientCapabilities: {},
39 clientInfo: { name: "mcp-test", version: "1.0.0" },
40 protocolVersion: "2025-06-18",
41 initializePayload: {
42 protocolVersion: "2025-06-18",
43 capabilities: {},
44 clientInfo: { name: "mcp-test", version: "1.0.0" },
45 },
46 getClient: Effect.die("unused"),
47});
48
49const device = {
50 hostId: "local",
51 id: "UDID-1",
52 platform: "ios" as const,
53 name: "iPhone 17 Pro",
54 version: "iOS 27.0",
55 booted: true,
56 physical: false,
57};
58const state = {
59 hosts: [
60 {
61 id: "local",
62 kind: "local" as const,
63 label: "This machine",
64 platforms: [
65 { platform: "ios" as const, available: true },
66 { platform: "android" as const, available: false, reason: "No SDK" },
67 ],
68 hubInstalled: true,
69 agentDeviceInstalled: true,
70 },
71 ],
72 hostStatus: "ready" as const,
73 hostStatuses: { local: { status: "ready" as const } },
74 devices: [device],
75 sessions: [],
76 onboardingCompleted: true,
77 agentAccessEnabled: true,
78 hubBasePath: "/api/device-hub",
79 revision: 1,
80};
81const png = new Uint8Array(24);
82new DataView(png.buffer).setUint32(0, 0x89504e47);
83new DataView(png.buffer).setUint32(4, 0x0d0a1a0a);
84new DataView(png.buffer).setUint32(12, 0x49484452);
85new DataView(png.buffer).setUint32(16, 1206);
86new DataView(png.buffer).setUint32(20, 2622);
87
88const unused = Effect.die("not used");
89const readiness = {
90 hostId: "local",
91 nodePath: process.execPath,
92 hub: { origin: "http://hub.test" },
93 devices: {
94 list: unused,
95 boot: () => unused,
96 attach: () => unused,
97 shutdown: () => unused,
98 screenshot: () => unused,
99 },
100 run: () => unused,
101 helpers: { serveSimAxSettings: null, serveSimCli: null },
102 agentDevice: null,
103};
104const layerProjectsMock = Layer.mock(ProjectService.ProjectService)({
105 getById: () => Effect.succeedNone,
106});
107
108const openSession = {
109 threadId,
110 hostId: "local",
111 deviceId: DeviceId.make("UDID-1"),
112 platform: "ios" as const,
113 openedAt: "2026-09-08T00:00:00.000Z",
114};
115const layerDeviceServiceMock = Layer.mock(DeviceService.DeviceService)({
116 state: Effect.succeed(state),
117 list: Effect.succeed(state),
118 agentReadinessIfSupported: () => Effect.succeed(readiness),
119 open: (input) =>
120 Effect.succeed({
121 threadId: input.threadId,
122 hostId: "local",
123 deviceId: input.deviceId,
124 platform: input.platform,
125 openedAt: "2026-09-08T00:00:00.000Z",
126 }),
127
128 sessionsForThread: (id) => Effect.succeed(id === threadId ? [openSession] : []),
129 locateSession: (input) =>
130 Effect.succeed(
131 input.threadId === threadId && input.deviceId === openSession.deviceId
132 ? Option.some(openSession)
133 : Option.none(),
134 ),
135 screenshot: () => Effect.succeed({ device, png }),
136 close: () => Effect.void,
137 testHost: () => Effect.die("not used"),
138 // As for an EAS device, agent-device knows the device by a different id than T3.
139 agentTarget: () =>
140 Effect.succeed({
141 agentDeviceId: "SIM-UDID",
142 session: "thread-device",
143 args: ["--config", "/host.json", "--session", "thread-device"],
144 }),
145 agentLauncher: ({ targetArgs }) =>
146 Effect.succeedSome(`/state/device/targets/thread-device/${targetArgs.join("_")}/agent-device`),
147});
148
149const layerTest = McpHttpServer.layerDeviceToolkit.pipe(
150 Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
151 Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
152 Layer.provideMerge(layerDeviceServiceMock),
153 Layer.provide(layerProjectsMock),
154 Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-device-toolkit-test-" })),
155 Layer.provide(NodeServices.layer),
156);
157
158it.effect("registers the device tools and returns the screenshot as image content", () =>
159 Effect.scoped(
160 Effect.gen(function* () {
161 const server = yield* McpServer.McpServer;
162 const names = server.tools.map(({ tool }) => tool.name).toSorted();
163 expect(names).toEqual(["device_close", "device_list", "device_open", "device_screenshot"]);
164
165 const callWith = (capabilities: ReadonlyArray<McpInvocationContext.McpCapability>) =>
166 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(capabilities));
167
168 const opened = yield* server
169 .callTool({ name: "device_open", arguments: { platform: "ios" } })
170 .pipe(callWith(["device"]), Effect.provideService(McpSchema.McpServerClient, client));
171 expect(opened.isError).toBe(false);
172 const openedContent = opened.structuredContent as {
173 agentDevice: { command: string; targetArgs: ReadonlyArray<string>; session: string };
174 quickStart: string;
175 };
176 // Callers that pass the target flags, like test-t3-mobile's pair-client.sh, keep working.
177 expect(openedContent.agentDevice).toMatchObject({
178 targetArgs: [
179 "--platform",
180 "ios",
181 "--udid",
182 "SIM-UDID",
183 "--config",
184 "/host.json",
185 "--session",
186 "thread-device",
187 ],
188 session: "thread-device",
189 });
190 expect(openedContent.quickStart).toContain(
191 `${openedContent.agentDevice.command} snapshot -i`,
192 );
193 // The launcher selects the device by agent-device's id for it, not T3's.
194 expect(openedContent.agentDevice.command).toBe(
195 "/state/device/targets/thread-device/--platform_ios_--udid_SIM-UDID_--config_/host.json_--session_thread-device/agent-device",
196 );
197
198 const shot = yield* server
199 .callTool({ name: "device_screenshot", arguments: { deviceId: "UDID-1" } })
200 .pipe(callWith(["device"]), Effect.provideService(McpSchema.McpServerClient, client));
201 expect(shot.isError).toBe(false);
202 expect(shot.content.map((entry) => entry.type)).toEqual(["text", "image"]);
203 expect(shot.structuredContent).toMatchObject({
204 screenshot: { mimeType: "image/png", width: 1206, height: 2622 },
205 });
206
207 const foreign = yield* server
208 .callTool({ name: "device_screenshot", arguments: { deviceId: "UDID-2" } })
209 .pipe(callWith(["device"]), Effect.provideService(McpSchema.McpServerClient, client));
210 expect(foreign.isError).toBe(true);
211 expect(foreign.content.map((entry) => entry.type)).toEqual(["text"]);
212
213 const listed = yield* server
214 .callTool({ name: "device_list", arguments: { hostId: "THIS MACHINE" } })
215 .pipe(callWith(["device"]), Effect.provideService(McpSchema.McpServerClient, client));
216 expect(listed.structuredContent).toMatchObject({
217 hosts: [{ id: "local" }],
218 devices: [device],
219 });
220
221 const unknownHost = yield* server
222 .callTool({ name: "device_screenshot", arguments: { hostId: "oliverMac" } })
223 .pipe(callWith(["device"]), Effect.provideService(McpSchema.McpServerClient, client));
224 expect(unknownHost.isError).toBe(true);
225 expect(unknownHost.content).toEqual([
226 { type: "text", text: "No device host oliverMac. Known hosts: This machine (local)." },
227 ]);
228
229 const denied = yield* server
230 .callTool({ name: "device_list", arguments: {} })
231 .pipe(callWith(["preview"]), Effect.provideService(McpSchema.McpServerClient, client));
232 expect(denied.isError).toBe(true);
233 // The agent can't see Settings, and a running session keeps the capabilities it started with,
234 // so the error says where the user turns access on and when it applies.
235 expect(denied.content).toEqual([
236 {
237 type: "text",
238 text: "Agent device access is turned off for this environment. Ask the user to turn on Agent device access in Settings > Integrations > Devices; it applies when the agent session next starts, such as in a new thread.",
239 },
240 ]);
241 }),
242 ).pipe(Effect.provide(layerTest)),
243);
244
245it.effect("rejects unavailable agent access before booting or opening a device", () => {
246 const layerUnavailable = Layer.mock(DeviceService.DeviceService)({
247 list: Effect.succeed(state),
248 agentReadinessIfSupported: () =>
249 Effect.fail(
250 new DeviceHostUnavailableError({ hostId: "local", reason: "Agent access is disabled." }),
251 ),
252 open: () => Effect.die("Must not boot or register a device when agent access fails"),
253 });
254 return Effect.gen(function* () {
255 const server = yield* McpServer.McpServer;
256 const result = yield* server
257 .callTool({ name: "device_open", arguments: { platform: "ios" } })
258 .pipe(
259 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(["device"])),
260 Effect.provideService(McpSchema.McpServerClient, client),
261 );
262 expect(result.isError).toBe(true);
263 expect(result.content).toEqual(
264 expect.arrayContaining([
265 expect.objectContaining({
266 type: "text",
267 text: expect.stringContaining("Agent access is disabled."),
268 }),
269 ]),
270 );
271 }).pipe(
272 Effect.scoped,
273 Effect.provide(
274 McpHttpServer.layerDeviceToolkit.pipe(
275 Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
276 Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
277 Layer.provide(layerUnavailable),
278 Layer.provide(layerProjectsMock),
279 Layer.provide(
280 ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-device-toolkit-test-" }),
281 ),
282 Layer.provide(NodeServices.layer),
283 ),
284 ),
285 );
286});
287
288describe("device targeting across hosts", () => {
289 const macHost = {
290 id: "mac-mini",
291 kind: "ssh" as const,
292 label: "Mac Mini",
293 platforms: [
294 { platform: "ios" as const, available: true },
295 { platform: "android" as const, available: true },
296 ],
297 hubInstalled: true,
298 agentDeviceInstalled: true,
299 };
300 const macIphone = { ...device, hostId: "mac-mini", id: "MAC-UDID" };
301 const localPixel = {
302 hostId: "local",
303 id: "Pixel_10",
304 platform: "android" as const,
305 name: "Pixel 10",
306 version: "Android 16",
307 booted: false,
308 physical: false,
309 };
310 const macPixel = { ...localPixel, hostId: "mac-mini" };
311 const multiHostState = {
312 ...state,
313 hosts: [...state.hosts, macHost],
314 hostStatuses: {
315 local: { status: "ready" as const },
316 "mac-mini": { status: "ready" as const },
317 },
318 devices: [device, macIphone, localPixel, macPixel],
319 };
320 const session = (hostId: string, deviceId: string, platform: "ios" | "android") => ({
321 threadId,
322 hostId,
323 deviceId: DeviceId.make(deviceId),
324 platform,
325 openedAt: "2026-09-08T00:00:00.000Z",
326 });
327 const thisMachine = { id: "local", label: "This machine" };
328 const macMini = { id: macHost.id, label: macHost.label };
329 // DeviceService's lookup errors; DeviceService.test.ts covers when each arises.
330 const onTwoHosts = new DeviceService.DeviceHostAmbiguousError({
331 deviceId: DeviceId.make("Pixel_10"),
332 hosts: [thisMachine, macMini],
333 });
334 const onTheMac = new DeviceService.DeviceOnOtherHostError({
335 deviceId: DeviceId.make("MAC-UDID"),
336 host: thisMachine,
337 hosts: [macMini],
338 });
339
340 const run = <A, E>(
341 sessions: ReadonlyArray<ReturnType<typeof session>>,
342 program: (calls: {
343 readonly opened: Array<{ hostId: string; deviceId: string }>;
344 readonly closed: Array<{ hostId?: string | undefined; deviceId?: string | undefined }>;
345 readonly call: (
346 name: string,
347 args: Record<string, unknown>,
348 ) => Effect.Effect<McpSchema.CallToolResult, McpSchema.McpErrorBase, McpServer.McpServer>;
349 }) => Effect.Effect<A, E, McpServer.McpServer>,
350 overrides: Partial<DeviceService.DeviceService["Service"]> = {},
351 ) => {
352 const opened: Array<{ hostId: string; deviceId: string }> = [];
353 const closed: Array<{ hostId?: string | undefined; deviceId?: string | undefined }> = [];
354 const layerDevices = Layer.mock(DeviceService.DeviceService)({
355 state: Effect.succeed(multiHostState),
356 list: Effect.succeed(multiHostState),
357 agentReadinessIfSupported: () => Effect.succeed(readiness),
358 open: (input) =>
359 Effect.sync(() => {
360 opened.push({ hostId: input.hostId ?? "local", deviceId: input.deviceId });
361 return session(input.hostId ?? "local", input.deviceId, input.platform);
362 }),
363 sessionsForThread: () => Effect.succeed(sessions),
364 locateDevice: (input) =>
365 Effect.succeed(
366 Option.fromUndefinedOr(
367 multiHostState.devices.find(
368 (candidate) =>
369 candidate.id === input.deviceId &&
370 (input.hostId === undefined || candidate.hostId === input.hostId),
371 ),
372 ),
373 ),
374 locateSession: (input) =>
375 Effect.succeed(
376 Option.fromUndefinedOr(
377 sessions.find(
378 (candidate) =>
379 candidate.deviceId === input.deviceId &&
380 (input.hostId === undefined || candidate.hostId === input.hostId),
381 ),
382 ),
383 ),
384 screenshot: (target) =>
385 Effect.succeed({
386 device:
387 multiHostState.devices.find(
388 (candidate) => candidate.hostId === target.hostId && candidate.id === target.deviceId,
389 ) ?? device,
390 png,
391 }),
392 close: (input) =>
393 Effect.sync(() => {
394 closed.push({ hostId: input.hostId, deviceId: input.deviceId });
395 }),
396 agentTarget: () =>
397 Effect.succeed({
398 agentDeviceId: "MAC-UDID",
399 session: "thread-device",
400 args: ["--config", "/mac.json", "--session", "thread-device"],
401 }),
402 agentLauncher: () => Effect.succeedSome("/state/device/targets/thread-device/agent-device"),
403 ...overrides,
404 });
405 const call = (name: string, args: Record<string, unknown>) =>
406 McpServer.McpServer.pipe(
407 Effect.flatMap((server) => server.callTool({ name, arguments: args })),
408 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(["device"])),
409 Effect.provideService(McpSchema.McpServerClient, client),
410 );
411 return program({ opened, closed, call }).pipe(
412 Effect.scoped,
413 Effect.provide(
414 McpHttpServer.layerDeviceToolkit.pipe(
415 Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
416 Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
417 Layer.provide(layerDevices),
418 Layer.provide(layerProjectsMock),
419 Layer.provide(
420 ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-device-toolkit-test-" }),
421 ),
422 Layer.provide(NodeServices.layer),
423 ),
424 ),
425 );
426 };
427 const text = (result: McpSchema.CallToolResult) =>
428 result.content.flatMap((entry) => (entry.type === "text" ? [entry.text] : [])).join("\n");
429
430 it.effect("opens a device id that exists only on another host", () =>
431 run([], ({ opened, call }) =>
432 Effect.gen(function* () {
433 const result = yield* call("device_open", { deviceId: "MAC-UDID" });
434 const byLabel = yield* call("device_open", { platform: "ios", hostId: "MAC MINI" });
435 expect(byLabel.isError).toBe(false);
436 expect(text(result)).not.toContain("No device");
437 expect(result.isError).toBe(false);
438 expect(opened).toEqual([
439 { hostId: "mac-mini", deviceId: "MAC-UDID" },
440 { hostId: "mac-mini", deviceId: "MAC-UDID" },
441 ]);
442 }),
443 ),
444 );
445
446 it.effect("binds the launcher to the id the device booted with", () => {
447 const targets: Array<string> = [];
448 return run(
449 [],
450 ({ call }) =>
451 Effect.gen(function* () {
452 const result = yield* call("device_open", { deviceId: "Pixel_10", hostId: "mac-mini" });
453 expect(result.isError).toBe(false);
454 expect(targets).toEqual(["emulator-5554", "emulator-5554"]);
455 }),
456 {
457 open: (input) =>
458 Effect.succeed(session(input.hostId ?? "local", "emulator-5554", "android")),
459 agentTarget: (target) =>
460 Effect.sync(() => {
461 targets.push(target.deviceId);
462 return { agentDeviceId: target.deviceId, session: "thread-device", args: [] };
463 }),
464 agentLauncher: (target) =>
465 Effect.sync(() => {
466 targets.push(target.deviceId);
467 return Option.some("/state/device/targets/thread-device/agent-device");
468 }),
469 },
470 );
471 });
472
473 it.effect("says a device closed during device_open was closed, not that its host is down", () =>
474 run(
475 [],
476 ({ call }) =>
477 Effect.gen(function* () {
478 const result = yield* call("device_open", { deviceId: "MAC-UDID" });
479 expect(result.isError).toBe(true);
480 expect(text(result)).toBe(
481 "The device was closed while device_open was preparing it. Call device_open again only if you still need it.",
482 );
483 }),
484 { agentLauncher: () => Effect.succeedNone },
485 ),
486 );
487
488 it.effect("refuses a device id that exists on two hosts and names both", () =>
489 run(
490 [],
491 ({ opened, call }) =>
492 Effect.gen(function* () {
493 const result = yield* call("device_open", { deviceId: "Pixel_10" });
494 expect(result.isError).toBe(true);
495 expect(text(result)).toContain("hostId local");
496 expect(text(result)).toContain("hostId mac-mini");
497 expect(text(result)).toBe(
498 "Device Pixel_10 is on more than one host: 'This machine' (hostId local), 'Mac Mini' (hostId mac-mini). Pass hostId.",
499 );
500 expect(opened).toEqual([]);
501 }),
502 { locateDevice: () => Effect.fail(onTwoHosts) },
503 ),
504 );
505
506 it.effect("keeps an explicit hostId and says which host has the device", () =>
507 run(
508 [],
509 ({ opened, call }) =>
510 Effect.gen(function* () {
511 const result = yield* call("device_open", { deviceId: "MAC-UDID", hostId: "local" });
512 expect(result.isError).toBe(true);
513 expect(text(result)).toContain("hostId mac-mini");
514 expect(text(result)).toBe(
515 "Device MAC-UDID is not on 'This machine' (hostId local). It is on 'Mac Mini' (hostId mac-mini); pass that hostId.",
516 );
517 expect(opened).toEqual([]);
518 }),
519 { locateDevice: () => Effect.fail(onTheMac) },
520 ),
521 );
522
523 it.effect("says no host has a device id, naming the host it was asked on", () =>
524 run([], ({ opened, call }) =>
525 Effect.gen(function* () {
526 const missing = (args: Record<string, unknown>) =>
527 call("device_open", { deviceId: "Pixel_9", ...args }).pipe(Effect.map(text));
528 expect(yield* missing({})).toBe(
529 "No device Pixel_9 on any host. Call device_list for current ids.",
530 );
531 expect(yield* missing({ hostId: "mac-mini" })).toBe(
532 "No device Pixel_9 on 'Mac Mini' (hostId mac-mini). Call device_list for current ids.",
533 );
534 expect(yield* missing({ hostId: "unknown-host" })).toBe(
535 "No device host unknown-host. Known hosts: This machine (local), Mac Mini (mac-mini).",
536 );
537 expect(opened).toEqual([]);
538 }),
539 ),
540 );
541
542 it.effect("screenshots an open device by id on whichever host it is on", () =>
543 run([session("mac-mini", "MAC-UDID", "ios")], ({ call }) =>
544 Effect.gen(function* () {
545 const result = yield* call("device_screenshot", { deviceId: "MAC-UDID" });
546 expect(result.isError).toBe(false);
547 expect(result.structuredContent).toMatchObject({ device: { hostId: "mac-mini" } });
548 const byLabel = yield* call("device_screenshot", { hostId: "MAC MINI" });
549 expect(byLabel.isError).toBe(false);
550 expect(byLabel.structuredContent).toMatchObject({ device: { hostId: "mac-mini" } });
551 }),
552 ),
553 );
554
555 it.effect("says why device_screenshot failed instead of a generic error", () =>
556 run(
557 [session("mac-mini", "MAC-UDID", "ios")],
558 ({ call }) =>
559 Effect.gen(function* () {
560 const wrongHost = yield* call("device_screenshot", {
561 deviceId: "MAC-UDID",
562 hostId: "local",
563 });
564 expect(wrongHost.isError).toBe(true);
565 expect(text(wrongHost)).toContain("It is on 'Mac Mini' (hostId mac-mini)");
566 expect(text(wrongHost)).toBe(
567 "Device MAC-UDID is not on 'This machine' (hostId local). It is on 'Mac Mini' (hostId mac-mini); pass that hostId.",
568 );
569 }),
570 { locateSession: () => Effect.fail(onTheMac) },
571 ),
572 );
573
574 it.effect("tells an agent to open a device id before screenshotting it", () =>
575 run([], ({ call }) =>
576 Effect.gen(function* () {
577 const result = yield* call("device_screenshot", { deviceId: "MAC-UDID" });
578 expect(result.isError).toBe(true);
579 expect(text(result)).toBe(
580 "Device MAC-UDID is not open in this thread. Call device_open first.",
581 );
582 }),
583 ),
584 );
585
586 it.effect("tells an agent with no open device to call device_open before a screenshot", () =>
587 run([], ({ call }) =>
588 Effect.gen(function* () {
589 const result = yield* call("device_screenshot", {});
590 expect(result.isError).toBe(true);
591 expect(text(result)).toBe("No device is open in this thread. Call device_open first.");
592 expect(result.structuredContent).toMatchObject({
593 error: { _tag: "DeviceToolUnavailableError" },
594 });
595 }),
596 ),
597 );
598
599 it.effect("refuses to close an id open on two hosts instead of closing both", () =>
600 run(
601 [session("local", "Pixel_10", "android"), session("mac-mini", "Pixel_10", "android")],
602 ({ closed, call }) =>
603 Effect.gen(function* () {
604 const result = yield* call("device_close", { deviceId: "Pixel_10" });
605 expect(result.isError).toBe(true);
606 expect(text(result)).toContain("hostId mac-mini");
607 expect(text(result)).toBe(
608 "Device Pixel_10 is on more than one host: 'This machine' (hostId local), 'Mac Mini' (hostId mac-mini). Pass hostId.",
609 );
610 expect(closed).toEqual([]);
611 }),
612 { locateSession: () => Effect.fail(onTwoHosts) },
613 ),
614 );
615
616 it.effect("closes an open device on its host and treats an unopened one as closed", () =>
617 run([session("mac-mini", "MAC-UDID", "ios")], ({ closed, call }) =>
618 Effect.gen(function* () {
619 expect((yield* call("device_close", { deviceId: "MAC-UDID" })).isError).toBe(false);
620 expect((yield* call("device_close", { deviceId: "Pixel_9" })).isError).toBe(false);
621 expect((yield* call("device_close", { hostId: "MAC MINI" })).isError).toBe(false);
622 const unknown = yield* call("device_close", { hostId: "unknown-host" });
623 expect(unknown.isError).toBe(true);
624 expect(text(unknown)).toContain("No device host unknown-host.");
625 expect(closed).toEqual([
626 { hostId: "mac-mini", deviceId: "MAC-UDID" },
627 { hostId: undefined, deviceId: "Pixel_9" },
628 { hostId: "mac-mini", deviceId: undefined },
629 ]);
630 }),
631 ),
632 );
633});