@cursor/july 0.1.23 → 0.1.24

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 (174) hide show
  1. package/dist/bin/agent-serve.js +0 -0
  2. package/dist/docs/404.html +1 -1
  3. package/dist/docs/ab.html +2 -2
  4. package/dist/docs/assets/{app.DYcC9FY-.js → app.CvSGaAxk.js} +1 -1
  5. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  6. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  7. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.C7vfzr7h.js} +2 -2
  8. package/dist/docs/building-with-agents.html +2 -2
  9. package/dist/docs/concepts.html +2 -2
  10. package/dist/docs/deployment.html +2 -2
  11. package/dist/docs/evals.html +2 -2
  12. package/dist/docs/example-agents/approval-buddy.html +2 -2
  13. package/dist/docs/example-agents/benny.html +2 -2
  14. package/dist/docs/example-agents/bugbot.html +2 -2
  15. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  16. package/dist/docs/example-agents/codeowners-review.html +2 -2
  17. package/dist/docs/example-agents/concierge.html +2 -2
  18. package/dist/docs/example-agents/fsd.html +2 -2
  19. package/dist/docs/example-agents/index.html +2 -2
  20. package/dist/docs/example-agents/knowledge-base.html +2 -2
  21. package/dist/docs/example-agents/oncall.html +2 -2
  22. package/dist/docs/example-agents/security-reviewer.html +2 -2
  23. package/dist/docs/example-agents/slack-agent.html +2 -2
  24. package/dist/docs/example-agents/weather-agent.html +2 -2
  25. package/dist/docs/guides/agent-to-agent.html +2 -2
  26. package/dist/docs/guides/cloud-runtime.html +2 -2
  27. package/dist/docs/guides/github.html +2 -2
  28. package/dist/docs/guides/human-in-the-loop.html +2 -2
  29. package/dist/docs/guides/mcp-oauth.html +2 -2
  30. package/dist/docs/guides/slack.html +2 -2
  31. package/dist/docs/guides/webhooks.html +2 -2
  32. package/dist/docs/hillclimbing.html +2 -2
  33. package/dist/docs/index.html +2 -2
  34. package/dist/docs/quickstart.html +2 -2
  35. package/dist/docs/reference/agent-config.html +2 -2
  36. package/dist/docs/reference/channels.html +2 -2
  37. package/dist/docs/reference/cli.html +2 -2
  38. package/dist/docs/reference/connections.html +2 -2
  39. package/dist/docs/reference/hooks.html +2 -2
  40. package/dist/docs/reference/http-api.html +2 -2
  41. package/dist/docs/reference/instructions.html +2 -2
  42. package/dist/docs/reference/playground.html +2 -2
  43. package/dist/docs/reference/project-layout.html +2 -2
  44. package/dist/docs/reference/prompt.html +2 -2
  45. package/dist/docs/reference/schedules.html +2 -2
  46. package/dist/docs/reference/sessions.html +2 -2
  47. package/dist/docs/reference/skills.html +2 -2
  48. package/dist/docs/reference/subagents.html +2 -2
  49. package/dist/docs/reference/tools.html +2 -2
  50. package/dist/docs/scaffolding-agents.html +2 -2
  51. package/dist/docs/storage.html +2 -2
  52. package/dist/docs/troubleshooting.html +2 -2
  53. package/dist/playground/assets/index-CidizGZv.css +1 -0
  54. package/dist/playground/assets/{index-DqXdAFGa.js → index-DTG9OsPV.js} +41 -41
  55. package/dist/playground/index.html +2 -2
  56. package/package.json +24 -24
  57. package/dist/channels/github/instrument.d.ts +0 -20
  58. package/dist/channels/github/instrument.d.ts.map +0 -1
  59. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  60. package/dist/internal/json-dir-store.d.ts +0 -32
  61. package/dist/internal/json-dir-store.d.ts.map +0 -1
  62. package/dist/internal/json-dir-store.js +0 -100
  63. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  64. package/src/bin/agent-serve.version.test.ts +0 -64
  65. package/src/channels/github/api.test.ts +0 -64
  66. package/src/channels/github/auth.test.ts +0 -105
  67. package/src/channels/github/cursor-account.test.ts +0 -204
  68. package/src/channels/github/forward.test.ts +0 -457
  69. package/src/channels/github/github.test.ts +0 -937
  70. package/src/channels/github/replay.test.ts +0 -179
  71. package/src/channels/slack/api.post-message.test.ts +0 -148
  72. package/src/channels/slack/approvals.test.ts +0 -328
  73. package/src/channels/slack/block-actions.test.ts +0 -452
  74. package/src/channels/slack/bot-mentions.test.ts +0 -267
  75. package/src/channels/slack/channel-watch.test.ts +0 -363
  76. package/src/channels/slack/cursor-account.test.ts +0 -253
  77. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  78. package/src/channels/slack/dispatch.test.ts +0 -795
  79. package/src/channels/slack/eval-directive.test.ts +0 -273
  80. package/src/channels/slack/message-body.test.ts +0 -54
  81. package/src/channels/slack/nudge-store.test.ts +0 -143
  82. package/src/channels/slack/slack.test.ts +0 -391
  83. package/src/channels/slack/stop.test.ts +0 -23
  84. package/src/channels/slack/thread-context.test.ts +0 -202
  85. package/src/evals/assertions.test.ts +0 -580
  86. package/src/evals/expect.test.ts +0 -144
  87. package/src/evals/judge.test.ts +0 -181
  88. package/src/evals/loaders.test.ts +0 -132
  89. package/src/evals/matchers.test.ts +0 -95
  90. package/src/evals/reporters.test.ts +0 -303
  91. package/src/evals/run-facts.test.ts +0 -259
  92. package/src/internal/ab-snapshot.test.ts +0 -325
  93. package/src/internal/approval-gate.test.ts +0 -49
  94. package/src/internal/approvals.integration.test.ts +0 -383
  95. package/src/internal/authored-loaders.test.ts +0 -31
  96. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  97. package/src/internal/channel-route-schema.test.ts +0 -294
  98. package/src/internal/chat-attach.test.ts +0 -262
  99. package/src/internal/cli-deploy.test.ts +0 -1991
  100. package/src/internal/cli-docs.test.ts +0 -161
  101. package/src/internal/cli-mcp.test.ts +0 -789
  102. package/src/internal/cli-skills.test.ts +0 -133
  103. package/src/internal/cli-slack.test.ts +0 -1647
  104. package/src/internal/cloud-merge.test.ts +0 -74
  105. package/src/internal/cron.test.ts +0 -22
  106. package/src/internal/cursor/account-mcp.test.ts +0 -807
  107. package/src/internal/cursor/backend-client.test.ts +0 -591
  108. package/src/internal/cursor/credentials.test.ts +0 -351
  109. package/src/internal/cursor/github-credentials.test.ts +0 -136
  110. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  111. package/src/internal/cursor-account.integration.test.ts +0 -441
  112. package/src/internal/cursor-event-relay.test.ts +0 -746
  113. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  114. package/src/internal/cursor-slack-relay.test.ts +0 -525
  115. package/src/internal/deploy-source.test.ts +0 -111
  116. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  117. package/src/internal/discovery.concurrency.test.ts +0 -60
  118. package/src/internal/discovery.cursor-account.test.ts +0 -133
  119. package/src/internal/discovery.cwd.test.ts +0 -83
  120. package/src/internal/discovery.hosting.test.ts +0 -80
  121. package/src/internal/discovery.identity.test.ts +0 -44
  122. package/src/internal/docs-site.test.ts +0 -66
  123. package/src/internal/duration.test.ts +0 -29
  124. package/src/internal/eval-judge-model.test.ts +0 -187
  125. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  126. package/src/internal/eval-run-store.storage.test.ts +0 -211
  127. package/src/internal/eval-runner.http.test.ts +0 -403
  128. package/src/internal/eval-runner.run.test.ts +0 -928
  129. package/src/internal/evals-client.test.ts +0 -307
  130. package/src/internal/event-mapper.test.ts +0 -243
  131. package/src/internal/github-fanout.test.ts +0 -213
  132. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  133. package/src/internal/host-kv.test.ts +0 -82
  134. package/src/internal/host-platforms.test.ts +0 -126
  135. package/src/internal/http-channel.test.ts +0 -402
  136. package/src/internal/init-project.test.ts +0 -270
  137. package/src/internal/install-cursor-skills.test.ts +0 -262
  138. package/src/internal/local-env.test.ts +0 -120
  139. package/src/internal/log-ring.test.ts +0 -31
  140. package/src/internal/logs-client.test.ts +0 -350
  141. package/src/internal/mcp-endpoint.test.ts +0 -436
  142. package/src/internal/mcp-host.test.ts +0 -298
  143. package/src/internal/mcp-oauth.test.ts +0 -148
  144. package/src/internal/net.test.ts +0 -17
  145. package/src/internal/peer-connections.test.ts +0 -128
  146. package/src/internal/peer-mcp.integration.test.ts +0 -289
  147. package/src/internal/playground/toolchain.test.ts +0 -53
  148. package/src/internal/playground-cli.test.ts +0 -187
  149. package/src/internal/playground-proxy.test.ts +0 -376
  150. package/src/internal/prompt-context.integration.test.ts +0 -232
  151. package/src/internal/prompt-context.test.ts +0 -127
  152. package/src/internal/reminder-runner.test.ts +0 -390
  153. package/src/internal/reminder-store.test.ts +0 -53
  154. package/src/internal/request-headers.test.ts +0 -27
  155. package/src/internal/resolve-prod-target.test.ts +0 -787
  156. package/src/internal/resolved-connections.test.ts +0 -295
  157. package/src/internal/router.test.ts +0 -57
  158. package/src/internal/sdk-runner.test.ts +0 -290
  159. package/src/internal/session-engine.coalesce.test.ts +0 -169
  160. package/src/internal/session-engine.concurrency.test.ts +0 -250
  161. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  162. package/src/internal/session-engine.interrupt.test.ts +0 -577
  163. package/src/internal/session-engine.storage.test.ts +0 -547
  164. package/src/internal/session-urls.test.ts +0 -28
  165. package/src/internal/sessions-client.test.ts +0 -518
  166. package/src/internal/storage-coordinator.test.ts +0 -517
  167. package/src/internal/tool-call.test.ts +0 -458
  168. package/src/internal/tool-result.test.ts +0 -52
  169. package/src/internal/trajectory.approvals.test.ts +0 -83
  170. package/src/internal/trajectory.subagents.test.ts +0 -198
  171. package/src/internal/turn-governor.test.ts +0 -137
  172. package/src/internal/update-check.test.ts +0 -485
  173. package/src/internal/workspace.test.ts +0 -207
  174. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,580 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { SessionEvent } from "../types.js";
3
- import {
4
- computeVerdict,
5
- createAssertions,
6
- EvalAssertionRecorder,
7
- EvalRequireFailure,
8
- verdictFailsRun,
9
- } from "./assertions.js";
10
- import { equals, includes, similarity } from "./expect.js";
11
-
12
- let sequence = 0;
13
-
14
- function event(type: string, data: unknown, turnId = "turn_1"): SessionEvent {
15
- sequence++;
16
- return {
17
- sessionId: "ses_1",
18
- seq: sequence,
19
- at: new Date(sequence * 1000).toISOString(),
20
- turnId,
21
- type,
22
- data,
23
- } as unknown as SessionEvent;
24
- }
25
-
26
- function weatherRun(): SessionEvent[] {
27
- return [
28
- event("message.received", { text: "weather in NYC?" }),
29
- event("actions.requested", {
30
- calls: [{ callId: "c1", toolName: "get_weather", args: { city: "NYC" } }],
31
- }),
32
- event("action.result", {
33
- callId: "c1",
34
- toolName: "get_weather",
35
- output: { tempF: 72 },
36
- isError: false,
37
- }),
38
- event("message.completed", { text: "Sunny, 72F", finishReason: "stop" }),
39
- event("turn.completed", {}),
40
- event("session.waiting", {}),
41
- ];
42
- }
43
-
44
- function setup(events: SessionEvent[] = weatherRun()) {
45
- const recorder = new EvalAssertionRecorder();
46
- const t = createAssertions({ recorder, events: () => events });
47
- return { recorder, t };
48
- }
49
-
50
- describe("severity handles", () => {
51
- it("records gates by default and keeps the wire shape compact", () => {
52
- const { recorder, t } = setup();
53
- t.succeeded();
54
- const [result] = recorder.results();
55
- expect(result).toMatchObject({ name: "succeeded", passed: true });
56
- // `gate` is the default everywhere, so it is omitted rather than repeated.
57
- expect(result?.severity).toBeUndefined();
58
- });
59
-
60
- it("demotes a gate to a tracked soft assertion", () => {
61
- const { recorder, t } = setup();
62
- t.calledTool("nope").soft();
63
- const [result] = recorder.results();
64
- expect(result?.severity).toBe("soft");
65
- // The miss is still recorded honestly; being soft only means it does not
66
- // decide the verdict, so the CLI shows `~` and the eval still passes.
67
- expect(result?.passed).toBe(false);
68
- expect(computeVerdict(recorder.results())).toBe("passed");
69
- });
70
-
71
- it("keeps a tracked score from failing the verdict when it has no bar", () => {
72
- const { recorder, t } = setup();
73
- t.check("Rainy", similarity("Sunny, 72F"));
74
- expect(recorder.results()[0]?.passed).toBe(true);
75
- expect(recorder.results()[0]?.score).toBeLessThan(0.5);
76
- expect(computeVerdict(recorder.results())).toBe("passed");
77
- });
78
-
79
- it("scores an eval when a soft threshold is missed", () => {
80
- const { recorder, t } = setup();
81
- t.check("Rainy", similarity("Sunny, 72F")).atLeast(0.9);
82
- const [result] = recorder.results();
83
- expect(result?.severity).toBe("soft");
84
- expect(result?.threshold).toBe(0.9);
85
- expect(result?.passed).toBe(false);
86
- expect(computeVerdict(recorder.results())).toBe("scored");
87
- });
88
-
89
- it("passes a soft assertion that clears its bar", () => {
90
- const { recorder, t } = setup();
91
- t.check("Sunny, 72F", similarity("Sunny, 72F")).atLeast(0.9);
92
- expect(recorder.results()[0]?.passed).toBe(true);
93
- expect(computeVerdict(recorder.results())).toBe("passed");
94
- });
95
-
96
- it("promotes a score to a hard gate with .gate(threshold)", () => {
97
- const { recorder, t } = setup();
98
- t.check("Rainy", similarity("Sunny, 72F")).gate(0.9);
99
- expect(recorder.results()[0]?.severity).toBeUndefined();
100
- expect(computeVerdict(recorder.results())).toBe("failed");
101
- });
102
-
103
- it("converts a boolean assertion to a score when given a threshold", () => {
104
- const { recorder, t } = setup();
105
- t.calledTool("get_weather").gate(1);
106
- expect(recorder.results()[0]?.passed).toBe(true);
107
- const second = setup();
108
- second.t.calledTool("missing").gate(1);
109
- expect(second.recorder.results()[0]?.passed).toBe(false);
110
- });
111
-
112
- it("re-reads severity on the last call, so chains are order-independent", () => {
113
- const { recorder, t } = setup();
114
- t.check("Rainy", similarity("Sunny")).atLeast(0.9).soft();
115
- // `.soft()` with no threshold keeps the 0.9 bar set by `.atLeast`.
116
- expect(recorder.results()[0]?.threshold).toBe(0.9);
117
- expect(computeVerdict(recorder.results())).toBe("scored");
118
- });
119
- });
120
-
121
- describe("computeVerdict / verdictFailsRun", () => {
122
- it("prefers a failed gate over a missed soft bar", () => {
123
- expect(
124
- computeVerdict([
125
- { name: "a", passed: false },
126
- { name: "b", passed: false, severity: "soft", threshold: 0.5 },
127
- ])
128
- ).toBe("failed");
129
- });
130
-
131
- it("treats an assertion with no severity as a gate", () => {
132
- expect(computeVerdict([{ name: "legacy", passed: false }])).toBe("failed");
133
- expect(computeVerdict([{ name: "legacy", passed: true }])).toBe("passed");
134
- });
135
-
136
- it("only fails the run on scored under --strict", () => {
137
- expect(verdictFailsRun("scored", false)).toBe(false);
138
- expect(verdictFailsRun("scored", true)).toBe(true);
139
- expect(verdictFailsRun("failed", false)).toBe(true);
140
- expect(verdictFailsRun("skipped", true)).toBe(false);
141
- expect(verdictFailsRun("passed", true)).toBe(false);
142
- });
143
- });
144
-
145
- describe("run-level assertions", () => {
146
- it("succeeded passes a healthy run left open for the next message", () => {
147
- const { recorder, t } = setup();
148
- t.succeeded();
149
- expect(recorder.results()[0]?.passed).toBe(true);
150
- });
151
-
152
- it("succeeded fails a run parked on an unanswered approval", () => {
153
- const { recorder, t } = setup([
154
- event("message.received", { text: "deploy" }),
155
- event("actions.requested", {
156
- calls: [{ callId: "c1", toolName: "deploy", args: {} }],
157
- }),
158
- event("action.approval_requested", { callId: "c1", toolName: "deploy" }),
159
- event("session.waiting", {}),
160
- ]);
161
- t.succeeded();
162
- t.parked();
163
- const [succeeded, parked] = recorder.results();
164
- expect(succeeded?.passed).toBe(false);
165
- expect(succeeded?.detail).toMatch(/unanswered approval/);
166
- expect(parked?.passed).toBe(true);
167
- });
168
-
169
- it("calledTool defaults to request-based matching for compatibility", () => {
170
- // A pending call still counts as "the agent used this tool".
171
- const { recorder, t } = setup([
172
- event("actions.requested", {
173
- calls: [{ callId: "c1", toolName: "slow", args: {} }],
174
- }),
175
- event("turn.completed", {}),
176
- ]);
177
- t.calledTool("slow");
178
- t.calledTool("slow", { status: "completed" });
179
- const [anyState, completed] = recorder.results();
180
- expect(anyState?.passed).toBe(true);
181
- expect(completed?.passed).toBe(false);
182
- });
183
-
184
- it("infers the parameter type of an inline matcher predicate", () => {
185
- const { recorder, t } = setup();
186
- // No annotation on `value`: the matcher union deliberately keeps its
187
- // function member so this compiles under noImplicitAny.
188
- t.calledTool("get_weather", {
189
- input: (value) => (value as { city: string }).city === "NYC",
190
- });
191
- t.calledTool("get_weather", { count: (count) => count >= 1 });
192
- // Nested inside an object literal, which is where a matcher predicate most
193
- // often lands (`{ input: { field: predicate } }`).
194
- t.calledTool("get_weather", {
195
- input: { city: (value) => String(value).startsWith("NY") },
196
- });
197
- expect(recorder.results().map((r) => r.passed)).toEqual([true, true, true]);
198
- });
199
-
200
- it("narrows calledTool with input, output, and count matchers", () => {
201
- const { recorder, t } = setup();
202
- t.calledTool("get_weather", { input: { city: "NYC" }, count: 1 });
203
- t.calledTool("get_weather", { output: { tempF: 72 } });
204
- t.calledTool("get_weather", { input: { city: /^NY/ } });
205
- t.calledTool("get_weather", { count: 2 });
206
- const results = recorder.results();
207
- expect(results.map((r) => r.passed)).toEqual([true, true, true, false]);
208
- expect(results[0]?.name).toBe(
209
- 'calledTool(get_weather, {input={"city":"NYC"}, count=1})'
210
- );
211
- });
212
-
213
- it("notCalledTool matches any lifecycle state", () => {
214
- const { recorder, t } = setup();
215
- t.notCalledTool("echo");
216
- t.notCalledTool("get_weather");
217
- expect(recorder.results().map((r) => r.passed)).toEqual([true, false]);
218
- });
219
-
220
- it("messageIncludes reads the joined assistant text", () => {
221
- const { recorder, t } = setup([
222
- event("message.completed", {
223
- text: "part one",
224
- finishReason: "tool_call",
225
- }),
226
- event("message.completed", { text: "part two", finishReason: "stop" }),
227
- event("turn.completed", {}),
228
- ]);
229
- t.messageIncludes("part one");
230
- t.messageIncludes(/part two/);
231
- t.messageIncludes("part three");
232
- expect(recorder.results().map((r) => r.passed)).toEqual([
233
- true,
234
- true,
235
- false,
236
- ]);
237
- });
238
-
239
- it("toolOrder allows unrelated calls between the required ones", () => {
240
- const { recorder, t } = setup([
241
- event("actions.requested", {
242
- calls: [
243
- { callId: "a", toolName: "prepare", args: {} },
244
- { callId: "b", toolName: "unrelated", args: {} },
245
- { callId: "c", toolName: "finalize", args: {} },
246
- ],
247
- }),
248
- event("turn.completed", {}),
249
- ]);
250
- t.toolOrder(["prepare", "finalize"]);
251
- t.toolOrder(["finalize", "prepare"]);
252
- const [forward, backward] = recorder.results();
253
- expect(forward?.passed).toBe(true);
254
- expect(backward?.passed).toBe(false);
255
- expect(backward?.detail).toMatch(/missing prepare after position/);
256
- });
257
-
258
- it("usedNoTools, maxToolCalls, and noFailedActions read the whole run", () => {
259
- const { recorder, t } = setup([
260
- event("actions.requested", {
261
- calls: [
262
- { callId: "a", toolName: "one", args: {} },
263
- { callId: "b", toolName: "two", args: {} },
264
- ],
265
- }),
266
- event("action.result", {
267
- callId: "b",
268
- toolName: "two",
269
- output: "boom",
270
- isError: true,
271
- }),
272
- event("turn.completed", {}),
273
- ]);
274
- t.usedNoTools();
275
- t.maxToolCalls(2);
276
- t.maxToolCalls(1);
277
- t.noFailedActions();
278
- expect(recorder.results().map((r) => r.passed)).toEqual([
279
- false,
280
- true,
281
- false,
282
- false,
283
- ]);
284
- expect(recorder.results()[3]?.detail).toBe("two");
285
- });
286
-
287
- it("calledSubagent matches identity, output, and status", () => {
288
- const { recorder, t } = setup([
289
- event("actions.requested", {
290
- calls: [{ callId: "t1", toolName: "task", args: {} }],
291
- }),
292
- event("subagent.called", { callId: "t1", name: "research" }),
293
- event("subagent.completed", { callId: "t1", name: "research" }),
294
- event("action.result", {
295
- callId: "t1",
296
- toolName: "task",
297
- output: "72F in NYC",
298
- isError: false,
299
- }),
300
- event("turn.completed", {}),
301
- ]);
302
- t.calledSubagent("research", { output: /72F/, status: "completed" });
303
- t.calledSubagent("research", { count: 2 });
304
- t.calledSubagent("other");
305
- expect(recorder.results().map((r) => r.passed)).toEqual([
306
- true,
307
- false,
308
- false,
309
- ]);
310
- });
311
-
312
- it("loadedSkill matches any tool call that opened the skill file", () => {
313
- const { recorder, t } = setup([
314
- event("actions.requested", {
315
- calls: [
316
- {
317
- callId: "c1",
318
- toolName: "read_file",
319
- args: { path: ".cursor/skills/alert-investigation/SKILL.md" },
320
- },
321
- ],
322
- }),
323
- event("turn.completed", {}),
324
- ]);
325
- t.loadedSkill("alert-investigation");
326
- t.loadedSkill("other-skill");
327
- expect(recorder.results().map((r) => r.passed)).toEqual([true, false]);
328
- });
329
- });
330
-
331
- describe("event assertions", () => {
332
- it("matches presence, absence, data, and count", () => {
333
- const { recorder, t } = setup();
334
- t.event("turn.completed");
335
- t.event("message.completed", { data: { text: /Sunny/ } });
336
- t.event("message.completed", { count: 2 });
337
- t.notEvent("turn.failed");
338
- t.notEvent("turn.completed");
339
- expect(recorder.results().map((r) => r.passed)).toEqual([
340
- true,
341
- true,
342
- false,
343
- true,
344
- false,
345
- ]);
346
- });
347
-
348
- it("eventOrder requires matching groups in stream order", () => {
349
- const { recorder, t } = setup();
350
- t.eventOrder([
351
- { type: "actions.requested" },
352
- { type: "action.result" },
353
- { type: "turn.completed" },
354
- ]);
355
- t.eventOrder([{ type: "turn.completed" }, { type: "actions.requested" }]);
356
- expect(recorder.results().map((r) => r.passed)).toEqual([true, false]);
357
- });
358
-
359
- it("eventOrder honors a numeric count per group", () => {
360
- const { recorder, t } = setup([
361
- event("subagent.called", { callId: "a", name: "r" }),
362
- event("subagent.called", { callId: "b", name: "r" }),
363
- event("turn.completed", {}),
364
- ]);
365
- t.eventOrder([
366
- { type: "subagent.called", count: 2 },
367
- { type: "turn.completed" },
368
- ]);
369
- t.eventOrder([
370
- { type: "subagent.called", count: 3 },
371
- { type: "turn.completed" },
372
- ]);
373
- expect(recorder.results().map((r) => r.passed)).toEqual([true, false]);
374
- });
375
-
376
- it("eventsSatisfy records a predicate throw as a failure detail", () => {
377
- const { recorder, t } = setup();
378
- t.eventsSatisfy("has a reply", (events) =>
379
- events.some((e) => e.type === "message.completed")
380
- );
381
- t.eventsSatisfy("throws", () => {
382
- throw new Error("bad predicate");
383
- });
384
- const results = recorder.results();
385
- expect(results[0]?.passed).toBe(true);
386
- expect(results[1]).toMatchObject({
387
- passed: false,
388
- detail: "bad predicate",
389
- });
390
- });
391
- });
392
-
393
- describe("require* lookups", () => {
394
- it("requireToolCall returns the matching call", () => {
395
- const { recorder, t } = setup();
396
- const call = t.requireToolCall("get_weather");
397
- expect(call.output).toEqual({ tempF: 72 });
398
- expect(recorder.results()[0]?.passed).toBe(true);
399
- });
400
-
401
- it("requireToolCall records a gate and stops the body when nothing matches", () => {
402
- const { recorder, t } = setup();
403
- expect(() => t.requireToolCall("missing")).toThrow(EvalRequireFailure);
404
- expect(recorder.results()[0]).toMatchObject({
405
- name: "requireToolCall(missing)",
406
- passed: false,
407
- });
408
- });
409
-
410
- it("requireInputRequest demands exactly one pending approval", () => {
411
- const { recorder, t } = setup([
412
- event("actions.requested", {
413
- calls: [{ callId: "c1", toolName: "deploy", args: { env: "prod" } }],
414
- }),
415
- event("action.approval_requested", {
416
- callId: "c1",
417
- toolName: "deploy",
418
- args: { env: "prod" },
419
- }),
420
- event("session.waiting", {}),
421
- ]);
422
- const request = t.requireInputRequest({ toolName: "deploy" });
423
- expect(request.args).toEqual({ env: "prod" });
424
- expect(() => t.requireInputRequest({ toolName: "other" })).toThrow(
425
- EvalRequireFailure
426
- );
427
- expect(recorder.results()[1]?.detail).toMatch(/found 0/);
428
- });
429
- });
430
-
431
- describe("turn scoping", () => {
432
- it("prefixes turn assertions and narrows them to that turn's events", () => {
433
- const recorder = new EvalAssertionRecorder();
434
- const firstTurn = [
435
- event("actions.requested", {
436
- calls: [{ callId: "c1", toolName: "search", args: {} }],
437
- }),
438
- event("message.completed", { text: "draft", finishReason: "stop" }),
439
- event("turn.completed", {}),
440
- ];
441
- const secondTurn = [
442
- event("actions.requested", {
443
- calls: [{ callId: "c2", toolName: "send_email", args: {} }],
444
- }),
445
- event(
446
- "message.completed",
447
- { text: "sent", finishReason: "stop" },
448
- "turn_2"
449
- ),
450
- event("turn.completed", {}, "turn_2"),
451
- ];
452
- const turnOne = createAssertions({
453
- recorder,
454
- events: () => firstTurn,
455
- scope: "turn[1]",
456
- });
457
- const run = createAssertions({
458
- recorder,
459
- events: () => [...firstTurn, ...secondTurn],
460
- });
461
-
462
- turnOne.calledTool("search");
463
- turnOne.notCalledTool("send_email");
464
- run.calledTool("send_email");
465
-
466
- const results = recorder.results();
467
- expect(results.map((r) => r.name)).toEqual([
468
- "turn[1].calledTool(search)",
469
- "turn[1].notCalledTool(send_email)",
470
- "calledTool(send_email)",
471
- ]);
472
- expect(results.map((r) => r.passed)).toEqual([true, true, true]);
473
- expect(results[0]?.scope).toBe("turn[1]");
474
- expect(results[2]?.scope).toBeUndefined();
475
- });
476
- });
477
-
478
- describe("score", () => {
479
- it("records a tracked score that does not gate until given a bar", () => {
480
- const { recorder, t } = setup();
481
- t.score("recall", 0.4);
482
- expect(recorder.results()[0]).toMatchObject({
483
- name: "score(recall)",
484
- severity: "soft",
485
- score: 0.4,
486
- passed: true,
487
- });
488
- expect(computeVerdict(recorder.results())).toBe("passed");
489
- });
490
-
491
- it("marks the eval scored once the score misses its bar", () => {
492
- const { recorder, t } = setup();
493
- t.score("recall", 0.4).atLeast(0.6);
494
- expect(recorder.results()[0]?.passed).toBe(false);
495
- expect(computeVerdict(recorder.results())).toBe("scored");
496
- });
497
-
498
- it("can be promoted to a hard gate", () => {
499
- const { recorder, t } = setup();
500
- t.score("recall", 0.4).gate(0.6);
501
- expect(computeVerdict(recorder.results())).toBe("failed");
502
- });
503
-
504
- it("fails loudly on a non-finite score rather than reporting NaN", () => {
505
- const { recorder, t } = setup();
506
- t.score("recall", Number.NaN);
507
- expect(recorder.results()[0]).toMatchObject({
508
- passed: false,
509
- score: undefined,
510
- detail: "score is not a finite number: NaN",
511
- });
512
- });
513
- });
514
-
515
- describe("check", () => {
516
- it("keeps the historical assertion name so output stays stable", () => {
517
- const { recorder, t } = setup();
518
- t.check("Sunny, 72F", includes("Sunny"));
519
- t.check(72, equals(72));
520
- expect(recorder.results().map((r) => r.name)).toEqual([
521
- "check(includes)",
522
- "check(equals)",
523
- ]);
524
- });
525
- });
526
-
527
- describe("recordAsync", () => {
528
- it("fills the slot in when the async score settles", async () => {
529
- const recorder = new EvalAssertionRecorder();
530
- recorder
531
- .recordAsync(
532
- { name: "judge.closedQA(x)", passed: true, severity: "soft" },
533
- Promise.resolve({ passed: true, score: 0.4, detail: "N (0.40)" })
534
- )
535
- .atLeast(0.6);
536
- await recorder.waitForPending();
537
- expect(recorder.results()[0]).toMatchObject({
538
- severity: "soft",
539
- score: 0.4,
540
- threshold: 0.6,
541
- passed: false,
542
- detail: "N (0.40)",
543
- });
544
- expect(computeVerdict(recorder.results())).toBe("scored");
545
- });
546
-
547
- it("turns a rejected score into a failed gate with the error message", async () => {
548
- const recorder = new EvalAssertionRecorder();
549
- recorder
550
- .recordAsync(
551
- { name: "judge.factuality(x)", passed: true, severity: "soft" },
552
- Promise.reject(new Error("judge reply had no choice"))
553
- )
554
- .atLeast(0.7);
555
- await recorder.waitForPending();
556
- expect(recorder.results()[0]).toMatchObject({
557
- passed: false,
558
- detail: "judge reply had no choice",
559
- });
560
- // Grading errors must not hide behind soft severity.
561
- expect(recorder.results()[0]?.severity).toBeUndefined();
562
- expect(computeVerdict(recorder.results())).toBe("failed");
563
- });
564
-
565
- it("waits for judges started while an earlier judge was settling", async () => {
566
- const recorder = new EvalAssertionRecorder();
567
- recorder.recordAsync(
568
- { name: "first", passed: true, severity: "soft" },
569
- Promise.resolve({}).then(() => {
570
- recorder.recordAsync(
571
- { name: "second", passed: true, severity: "soft" },
572
- Promise.resolve({ score: 1 })
573
- );
574
- return { score: 1 };
575
- })
576
- );
577
- await recorder.waitForPending();
578
- expect(recorder.results().map((r) => r.score)).toEqual([1, 1]);
579
- });
580
- });