@cursor/july 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/AGENTS.md +10 -0
  2. package/dist/bin/agent-serve.js +0 -0
  3. package/dist/channels/github/instrument.d.ts +20 -0
  4. package/dist/channels/github/instrument.d.ts.map +1 -0
  5. package/dist/channels/slack/api.d.ts +2 -0
  6. package/dist/channels/slack/api.d.ts.map +1 -1
  7. package/dist/channels/slack/api.js +3 -0
  8. package/dist/channels/slack/bot-mentions.d.ts +106 -0
  9. package/dist/channels/slack/bot-mentions.d.ts.map +1 -0
  10. package/dist/channels/slack/bot-mentions.js +243 -0
  11. package/dist/channels/slack/dispatch.d.ts +6 -0
  12. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  13. package/dist/channels/slack/dispatch.js +24 -3
  14. package/dist/channels/slack/inbound.d.ts +10 -1
  15. package/dist/channels/slack/inbound.d.ts.map +1 -1
  16. package/dist/channels/slack/inbound.js +12 -4
  17. package/dist/channels/slack/index.d.ts +1 -0
  18. package/dist/channels/slack/index.d.ts.map +1 -1
  19. package/dist/channels/slack/index.js +1 -0
  20. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  21. package/dist/channels/slack/slack-channel.js +61 -22
  22. package/dist/channels/slack/types.d.ts +58 -0
  23. package/dist/channels/slack/types.d.ts.map +1 -1
  24. package/dist/docs/404.html +1 -1
  25. package/dist/docs/ab.html +2 -2
  26. package/dist/docs/assets/{app.CrsWMchO.js → app.jDxLzWv4.js} +1 -1
  27. package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
  28. package/dist/docs/assets/chunks/{VPLocalSearchBox.D1JqzSh8.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
  29. package/dist/docs/assets/chunks/{theme.DaBvZYwl.js → theme.CLazCWlJ.js} +2 -2
  30. package/dist/docs/building-with-agents.html +2 -2
  31. package/dist/docs/concepts.html +2 -2
  32. package/dist/docs/deployment.html +2 -2
  33. package/dist/docs/evals.html +2 -2
  34. package/dist/docs/example-agents/approval-buddy.html +2 -2
  35. package/dist/docs/example-agents/benny.html +2 -2
  36. package/dist/docs/example-agents/bugbot.html +2 -2
  37. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  38. package/dist/docs/example-agents/codeowners-review.html +2 -2
  39. package/dist/docs/example-agents/concierge.html +2 -2
  40. package/dist/docs/example-agents/fsd.html +2 -2
  41. package/dist/docs/example-agents/index.html +2 -2
  42. package/dist/docs/example-agents/knowledge-base.html +2 -2
  43. package/dist/docs/example-agents/oncall.html +2 -2
  44. package/dist/docs/example-agents/security-reviewer.html +2 -2
  45. package/dist/docs/example-agents/slack-agent.html +2 -2
  46. package/dist/docs/example-agents/weather-agent.html +2 -2
  47. package/dist/docs/guides/agent-to-agent.html +2 -2
  48. package/dist/docs/guides/cloud-runtime.html +2 -2
  49. package/dist/docs/guides/github.html +2 -2
  50. package/dist/docs/guides/human-in-the-loop.html +2 -2
  51. package/dist/docs/guides/mcp-oauth.html +2 -2
  52. package/dist/docs/guides/slack.html +2 -2
  53. package/dist/docs/guides/webhooks.html +2 -2
  54. package/dist/docs/hillclimbing.html +2 -2
  55. package/dist/docs/index.html +2 -2
  56. package/dist/docs/quickstart.html +2 -2
  57. package/dist/docs/reference/agent-config.html +2 -2
  58. package/dist/docs/reference/channels.html +2 -2
  59. package/dist/docs/reference/cli.html +2 -2
  60. package/dist/docs/reference/connections.html +2 -2
  61. package/dist/docs/reference/hooks.html +2 -2
  62. package/dist/docs/reference/http-api.html +2 -2
  63. package/dist/docs/reference/instructions.html +2 -2
  64. package/dist/docs/reference/playground.html +2 -2
  65. package/dist/docs/reference/project-layout.html +2 -2
  66. package/dist/docs/reference/prompt.html +2 -2
  67. package/dist/docs/reference/schedules.html +2 -2
  68. package/dist/docs/reference/sessions.html +2 -2
  69. package/dist/docs/reference/skills.html +2 -2
  70. package/dist/docs/reference/subagents.html +2 -2
  71. package/dist/docs/reference/tools.html +2 -2
  72. package/dist/docs/scaffolding-agents.html +2 -2
  73. package/dist/docs/storage.html +2 -2
  74. package/dist/docs/troubleshooting.html +2 -2
  75. package/dist/internal/json-dir-store.d.ts +32 -0
  76. package/dist/internal/json-dir-store.d.ts.map +1 -0
  77. package/dist/internal/json-dir-store.js +100 -0
  78. package/dist/internal/resolved-connections.d.ts +1 -1
  79. package/dist/internal/resolved-connections.d.ts.map +1 -1
  80. package/dist/internal/resolved-connections.js +10 -0
  81. package/dist/internal/session-engine.d.ts +4 -1
  82. package/dist/internal/session-engine.d.ts.map +1 -1
  83. package/dist/internal/session-engine.js +13 -2
  84. package/dist/playground/assets/index-CjOQ4hN9.css +1 -0
  85. package/dist/playground/assets/{index-C2SU2xV5.js → index-dshZQJCp.js} +46 -46
  86. package/dist/playground/index.html +2 -2
  87. package/dist/types.d.ts +7 -0
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js +9 -0
  90. package/package.json +25 -25
  91. package/skills/create-agent/SKILL.md +36 -4
  92. package/skills/evals/SKILL.md +3 -0
  93. package/skills/framework-map/SKILL.md +14 -0
  94. package/skills/github/SKILL.md +6 -1
  95. package/skills/hillclimb/SKILL.md +28 -7
  96. package/src/bin/agent-serve.version.test.ts +62 -0
  97. package/src/channels/github/api.test.ts +64 -0
  98. package/src/channels/github/auth.test.ts +105 -0
  99. package/src/channels/github/cursor-account.test.ts +204 -0
  100. package/src/channels/github/forward.test.ts +457 -0
  101. package/src/channels/github/github.test.ts +937 -0
  102. package/src/channels/github/replay.test.ts +179 -0
  103. package/src/channels/slack/api.post-message.test.ts +148 -0
  104. package/src/channels/slack/api.ts +5 -0
  105. package/src/channels/slack/approvals.test.ts +328 -0
  106. package/src/channels/slack/block-actions.test.ts +452 -0
  107. package/src/channels/slack/bot-mentions.test.ts +217 -0
  108. package/src/channels/slack/bot-mentions.ts +315 -0
  109. package/src/channels/slack/channel-watch.test.ts +363 -0
  110. package/src/channels/slack/cursor-account.test.ts +253 -0
  111. package/src/channels/slack/defaults.final-post.test.ts +182 -0
  112. package/src/channels/slack/dispatch.test.ts +795 -0
  113. package/src/channels/slack/dispatch.ts +27 -1
  114. package/src/channels/slack/eval-directive.test.ts +273 -0
  115. package/src/channels/slack/inbound.ts +25 -4
  116. package/src/channels/slack/index.ts +1 -0
  117. package/src/channels/slack/message-body.test.ts +54 -0
  118. package/src/channels/slack/nudge-store.test.ts +143 -0
  119. package/src/channels/slack/slack-channel.ts +66 -8
  120. package/src/channels/slack/slack.test.ts +391 -0
  121. package/src/channels/slack/stop.test.ts +23 -0
  122. package/src/channels/slack/thread-context.test.ts +202 -0
  123. package/src/channels/slack/types.ts +60 -0
  124. package/src/evals/assertions.test.ts +580 -0
  125. package/src/evals/expect.test.ts +144 -0
  126. package/src/evals/judge.test.ts +181 -0
  127. package/src/evals/loaders.test.ts +132 -0
  128. package/src/evals/matchers.test.ts +95 -0
  129. package/src/evals/reporters.test.ts +303 -0
  130. package/src/evals/run-facts.test.ts +259 -0
  131. package/src/internal/ab-snapshot.test.ts +325 -0
  132. package/src/internal/approval-gate.test.ts +49 -0
  133. package/src/internal/approvals.integration.test.ts +383 -0
  134. package/src/internal/authored-loaders.test.ts +31 -0
  135. package/src/internal/builtin-tools/reminders.test.ts +201 -0
  136. package/src/internal/channel-route-schema.test.ts +294 -0
  137. package/src/internal/chat-attach.test.ts +262 -0
  138. package/src/internal/cli-deploy.test.ts +1991 -0
  139. package/src/internal/cli-mcp.test.ts +789 -0
  140. package/src/internal/cli-skills.test.ts +133 -0
  141. package/src/internal/cli-slack.test.ts +1647 -0
  142. package/src/internal/cloud-merge.test.ts +74 -0
  143. package/src/internal/cron.test.ts +22 -0
  144. package/src/internal/cursor/account-mcp.test.ts +807 -0
  145. package/src/internal/cursor/backend-client.test.ts +591 -0
  146. package/src/internal/cursor/credentials.test.ts +351 -0
  147. package/src/internal/cursor/github-credentials.test.ts +136 -0
  148. package/src/internal/cursor-account-mcp-auth.test.ts +310 -0
  149. package/src/internal/cursor-account.integration.test.ts +441 -0
  150. package/src/internal/cursor-event-relay.test.ts +746 -0
  151. package/src/internal/cursor-github-credentials.integration.test.ts +271 -0
  152. package/src/internal/cursor-slack-relay.test.ts +525 -0
  153. package/src/internal/deploy-source.test.ts +111 -0
  154. package/src/internal/discovery.builtin-tools.test.ts +94 -0
  155. package/src/internal/discovery.concurrency.test.ts +60 -0
  156. package/src/internal/discovery.cursor-account.test.ts +133 -0
  157. package/src/internal/discovery.cwd.test.ts +83 -0
  158. package/src/internal/discovery.hosting.test.ts +80 -0
  159. package/src/internal/discovery.identity.test.ts +44 -0
  160. package/src/internal/docs-site.test.ts +66 -0
  161. package/src/internal/duration.test.ts +29 -0
  162. package/src/internal/eval-judge-model.test.ts +187 -0
  163. package/src/internal/eval-run-store.cancel.test.ts +142 -0
  164. package/src/internal/eval-run-store.storage.test.ts +211 -0
  165. package/src/internal/eval-runner.http.test.ts +403 -0
  166. package/src/internal/eval-runner.run.test.ts +928 -0
  167. package/src/internal/evals-client.test.ts +307 -0
  168. package/src/internal/event-mapper.test.ts +243 -0
  169. package/src/internal/github-fanout.test.ts +213 -0
  170. package/src/internal/handleAgentServeTrigger.test.ts +179 -0
  171. package/src/internal/host-kv.test.ts +82 -0
  172. package/src/internal/host-platforms.test.ts +126 -0
  173. package/src/internal/http-channel.test.ts +402 -0
  174. package/src/internal/init-project.test.ts +269 -0
  175. package/src/internal/install-cursor-skills.test.ts +262 -0
  176. package/src/internal/local-env.test.ts +100 -0
  177. package/src/internal/log-ring.test.ts +31 -0
  178. package/src/internal/logs-client.test.ts +350 -0
  179. package/src/internal/mcp-endpoint.test.ts +436 -0
  180. package/src/internal/mcp-host.test.ts +298 -0
  181. package/src/internal/mcp-oauth.test.ts +148 -0
  182. package/src/internal/net.test.ts +17 -0
  183. package/src/internal/peer-connections.test.ts +128 -0
  184. package/src/internal/peer-mcp.integration.test.ts +289 -0
  185. package/src/internal/playground/toolchain.test.ts +53 -0
  186. package/src/internal/playground-cli.test.ts +187 -0
  187. package/src/internal/playground-proxy.test.ts +376 -0
  188. package/src/internal/prompt-context.integration.test.ts +232 -0
  189. package/src/internal/prompt-context.test.ts +127 -0
  190. package/src/internal/reminder-runner.test.ts +390 -0
  191. package/src/internal/reminder-store.test.ts +53 -0
  192. package/src/internal/request-headers.test.ts +27 -0
  193. package/src/internal/resolve-prod-target.test.ts +787 -0
  194. package/src/internal/resolved-connections.test.ts +295 -0
  195. package/src/internal/resolved-connections.ts +18 -1
  196. package/src/internal/router.test.ts +57 -0
  197. package/src/internal/sdk-runner.test.ts +290 -0
  198. package/src/internal/session-engine.coalesce.test.ts +169 -0
  199. package/src/internal/session-engine.concurrency.test.ts +250 -0
  200. package/src/internal/session-engine.host-oauth-mcp.test.ts +110 -0
  201. package/src/internal/session-engine.interrupt.test.ts +577 -0
  202. package/src/internal/session-engine.storage.test.ts +547 -0
  203. package/src/internal/session-engine.ts +15 -1
  204. package/src/internal/session-urls.test.ts +28 -0
  205. package/src/internal/sessions-client.test.ts +518 -0
  206. package/src/internal/storage-coordinator.test.ts +517 -0
  207. package/src/internal/tool-call.test.ts +458 -0
  208. package/src/internal/tool-result.test.ts +52 -0
  209. package/src/internal/trajectory.approvals.test.ts +83 -0
  210. package/src/internal/trajectory.subagents.test.ts +198 -0
  211. package/src/internal/turn-governor.test.ts +137 -0
  212. package/src/internal/update-check.test.ts +485 -0
  213. package/src/internal/workspace.test.ts +81 -0
  214. package/src/storage-backends/cursor-hosted.test.ts +121 -0
  215. package/src/types.ts +12 -0
  216. package/dist/docs/assets/chunks/@localSearchIndexroot.BnHRjfoe.js +0 -1
  217. package/dist/playground/assets/index-CidizGZv.css +0 -1
@@ -0,0 +1,403 @@
1
+ /**
2
+ * Runs the eval runner against a real HTTP agent stub.
3
+ *
4
+ * `eval-runner.run.test.ts` mocks the session transport to cover grading logic;
5
+ * this file keeps the transport real, so the assertions are graded from events
6
+ * that actually arrived over the NDJSON session stream. That is the part a mock
7
+ * cannot prove.
8
+ */
9
+
10
+ import { createServer, type Server } from "node:http";
11
+ import type { AddressInfo } from "node:net";
12
+ import { afterEach, describe, expect, it } from "vitest";
13
+ import type { EvalDefinition, EvalRunResult } from "../evals.js";
14
+ import { defineEval, includes } from "../evals.js";
15
+ import type { SessionEvent } from "../types.js";
16
+ import { expandEvalModule, runDiscoveredEvals } from "./eval-runner.js";
17
+
18
+ interface StubAgent {
19
+ url: string;
20
+ /** Messages the runner sent, in order. */
21
+ received: string[];
22
+ close(): Promise<void>;
23
+ }
24
+
25
+ /** One scripted turn: the events the stub streams back for that message. */
26
+ type TurnScript = (message: string, turnId: string) => ScriptedEvent[];
27
+
28
+ /**
29
+ * A scripted event without its envelope cursor; `appendTurn` fills in
30
+ * `sessionId` and `index`. Loosely typed on purpose: the stub composes events
31
+ * generically, which the `type`/`data` discriminated union cannot express.
32
+ */
33
+ interface ScriptedEvent {
34
+ at: string;
35
+ turnId?: string;
36
+ type: string;
37
+ data: unknown;
38
+ }
39
+
40
+ async function startStubAgent(script: TurnScript): Promise<StubAgent> {
41
+ const received: string[] = [];
42
+ const sessions = new Map<string, SessionEvent[]>();
43
+ let nextSession = 0;
44
+ let nextTurn = 0;
45
+
46
+ const appendTurn = (sessionId: string, message: string): void => {
47
+ const events = sessions.get(sessionId)!;
48
+ nextTurn++;
49
+ for (const event of script(message, `turn_${nextTurn}`)) {
50
+ // `index` is the monotonic per-session cursor a client reconnects with
51
+ // via `?startIndex=`, so it must be the event's position in this session.
52
+ events.push({
53
+ ...event,
54
+ sessionId,
55
+ index: events.length,
56
+ } as SessionEvent);
57
+ }
58
+ };
59
+
60
+ const server: Server = createServer((req, res) => {
61
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
62
+ const chunks: Buffer[] = [];
63
+ req.on("data", (chunk: Buffer) => chunks.push(chunk));
64
+ req.on("end", () => {
65
+ const body =
66
+ chunks.length === 0
67
+ ? {}
68
+ : (JSON.parse(Buffer.concat(chunks).toString("utf8")) as {
69
+ message?: string;
70
+ });
71
+ const streamMatch = /^\/v1\/session\/([^/]+)\/stream$/.exec(url.pathname);
72
+ if (streamMatch !== null) {
73
+ const events = sessions.get(streamMatch[1]!) ?? [];
74
+ const startIndex = Number(url.searchParams.get("startIndex") ?? "0");
75
+ res.writeHead(200, { "content-type": "application/x-ndjson" });
76
+ for (const event of events.slice(startIndex)) {
77
+ res.write(`${JSON.stringify(event)}\n`);
78
+ }
79
+ res.end();
80
+ return;
81
+ }
82
+ if (url.pathname === "/v1/session") {
83
+ nextSession++;
84
+ const sessionId = `ses_${nextSession}`;
85
+ sessions.set(sessionId, []);
86
+ received.push(body.message ?? "");
87
+ appendTurn(sessionId, body.message ?? "");
88
+ res.writeHead(200, { "content-type": "application/json" });
89
+ res.end(
90
+ JSON.stringify({ ok: true, sessionId, continuationToken: "tok_1" })
91
+ );
92
+ return;
93
+ }
94
+ const followUp = /^\/v1\/session\/([^/]+)$/.exec(url.pathname);
95
+ if (followUp !== null) {
96
+ received.push(body.message ?? "");
97
+ appendTurn(followUp[1]!, body.message ?? "");
98
+ res.writeHead(200, { "content-type": "application/json" });
99
+ res.end(JSON.stringify({ ok: true, continuationToken: "tok_2" }));
100
+ return;
101
+ }
102
+ res.writeHead(404).end();
103
+ });
104
+ });
105
+
106
+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
107
+ const { port } = server.address() as AddressInfo;
108
+ return {
109
+ url: `http://127.0.0.1:${port}`,
110
+ received,
111
+ close: () =>
112
+ new Promise<void>((resolve) => {
113
+ server.close(() => resolve());
114
+ }),
115
+ };
116
+ }
117
+
118
+ function event(
119
+ type: string,
120
+ data: unknown,
121
+ turnId: string | undefined
122
+ ): ScriptedEvent {
123
+ return { at: new Date().toISOString(), turnId, type, data };
124
+ }
125
+
126
+ /** A weather turn: one completed tool call, one reply, then park. */
127
+ const weatherScript: TurnScript = (message, turnId) => [
128
+ event("message.received", { text: message }, turnId),
129
+ event(
130
+ "actions.requested",
131
+ {
132
+ calls: [
133
+ {
134
+ callId: `${turnId}_c1`,
135
+ toolName: "get_weather",
136
+ args: { city: "NYC" },
137
+ },
138
+ ],
139
+ },
140
+ turnId
141
+ ),
142
+ event(
143
+ "action.result",
144
+ {
145
+ callId: `${turnId}_c1`,
146
+ toolName: "get_weather",
147
+ output: { tempF: 72 },
148
+ isError: false,
149
+ },
150
+ turnId
151
+ ),
152
+ event(
153
+ "message.completed",
154
+ { text: "Sunny, 72F in NYC.", finishReason: "stop" },
155
+ turnId
156
+ ),
157
+ event("turn.completed", {}, turnId),
158
+ event("session.waiting", {}, undefined),
159
+ ];
160
+
161
+ let stub: StubAgent | undefined;
162
+
163
+ afterEach(async () => {
164
+ await stub?.close();
165
+ stub = undefined;
166
+ });
167
+
168
+ async function run(
169
+ definition: EvalDefinition,
170
+ baseUrl: string
171
+ ): Promise<EvalRunResult[]> {
172
+ return runDiscoveredEvals({
173
+ projectRoot: "/unused",
174
+ baseUrl,
175
+ discovered: {
176
+ evals: expandEvalModule("http", definition).map((e) => ({
177
+ id: e.id,
178
+ fileId: "http",
179
+ path: "/repo/evals/http.eval.ts",
180
+ definition: e.definition,
181
+ })),
182
+ config: { maxConcurrency: 2 },
183
+ },
184
+ });
185
+ }
186
+
187
+ describe("runner over a real session stream", () => {
188
+ it("grades assertions from events that arrived over HTTP", async () => {
189
+ stub = await startStubAgent(weatherScript);
190
+ const [result] = await run(
191
+ defineEval({
192
+ async test(t) {
193
+ await t.send("What is the weather in NYC?");
194
+ t.succeeded();
195
+ t.calledTool("get_weather", {
196
+ input: { city: "NYC" },
197
+ output: { tempF: 72 },
198
+ status: "completed",
199
+ count: 1,
200
+ });
201
+ t.noFailedActions();
202
+ t.messageIncludes("Sunny");
203
+ t.check(t.reply, includes("72F"));
204
+ t.maxToolCalls(1);
205
+ },
206
+ }),
207
+ stub.url
208
+ );
209
+ expect(result?.verdict).toBe("passed");
210
+ expect(result?.assertions.every((a) => a.passed)).toBe(true);
211
+ expect(stub.received).toEqual(["What is the weather in NYC?"]);
212
+ // The transport-derived views the CLI and playground print.
213
+ expect(result?.tools).toEqual(["get_weather"]);
214
+ expect(result?.toolCalls).toEqual([
215
+ {
216
+ toolName: "get_weather",
217
+ args: { city: "NYC" },
218
+ output: { tempF: 72 },
219
+ isError: false,
220
+ },
221
+ ]);
222
+ expect(result?.finalText).toBe("Sunny, 72F in NYC.");
223
+ expect(result?.sessionId).toBe("ses_1");
224
+ });
225
+
226
+ it("resumes the stream so a second send reads the second turn", async () => {
227
+ // Each turn replies with the message it received and calls a distinct tool,
228
+ // so a send that replayed the earlier turn would be unmistakable. The
229
+ // stream replays from an index and stops at the first terminal event, so
230
+ // this is the regression test for resuming at the right cursor.
231
+ stub = await startStubAgent((message, turnId) => [
232
+ event("message.received", { text: message }, turnId),
233
+ event(
234
+ "actions.requested",
235
+ {
236
+ calls: [
237
+ { callId: `${turnId}_c1`, toolName: `tool_${message}`, args: {} },
238
+ ],
239
+ },
240
+ turnId
241
+ ),
242
+ event(
243
+ "action.result",
244
+ {
245
+ callId: `${turnId}_c1`,
246
+ toolName: `tool_${message}`,
247
+ output: "ok",
248
+ isError: false,
249
+ },
250
+ turnId
251
+ ),
252
+ event(
253
+ "message.completed",
254
+ { text: `reply to ${message}`, finishReason: "stop" },
255
+ turnId
256
+ ),
257
+ event("turn.completed", {}, turnId),
258
+ event("session.waiting", {}, undefined),
259
+ ]);
260
+
261
+ const [result] = await run(
262
+ defineEval({
263
+ async test(t) {
264
+ const first = await t.send("first");
265
+ t.check(first.message, includes("reply to first"));
266
+
267
+ const second = await t.send("second");
268
+ t.check(second.message, includes("reply to second"));
269
+ t.check(t.reply, includes("reply to second"));
270
+
271
+ // Each turn sees only its own tool call.
272
+ first.calledTool("tool_first", { count: 1 });
273
+ first.notCalledTool("tool_second");
274
+ second.calledTool("tool_second", { count: 1 });
275
+ second.notCalledTool("tool_first");
276
+
277
+ // The run sees both, exactly once each.
278
+ t.calledTool("tool_first", { count: 1 });
279
+ t.calledTool("tool_second", { count: 1 });
280
+ t.maxToolCalls(2);
281
+ t.toolOrder(["tool_first", "tool_second"]);
282
+ t.check(second.sessionId, includes(first.sessionId));
283
+ },
284
+ }),
285
+ stub.url
286
+ );
287
+ expect(result?.verdict).toBe("passed");
288
+ const failed = result!.assertions.filter((a) => !a.passed);
289
+ expect(failed).toEqual([]);
290
+ expect(stub.received).toEqual(["first", "second"]);
291
+ expect(result?.inputs).toEqual(["first", "second"]);
292
+ expect(result?.finalText).toBe("reply to second");
293
+ });
294
+
295
+ it("fails a run whose turn failed on the wire", async () => {
296
+ stub = await startStubAgent((message, turnId) => [
297
+ event("message.received", { text: message }, turnId),
298
+ event("turn.failed", { message: "provider unavailable" }, turnId),
299
+ event("session.waiting", {}, undefined),
300
+ ]);
301
+ const [result] = await run(
302
+ defineEval({
303
+ async test(t) {
304
+ await t.send("hello");
305
+ t.succeeded();
306
+ },
307
+ }),
308
+ stub.url
309
+ );
310
+ expect(result?.verdict).toBe("failed");
311
+ expect(result?.assertions[0]).toMatchObject({
312
+ name: "succeeded",
313
+ passed: false,
314
+ detail: "provider unavailable",
315
+ });
316
+ });
317
+
318
+ it("detects a run parked on an unanswered approval request", async () => {
319
+ stub = await startStubAgent((message, turnId) => [
320
+ event("message.received", { text: message }, turnId),
321
+ event(
322
+ "actions.requested",
323
+ {
324
+ calls: [{ callId: "c1", toolName: "deploy", args: { env: "prod" } }],
325
+ },
326
+ turnId
327
+ ),
328
+ event(
329
+ "action.approval_requested",
330
+ { callId: "c1", toolName: "deploy", args: { env: "prod" } },
331
+ turnId
332
+ ),
333
+ event("session.waiting", {}, undefined),
334
+ ]);
335
+ const [result] = await run(
336
+ defineEval({
337
+ async test(t) {
338
+ await t.send("deploy to prod");
339
+ t.parked();
340
+ const request = t.requireInputRequest({ toolName: "deploy" });
341
+ t.check(request.args, includes("prod"));
342
+ t.calledTool("deploy", { status: "pending", count: 1 });
343
+ },
344
+ }),
345
+ stub.url
346
+ );
347
+ expect(result?.verdict).toBe("passed");
348
+ expect(result?.assertions.map((a) => a.passed)).toEqual([
349
+ true,
350
+ true,
351
+ true,
352
+ true,
353
+ ]);
354
+ });
355
+
356
+ it("records a failed tool call without failing the turn", async () => {
357
+ stub = await startStubAgent((message, turnId) => [
358
+ event("message.received", { text: message }, turnId),
359
+ event(
360
+ "actions.requested",
361
+ {
362
+ calls: [
363
+ { callId: "c1", toolName: "bash", args: { command: "false" } },
364
+ ],
365
+ },
366
+ turnId
367
+ ),
368
+ event(
369
+ "action.result",
370
+ { callId: "c1", toolName: "bash", output: "exit 1", isError: true },
371
+ turnId
372
+ ),
373
+ event(
374
+ "message.completed",
375
+ { text: "That command failed.", finishReason: "stop" },
376
+ turnId
377
+ ),
378
+ event("turn.completed", {}, turnId),
379
+ event("session.waiting", {}, undefined),
380
+ ]);
381
+ const [result] = await run(
382
+ defineEval({
383
+ async test(t) {
384
+ await t.send("run false");
385
+ t.succeeded();
386
+ t.calledTool("bash", { status: "failed", count: 1 });
387
+ t.noFailedActions();
388
+ },
389
+ }),
390
+ stub.url
391
+ );
392
+ expect(result?.verdict).toBe("failed");
393
+ const byName = new Map(result!.assertions.map((a) => [a.name, a]));
394
+ expect(byName.get("succeeded")?.passed).toBe(true);
395
+ expect(
396
+ byName.get("calledTool(bash, {status=failed, count=1})")?.passed
397
+ ).toBe(true);
398
+ expect(byName.get("noFailedActions")).toMatchObject({
399
+ passed: false,
400
+ detail: "bash",
401
+ });
402
+ });
403
+ });