Skip to content

Commit 5f077f0

Browse files
committed
test(server): cover host labels across device tools
1 parent 43a84a3 commit 5f077f0

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎apps/server/src/mcp/McpDeviceToolkit.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,14 @@ describe("device targeting across hosts", () => {
435435
run([], ({ opened, call }) =>
436436
Effect.gen(function* () {
437437
const result = yield* call("device_open", { deviceId: "MAC-UDID" });
438+
const byLabel = yield* call("device_open", { platform: "ios", hostId: "MAC MINI" });
439+
expect(byLabel.isError).toBe(false);
438440
expect(text(result)).not.toContain("No device");
439441
expect(result.isError).toBe(false);
440-
expect(opened).toEqual([{ hostId: "mac-mini", deviceId: "MAC-UDID" }]);
442+
expect(opened).toEqual([
443+
{ hostId: "mac-mini", deviceId: "MAC-UDID" },
444+
{ hostId: "mac-mini", deviceId: "MAC-UDID" },
445+
]);
441446
}),
442447
),
443448
);
@@ -531,7 +536,7 @@ describe("device targeting across hosts", () => {
531536
"No device Pixel_9 on 'Mac Mini' (hostId mac-mini). Call device_list for current ids.",
532537
);
533538
expect(yield* missing({ hostId: "unknown-host" })).toBe(
534-
"No device Pixel_9 on hostId unknown-host. Call device_list for current ids.",
539+
"No device host unknown-host. Known hosts: This machine (local), Mac Mini (mac-mini).",
535540
);
536541
expect(opened).toEqual([]);
537542
}),
@@ -544,6 +549,9 @@ describe("device targeting across hosts", () => {
544549
const result = yield* call("device_screenshot", { deviceId: "MAC-UDID" });
545550
expect(result.isError).toBe(false);
546551
expect(result.structuredContent).toMatchObject({ device: { hostId: "mac-mini" } });
552+
const byLabel = yield* call("device_screenshot", { hostId: "MAC MINI" });
553+
expect(byLabel.isError).toBe(false);
554+
expect(byLabel.structuredContent).toMatchObject({ device: { hostId: "mac-mini" } });
547555
}),
548556
),
549557
);
@@ -614,9 +622,14 @@ describe("device targeting across hosts", () => {
614622
Effect.gen(function* () {
615623
expect((yield* call("device_close", { deviceId: "MAC-UDID" })).isError).toBe(false);
616624
expect((yield* call("device_close", { deviceId: "Pixel_9" })).isError).toBe(false);
625+
expect((yield* call("device_close", { hostId: "MAC MINI" })).isError).toBe(false);
626+
const unknown = yield* call("device_close", { hostId: "unknown-host" });
627+
expect(unknown.isError).toBe(true);
628+
expect(text(unknown)).toContain("No device host unknown-host.");
617629
expect(closed).toEqual([
618630
{ hostId: "mac-mini", deviceId: "MAC-UDID" },
619631
{ hostId: undefined, deviceId: "Pixel_9" },
632+
{ hostId: "mac-mini", deviceId: undefined },
620633
]);
621634
}),
622635
),

‎apps/server/src/mcp/toolkits/device/handlers.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ describe("device tool helpers", () => {
3131
it.effect("resolves a host by exact id or case-insensitive label", () =>
3232
Effect.gen(function* () {
3333
const mac = "0dc4f37b-5e0a-4f4c-9a51-0c6b8e8a1f2d";
34+
expect(yield* resolveHostId(hosts, undefined)).toBeUndefined();
35+
expect(yield* resolveHostId([...hosts, { ...hosts[1]!, label: "local" }], "local")).toBe(
36+
"local",
37+
);
3438
expect(yield* resolveHostId(hosts, mac)).toBe(mac);
3539
expect(yield* resolveHostId(hosts, "olivermac")).toBe(mac);
3640
}),

0 commit comments

Comments
 (0)