Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AcpCoreRuntimeEvents.test.ts

245 lines7.1 KB

1import { ProviderDriverKind, RuntimeRequestId, TurnId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 makeAcpAssistantItemEvent,
6 makeAcpContentDeltaEvent,
7 makeAcpPlanUpdatedEvent,
8 makeAcpRequestOpenedEvent,
9 makeAcpRequestResolvedEvent,
10 makeAcpToolCallEvent,
11} from "./AcpCoreRuntimeEvents.ts";
12​
13describe("AcpCoreRuntimeEvents", () => {
14 it("maps ACP permission requests to canonical runtime events", () => {
15 const stamp = { eventId: "event-1" as never, createdAt: "2026-03-27T00:00:00.000Z" };
16 const turnId = TurnId.make("turn-1");
17 const permissionRequest = {
18 kind: "execute" as const,
19 detail: "cat package.json",
20 toolCall: {
21 toolCallId: "tool-1",
22 kind: "execute",
23 status: "pending" as const,
24 command: "cat package.json",
25 detail: "cat package.json",
26 data: { toolCallId: "tool-1", kind: "execute" },
27 },
28 };
29​
30 const openedEvent = makeAcpRequestOpenedEvent({
31 stamp,
32 provider: ProviderDriverKind.make("cursor"),
33 threadId: "thread-1" as never,
34 turnId,
35 requestId: RuntimeRequestId.make("request-1"),
36 permissionRequest,
37 detail: "cat package.json",
38 args: { command: ["cat", "package.json"] },
39 source: "acp.jsonrpc",
40 method: "session/request_permission",
41 rawPayload: { sessionId: "session-1" },
42 });
43 expect(openedEvent).toMatchObject({
44 type: "request.opened",
45 payload: {
46 requestType: "exec_command_approval",
47 detail: "cat package.json",
48 },
49 });
50 expect(openedEvent).not.toHaveProperty("payload.options");
51​
52 expect(
53 makeAcpRequestResolvedEvent({
54 stamp,
55 provider: ProviderDriverKind.make("cursor"),
56 threadId: "thread-1" as never,
57 turnId,
58 requestId: RuntimeRequestId.make("request-1"),
59 permissionRequest,
60 decision: "accept",
61 }),
62 ).toMatchObject({
63 type: "request.resolved",
64 payload: {
65 requestType: "exec_command_approval",
66 decision: "accept",
67 },
68 });
69 });
70​
71 it("preserves a native file approval without a remembered-allow choice", () => {
72 const event = makeAcpRequestOpenedEvent({
73 stamp: { eventId: "approval-1" as never, createdAt: "2026-09-02T00:00:00.000Z" },
74 provider: ProviderDriverKind.make("antigravity"),
75 threadId: "thread-1" as never,
76 turnId: TurnId.make("turn-1"),
77 requestId: RuntimeRequestId.make("request-1"),
78 permissionRequest: { kind: "edit" },
79 approvalOptions: [
80 { decision: "accept", label: "Allow once" },
81 { decision: "decline", label: "Reject" },
82 ],
83 detail: "Edit package.json",
84 args: {},
85 source: "acp.jsonrpc",
86 method: "session/request_permission",
87 rawPayload: { sessionId: "session-1" },
88 });
89​
90 expect(event.payload).toEqual({
91 requestType: "file_change_approval",
92 detail: "Edit package.json",
93 args: {},
94 options: [
95 { decision: "accept", label: "Allow once" },
96 { decision: "decline", label: "Reject" },
97 ],
98 });
99 });
100​
101 it("maps generic ACP permission kinds to dynamic tool approvals", () => {
102 const stamp = { eventId: "event-1" as never, createdAt: "2026-03-27T00:00:00.000Z" };
103​
104 for (const kind of ["search", "fetch", "other", "unknown", "future-tool-kind"]) {
105 const permissionRequest = { kind };
106 const request = {
107 stamp,
108 provider: ProviderDriverKind.make("cursor"),
109 threadId: "thread-1" as never,
110 turnId: TurnId.make("turn-1"),
111 requestId: RuntimeRequestId.make(`request-${kind}`),
112 permissionRequest,
113 };
114​
115 expect(
116 makeAcpRequestOpenedEvent({
117 ...request,
118 detail: kind,
119 args: {},
120 source: "acp.jsonrpc",
121 method: "session/request_permission",
122 rawPayload: { sessionId: "session-1" },
123 }),
124 ).toMatchObject({
125 type: "request.opened",
126 payload: { requestType: "dynamic_tool_call" },
127 });
128​
129 expect(
130 makeAcpRequestResolvedEvent({
131 ...request,
132 decision: "accept",
133 }),
134 ).toMatchObject({
135 type: "request.resolved",
136 payload: { requestType: "dynamic_tool_call" },
137 });
138 }
139 });
140​
141 it("maps ACP core plan, tool-call, and content updates", () => {
142 const stamp = { eventId: "event-1" as never, createdAt: "2026-03-27T00:00:00.000Z" };
143 const turnId = TurnId.make("turn-1");
144​
145 expect(
146 makeAcpPlanUpdatedEvent({
147 stamp,
148 provider: ProviderDriverKind.make("cursor"),
149 threadId: "thread-1" as never,
150 turnId,
151 payload: {
152 plan: [{ step: "Inspect state", status: "inProgress" }],
153 },
154 source: "acp.cursor.extension",
155 method: "cursor/update_todos",
156 rawPayload: { todos: [] },
157 }),
158 ).toMatchObject({
159 type: "turn.plan.updated",
160 raw: {
161 method: "cursor/update_todos",
162 },
163 });
164​
165 expect(
166 makeAcpToolCallEvent({
167 stamp,
168 provider: ProviderDriverKind.make("cursor"),
169 threadId: "thread-1" as never,
170 turnId,
171 toolCall: {
172 toolCallId: "tool-1",
173 kind: "execute",
174 status: "completed",
175 title: "Terminal",
176 detail: "bun run test",
177 data: { command: "bun run test" },
178 },
179 rawPayload: { sessionId: "session-1" },
180 }),
181 ).toMatchObject({
182 type: "item.completed",
183 payload: {
184 itemType: "command_execution",
185 status: "completed",
186 },
187 });
188​
189 expect(
190 makeAcpContentDeltaEvent({
191 stamp,
192 provider: ProviderDriverKind.make("cursor"),
193 threadId: "thread-1" as never,
194 turnId,
195 itemId: "assistant:session-1:segment:0",
196 text: "hello",
197 rawPayload: { sessionId: "session-1" },
198 }),
199 ).toMatchObject({
200 type: "content.delta",
201 itemId: "assistant:session-1:segment:0",
202 payload: {
203 delta: "hello",
204 },
205 });
206​
207 expect(
208 makeAcpAssistantItemEvent({
209 stamp,
210 provider: ProviderDriverKind.make("cursor"),
211 threadId: "thread-1" as never,
212 turnId,
213 itemId: "assistant:session-1:segment:0",
214 lifecycle: "item.started",
215 }),
216 ).toMatchObject({
217 type: "item.started",
218 itemId: "assistant:session-1:segment:0",
219 payload: {
220 itemType: "assistant_message",
221 status: "inProgress",
222 },
223 });
224 });
225​
226 it("maps thoughts to the reasoning stream", () => {
227 expect(
228 makeAcpContentDeltaEvent({
229 stamp: { eventId: "thought-1" as never, createdAt: "2026-09-02T00:00:00.000Z" },
230 provider: ProviderDriverKind.make("cursor"),
231 threadId: "thread-1" as never,
232 turnId: TurnId.make("turn-1"),
233 streamKind: "reasoning_text",
234 text: "Inspect the current implementation first.",
235 rawPayload: { sessionId: "session-1" },
236 }),
237 ).toMatchObject({
238 type: "content.delta",
239 payload: {
240 streamKind: "reasoning_text",
241 delta: "Inspect the current implementation first.",
242 },
243 });
244 });
245});