@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 105 lines 4.52 KB
Raw
1 import type { DeviceHostSummary } from "@t3tools/contracts";
2 import * as Effect from "effect/Effect";
3 import { describe, expect, it } from "@effect/vitest";
4
5 import { agentDeviceQuickStart, pngDimensions, resolveHostId } from "./handlers.ts";
6
7 const device = {
8 hostId: "local",
9 id: "ABCD-1234",
10 platform: "ios" as const,
11 name: "iPhone 17 Pro",
12 version: "iOS 27.0",
13 booted: true,
14 physical: false,
15 };
16
17 const hosts = [
18 { id: "local", label: "This machine" },
19 { id: "0dc4f37b-5e0a-4f4c-9a51-0c6b8e8a1f2d", label: "oliverMac" },
20 { id: "mini-1", label: "Mac mini" },
21 { id: "mini-2", label: "Mac mini" },
22 ].map((host): DeviceHostSummary => ({
23 ...host,
24 kind: host.id === "local" ? "local" : "ssh",
25 platforms: [],
26 hubInstalled: true,
27 agentDeviceInstalled: true,
28 }));
29
30 describe("device tool helpers", () => {
31 it.effect("resolves a host by exact id or case-insensitive label", () =>
32 Effect.gen(function* () {
33 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 );
38 expect(yield* resolveHostId(hosts, mac)).toBe(mac);
39 expect(yield* resolveHostId(hosts, "olivermac")).toBe(mac);
40 }),
41 );
42
43 it.effect("rejects an unknown or ambiguous host and lists the candidates", () =>
44 Effect.gen(function* () {
45 const unknown = yield* Effect.flip(resolveHostId(hosts, "studio"));
46 expect(unknown.reason).toContain("This machine (local)");
47 expect(unknown.reason).toContain("oliverMac (0dc4f37b-5e0a-4f4c-9a51-0c6b8e8a1f2d)");
48 const ambiguous = yield* Effect.flip(resolveHostId(hosts, "mac mini"));
49 expect(ambiguous.reason).toContain("Mac mini (mini-1), Mac mini (mini-2)");
50 expect(ambiguous.reason).not.toContain("oliverMac");
51 }),
52 );
53
54 it("uses the absolute launcher in every quick-start command", () => {
55 const text = agentDeviceQuickStart(
56 device,
57 ["--session", "thread-1", "--config", "/tmp/host.json"],
58 "/tmp/t3 tools/agent-device",
59 );
60 expect(text).toContain(
61 "'/tmp/t3 tools/agent-device' snapshot -i --session thread-1 --config /tmp/host.json",
62 );
63 expect(text).not.toContain(" agent-device ");
64 expect(text).not.toContain("is on PATH");
65 });
66
67 it("shows a bound launcher's commands without flags and keeps device actions off simctl and ssh", () => {
68 const command = "/state/device/targets/t3-a/agent-device";
69 const text = agentDeviceQuickStart(device, [], command);
70 const examples = text.split("\n").filter((line) => line.trimStart().startsWith(command));
71 expect(examples).toContain(` ${command} snapshot -i # accessibility tree with @eN refs`);
72 expect(examples.find((line) => line.includes(" screenshot "))).toContain("--pixel-density <n>");
73 expect(agentDeviceQuickStart({ ...device, platform: "android" }, [], command)).not.toContain(
74 "--pixel-density",
75 );
76 expect(examples.join("\n")).not.toMatch(/--(?:platform|udid|serial|config|session)\b/);
77 expect(text).not.toContain("remain available");
78 expect(text).toContain("Do not use simctl, idb, adb or ssh for those actions.");
79 expect(text).toContain("If it is missing, call device_open again.");
80 });
81
82 it("opens the app before snapshots, CLI screenshots or input, looks with device_screenshot, and records the device screen", () => {
83 const command = "/state/device/targets/t3-a/agent-device";
84 const text = agentDeviceQuickStart(device, [], command);
85 // device_open starts no agent-device session, and an iOS snapshot needs one with an app.
86 expect(text).toContain(
87 "Run open <bundle-or-package-id> (apps lists them) before snapshots, CLI screenshots or input; it starts the session they need. Use device_screenshot just to look.",
88 );
89 // App-scoped recording needs an app opened in the session; device scope does not.
90 expect(text).toContain(
91 ` ${command} record start --scope device /tmp/run.mp4 # then record stop`,
92 );
93 });
94
95 it("reads PNG dimensions from the IHDR chunk", () => {
96 const png = new Uint8Array(24);
97 new DataView(png.buffer).setUint32(0, 0x89504e47);
98 new DataView(png.buffer).setUint32(4, 0x0d0a1a0a);
99 new DataView(png.buffer).setUint32(12, 0x49484452);
100 new DataView(png.buffer).setUint32(16, 1179);
101 new DataView(png.buffer).setUint32(20, 2556);
102 expect(pngDimensions(png)).toEqual({ width: 1179, height: 2556 });
103 expect(pngDimensions(new Uint8Array([1, 2, 3]))).toEqual({ width: 0, height: 0 });
104 });
105 });