@cursor/july 0.1.20 → 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.
- package/dist/bin/agent-serve.js +0 -0
- package/dist/channels/github/instrument.d.ts +20 -0
- package/dist/channels/github/instrument.d.ts.map +1 -0
- package/dist/channels/slack/api.d.ts +2 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +3 -0
- package/dist/channels/slack/bot-mentions.d.ts +106 -0
- package/dist/channels/slack/bot-mentions.d.ts.map +1 -0
- package/dist/channels/slack/bot-mentions.js +243 -0
- package/dist/channels/slack/dispatch.d.ts +6 -0
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +24 -3
- package/dist/channels/slack/inbound.d.ts +10 -1
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +12 -4
- package/dist/channels/slack/index.d.ts +1 -0
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +1 -0
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +61 -22
- package/dist/channels/slack/types.d.ts +58 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/docs/404.html +1 -1
- package/dist/docs/ab.html +2 -2
- package/dist/docs/assets/{app.T-5ImnM3.js → app.jDxLzWv4.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.OMGMWH6H.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DLg4yB4D.js → theme.CLazCWlJ.js} +2 -2
- package/dist/docs/building-with-agents.html +2 -2
- package/dist/docs/concepts.html +2 -2
- package/dist/docs/deployment.html +2 -2
- package/dist/docs/evals.html +2 -2
- package/dist/docs/example-agents/approval-buddy.html +2 -2
- package/dist/docs/example-agents/benny.html +2 -2
- package/dist/docs/example-agents/bugbot.html +2 -2
- package/dist/docs/example-agents/codebase-wiki.html +2 -2
- package/dist/docs/example-agents/codeowners-review.html +2 -2
- package/dist/docs/example-agents/concierge.html +2 -2
- package/dist/docs/example-agents/fsd.html +2 -2
- package/dist/docs/example-agents/index.html +2 -2
- package/dist/docs/example-agents/knowledge-base.html +2 -2
- package/dist/docs/example-agents/oncall.html +2 -2
- package/dist/docs/example-agents/security-reviewer.html +2 -2
- package/dist/docs/example-agents/slack-agent.html +2 -2
- package/dist/docs/example-agents/weather-agent.html +2 -2
- package/dist/docs/guides/agent-to-agent.html +2 -2
- package/dist/docs/guides/cloud-runtime.html +2 -2
- package/dist/docs/guides/github.html +2 -2
- package/dist/docs/guides/human-in-the-loop.html +2 -2
- package/dist/docs/guides/mcp-oauth.html +2 -2
- package/dist/docs/guides/slack.html +2 -2
- package/dist/docs/guides/webhooks.html +2 -2
- package/dist/docs/hillclimbing.html +2 -2
- package/dist/docs/index.html +2 -2
- package/dist/docs/quickstart.html +2 -2
- package/dist/docs/reference/agent-config.html +2 -2
- package/dist/docs/reference/channels.html +2 -2
- package/dist/docs/reference/cli.html +2 -2
- package/dist/docs/reference/connections.html +2 -2
- package/dist/docs/reference/hooks.html +2 -2
- package/dist/docs/reference/http-api.html +2 -2
- package/dist/docs/reference/instructions.html +2 -2
- package/dist/docs/reference/playground.html +2 -2
- package/dist/docs/reference/project-layout.html +2 -2
- package/dist/docs/reference/prompt.html +2 -2
- package/dist/docs/reference/schedules.html +2 -2
- package/dist/docs/reference/sessions.html +2 -2
- package/dist/docs/reference/skills.html +2 -2
- package/dist/docs/reference/subagents.html +2 -2
- package/dist/docs/reference/tools.html +2 -2
- package/dist/docs/scaffolding-agents.html +2 -2
- package/dist/docs/storage.html +2 -2
- package/dist/docs/troubleshooting.html +2 -2
- package/dist/internal/json-dir-store.d.ts +32 -0
- package/dist/internal/json-dir-store.d.ts.map +1 -0
- package/dist/internal/json-dir-store.js +100 -0
- package/dist/internal/resolved-connections.d.ts +1 -1
- package/dist/internal/resolved-connections.d.ts.map +1 -1
- package/dist/internal/resolved-connections.js +10 -0
- package/dist/internal/session-engine.d.ts +4 -1
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +13 -2
- package/dist/playground/assets/index-CjOQ4hN9.css +1 -0
- package/dist/playground/assets/index-dshZQJCp.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/package.json +24 -24
- package/src/bin/agent-serve.version.test.ts +62 -0
- package/src/channels/github/api.test.ts +64 -0
- package/src/channels/github/auth.test.ts +105 -0
- package/src/channels/github/cursor-account.test.ts +204 -0
- package/src/channels/github/forward.test.ts +457 -0
- package/src/channels/github/github.test.ts +937 -0
- package/src/channels/github/replay.test.ts +179 -0
- package/src/channels/slack/api.post-message.test.ts +148 -0
- package/src/channels/slack/api.ts +5 -0
- package/src/channels/slack/approvals.test.ts +328 -0
- package/src/channels/slack/block-actions.test.ts +452 -0
- package/src/channels/slack/bot-mentions.test.ts +217 -0
- package/src/channels/slack/bot-mentions.ts +315 -0
- package/src/channels/slack/channel-watch.test.ts +363 -0
- package/src/channels/slack/cursor-account.test.ts +253 -0
- package/src/channels/slack/defaults.final-post.test.ts +182 -0
- package/src/channels/slack/dispatch.test.ts +795 -0
- package/src/channels/slack/dispatch.ts +27 -1
- package/src/channels/slack/eval-directive.test.ts +273 -0
- package/src/channels/slack/inbound.ts +25 -4
- package/src/channels/slack/index.ts +1 -0
- package/src/channels/slack/message-body.test.ts +54 -0
- package/src/channels/slack/nudge-store.test.ts +143 -0
- package/src/channels/slack/slack-channel.ts +66 -8
- package/src/channels/slack/slack.test.ts +391 -0
- package/src/channels/slack/stop.test.ts +23 -0
- package/src/channels/slack/thread-context.test.ts +202 -0
- package/src/channels/slack/types.ts +60 -0
- package/src/evals/assertions.test.ts +580 -0
- package/src/evals/expect.test.ts +144 -0
- package/src/evals/judge.test.ts +181 -0
- package/src/evals/loaders.test.ts +132 -0
- package/src/evals/matchers.test.ts +95 -0
- package/src/evals/reporters.test.ts +303 -0
- package/src/evals/run-facts.test.ts +259 -0
- package/src/internal/ab-snapshot.test.ts +325 -0
- package/src/internal/approval-gate.test.ts +49 -0
- package/src/internal/approvals.integration.test.ts +383 -0
- package/src/internal/authored-loaders.test.ts +31 -0
- package/src/internal/builtin-tools/reminders.test.ts +201 -0
- package/src/internal/channel-route-schema.test.ts +294 -0
- package/src/internal/chat-attach.test.ts +262 -0
- package/src/internal/cli-deploy.test.ts +1991 -0
- package/src/internal/cli-mcp.test.ts +789 -0
- package/src/internal/cli-skills.test.ts +133 -0
- package/src/internal/cli-slack.test.ts +1647 -0
- package/src/internal/cloud-merge.test.ts +74 -0
- package/src/internal/cron.test.ts +22 -0
- package/src/internal/cursor/account-mcp.test.ts +807 -0
- package/src/internal/cursor/backend-client.test.ts +591 -0
- package/src/internal/cursor/credentials.test.ts +351 -0
- package/src/internal/cursor/github-credentials.test.ts +136 -0
- package/src/internal/cursor-account-mcp-auth.test.ts +310 -0
- package/src/internal/cursor-account.integration.test.ts +441 -0
- package/src/internal/cursor-event-relay.test.ts +746 -0
- package/src/internal/cursor-github-credentials.integration.test.ts +271 -0
- package/src/internal/cursor-slack-relay.test.ts +525 -0
- package/src/internal/deploy-source.test.ts +111 -0
- package/src/internal/discovery.builtin-tools.test.ts +94 -0
- package/src/internal/discovery.concurrency.test.ts +60 -0
- package/src/internal/discovery.cursor-account.test.ts +133 -0
- package/src/internal/discovery.cwd.test.ts +83 -0
- package/src/internal/discovery.hosting.test.ts +80 -0
- package/src/internal/discovery.identity.test.ts +44 -0
- package/src/internal/docs-site.test.ts +66 -0
- package/src/internal/duration.test.ts +29 -0
- package/src/internal/eval-judge-model.test.ts +187 -0
- package/src/internal/eval-run-store.cancel.test.ts +142 -0
- package/src/internal/eval-run-store.storage.test.ts +211 -0
- package/src/internal/eval-runner.http.test.ts +403 -0
- package/src/internal/eval-runner.run.test.ts +928 -0
- package/src/internal/evals-client.test.ts +307 -0
- package/src/internal/event-mapper.test.ts +243 -0
- package/src/internal/github-fanout.test.ts +213 -0
- package/src/internal/handleAgentServeTrigger.test.ts +179 -0
- package/src/internal/host-kv.test.ts +82 -0
- package/src/internal/host-platforms.test.ts +126 -0
- package/src/internal/http-channel.test.ts +402 -0
- package/src/internal/init-project.test.ts +269 -0
- package/src/internal/install-cursor-skills.test.ts +262 -0
- package/src/internal/local-env.test.ts +100 -0
- package/src/internal/log-ring.test.ts +31 -0
- package/src/internal/logs-client.test.ts +350 -0
- package/src/internal/mcp-endpoint.test.ts +436 -0
- package/src/internal/mcp-host.test.ts +298 -0
- package/src/internal/mcp-oauth.test.ts +148 -0
- package/src/internal/net.test.ts +17 -0
- package/src/internal/peer-connections.test.ts +128 -0
- package/src/internal/peer-mcp.integration.test.ts +289 -0
- package/src/internal/playground/toolchain.test.ts +53 -0
- package/src/internal/playground-cli.test.ts +187 -0
- package/src/internal/playground-proxy.test.ts +376 -0
- package/src/internal/prompt-context.integration.test.ts +232 -0
- package/src/internal/prompt-context.test.ts +127 -0
- package/src/internal/reminder-runner.test.ts +390 -0
- package/src/internal/reminder-store.test.ts +53 -0
- package/src/internal/request-headers.test.ts +27 -0
- package/src/internal/resolve-prod-target.test.ts +787 -0
- package/src/internal/resolved-connections.test.ts +295 -0
- package/src/internal/resolved-connections.ts +18 -1
- package/src/internal/router.test.ts +57 -0
- package/src/internal/sdk-runner.test.ts +290 -0
- package/src/internal/session-engine.coalesce.test.ts +169 -0
- package/src/internal/session-engine.concurrency.test.ts +250 -0
- package/src/internal/session-engine.host-oauth-mcp.test.ts +110 -0
- package/src/internal/session-engine.interrupt.test.ts +577 -0
- package/src/internal/session-engine.storage.test.ts +547 -0
- package/src/internal/session-engine.ts +15 -1
- package/src/internal/session-urls.test.ts +28 -0
- package/src/internal/sessions-client.test.ts +518 -0
- package/src/internal/storage-coordinator.test.ts +517 -0
- package/src/internal/tool-call.test.ts +458 -0
- package/src/internal/tool-result.test.ts +52 -0
- package/src/internal/trajectory.approvals.test.ts +83 -0
- package/src/internal/trajectory.subagents.test.ts +198 -0
- package/src/internal/turn-governor.test.ts +137 -0
- package/src/internal/update-check.test.ts +485 -0
- package/src/internal/workspace.test.ts +81 -0
- package/src/storage-backends/cursor-hosted.test.ts +121 -0
- package/src/types.ts +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.CvejISXF.js +0 -1
- package/dist/playground/assets/index-CidizGZv.css +0 -1
- package/dist/playground/assets/index-CuiAKZaP.js +0 -85
|
@@ -0,0 +1,580 @@
|
|
|
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
|
+
});
|