Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { summarizeT3ToolCalls, type T3ToolSummaryCall } from "./t3ToolSummary.ts";
4
5function completed(input: unknown, output?: unknown): T3ToolSummaryCall {
6 return { input, output, outcome: "completed" };
7}
8
9describe("summarizeT3ToolCalls", () => {
10 it("reads provider result envelopes without treating JSON in the message as result data", () => {
11 const result = { messageId: "message-1", threadId: "actual-thread" };
12 const json = JSON.stringify(result);
13 const outputs = [
14 result,
15 { structuredContent: result },
16 [{ type: "text", text: json }],
17 { content: [{ text: { text: json } }], isError: false },
18 json,
19 ];
20 const calls = outputs.map((output) =>
21 completed(
22 {
23 toolName: "t3_thread_send",
24 args: { threadId: "input-thread", message: '{"threadId":"fake"}' },
25 },
26 output,
27 ),
28 );
29 expect(summarizeT3ToolCalls("thread-send", calls).label).toBe("Sent 1 message to 1 thread");
30 expect(
31 summarizeT3ToolCalls("thread-send", [
32 completed({ toolName: "t3_thread_send", args: { threadId: "input-thread" } }),
33 completed({ threadId: "input-thread" }),
34 ]).label,
35 ).toBe("Sent 2 messages to 1 thread");
36 });
37
38 it("excludes failed and unfinished sends even if the provider reports completed", () => {
39 const calls: T3ToolSummaryCall[] = [
40 completed({ threadId: "success" }, { messageId: "ok", threadId: "success" }),
41 completed(
42 { threadId: "failed" },
43 { isError: true, structuredContent: { threadId: "failed" } },
44 ),
45 completed({ threadId: "failed" }, [
46 { type: "text", text: JSON.stringify({ _tag: "OrchestratorMcpFailure" }) },
47 ]),
48 { input: { threadId: "cancelled" }, output: undefined, outcome: "unfinished" },
49 ];
50 expect(summarizeT3ToolCalls("thread-send", calls)).toEqual({
51 label: "Sent 1 message to 1 thread",
52 failedCount: 2,
53 });
54 expect(summarizeT3ToolCalls("thread-send", [calls[1]!])).toEqual({
55 label: "Tried to send 1 message to 1 thread",
56 failedCount: 1,
57 });
58 });
59
60 it("does not confuse a child's failure or wait timeout with failure of the orchestration call", () => {
61 const failedChild = { taskId: "task-1", status: "failed", summary: "command not found" };
62 expect(
63 summarizeT3ToolCalls("delegate", [completed({}, failedChild), completed({}, failedChild)]),
64 ).toEqual({
65 label: "Delegated 1 task",
66 failedCount: 0,
67 });
68 expect(
69 summarizeT3ToolCalls(
70 "task-status",
71 Array.from({ length: 4 }, () => completed({ taskId: "task-1" }, failedChild)),
72 ).label,
73 ).toBe("Checked task status 4 times");
74 expect(
75 summarizeT3ToolCalls("thread-wait", [
76 completed({ threadId: "thread-1" }, { threadId: "thread-1", timedOut: true }),
77 ]),
78 ).toEqual({
79 label: "Waited on 1 thread",
80 failedCount: 0,
81 });
82 });
83});