@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,225 @@
|
|
|
1
|
+
import { t as FinishReason } from "./run-record-8RdIf0RD.js";
|
|
2
|
+
import { MatcherResult, MatcherState } from "vitest";
|
|
3
|
+
/**
|
|
4
|
+
* Every span belongs to one trace, with one root (one span whose parent is not among them): browser and server spans
|
|
5
|
+
* of a turn joined up. Reads what `toHaveSpan` reads. No spans at all fails.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* expect([...browser.spans, ...server.spans]).toBeOneTrace();
|
|
9
|
+
*/
|
|
10
|
+
declare function toBeOneTrace(this: MatcherState, received: unknown): MatcherResult;
|
|
11
|
+
/**
|
|
12
|
+
* The tool result failed (`isError`, or an `Error:` text), and, when `code` is given, with that code
|
|
13
|
+
* (`structuredContent.error.code`, else the `[code]` in `Error [code]: …`).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* expect(await tools.call("add_to_cart", { qty: 0 })).toBeToolError("invalid_input");
|
|
17
|
+
*/
|
|
18
|
+
declare function toBeToolError(this: MatcherState, received: unknown, code?: string): MatcherResult;
|
|
19
|
+
/**
|
|
20
|
+
* The tool result succeeded (not `isError`, no `Error:` text), and, when `expected` is given, its text contains that
|
|
21
|
+
* string, matches that RegExp or satisfies that asymmetric matcher.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* expect(await tools.call("add_to_cart", { qty: 2 })).toBeToolResult(/2 × Field Mug/);
|
|
25
|
+
*/
|
|
26
|
+
declare function toBeToolResult(this: MatcherState, received: unknown, expected?: unknown): MatcherResult;
|
|
27
|
+
/**
|
|
28
|
+
* One of `values` (strings found inside any text, or RegExps) is somewhere in this sink: an event log, a console spy
|
|
29
|
+
* (`vi.spyOn(console, "error")`), a `Response` (its body), a mock adapter (what it was sent), a run, or any value.
|
|
30
|
+
* Use it negated: `expect(sink).not.toContainSensitive(["A1234567"])`. The failure names the sink and the path where
|
|
31
|
+
* the value was found, and prints nothing else of the sink's content. On a `Response` it is async: `await` it. A sink
|
|
32
|
+
* nested deeper than it looks (24 levels) fails with the path where it stopped, unless a value was found: "not there"
|
|
33
|
+
* is never claimed for a part it did not read.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* for (const sink of [events, logs, adapter]) expect(sink).not.toContainSensitive(["A1234567"]);
|
|
37
|
+
* await expect(response).not.toContainSensitive(["sk-test-key"]);
|
|
38
|
+
*/
|
|
39
|
+
declare function toContainSensitive(this: MatcherState, received: unknown, values: (string | RegExp)[]): MatcherResult;
|
|
40
|
+
/**
|
|
41
|
+
* The run's answer (the text it replied with) contains this string, matches this RegExp or satisfies this asymmetric
|
|
42
|
+
* matcher. On a `mockAdapter`, its last top-level run's answer (a sub-agent's run is not it).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* expect(run).toHaveAnswered(/back in your cart/i);
|
|
46
|
+
*/
|
|
47
|
+
declare function toHaveAnswered(this: MatcherState, received: unknown, expected: unknown): MatcherResult;
|
|
48
|
+
/**
|
|
49
|
+
* Every model step of the mock adapter's runs was offered these tools: a list (each was offered; others may be too)
|
|
50
|
+
* or an asymmetric matcher over the names (`expect.not.arrayContaining(["place_order"])`). An adapter that has not run
|
|
51
|
+
* fails it either way, negated too. Negated with a list it is refused: "not every step was offered them" would pass
|
|
52
|
+
* when one step was offered `place_order`; to say "no step was offered it", use the asymmetric form above (one tool per
|
|
53
|
+
* assertion: `expect.not.arrayContaining([a, b])` also matches a step offered only `a`).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* expect(adapter).toHaveBeenOfferedTools(["search_products", "add_to_cart"]);
|
|
57
|
+
* expect(adapter).toHaveBeenOfferedTools(expect.not.arrayContaining(["place_order"]));
|
|
58
|
+
*/
|
|
59
|
+
declare function toHaveBeenOfferedTools(this: MatcherState, received: unknown, expected: unknown): MatcherResult;
|
|
60
|
+
/**
|
|
61
|
+
* The run called `tool`, with an input that contains `input` when given (a partial match: other keys may be there).
|
|
62
|
+
* Reads a `WebAgentResult`, a `mockAdapter` or the `runs` fixture's `RunLog`. The error `agent.invoke` rejected with
|
|
63
|
+
* carries no calls, so it is refused (a negated call would pass on nothing): assert on the `mockAdapter` instead.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* expect(run).toHaveCalledTool("add_to_cart", { qty: 2 });
|
|
67
|
+
* expect(run).not.toHaveCalledTool("place_order");
|
|
68
|
+
*/
|
|
69
|
+
declare function toHaveCalledTool(this: MatcherState, received: unknown, tool: string, input?: Record<string, unknown>): MatcherResult;
|
|
70
|
+
/**
|
|
71
|
+
* The run called exactly these tools, in this order (no other call before, between or after). Reads what
|
|
72
|
+
* `toHaveCalledTool` reads; the error `agent.invoke` rejected with carries no calls, so it is refused.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* expect(run).toHaveCalledTools(["track_last_order", "add_to_cart"]);
|
|
76
|
+
*/
|
|
77
|
+
declare function toHaveCalledTools(this: MatcherState, received: unknown, tools: string[]): MatcherResult;
|
|
78
|
+
/**
|
|
79
|
+
* These event types happened in this order. Other events may come between them (several `fill`s, a `yield`): the
|
|
80
|
+
* list is checked as a subsequence of what happened.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* expect(events).toHaveEventOrder(["start", "fill", "park", "result"]);
|
|
84
|
+
*/
|
|
85
|
+
declare function toHaveEventOrder(this: MatcherState, received: unknown, order: string[]): MatcherResult;
|
|
86
|
+
/**
|
|
87
|
+
* The agent's value went into `field` (a `fill` event: a form control's `name`, or a tool parameter's), and, when
|
|
88
|
+
* `value` is given, that value (compared as is, or as text: `"2"` matches `2`).
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* expect(events).toHaveFilled("qty", "2");
|
|
92
|
+
*/
|
|
93
|
+
declare function toHaveFilled(this: MatcherState, received: unknown, field: string, value?: unknown): MatcherResult;
|
|
94
|
+
/**
|
|
95
|
+
* The run ended this way: `"stop"`, `"max-steps"`, `"aborted"` or `"error"`; with `code` too, the adapter's error
|
|
96
|
+
* code (`"rate_limited"`, `"network"`…). A `WebAgentResult` reads as `"stop"` (see the matcher's page); a
|
|
97
|
+
* `mockAdapter` knows exactly (its last top-level run, not a sub-agent's); the error `agent.invoke` rejected with reads as `"error"` (or `"aborted"`).
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* expect(adapter).toHaveFinishedWith("error", "rate_limited");
|
|
101
|
+
*/
|
|
102
|
+
declare function toHaveFinishedWith(this: MatcherState, received: unknown, reason: FinishReason, code?: string): MatcherResult;
|
|
103
|
+
/** Options for {@link toHaveNoHardcodedText}. */
|
|
104
|
+
interface NoHardcodedTextOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Text that is allowed although it is not a marker: what the person typed, what the model or a tool answered, an
|
|
107
|
+
* adapter's own name. A string is removed wherever it appears; a RegExp (use the `g` flag) likewise.
|
|
108
|
+
*/
|
|
109
|
+
allow?: readonly (string | RegExp)[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The rendered chat shows no text that bypassed its messages catalog: render it with the sentinel catalog
|
|
113
|
+
* (`renderChat({ sentinel: true })`), and every text node and every `aria-label`, `placeholder`, `title`, `alt` and
|
|
114
|
+
* `aria-valuetext` holds only `⟦markers⟧`, punctuation, digits, or text you `allow` (the person's and the model's own
|
|
115
|
+
* words). Fails with each stray string and where it is.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* const chat = await renderChat({ adapter, sentinel: true });
|
|
119
|
+
* await expect(chat).toHaveNoHardcodedText({ allow: ["Add a mug", "Added."] });
|
|
120
|
+
*/
|
|
121
|
+
declare function toHaveNoHardcodedText(this: MatcherState, received: unknown, options?: NoHardcodedTextOptions): MatcherResult;
|
|
122
|
+
/**
|
|
123
|
+
* A tool waited for the person (a `park` event: a confirmation, a question), `tool` when given, with a prompt that
|
|
124
|
+
* contains / matches `prompt` when given.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* await expect.poll(() => events).toHaveParked("place_order");
|
|
128
|
+
*/
|
|
129
|
+
declare function toHaveParked(this: MatcherState, received: unknown, tool?: string, prompt?: unknown): MatcherResult;
|
|
130
|
+
/**
|
|
131
|
+
* The spans include one named `name` (exactly, or matching a RegExp) whose attributes include `attributes` (each value
|
|
132
|
+
* compared with `equals`, so asymmetric matchers work). Reads a memory exporter, an OpenTelemetry
|
|
133
|
+
* `InMemorySpanExporter`, an array of spans or span trees.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* expect(spans).toHaveSpan("execute_tool add_to_cart", { "webmcp.tool.confirm": "accepted" });
|
|
137
|
+
* expect(spans).toHaveSpan(/^chat /, { "gen_ai.usage.input_tokens": expect.any(Number) });
|
|
138
|
+
*/
|
|
139
|
+
declare function toHaveSpan(this: MatcherState, received: unknown, name: string | RegExp, attributes?: Record<string, unknown>): MatcherResult;
|
|
140
|
+
/**
|
|
141
|
+
* A tool run started (a `start` event), for `tool` when given.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* expect(events).toHaveStarted("place_order");
|
|
145
|
+
*/
|
|
146
|
+
declare function toHaveStarted(this: MatcherState, received: unknown, tool?: string): MatcherResult;
|
|
147
|
+
/**
|
|
148
|
+
* The tool result's `structuredContent` has these keys with these values (a partial match: other keys may be there).
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* expect(await tools.call("cart_total")).toHaveStructuredContent({ total: 48 });
|
|
152
|
+
*/
|
|
153
|
+
declare function toHaveStructuredContent(this: MatcherState, received: unknown, expected: Record<string, unknown>): MatcherResult;
|
|
154
|
+
/**
|
|
155
|
+
* The cursor got out of the person's way (a `yield` event), for `reason` when given (`"pointer"`, `"keyboard"`,
|
|
156
|
+
* `"scroll"`…).
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* expect(events).toHaveYielded();
|
|
160
|
+
*/
|
|
161
|
+
declare function toHaveYielded(this: MatcherState, received: unknown, reason?: string): MatcherResult;
|
|
162
|
+
/** Every matcher of the kit, by name: what `expect.extend` receives. */
|
|
163
|
+
declare const webAgentsMatchers: {
|
|
164
|
+
toBeToolResult: typeof toBeToolResult;
|
|
165
|
+
toBeToolError: typeof toBeToolError;
|
|
166
|
+
toHaveStructuredContent: typeof toHaveStructuredContent;
|
|
167
|
+
toHaveStarted: typeof toHaveStarted;
|
|
168
|
+
toHaveFilled: typeof toHaveFilled;
|
|
169
|
+
toHaveParked: typeof toHaveParked;
|
|
170
|
+
toHaveYielded: typeof toHaveYielded;
|
|
171
|
+
toHaveEventOrder: typeof toHaveEventOrder;
|
|
172
|
+
toHaveCalledTool: typeof toHaveCalledTool;
|
|
173
|
+
toHaveCalledTools: typeof toHaveCalledTools;
|
|
174
|
+
toHaveAnswered: typeof toHaveAnswered;
|
|
175
|
+
toHaveFinishedWith: typeof toHaveFinishedWith;
|
|
176
|
+
toHaveBeenOfferedTools: typeof toHaveBeenOfferedTools;
|
|
177
|
+
toHaveSpan: typeof toHaveSpan;
|
|
178
|
+
toBeOneTrace: typeof toBeOneTrace;
|
|
179
|
+
toContainSensitive: typeof toContainSensitive;
|
|
180
|
+
toHaveNoHardcodedText: typeof toHaveNoHardcodedText;
|
|
181
|
+
};
|
|
182
|
+
/** The kit's matchers, as `expect(…)` sees them. */
|
|
183
|
+
interface WebAgentsMatchers<R = unknown> {
|
|
184
|
+
/** Succeeded (not `isError`, no `Error:` text); its text contains / matches `expected` when given. */
|
|
185
|
+
toBeToolResult(expected?: string | RegExp | unknown): R;
|
|
186
|
+
/** Failed; with that error code when given (`structuredContent.error.code` or `Error [code]:`). */
|
|
187
|
+
toBeToolError(code?: string): R;
|
|
188
|
+
/** `structuredContent` has these keys with these values (partial match). */
|
|
189
|
+
toHaveStructuredContent(expected: Record<string, unknown>): R;
|
|
190
|
+
/** A run of `tool` (any tool when omitted) started. */
|
|
191
|
+
toHaveStarted(tool?: string): R;
|
|
192
|
+
/** The agent filled `field` (with `value` when given). */
|
|
193
|
+
toHaveFilled(field: string, value?: unknown): R;
|
|
194
|
+
/** A tool (`tool` when given) waited for the person, with a prompt matching `prompt` when given. */
|
|
195
|
+
toHaveParked(tool?: string, prompt?: string | RegExp): R;
|
|
196
|
+
/** The cursor yielded to the person (for `reason` when given). */
|
|
197
|
+
toHaveYielded(reason?: string): R;
|
|
198
|
+
/** These event types happened in this order (others may come between). */
|
|
199
|
+
toHaveEventOrder(order: string[]): R;
|
|
200
|
+
/** The run called `tool`, with an input containing `input` when given. */
|
|
201
|
+
toHaveCalledTool(tool: string, input?: Record<string, unknown>): R;
|
|
202
|
+
/** The run called exactly these tools, in this order. */
|
|
203
|
+
toHaveCalledTools(tools: string[]): R;
|
|
204
|
+
/** The run's answer contains / matches `expected`. */
|
|
205
|
+
toHaveAnswered(expected: string | RegExp | unknown): R;
|
|
206
|
+
/** The run ended with `reason` (and the adapter's error `code`, when given). */
|
|
207
|
+
toHaveFinishedWith(reason: FinishReason, code?: string): R;
|
|
208
|
+
/** Every model step of the mock adapter was offered these tools (or the names satisfy the asymmetric matcher). */
|
|
209
|
+
toHaveBeenOfferedTools(expected: string[] | unknown): R;
|
|
210
|
+
/** A span named `name` (or matching it) whose attributes include these. Reads a memory exporter or an array of spans. */
|
|
211
|
+
toHaveSpan(name: string | RegExp, attributes?: Record<string, unknown>): R;
|
|
212
|
+
/** Every span is in one trace, with one root. */
|
|
213
|
+
toBeOneTrace(): R;
|
|
214
|
+
/** One of `values` is in this sink (use it negated). Async on a `Response`. */
|
|
215
|
+
toContainSensitive(values: (string | RegExp)[]): R;
|
|
216
|
+
/**
|
|
217
|
+
* The rendered chat (`renderChat({ sentinel: true })`, or an element) shows only catalog markers, punctuation and
|
|
218
|
+
* digits, plus the text in `allow` (the person's and the model's own words).
|
|
219
|
+
*/
|
|
220
|
+
toHaveNoHardcodedText(options?: NoHardcodedTextOptions): R;
|
|
221
|
+
}
|
|
222
|
+
declare module "vitest" {
|
|
223
|
+
interface Matchers<R, T> extends WebAgentsMatchers<R> {}
|
|
224
|
+
}
|
|
225
|
+
export { webAgentsMatchers as n, NoHardcodedTextOptions as r, WebAgentsMatchers as t };
|