| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { agentDeviceQuickStart, agentDeviceTargetArgs, pngDimensions } from "./handlers.ts"; |
| 4 | |
| 5 | const device = { |
| 6 | hostId: "local", |
| 7 | id: "ABCD-1234", |
| 8 | platform: "ios" as const, |
| 9 | name: "iPhone 17 Pro", |
| 10 | version: "iOS 27.0", |
| 11 | booted: true, |
| 12 | physical: false, |
| 13 | }; |
| 14 | |
| 15 | describe("device tool helpers", () => { |
| 16 | it("pins agent-device commands to the device by platform-specific flag", () => { |
| 17 | expect(agentDeviceTargetArgs(device)).toEqual(["--platform", "ios", "--udid", "ABCD-1234"]); |
| 18 | expect(agentDeviceTargetArgs({ ...device, platform: "android", id: "emulator-5554" })).toEqual([ |
| 19 | "--platform", |
| 20 | "android", |
| 21 | "--serial", |
| 22 | "emulator-5554", |
| 23 | ]); |
| 24 | }); |
| 25 | |
| 26 | it("writes the quick start around the pinned target", () => { |
| 27 | const text = agentDeviceQuickStart(device); |
| 28 | expect(text).toContain("agent-device snapshot -i --platform ios --udid ABCD-1234"); |
| 29 | expect(text).toContain("iPhone 17 Pro (iOS 27.0)"); |
| 30 | expect(text).toContain("XCTest runner"); |
| 31 | }); |
| 32 | |
| 33 | it("uses the absolute launcher in every quick-start command", () => { |
| 34 | const text = agentDeviceQuickStart( |
| 35 | device, |
| 36 | ["--session", "thread-1", "--config", "/tmp/host.json"], |
| 37 | "/tmp/t3 tools/agent-device", |
| 38 | ); |
| 39 | expect(text).toContain( |
| 40 | "'/tmp/t3 tools/agent-device' snapshot -i --session thread-1 --config /tmp/host.json", |
| 41 | ); |
| 42 | expect(text).not.toContain(" agent-device "); |
| 43 | expect(text).not.toContain("is on PATH"); |
| 44 | }); |
| 45 | |
| 46 | it("reads PNG dimensions from the IHDR chunk", () => { |
| 47 | const png = new Uint8Array(24); |
| 48 | new DataView(png.buffer).setUint32(0, 0x89504e47); |
| 49 | new DataView(png.buffer).setUint32(4, 0x0d0a1a0a); |
| 50 | new DataView(png.buffer).setUint32(12, 0x49484452); |
| 51 | new DataView(png.buffer).setUint32(16, 1179); |
| 52 | new DataView(png.buffer).setUint32(20, 2556); |
| 53 | expect(pngDimensions(png)).toEqual({ width: 1179, height: 2556 }); |
| 54 | expect(pngDimensions(new Uint8Array([1, 2, 3]))).toEqual({ width: 0, height: 0 }); |
| 55 | }); |
| 56 | }); |