@webmcp-agents/testing 0.0.0-stage → 0.5.0
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/README.md +88 -2
- package/dist/chat-peer-CzVYDy7A.js +24 -0
- package/dist/chat.d.ts +193 -0
- package/dist/chat.js +409 -0
- package/dist/guard-9H8JcSkn.js +151 -0
- package/dist/ids-HmfSbtOs.js +29 -0
- package/dist/index-BYejUroK.d.ts +86 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +338 -0
- package/dist/matchers-BwXSMeTG.d.ts +225 -0
- package/dist/matchers-CcMe-gCr.js +653 -0
- package/dist/matchers.d.ts +2 -0
- package/dist/matchers.js +1 -0
- package/dist/observe-spans-D8lEWEjY.js +28 -0
- package/dist/peer-mZEQ4Hla.js +30 -0
- package/dist/playwright.d.ts +38 -0
- package/dist/playwright.js +54 -0
- package/dist/record-runs-DjiNzXC_.js +36 -0
- package/dist/record-runs-DofdrRju.js +1 -0
- package/dist/run-record-8RdIf0RD.d.ts +65 -0
- package/dist/run-record-MOCfkhN0.js +196 -0
- package/dist/script-C3gmfClf.js +52 -0
- package/dist/script-CuyU-jLV.d.ts +71 -0
- package/dist/sentinel-D154AjQn.js +15 -0
- package/dist/server.d.ts +113 -0
- package/dist/server.js +266 -0
- package/dist/setup.d.ts +1 -0
- package/dist/setup.js +89 -0
- package/dist/telemetry-Ct63NJwU.js +130 -0
- package/dist/telemetry.d.ts +2 -0
- package/dist/telemetry.js +1 -0
- package/dist/vitest.d.ts +56 -0
- package/dist/vitest.js +164 -0
- package/dist/wait-DJ--Kfhb.js +29 -0
- package/package.json +133 -3
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { _ as textMatches, a as MatcherInputError, c as hint, d as kindOf, f as listEvents, g as show, h as resultText, i as readRun, l as isAsymmetric, m as readToolResult, n as RUN_RECORD, o as describeEvent, p as readEvents, r as isRunLog, s as errorCode, u as isFailed, v as isEventLog } from "./run-record-MOCfkhN0.js";
|
|
2
|
+
import { i as readSpans, n as isMemoryExporter, o as spanTree } from "./telemetry-Ct63NJwU.js";
|
|
3
|
+
import { t as SENTINEL } from "./sentinel-D154AjQn.js";
|
|
4
|
+
import { expect } from "vitest";
|
|
5
|
+
// src/matchers/to-be-one-trace.ts
|
|
6
|
+
/**
|
|
7
|
+
* Every span belongs to one trace, with one root (one span whose parent is not among them): browser and server spans
|
|
8
|
+
* of a turn joined up. Reads what `toHaveSpan` reads. No spans at all fails.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* expect([...browser.spans, ...server.spans]).toBeOneTrace();
|
|
12
|
+
*/
|
|
13
|
+
function toBeOneTrace(received) {
|
|
14
|
+
const spans = readSpans(received);
|
|
15
|
+
if (!spans) throw new MatcherInputError(`toBeOneTrace needs spans: a memoryExporter(), an InMemorySpanExporter or an array of spans, got ${show(received, 60)}.`);
|
|
16
|
+
const traces = [...new Set(spans.map((s) => s.traceId))];
|
|
17
|
+
const roots = spanTree(spans);
|
|
18
|
+
const head = hint(this, "toBeOneTrace");
|
|
19
|
+
const why = spans.length === 0 ? "there are no spans" : traces.length > 1 ? `they belong to ${traces.length} traces (${traces.map((t) => t.slice(0, 8)).join(", ")}…)` : `there are ${roots.length} roots: ${roots.map((r) => show(r.span.name, 60)).join(", ")}`;
|
|
20
|
+
return {
|
|
21
|
+
pass: spans.length > 0 && traces.length === 1 && roots.length === 1,
|
|
22
|
+
message: () => this.isNot ? `${head}\n\n Expected the ${spans.length} span(s) not to form one trace with one root, but they do (root ${show(roots[0]?.span.name)}).` : `${head}\n\n Expected one trace with one root, but ${why}.`
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// src/matchers/to-be-tool-error.ts
|
|
26
|
+
/**
|
|
27
|
+
* The tool result failed (`isError`, or an `Error:` text), and, when `code` is given, with that code
|
|
28
|
+
* (`structuredContent.error.code`, else the `[code]` in `Error [code]: …`).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* expect(await tools.call("add_to_cart", { qty: 0 })).toBeToolError("invalid_input");
|
|
32
|
+
*/
|
|
33
|
+
function toBeToolError(received, code) {
|
|
34
|
+
if (code !== void 0 && typeof code !== "string") throw new MatcherInputError(`toBeToolError takes an error code string (e.g. "not_found"), got ${show(code)}.`);
|
|
35
|
+
const result = readToolResult(received, "toBeToolError");
|
|
36
|
+
const text = resultText(result);
|
|
37
|
+
const failed = isFailed(result);
|
|
38
|
+
const actual = errorCode(result);
|
|
39
|
+
const pass = failed && (code === void 0 || actual === code);
|
|
40
|
+
const head = hint(this, "toBeToolError", code === void 0 ? [] : [code]);
|
|
41
|
+
return {
|
|
42
|
+
pass,
|
|
43
|
+
message: () => {
|
|
44
|
+
if (this.isNot) return code === void 0 ? `${head}\n\n Expected the call to succeed, but it failed${actual ? ` with code "${actual}"` : ""}.\n Text: ${show(text)}` : `${head}\n\n Expected the call not to fail with code "${code}", but it did.\n Text: ${show(text)}`;
|
|
45
|
+
if (!failed) return `${head}\n\n Expected the call to fail${code ? ` with code "${code}"` : ""}, but it succeeded.\n Text: ${show(text)}`;
|
|
46
|
+
return `${head}\n\n The call failed, but with ${actual ? `code "${actual}"` : "no error code"}, not "${code}".\n Text: ${show(text)}`;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// src/matchers/to-be-tool-result.ts
|
|
51
|
+
/**
|
|
52
|
+
* The tool result succeeded (not `isError`, no `Error:` text), and, when `expected` is given, its text contains that
|
|
53
|
+
* string, matches that RegExp or satisfies that asymmetric matcher.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* expect(await tools.call("add_to_cart", { qty: 2 })).toBeToolResult(/2 × Field Mug/);
|
|
57
|
+
*/
|
|
58
|
+
function toBeToolResult(received, expected) {
|
|
59
|
+
const result = readToolResult(received, "toBeToolResult");
|
|
60
|
+
const text = resultText(result);
|
|
61
|
+
const failed = isFailed(result);
|
|
62
|
+
const textOk = expected === void 0 || textMatches(this, text, expected);
|
|
63
|
+
const pass = !failed && textOk;
|
|
64
|
+
const head = hint(this, "toBeToolResult", expected === void 0 ? [] : [expected]);
|
|
65
|
+
return {
|
|
66
|
+
pass,
|
|
67
|
+
message: () => {
|
|
68
|
+
if (this.isNot) return expected === void 0 ? `${head}\n\n Expected the call to fail, but it succeeded.\n Text: ${show(text)}` : `${head}\n\n Expected a result whose text does not match ${show(expected)}, but the call succeeded with it.\n Text: ${show(text)}`;
|
|
69
|
+
if (failed) {
|
|
70
|
+
const code = errorCode(result);
|
|
71
|
+
return `${head}\n\n Expected the call to succeed, but it failed${code ? ` with code "${code}"` : ""}.\n Text: ${show(text)}`;
|
|
72
|
+
}
|
|
73
|
+
return `${head}\n\n The call succeeded, but its text does not match.\n Expected: ${show(expected)}\n Text: ${show(text)}`;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// src/matchers/to-contain-sensitive.ts
|
|
78
|
+
const MAX_DEPTH = 24;
|
|
79
|
+
const has = (name) => typeof globalThis[name] === "function";
|
|
80
|
+
const key = (path, k) => /^[A-Za-z_$][\w$]*$/.test(k) ? `${path}.${k}` : `${path}[${JSON.stringify(k)}]`;
|
|
81
|
+
/**
|
|
82
|
+
* Walk `value`, handing every string (and number) to the walker with its path. Cycles and DOM nodes are skipped. The
|
|
83
|
+
* web's own containers are read through their API (a `URL`'s href, a `Request`'s url and headers, the entries of
|
|
84
|
+
* `Headers`, `URLSearchParams` and `FormData`): their data is in no own enumerable property.
|
|
85
|
+
*/
|
|
86
|
+
function walk(value, path, w, depth = 0) {
|
|
87
|
+
if (typeof value === "string") {
|
|
88
|
+
w.onString(value, path);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
92
|
+
w.onString(String(value), path);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (typeof value !== "object" || value === null) return;
|
|
96
|
+
if (w.seen.has(value)) return;
|
|
97
|
+
if (depth > MAX_DEPTH) {
|
|
98
|
+
w.tooDeep.push(path);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
w.seen.add(value);
|
|
102
|
+
const next = (v, p) => walk(v, p, w, depth + 1);
|
|
103
|
+
if (typeof Node !== "undefined" && value instanceof Node) return;
|
|
104
|
+
if (value instanceof Error) {
|
|
105
|
+
next(value.message, `${path}.message`);
|
|
106
|
+
if (value.cause !== void 0) next(value.cause, `${path}.cause`);
|
|
107
|
+
if (value instanceof AggregateError) next(value.errors, `${path}.errors`);
|
|
108
|
+
for (const [k, v] of Object.entries(value)) if (k !== "message" && k !== "cause") next(v, key(path, k));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (has("URL") && value instanceof URL) {
|
|
112
|
+
next(value.href, `${path}.href`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (has("Request") && value instanceof Request) {
|
|
116
|
+
next(value.url, `${path}.url`);
|
|
117
|
+
next(value.headers, `${path}.headers`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (has("Headers") && value instanceof Headers || has("URLSearchParams") && value instanceof URLSearchParams || has("FormData") && value instanceof FormData) {
|
|
121
|
+
for (const [k, v] of value.entries()) {
|
|
122
|
+
next(k, `${path}.keys()`);
|
|
123
|
+
next(typeof v === "string" ? v : v.name, `${path}.get(${show(k, 30)})`);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (value instanceof Map) {
|
|
128
|
+
for (const [k, v] of value) {
|
|
129
|
+
next(k, `${path}.keys()`);
|
|
130
|
+
next(v, `${path}.get(${show(k, 30)})`);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(value) || value instanceof Set) {
|
|
135
|
+
for (const [i, v] of [...value].entries()) next(v, `${path}[${i}]`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
for (const [k, v] of Object.entries(value)) next(v, key(path, k));
|
|
139
|
+
}
|
|
140
|
+
const found = (text, needle) => {
|
|
141
|
+
if (typeof needle === "string") return text.includes(needle);
|
|
142
|
+
needle.lastIndex = 0;
|
|
143
|
+
return needle.test(text);
|
|
144
|
+
};
|
|
145
|
+
const isSpy = (value) => (typeof value === "function" || typeof value === "object") && value !== null && Array.isArray(value.mock?.calls);
|
|
146
|
+
/** Scan a sink that is already in memory (everything but a `Response`). */
|
|
147
|
+
function scan(received, needles) {
|
|
148
|
+
const hits = [];
|
|
149
|
+
const tooDeep = [];
|
|
150
|
+
const check = (event) => ({
|
|
151
|
+
onString: (text, path) => {
|
|
152
|
+
for (const needle of needles) if (found(text, needle)) hits.push({
|
|
153
|
+
needle,
|
|
154
|
+
path,
|
|
155
|
+
...event ? { event } : {}
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
tooDeep,
|
|
159
|
+
seen: /* @__PURE__ */ new WeakSet()
|
|
160
|
+
});
|
|
161
|
+
const events = isEventLog(received) ? received.events : isEventArray(received) ? received : void 0;
|
|
162
|
+
if (events) {
|
|
163
|
+
for (const [i, e] of events.entries()) walk(e, `events[${i}]`, check(describeEvent(e.type === "fill" ? {
|
|
164
|
+
...e,
|
|
165
|
+
value: "…"
|
|
166
|
+
} : e)));
|
|
167
|
+
return {
|
|
168
|
+
sink: "the event log",
|
|
169
|
+
hits,
|
|
170
|
+
tooDeep
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (isRunLog(received)) {
|
|
174
|
+
for (const [i, e] of received.events.entries()) walk(e, `events[${i}]`, check(`${e.type}${"tool" in e ? ` ${e.tool}` : ""}`));
|
|
175
|
+
return {
|
|
176
|
+
sink: "the run log",
|
|
177
|
+
hits,
|
|
178
|
+
tooDeep
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (isMemoryExporter(received)) {
|
|
182
|
+
for (const [i, s] of received.spans.entries()) walk(s, `spans[${i}]`, check(s.name));
|
|
183
|
+
return {
|
|
184
|
+
sink: "the spans",
|
|
185
|
+
hits,
|
|
186
|
+
tooDeep
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (isSpy(received)) {
|
|
190
|
+
for (const [i, args] of received.mock.calls.entries()) walk(args, `calls[${i}]`, check());
|
|
191
|
+
return {
|
|
192
|
+
sink: `the spy "${received.getMockName?.() || "spy"}"`,
|
|
193
|
+
hits,
|
|
194
|
+
tooDeep
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const record = received?.[RUN_RECORD];
|
|
198
|
+
if (record) {
|
|
199
|
+
walk(received.requests, "requests", check());
|
|
200
|
+
walk(record, "record", check());
|
|
201
|
+
return {
|
|
202
|
+
sink: "the mock adapter",
|
|
203
|
+
hits,
|
|
204
|
+
tooDeep
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
walk(received, "value", check());
|
|
208
|
+
return {
|
|
209
|
+
sink: "the value",
|
|
210
|
+
hits,
|
|
211
|
+
tooDeep
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** Scan a `Response`'s body: as JSON when it parses, else as text. */
|
|
215
|
+
async function scanResponse(res, needles) {
|
|
216
|
+
const text = await res.clone().text();
|
|
217
|
+
let json;
|
|
218
|
+
try {
|
|
219
|
+
json = JSON.parse(text);
|
|
220
|
+
} catch {
|
|
221
|
+
json = void 0;
|
|
222
|
+
}
|
|
223
|
+
const scanned = json === void 0 ? scan(text, needles) : scan(json, needles);
|
|
224
|
+
return {
|
|
225
|
+
sink: `the Response body (status ${res.status})`,
|
|
226
|
+
tooDeep: scanned.tooDeep,
|
|
227
|
+
hits: scanned.hits.map((h) => ({
|
|
228
|
+
...h,
|
|
229
|
+
path: json === void 0 ? "body (text)" : h.path.replace(/^value/, "body")
|
|
230
|
+
}))
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const isEventArray = (value) => Array.isArray(value) && value.length > 0 && value.every((e) => typeof e?.type === "string");
|
|
234
|
+
/**
|
|
235
|
+
* One of `values` (strings found inside any text, or RegExps) is somewhere in this sink: an event log, a console spy
|
|
236
|
+
* (`vi.spyOn(console, "error")`), a `Response` (its body), a mock adapter (what it was sent), a run, or any value.
|
|
237
|
+
* Use it negated: `expect(sink).not.toContainSensitive(["A1234567"])`. The failure names the sink and the path where
|
|
238
|
+
* the value was found, and prints nothing else of the sink's content. On a `Response` it is async: `await` it. A sink
|
|
239
|
+
* nested deeper than it looks (24 levels) fails with the path where it stopped, unless a value was found: "not there"
|
|
240
|
+
* is never claimed for a part it did not read.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* for (const sink of [events, logs, adapter]) expect(sink).not.toContainSensitive(["A1234567"]);
|
|
244
|
+
* await expect(response).not.toContainSensitive(["sk-test-key"]);
|
|
245
|
+
*/
|
|
246
|
+
function toContainSensitive(received, values) {
|
|
247
|
+
if (!Array.isArray(values) || values.length === 0 || !values.every((v) => typeof v === "string" && v.length > 0 || v instanceof RegExp)) throw new MatcherInputError(`toContainSensitive takes a non-empty list of the values to look for (strings or RegExps), got ${show(values)}.`);
|
|
248
|
+
if (received === void 0) throw new MatcherInputError("toContainSensitive needs a sink to look in (an event log, a spy, a Response, a mock adapter or a value), got undefined.");
|
|
249
|
+
const head = hint(this, "toContainSensitive", [values]);
|
|
250
|
+
const verdict = ({ sink, hits, tooDeep }) => {
|
|
251
|
+
if (!hits.length && tooDeep.length) throw new MatcherInputError(`toContainSensitive could not read all of ${sink}: it stops ${MAX_DEPTH} levels down, at ${tooDeep.slice(0, 3).join(", ")}${tooDeep.length > 3 ? ` and ${tooDeep.length - 3} more` : ""}. Pass the nested part itself.`);
|
|
252
|
+
return {
|
|
253
|
+
pass: hits.length > 0,
|
|
254
|
+
message: () => this.isNot ? `${head}\n\n Found in ${sink}:\n${hits.slice(0, 10).map((h) => ` - ${show(h.needle)} at ${h.path}${h.event ? ` (event: ${h.event})` : ""}`).join("\n")}${hits.length > 10 ? `\n … and ${hits.length - 10} more` : ""}` : `${head}\n\n Expected ${sink} to contain one of ${values.map((v) => show(v)).join(", ")}, but none is in it.`
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
if (typeof Response !== "undefined" && received instanceof Response) return scanResponse(received, values).then(verdict);
|
|
258
|
+
return verdict(scan(received, values));
|
|
259
|
+
}
|
|
260
|
+
// src/matchers/to-have-answered.ts
|
|
261
|
+
/**
|
|
262
|
+
* The run's answer (the text it replied with) contains this string, matches this RegExp or satisfies this asymmetric
|
|
263
|
+
* matcher. On a `mockAdapter`, its last top-level run's answer (a sub-agent's run is not it).
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* expect(run).toHaveAnswered(/back in your cart/i);
|
|
267
|
+
*/
|
|
268
|
+
function toHaveAnswered(received, expected) {
|
|
269
|
+
if (expected === void 0) throw new MatcherInputError("toHaveAnswered takes the expected answer: a string it contains, a RegExp or an asymmetric matcher.");
|
|
270
|
+
const run = readRun(received, "toHaveAnswered");
|
|
271
|
+
const answer = run.answer;
|
|
272
|
+
const pass = answer !== void 0 && textMatches(this, answer, expected);
|
|
273
|
+
const head = hint(this, "toHaveAnswered", [expected]);
|
|
274
|
+
return {
|
|
275
|
+
pass,
|
|
276
|
+
message: () => {
|
|
277
|
+
if (this.isNot) return `${head}\n\n Expected the answer not to match ${show(expected)}, but it does.\n Answer: ${show(answer)}`;
|
|
278
|
+
if (answer === void 0) return `${head}\n\n ${run.source} has no answer: the run ${run.finish ? `ended with "${run.finish.reason}"${run.finish.error ? ` (${run.finish.error})` : ""}` : "has not run"}.`;
|
|
279
|
+
return `${head}\n\n Expected the answer to match ${show(expected)}.\n Answer: ${show(answer, 400)}`;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
// src/matchers/to-have-been-offered-tools.ts
|
|
284
|
+
/**
|
|
285
|
+
* Every model step of the mock adapter's runs was offered these tools: a list (each was offered; others may be too)
|
|
286
|
+
* or an asymmetric matcher over the names (`expect.not.arrayContaining(["place_order"])`). An adapter that has not run
|
|
287
|
+
* fails it either way, negated too. Negated with a list it is refused: "not every step was offered them" would pass
|
|
288
|
+
* when one step was offered `place_order`; to say "no step was offered it", use the asymmetric form above (one tool per
|
|
289
|
+
* assertion: `expect.not.arrayContaining([a, b])` also matches a step offered only `a`).
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* expect(adapter).toHaveBeenOfferedTools(["search_products", "add_to_cart"]);
|
|
293
|
+
* expect(adapter).toHaveBeenOfferedTools(expect.not.arrayContaining(["place_order"]));
|
|
294
|
+
*/
|
|
295
|
+
function toHaveBeenOfferedTools(received, expected) {
|
|
296
|
+
const record = received?.[RUN_RECORD];
|
|
297
|
+
if (!record) throw new MatcherInputError(`toHaveBeenOfferedTools needs a mockAdapter (it records what each step was offered), got ${kindOf(received)}.`);
|
|
298
|
+
if (!Array.isArray(expected) && !isAsymmetric(expected)) throw new MatcherInputError(`toHaveBeenOfferedTools takes a list of tool names or an asymmetric matcher, got ${show(expected)}.`);
|
|
299
|
+
if (this.isNot && Array.isArray(expected)) throw new MatcherInputError(`.not.toHaveBeenOfferedTools(${show(expected)}) would pass when only some steps were not offered them. To say no step was offered a tool, write toHaveBeenOfferedTools(expect.not.arrayContaining([${show(expected[0] ?? "tool_name")}])), one tool per assertion.`);
|
|
300
|
+
const matcher = Array.isArray(expected) ? expect.arrayContaining(expected) : expected;
|
|
301
|
+
const steps = record.offered;
|
|
302
|
+
const bad = steps.findIndex((names) => !this.equals(names, matcher));
|
|
303
|
+
const pass = steps.length > 0 ? bad === -1 : this.isNot;
|
|
304
|
+
const head = hint(this, "toHaveBeenOfferedTools", [expected]);
|
|
305
|
+
return {
|
|
306
|
+
pass,
|
|
307
|
+
message: () => {
|
|
308
|
+
if (!steps.length) return `${head}\n\n The mock adapter has not run: no model step was offered any tools yet.`;
|
|
309
|
+
if (this.isNot) return `${head}\n\n Expected some step's tools not to match ${show(expected)}, but every step's did.\n Step 1 offered: ${steps[0].join(", ") || "(none)"}`;
|
|
310
|
+
const names = steps[bad];
|
|
311
|
+
const missing = Array.isArray(expected) ? expected.filter((n) => !names.includes(n)) : [];
|
|
312
|
+
return `${head}\n\n Model step ${bad + 1} of ${steps.length} was offered: ${names.join(", ") || "(no tools)"}${missing.length ? `\n Missing: ${missing.join(", ")}` : ""}`;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// src/matchers/to-have-called-tool.ts
|
|
317
|
+
/**
|
|
318
|
+
* The run called `tool`, with an input that contains `input` when given (a partial match: other keys may be there).
|
|
319
|
+
* Reads a `WebAgentResult`, a `mockAdapter` or the `runs` fixture's `RunLog`. The error `agent.invoke` rejected with
|
|
320
|
+
* carries no calls, so it is refused (a negated call would pass on nothing): assert on the `mockAdapter` instead.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* expect(run).toHaveCalledTool("add_to_cart", { qty: 2 });
|
|
324
|
+
* expect(run).not.toHaveCalledTool("place_order");
|
|
325
|
+
*/
|
|
326
|
+
function toHaveCalledTool(received, tool, input) {
|
|
327
|
+
if (typeof tool !== "string") throw new MatcherInputError(`toHaveCalledTool takes the tool's name first, got ${show(tool)}.`);
|
|
328
|
+
const run = readRun(received, "toHaveCalledTool");
|
|
329
|
+
const named = run.calls.filter((c) => c.name === tool);
|
|
330
|
+
const matches = (value) => typeof input === "object" && input !== null ? this.equals(value, expect.objectContaining(input)) : this.equals(value, input);
|
|
331
|
+
const hits = input === void 0 ? named : named.filter((c) => matches(c.input));
|
|
332
|
+
const called = run.calls.map((c) => c.name).join(" → ") || "(no tools)";
|
|
333
|
+
const head = hint(this, "toHaveCalledTool", input === void 0 ? [tool] : [tool, input]);
|
|
334
|
+
return {
|
|
335
|
+
pass: hits.length > 0,
|
|
336
|
+
message: () => {
|
|
337
|
+
if (this.isNot) return `${head}\n\n Expected "${tool}" not to be called${input === void 0 ? "" : ` with ${show(input)}`}, but ${run.source} called it ${hits.length} time(s).\n ${tool} input: ${show(hits[0]?.input)}\n Called: ${called}`;
|
|
338
|
+
if (!named.length) return `${head}\n\n Expected "${tool}" to be called, but ${run.source} never called it.\n Called: ${called}`;
|
|
339
|
+
return `${head}\n\n "${tool}" was called, but not with ${show(input)}.\n${named.map((c) => ` ${tool} input: ${show(c.input)}`).join("\n")}`;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
// src/matchers/to-have-called-tools.ts
|
|
344
|
+
/**
|
|
345
|
+
* The run called exactly these tools, in this order (no other call before, between or after). Reads what
|
|
346
|
+
* `toHaveCalledTool` reads; the error `agent.invoke` rejected with carries no calls, so it is refused.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* expect(run).toHaveCalledTools(["track_last_order", "add_to_cart"]);
|
|
350
|
+
*/
|
|
351
|
+
function toHaveCalledTools(received, tools) {
|
|
352
|
+
if (!Array.isArray(tools) || !tools.every((t) => typeof t === "string")) throw new MatcherInputError(`toHaveCalledTools takes the tool names in order, e.g. ["track_last_order", "add_to_cart"], got ${show(tools)}.`);
|
|
353
|
+
const run = readRun(received, "toHaveCalledTools");
|
|
354
|
+
const names = run.calls.map((c) => c.name);
|
|
355
|
+
const pass = names.length === tools.length && names.every((n, i) => n === tools[i]);
|
|
356
|
+
const head = hint(this, "toHaveCalledTools", [tools]);
|
|
357
|
+
return {
|
|
358
|
+
pass,
|
|
359
|
+
message: () => {
|
|
360
|
+
const expected = tools.join(" → ") || "(no tools)";
|
|
361
|
+
const called = names.join(" → ") || "(no tools)";
|
|
362
|
+
if (this.isNot) return `${head}\n\n Expected the run not to call exactly ${expected}, but it did.`;
|
|
363
|
+
const lines = [
|
|
364
|
+
`${head}`,
|
|
365
|
+
"",
|
|
366
|
+
` Expected tools, in order: ${expected}`,
|
|
367
|
+
` Called: ${called}`
|
|
368
|
+
];
|
|
369
|
+
const at = names.findIndex((n, i) => n !== tools[i]);
|
|
370
|
+
if (at >= 0) {
|
|
371
|
+
const offset = 29 + names.slice(0, at).reduce((w, n) => w + n.length + 3, 0);
|
|
372
|
+
lines.push(`${" ".repeat(offset)}^ ${tools.includes(names[at]) ? "out of order" : "unexpected"}`);
|
|
373
|
+
lines.push(` ${names[at]} input: ${show(run.calls[at].input)}`);
|
|
374
|
+
} else lines.push(` Missing: ${tools.slice(names.length).join(" → ")}`);
|
|
375
|
+
return lines.join("\n");
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
// src/matchers/to-have-event-order.ts
|
|
380
|
+
/**
|
|
381
|
+
* These event types happened in this order. Other events may come between them (several `fill`s, a `yield`): the
|
|
382
|
+
* list is checked as a subsequence of what happened.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* expect(events).toHaveEventOrder(["start", "fill", "park", "result"]);
|
|
386
|
+
*/
|
|
387
|
+
function toHaveEventOrder(received, order) {
|
|
388
|
+
if (!Array.isArray(order) || !order.every((t) => typeof t === "string")) throw new MatcherInputError(`toHaveEventOrder takes a list of event types, e.g. ["start", "fill", "result"], got ${show(order)}.`);
|
|
389
|
+
const events = readEvents(received, "toHaveEventOrder");
|
|
390
|
+
const types = events.map((e) => e.type);
|
|
391
|
+
let at = 0;
|
|
392
|
+
for (const t of types) if (t === order[at]) at++;
|
|
393
|
+
const pass = at === order.length;
|
|
394
|
+
const head = hint(this, "toHaveEventOrder", [order]);
|
|
395
|
+
return {
|
|
396
|
+
pass,
|
|
397
|
+
message: () => this.isNot ? `${head}\n\n Expected the events not to happen in the order ${order.join(" → ")}, but they did.\n Happened: ${types.join(" → ") || "(nothing)"}` : `${head}\n\n Expected, in order: ${order.join(" → ")}\n Happened: ${types.join(" → ") || "(nothing)"}\n Missing from "${order[at]}" on (step ${at + 1} of ${order.length}).\n Events:\n${listEvents(events)}`
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
// src/matchers/to-have-filled.ts
|
|
401
|
+
/**
|
|
402
|
+
* The agent's value went into `field` (a `fill` event: a form control's `name`, or a tool parameter's), and, when
|
|
403
|
+
* `value` is given, that value (compared as is, or as text: `"2"` matches `2`).
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* expect(events).toHaveFilled("qty", "2");
|
|
407
|
+
*/
|
|
408
|
+
function toHaveFilled(received, field, value) {
|
|
409
|
+
if (typeof field !== "string") throw new MatcherInputError(`toHaveFilled takes the field's name first, got ${show(field)}.`);
|
|
410
|
+
const events = readEvents(received, "toHaveFilled");
|
|
411
|
+
const fills = events.filter((e) => e.type === "fill" && e.field === field);
|
|
412
|
+
const same = (v) => this.equals(v, value) || typeof value !== "object" && String(v) === String(value);
|
|
413
|
+
const hits = value === void 0 ? fills : fills.filter((e) => same(e.value));
|
|
414
|
+
const head = hint(this, "toHaveFilled", value === void 0 ? [field] : [field, value]);
|
|
415
|
+
return {
|
|
416
|
+
pass: hits.length > 0,
|
|
417
|
+
message: () => {
|
|
418
|
+
if (this.isNot) return `${head}\n\n Expected "${field}" not to be filled${value === void 0 ? "" : ` with ${show(value)}`}, but it was.\n Events:\n${listEvents(events)}`;
|
|
419
|
+
if (!fills.length) return `${head}\n\n Expected "${field}" to be filled, but no fill went into it.\n Events:\n${listEvents(events)}`;
|
|
420
|
+
return `${head}\n\n "${field}" was filled with ${fills.map((e) => show(e.value, 40)).join(", ")}, not ${show(value)}.`;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
// src/matchers/to-have-finished-with.ts
|
|
425
|
+
const REASONS = [
|
|
426
|
+
"stop",
|
|
427
|
+
"max-steps",
|
|
428
|
+
"aborted",
|
|
429
|
+
"error"
|
|
430
|
+
];
|
|
431
|
+
/**
|
|
432
|
+
* The run ended this way: `"stop"`, `"max-steps"`, `"aborted"` or `"error"`; with `code` too, the adapter's error
|
|
433
|
+
* code (`"rate_limited"`, `"network"`…). A `WebAgentResult` reads as `"stop"` (see the matcher's page); a
|
|
434
|
+
* `mockAdapter` knows exactly (its last top-level run, not a sub-agent's); the error `agent.invoke` rejected with reads as `"error"` (or `"aborted"`).
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* expect(adapter).toHaveFinishedWith("error", "rate_limited");
|
|
438
|
+
*/
|
|
439
|
+
function toHaveFinishedWith(received, reason, code) {
|
|
440
|
+
if (!REASONS.includes(reason)) throw new MatcherInputError(`toHaveFinishedWith takes one of ${REASONS.map((r) => `"${r}"`).join(", ")}, got ${show(reason)}.`);
|
|
441
|
+
const run = readRun(received, "toHaveFinishedWith");
|
|
442
|
+
const finish = run.finish;
|
|
443
|
+
const pass = !!finish && finish.reason === reason && (code === void 0 || finish.code === code);
|
|
444
|
+
const head = hint(this, "toHaveFinishedWith", code === void 0 ? [reason] : [reason, code]);
|
|
445
|
+
const ended = finish ? `"${finish.reason}"${finish.code ? ` with code "${finish.code}"` : ""}${finish.error ? ` (${show(finish.error, 120)})` : ""}` : "nothing yet: no run finished";
|
|
446
|
+
return {
|
|
447
|
+
pass,
|
|
448
|
+
message: () => this.isNot ? `${head}\n\n Expected the run not to end with "${reason}"${code ? ` and code "${code}"` : ""}, but it did.` : `${head}\n\n Expected the run to end with "${reason}"${code ? ` and code "${code}"` : ""}.\n It ended with ${ended}, according to ${run.source}.${run.finishNote ? `\n Note: ${run.finishNote}` : ""}`
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
// src/matchers/to-have-no-hardcoded-text.ts
|
|
452
|
+
/** Attributes a person (or their screen reader) reads. */
|
|
453
|
+
const READ_ATTRIBUTES = [
|
|
454
|
+
"aria-label",
|
|
455
|
+
"placeholder",
|
|
456
|
+
"title",
|
|
457
|
+
"alt",
|
|
458
|
+
"aria-valuetext",
|
|
459
|
+
"aria-roledescription",
|
|
460
|
+
"aria-description"
|
|
461
|
+
];
|
|
462
|
+
/** Elements whose text is not shown: styles, scripts, and the drawing inside an icon. */
|
|
463
|
+
const SKIP = "style, script, template, svg";
|
|
464
|
+
/** Any letter, in any script: digits and punctuation around markers are not words. */
|
|
465
|
+
const LETTER = /\p{L}/u;
|
|
466
|
+
function rootOf(received) {
|
|
467
|
+
const host = received?.host ?? received;
|
|
468
|
+
if (typeof Element !== "undefined" && host instanceof Element) return host;
|
|
469
|
+
throw new MatcherInputError(`toHaveNoHardcodedText reads a rendered chat (what renderChat() returns) or an element, but got ${show(received)}.`);
|
|
470
|
+
}
|
|
471
|
+
const where = (el) => {
|
|
472
|
+
const part = el.closest("[data-wa-part]")?.getAttribute("data-wa-part");
|
|
473
|
+
return `<${el.tagName.toLowerCase()}${part ? ` data-wa-part="${part}"` : ""}>`;
|
|
474
|
+
};
|
|
475
|
+
/** What is left of `text` once markers and allowed text are taken out. */
|
|
476
|
+
function stray(text, allow) {
|
|
477
|
+
let rest = text.replace(SENTINEL, " ");
|
|
478
|
+
for (const a of allow) rest = typeof a === "string" ? rest.split(a).join(" ") : rest.replace(a, " ");
|
|
479
|
+
return rest.replace(/\s+/g, " ").trim();
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* The rendered chat shows no text that bypassed its messages catalog: render it with the sentinel catalog
|
|
483
|
+
* (`renderChat({ sentinel: true })`), and every text node and every `aria-label`, `placeholder`, `title`, `alt` and
|
|
484
|
+
* `aria-valuetext` holds only `⟦markers⟧`, punctuation, digits, or text you `allow` (the person's and the model's own
|
|
485
|
+
* words). Fails with each stray string and where it is.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* const chat = await renderChat({ adapter, sentinel: true });
|
|
489
|
+
* await expect(chat).toHaveNoHardcodedText({ allow: ["Add a mug", "Added."] });
|
|
490
|
+
*/
|
|
491
|
+
function toHaveNoHardcodedText(received, options = {}) {
|
|
492
|
+
const root = rootOf(received);
|
|
493
|
+
const allow = options.allow ?? [];
|
|
494
|
+
const found = [];
|
|
495
|
+
const walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
496
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
497
|
+
const parent = node.parentElement;
|
|
498
|
+
if (!parent || parent.closest(SKIP)) continue;
|
|
499
|
+
const left = stray(node.textContent ?? "", allow);
|
|
500
|
+
if (LETTER.test(left)) found.push(`text ${show(left)} in ${where(parent)}`);
|
|
501
|
+
}
|
|
502
|
+
for (const el of [root, ...root.querySelectorAll("*")]) {
|
|
503
|
+
if (el.closest(SKIP) && el.tagName.toLowerCase() !== "svg") continue;
|
|
504
|
+
for (const attr of READ_ATTRIBUTES) {
|
|
505
|
+
const value = el.getAttribute(attr);
|
|
506
|
+
if (value === null) continue;
|
|
507
|
+
const left = stray(value, allow);
|
|
508
|
+
if (LETTER.test(left)) found.push(`${attr} ${show(left)} on ${where(el)}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const head = hint(this, "toHaveNoHardcodedText", []);
|
|
512
|
+
return {
|
|
513
|
+
pass: found.length === 0,
|
|
514
|
+
message: () => this.isNot ? `${head}\n\n Expected text outside the catalog, but every string is a marker or allowed.` : `${head}\n\n Expected every string to come from the catalog, but found ${found.length} that did not:\n${found.map((f) => ` - ${f}`).join("\n")}`
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
// src/matchers/to-have-parked.ts
|
|
518
|
+
/**
|
|
519
|
+
* A tool waited for the person (a `park` event: a confirmation, a question), `tool` when given, with a prompt that
|
|
520
|
+
* contains / matches `prompt` when given.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* await expect.poll(() => events).toHaveParked("place_order");
|
|
524
|
+
*/
|
|
525
|
+
function toHaveParked(received, tool, prompt) {
|
|
526
|
+
const events = readEvents(received, "toHaveParked");
|
|
527
|
+
const parks = events.filter((e) => e.type === "park");
|
|
528
|
+
const hits = parks.filter((e) => (tool === void 0 || e.tool === tool) && (prompt === void 0 || textMatches(this, e.prompt, prompt)));
|
|
529
|
+
const args = [tool, prompt].filter((a) => a !== void 0);
|
|
530
|
+
const head = hint(this, "toHaveParked", args);
|
|
531
|
+
return {
|
|
532
|
+
pass: hits.length > 0,
|
|
533
|
+
message: () => {
|
|
534
|
+
if (this.isNot) return `${head}\n\n Expected no tool to wait for the person, but ${hits.map((e) => `"${e.tool}" parked with the prompt ${show(e.prompt)}`).join("; ")}.`;
|
|
535
|
+
if (!parks.length) return `${head}\n\n Expected ${tool ? `"${tool}"` : "a tool"} to wait for the person, but nothing parked.\n Events:\n${listEvents(events)}`;
|
|
536
|
+
return `${head}\n\n Expected ${tool ? `"${tool}"` : "a tool"} to park${prompt === void 0 ? "" : ` with a prompt matching ${show(prompt)}`}; what parked: ${parks.map((e) => `"${e.tool}" (${show(e.prompt)})`).join(", ")}.`;
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
// src/matchers/to-have-span.ts
|
|
541
|
+
/**
|
|
542
|
+
* The spans include one named `name` (exactly, or matching a RegExp) whose attributes include `attributes` (each value
|
|
543
|
+
* compared with `equals`, so asymmetric matchers work). Reads a memory exporter, an OpenTelemetry
|
|
544
|
+
* `InMemorySpanExporter`, an array of spans or span trees.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* expect(spans).toHaveSpan("execute_tool add_to_cart", { "webmcp.tool.confirm": "accepted" });
|
|
548
|
+
* expect(spans).toHaveSpan(/^chat /, { "gen_ai.usage.input_tokens": expect.any(Number) });
|
|
549
|
+
*/
|
|
550
|
+
function toHaveSpan(received, name, attributes) {
|
|
551
|
+
const spans = readSpans(received);
|
|
552
|
+
if (!spans) throw new MatcherInputError(`toHaveSpan needs spans: a memoryExporter(), an InMemorySpanExporter or an array of spans, got ${show(received, 60)}.`);
|
|
553
|
+
const named = spans.filter((s) => {
|
|
554
|
+
if (typeof name === "string") return s.name === name;
|
|
555
|
+
name.lastIndex = 0;
|
|
556
|
+
return name.test(s.name);
|
|
557
|
+
});
|
|
558
|
+
const matching = named.filter((s) => Object.entries(attributes ?? {}).every(([k, v]) => this.equals(s.attributes[k], v)));
|
|
559
|
+
const head = hint(this, "toHaveSpan", attributes ? [name, attributes] : [name]);
|
|
560
|
+
const list = spans.length ? spans.map((s) => ` ${s.name}`).join("\n") : " (no spans)";
|
|
561
|
+
const closest = named[0];
|
|
562
|
+
return {
|
|
563
|
+
pass: matching.length > 0,
|
|
564
|
+
message: () => this.isNot ? `${head}\n\n Expected no span ${show(name)}${attributes ? " with these attributes" : ""}, but found ${matching.length}.` : closest ? `${head}\n\n Found ${named.length} span(s) ${show(name)}, none with these attributes. The first one has:\n${Object.keys(attributes ?? {}).map((k) => ` ${k}: ${show(closest.attributes[k], 80)} (expected ${show(attributes?.[k], 80)})`).join("\n")}` : `${head}\n\n Expected a span ${show(name)}, but there is none. Spans:\n${list}`
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
// src/matchers/to-have-started.ts
|
|
568
|
+
/**
|
|
569
|
+
* A tool run started (a `start` event), for `tool` when given.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* expect(events).toHaveStarted("place_order");
|
|
573
|
+
*/
|
|
574
|
+
function toHaveStarted(received, tool) {
|
|
575
|
+
const events = readEvents(received, "toHaveStarted");
|
|
576
|
+
const starts = events.filter((e) => e.type === "start" && (tool === void 0 || e.tool === tool));
|
|
577
|
+
const head = hint(this, "toHaveStarted", tool === void 0 ? [] : [tool]);
|
|
578
|
+
return {
|
|
579
|
+
pass: starts.length > 0,
|
|
580
|
+
message: () => this.isNot ? `${head}\n\n Expected no run of ${tool ? `"${tool}"` : "any tool"} to start, but it started ${starts.length} time(s).\n Events:\n${listEvents(events)}` : `${head}\n\n Expected a run of ${tool ? `"${tool}"` : "a tool"} to start, but none did.\n Events:\n${listEvents(events)}`
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
// src/matchers/to-have-structured-content.ts
|
|
584
|
+
/**
|
|
585
|
+
* The tool result's `structuredContent` has these keys with these values (a partial match: other keys may be there).
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* expect(await tools.call("cart_total")).toHaveStructuredContent({ total: 48 });
|
|
589
|
+
*/
|
|
590
|
+
function toHaveStructuredContent(received, expected) {
|
|
591
|
+
if (typeof expected !== "object" || expected === null || Array.isArray(expected)) throw new MatcherInputError(`toHaveStructuredContent takes an object of the keys to check, got ${kindOf(expected)}.`);
|
|
592
|
+
const actual = readToolResult(received, "toHaveStructuredContent").structuredContent;
|
|
593
|
+
const pass = actual !== void 0 && this.equals(actual, expect.objectContaining(expected));
|
|
594
|
+
const head = hint(this, "toHaveStructuredContent", [expected]);
|
|
595
|
+
return {
|
|
596
|
+
pass,
|
|
597
|
+
message: () => {
|
|
598
|
+
if (this.isNot) return `${head}\n\n Expected structuredContent not to match ${show(expected)}, but it does.\n structuredContent: ${show(actual)}`;
|
|
599
|
+
if (actual === void 0) return `${head}\n\n The result has no structuredContent.\n Expected: ${show(expected)}`;
|
|
600
|
+
const differing = Object.keys(expected).filter((k) => !this.equals(actual[k], expected[k]));
|
|
601
|
+
return `${head}\n\n structuredContent differs at ${differing.map((k) => `"${k}"`).join(", ")}.\n` + differing.map((k) => ` ${k}: expected ${show(expected[k])}, got ${show(actual[k])}`).join("\n");
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
// src/matchers/to-have-yielded.ts
|
|
606
|
+
/**
|
|
607
|
+
* The cursor got out of the person's way (a `yield` event), for `reason` when given (`"pointer"`, `"keyboard"`,
|
|
608
|
+
* `"scroll"`…).
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* expect(events).toHaveYielded();
|
|
612
|
+
*/
|
|
613
|
+
function toHaveYielded(received, reason) {
|
|
614
|
+
const events = readEvents(received, "toHaveYielded");
|
|
615
|
+
const yields = events.filter((e) => e.type === "yield");
|
|
616
|
+
const hits = yields.filter((e) => reason === void 0 || e.reason === reason);
|
|
617
|
+
const head = hint(this, "toHaveYielded", reason === void 0 ? [] : [reason]);
|
|
618
|
+
return {
|
|
619
|
+
pass: hits.length > 0,
|
|
620
|
+
message: () => {
|
|
621
|
+
if (this.isNot) return `${head}\n\n Expected the cursor not to yield${reason ? ` for "${reason}"` : ""}, but it yielded (${hits.map((e) => e.reason).join(", ")}).`;
|
|
622
|
+
if (!yields.length) return `${head}\n\n Expected the cursor to yield to the person, but it never did.\n Events:\n${listEvents(events)}`;
|
|
623
|
+
return `${head}\n\n The cursor yielded for ${yields.map((e) => `"${e.reason}"`).join(", ")}, not "${reason}".`;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
// src/matchers.ts
|
|
628
|
+
/**
|
|
629
|
+
* `@webmcp-agents/testing/matchers`: registers the kit's matchers on Vitest's `expect` and declares their types. List
|
|
630
|
+
* it in `setupFiles` (`./setup` imports it, and so does the main entry), and every test file gets them.
|
|
631
|
+
*/
|
|
632
|
+
/** Every matcher of the kit, by name: what `expect.extend` receives. */
|
|
633
|
+
const webAgentsMatchers = {
|
|
634
|
+
toBeToolResult,
|
|
635
|
+
toBeToolError,
|
|
636
|
+
toHaveStructuredContent,
|
|
637
|
+
toHaveStarted,
|
|
638
|
+
toHaveFilled,
|
|
639
|
+
toHaveParked,
|
|
640
|
+
toHaveYielded,
|
|
641
|
+
toHaveEventOrder,
|
|
642
|
+
toHaveCalledTool,
|
|
643
|
+
toHaveCalledTools,
|
|
644
|
+
toHaveAnswered,
|
|
645
|
+
toHaveFinishedWith,
|
|
646
|
+
toHaveBeenOfferedTools,
|
|
647
|
+
toHaveSpan,
|
|
648
|
+
toBeOneTrace,
|
|
649
|
+
toContainSensitive,
|
|
650
|
+
toHaveNoHardcodedText
|
|
651
|
+
};
|
|
652
|
+
expect.extend(webAgentsMatchers);
|
|
653
|
+
export { webAgentsMatchers as t };
|
package/dist/matchers.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as webAgentsMatchers } from "./matchers-CcMe-gCr.js";
|