Open History to see the last commit
1import type { OrchestrationV2TurnItem, RunId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { isRunUsingComputer, selectLatestComputerUse } from "./computerUsePreview";
5
6const tool = (
7 id: string,
8 status: OrchestrationV2TurnItem["status"],
9 extra: Partial<Extract<OrchestrationV2TurnItem, { type: "dynamic_tool" }>> = {},
10) =>
11 ({
12 id,
13 type: "dynamic_tool",
14 status,
15 toolName: "mcp__cua-driver__click",
16 input: {},
17 ...extra,
18 }) as unknown as OrchestrationV2TurnItem;
19
20describe("selectLatestComputerUse", () => {
21 it("picks the newest computer use call with its app, whatever the provider", () => {
22 const safari = {
23 _tag: "native-app",
24 app: { _tag: "app-id", appId: "com.apple.Safari" },
25 } as const;
26 expect(
27 selectLatestComputerUse([
28 tool("older", "completed", { toolSurface: "computer" }),
29 tool("newest", "running", {
30 toolSurface: "computer",
31 toolIcon: safari,
32 toolSource: { key: "native-app:com.apple.safari", name: "Safari", kind: "computer" },
33 }),
34 tool("unrelated", "running"),
35 ]),
36 ).toEqual({
37 itemId: "newest",
38 app: safari.app,
39 appName: "Safari",
40 inProgress: true,
41 });
42 });
43
44 it("finds nothing in a thread without computer use", () => {
45 expect(selectLatestComputerUse([tool("plain", "completed")])).toBeNull();
46 });
47});
48
49describe("isRunUsingComputer", () => {
50 const run = "run-1" as RunId;
51 it("is true only once the running run has made a computer use call", () => {
52 const earlier = tool("earlier", "completed", {
53 runId: "run-0" as RunId,
54 toolSurface: "computer",
55 });
56 const plain = tool("plain", "completed", { runId: run });
57 expect(isRunUsingComputer([earlier, plain], run)).toBe(false);
58 expect(
59 isRunUsingComputer(
60 [earlier, plain, tool("click", "completed", { runId: run, toolSurface: "computer" })],
61 run,
62 ),
63 ).toBe(true);
64 expect(isRunUsingComputer([earlier], null)).toBe(false);
65 });
66});