@frontmcp/testing 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/esm/fixtures/index.mjs +2377 -0
  2. package/esm/index.mjs +4768 -0
  3. package/esm/matchers/index.mjs +646 -0
  4. package/esm/package.json +127 -0
  5. package/esm/playwright/index.mjs +19 -0
  6. package/esm/setup.mjs +680 -0
  7. package/fixtures/index.js +2418 -0
  8. package/index.js +4866 -0
  9. package/jest-preset.js +3 -3
  10. package/matchers/index.js +673 -0
  11. package/package.json +51 -23
  12. package/playwright/index.js +46 -0
  13. package/setup.js +651 -0
  14. package/src/assertions/index.js +0 -18
  15. package/src/assertions/index.js.map +0 -1
  16. package/src/assertions/mcp-assertions.js +0 -220
  17. package/src/assertions/mcp-assertions.js.map +0 -1
  18. package/src/auth/auth-headers.js +0 -62
  19. package/src/auth/auth-headers.js.map +0 -1
  20. package/src/auth/index.js +0 -15
  21. package/src/auth/index.js.map +0 -1
  22. package/src/auth/mock-api-server.js +0 -200
  23. package/src/auth/mock-api-server.js.map +0 -1
  24. package/src/auth/mock-oauth-server.js +0 -253
  25. package/src/auth/mock-oauth-server.js.map +0 -1
  26. package/src/auth/token-factory.js +0 -181
  27. package/src/auth/token-factory.js.map +0 -1
  28. package/src/auth/user-fixtures.js +0 -92
  29. package/src/auth/user-fixtures.js.map +0 -1
  30. package/src/client/index.js +0 -12
  31. package/src/client/index.js.map +0 -1
  32. package/src/client/mcp-test-client.builder.js +0 -163
  33. package/src/client/mcp-test-client.builder.js.map +0 -1
  34. package/src/client/mcp-test-client.js +0 -937
  35. package/src/client/mcp-test-client.js.map +0 -1
  36. package/src/client/mcp-test-client.types.js +0 -16
  37. package/src/client/mcp-test-client.types.js.map +0 -1
  38. package/src/errors/index.js +0 -85
  39. package/src/errors/index.js.map +0 -1
  40. package/src/example-tools/index.js +0 -40
  41. package/src/example-tools/index.js.map +0 -1
  42. package/src/example-tools/tool-configs.js +0 -222
  43. package/src/example-tools/tool-configs.js.map +0 -1
  44. package/src/expect.js +0 -31
  45. package/src/expect.js.map +0 -1
  46. package/src/fixtures/fixture-types.js +0 -7
  47. package/src/fixtures/fixture-types.js.map +0 -1
  48. package/src/fixtures/index.js +0 -16
  49. package/src/fixtures/index.js.map +0 -1
  50. package/src/fixtures/test-fixture.js +0 -311
  51. package/src/fixtures/test-fixture.js.map +0 -1
  52. package/src/http-mock/http-mock.js +0 -544
  53. package/src/http-mock/http-mock.js.map +0 -1
  54. package/src/http-mock/http-mock.types.js +0 -10
  55. package/src/http-mock/http-mock.types.js.map +0 -1
  56. package/src/http-mock/index.js +0 -11
  57. package/src/http-mock/index.js.map +0 -1
  58. package/src/index.js +0 -167
  59. package/src/index.js.map +0 -1
  60. package/src/interceptor/index.js +0 -15
  61. package/src/interceptor/index.js.map +0 -1
  62. package/src/interceptor/interceptor-chain.js +0 -207
  63. package/src/interceptor/interceptor-chain.js.map +0 -1
  64. package/src/interceptor/interceptor.types.js +0 -7
  65. package/src/interceptor/interceptor.types.js.map +0 -1
  66. package/src/interceptor/mock-registry.js +0 -189
  67. package/src/interceptor/mock-registry.js.map +0 -1
  68. package/src/matchers/index.js +0 -12
  69. package/src/matchers/index.js.map +0 -1
  70. package/src/matchers/matcher-types.js +0 -10
  71. package/src/matchers/matcher-types.js.map +0 -1
  72. package/src/matchers/mcp-matchers.js +0 -395
  73. package/src/matchers/mcp-matchers.js.map +0 -1
  74. package/src/platform/index.js +0 -47
  75. package/src/platform/index.js.map +0 -1
  76. package/src/platform/platform-client-info.js +0 -155
  77. package/src/platform/platform-client-info.js.map +0 -1
  78. package/src/platform/platform-types.js +0 -110
  79. package/src/platform/platform-types.js.map +0 -1
  80. package/src/playwright/index.js +0 -49
  81. package/src/playwright/index.js.map +0 -1
  82. package/src/server/index.js +0 -10
  83. package/src/server/index.js.map +0 -1
  84. package/src/server/test-server.js +0 -341
  85. package/src/server/test-server.js.map +0 -1
  86. package/src/setup.js +0 -30
  87. package/src/setup.js.map +0 -1
  88. package/src/transport/index.js +0 -10
  89. package/src/transport/index.js.map +0 -1
  90. package/src/transport/streamable-http.transport.js +0 -438
  91. package/src/transport/streamable-http.transport.js.map +0 -1
  92. package/src/transport/transport.interface.js +0 -7
  93. package/src/transport/transport.interface.js.map +0 -1
  94. package/src/ui/index.js +0 -23
  95. package/src/ui/index.js.map +0 -1
  96. package/src/ui/ui-assertions.js +0 -367
  97. package/src/ui/ui-assertions.js.map +0 -1
  98. package/src/ui/ui-matchers.js +0 -493
  99. package/src/ui/ui-matchers.js.map +0 -1
  100. /package/{src/assertions → assertions}/index.d.ts +0 -0
  101. /package/{src/assertions → assertions}/mcp-assertions.d.ts +0 -0
  102. /package/{src/auth → auth}/auth-headers.d.ts +0 -0
  103. /package/{src/auth → auth}/index.d.ts +0 -0
  104. /package/{src/auth → auth}/mock-api-server.d.ts +0 -0
  105. /package/{src/auth → auth}/mock-oauth-server.d.ts +0 -0
  106. /package/{src/auth → auth}/token-factory.d.ts +0 -0
  107. /package/{src/auth → auth}/user-fixtures.d.ts +0 -0
  108. /package/{src/client → client}/index.d.ts +0 -0
  109. /package/{src/client → client}/mcp-test-client.builder.d.ts +0 -0
  110. /package/{src/client → client}/mcp-test-client.d.ts +0 -0
  111. /package/{src/client → client}/mcp-test-client.types.d.ts +0 -0
  112. /package/{src/errors → errors}/index.d.ts +0 -0
  113. /package/{src/example-tools → example-tools}/index.d.ts +0 -0
  114. /package/{src/example-tools → example-tools}/tool-configs.d.ts +0 -0
  115. /package/{src/expect.d.ts → expect.d.ts} +0 -0
  116. /package/{src/fixtures → fixtures}/fixture-types.d.ts +0 -0
  117. /package/{src/fixtures → fixtures}/index.d.ts +0 -0
  118. /package/{src/fixtures → fixtures}/test-fixture.d.ts +0 -0
  119. /package/{src/http-mock → http-mock}/http-mock.d.ts +0 -0
  120. /package/{src/http-mock → http-mock}/http-mock.types.d.ts +0 -0
  121. /package/{src/http-mock → http-mock}/index.d.ts +0 -0
  122. /package/{src/index.d.ts → index.d.ts} +0 -0
  123. /package/{src/interceptor → interceptor}/index.d.ts +0 -0
  124. /package/{src/interceptor → interceptor}/interceptor-chain.d.ts +0 -0
  125. /package/{src/interceptor → interceptor}/interceptor.types.d.ts +0 -0
  126. /package/{src/interceptor → interceptor}/mock-registry.d.ts +0 -0
  127. /package/{src/matchers → matchers}/index.d.ts +0 -0
  128. /package/{src/matchers → matchers}/matcher-types.d.ts +0 -0
  129. /package/{src/matchers → matchers}/mcp-matchers.d.ts +0 -0
  130. /package/{src/platform → platform}/index.d.ts +0 -0
  131. /package/{src/platform → platform}/platform-client-info.d.ts +0 -0
  132. /package/{src/platform → platform}/platform-types.d.ts +0 -0
  133. /package/{src/playwright → playwright}/index.d.ts +0 -0
  134. /package/{src/server → server}/index.d.ts +0 -0
  135. /package/{src/server → server}/test-server.d.ts +0 -0
  136. /package/{src/setup.d.ts → setup.d.ts} +0 -0
  137. /package/{src/transport → transport}/index.d.ts +0 -0
  138. /package/{src/transport → transport}/streamable-http.transport.d.ts +0 -0
  139. /package/{src/transport → transport}/transport.interface.d.ts +0 -0
  140. /package/{src/ui → ui}/index.d.ts +0 -0
  141. /package/{src/ui → ui}/ui-assertions.d.ts +0 -0
  142. /package/{src/ui → ui}/ui-matchers.d.ts +0 -0
@@ -1,367 +0,0 @@
1
- "use strict";
2
- /**
3
- * @file ui-assertions.ts
4
- * @description UI-specific assertion helpers for testing tool UI responses
5
- *
6
- * The metadata keys used in these assertions align with the UIMetadata interface
7
- * from @frontmcp/ui/adapters. Key fields include:
8
- * - `ui/html`: Inline rendered HTML (universal)
9
- * - `ui/mimeType`: MIME type for the HTML content
10
- * - `openai/outputTemplate`: Resource URI for widget template (OpenAI)
11
- * - `openai/widgetAccessible`: Whether widget can invoke tools (OpenAI)
12
- *
13
- * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}
14
- *
15
- * @example
16
- * ```typescript
17
- * import { UIAssertions } from '@frontmcp/testing';
18
- *
19
- * const result = await client.tools.call('my-tool', {});
20
- * const html = UIAssertions.assertRenderedUI(result);
21
- * UIAssertions.assertXssSafe(html);
22
- * UIAssertions.assertDataBinding(html, result.json(), ['location', 'temperature']);
23
- * ```
24
- */
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UIAssertions = void 0;
27
- const platform_types_1 = require("../platform/platform-types");
28
- // Type-only reference: Metadata keys used below align with UIMetadata from @frontmcp/ui/adapters
29
- // This is an optional peer dependency, so we don't import it directly
30
- // ═══════════════════════════════════════════════════════════════════
31
- // HELPER FUNCTIONS
32
- // ═══════════════════════════════════════════════════════════════════
33
- /**
34
- * Escape special regex metacharacters in a string.
35
- * This prevents user-provided tag/class names from being interpreted as regex patterns.
36
- */
37
- function escapeRegex(str) {
38
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
39
- }
40
- // ═══════════════════════════════════════════════════════════════════
41
- // UI ASSERTIONS
42
- // ═══════════════════════════════════════════════════════════════════
43
- /**
44
- * UI-specific assertion helpers.
45
- * Use these for imperative-style assertions with detailed error messages.
46
- */
47
- exports.UIAssertions = {
48
- /**
49
- * Assert tool result has valid rendered UI HTML.
50
- * @param result - The tool result wrapper
51
- * @returns The rendered HTML string
52
- * @throws Error if no UI HTML found or if mdx-fallback detected
53
- */
54
- assertRenderedUI(result) {
55
- const meta = result.raw._meta;
56
- if (!meta) {
57
- throw new Error('Expected tool result to have _meta, but _meta is undefined');
58
- }
59
- const html = meta['ui/html'];
60
- if (!html) {
61
- throw new Error('Expected tool result to have ui/html in _meta, but it is missing');
62
- }
63
- if (typeof html !== 'string') {
64
- throw new Error(`Expected ui/html to be a string, but got ${typeof html}`);
65
- }
66
- if (html.includes('mdx-fallback')) {
67
- throw new Error('Got mdx-fallback instead of rendered HTML - MDX/React rendering failed. ' +
68
- 'Check that @mdx-js/mdx is installed and the template syntax is valid.');
69
- }
70
- return html;
71
- },
72
- /**
73
- * Assert HTML contains all expected bound values from tool output.
74
- * @param html - The rendered HTML string
75
- * @param output - The tool output object
76
- * @param keys - Array of keys whose values should appear in the HTML
77
- * @throws Error if any expected value is missing from the HTML
78
- */
79
- assertDataBinding(html, output, keys) {
80
- const missingKeys = [];
81
- for (const key of keys) {
82
- const value = output[key];
83
- if (value === undefined || value === null) {
84
- continue; // Skip undefined/null values
85
- }
86
- const stringValue = String(value);
87
- if (!html.includes(stringValue)) {
88
- missingKeys.push(`${key}="${stringValue}"`);
89
- }
90
- }
91
- if (missingKeys.length > 0) {
92
- throw new Error(`Expected HTML to contain bound values for: ${missingKeys.join(', ')}. ` + 'Data binding may have failed.');
93
- }
94
- },
95
- /**
96
- * Assert HTML is XSS-safe (no scripts, event handlers, or javascript: URIs).
97
- * @param html - The rendered HTML string
98
- * @throws Error if potential XSS vulnerabilities are detected
99
- */
100
- assertXssSafe(html) {
101
- const vulnerabilities = [];
102
- if (/<script[\s>]/i.test(html)) {
103
- vulnerabilities.push('<script> tag detected');
104
- }
105
- if (/\son\w+\s*=/i.test(html)) {
106
- vulnerabilities.push('inline event handler detected (onclick, onerror, etc.)');
107
- }
108
- if (/javascript:/i.test(html)) {
109
- vulnerabilities.push('javascript: URI detected');
110
- }
111
- if (vulnerabilities.length > 0) {
112
- throw new Error(`Potential XSS vulnerabilities found: ${vulnerabilities.join('; ')}`);
113
- }
114
- },
115
- /**
116
- * Assert HTML has proper structure (not escaped raw content).
117
- * @param html - The rendered HTML string
118
- * @throws Error if HTML appears to be raw/unrendered content
119
- */
120
- assertProperHtmlStructure(html) {
121
- // Check for escaped HTML entities that suggest content wasn't rendered
122
- if (html.includes('&lt;') && html.includes('&gt;')) {
123
- throw new Error('HTML contains escaped HTML entities (&lt;, &gt;) - content was likely not rendered. ' +
124
- 'Check that the template is being processed correctly.');
125
- }
126
- // Check that there's at least one HTML tag
127
- if (!/<[a-z]/i.test(html)) {
128
- throw new Error('HTML contains no HTML tags - content may be plain text or rendering failed.');
129
- }
130
- },
131
- /**
132
- * Assert HTML contains a specific element.
133
- * @param html - The rendered HTML string
134
- * @param tag - The HTML tag name to look for
135
- * @throws Error if the element is not found
136
- */
137
- assertContainsElement(html, tag) {
138
- // Escape regex metacharacters to prevent user input from breaking the regex
139
- const regex = new RegExp(`<${escapeRegex(tag)}[\\s>]`, 'i');
140
- if (!regex.test(html)) {
141
- throw new Error(`Expected HTML to contain <${tag}> element`);
142
- }
143
- },
144
- /**
145
- * Assert HTML contains a specific CSS class.
146
- * @param html - The rendered HTML string
147
- * @param className - The CSS class name to look for
148
- * @throws Error if the class is not found
149
- */
150
- assertHasCssClass(html, className) {
151
- // Escape regex metacharacters to prevent user input from breaking the regex
152
- const classRegex = new RegExp(`class(?:Name)?\\s*=\\s*["'][^"']*\\b${escapeRegex(className)}\\b[^"']*["']`, 'i');
153
- if (!classRegex.test(html)) {
154
- throw new Error(`Expected HTML to have CSS class "${className}"`);
155
- }
156
- },
157
- /**
158
- * Assert HTML does NOT contain specific content.
159
- * Useful for verifying custom components were rendered, not left as raw tags.
160
- * @param html - The rendered HTML string
161
- * @param content - The content that should NOT appear
162
- * @throws Error if the content is found
163
- */
164
- assertNotContainsRaw(html, content) {
165
- if (html.includes(content)) {
166
- throw new Error(`HTML contains raw content "${content}" - this component may not have been rendered. ` +
167
- 'Check that all custom components are properly passed to the renderer.');
168
- }
169
- },
170
- /**
171
- * Assert that widget metadata is present in the result.
172
- * Checks for ui/html, openai/outputTemplate, or ui/mimeType.
173
- * @param result - The tool result wrapper
174
- * @throws Error if widget metadata is missing
175
- */
176
- assertWidgetMetadata(result) {
177
- const meta = result.raw._meta;
178
- if (!meta) {
179
- throw new Error('Expected tool result to have _meta with widget metadata');
180
- }
181
- // Check for any widget-related metadata fields (aligned with toHaveWidgetMetadata matcher)
182
- const hasUiHtml = Boolean(meta['ui/html']);
183
- const hasOutputTemplate = Boolean(meta['openai/outputTemplate']);
184
- const hasMimeType = Boolean(meta['ui/mimeType']);
185
- if (!hasUiHtml && !hasOutputTemplate && !hasMimeType) {
186
- throw new Error('Expected _meta to have widget metadata (ui/html, openai/outputTemplate, or ui/mimeType)');
187
- }
188
- },
189
- /**
190
- * Comprehensive UI validation that runs all checks.
191
- * @param result - The tool result wrapper
192
- * @param boundKeys - Optional array of output keys to check for data binding
193
- * @returns The rendered HTML string
194
- * @throws Error if any validation fails
195
- */
196
- assertValidUI(result, boundKeys) {
197
- // 1. Get and validate HTML exists
198
- const html = exports.UIAssertions.assertRenderedUI(result);
199
- // 2. Check HTML structure
200
- exports.UIAssertions.assertProperHtmlStructure(html);
201
- // 3. Check XSS safety
202
- exports.UIAssertions.assertXssSafe(html);
203
- // 4. Check data binding if keys provided
204
- if (boundKeys && boundKeys.length > 0) {
205
- try {
206
- const output = JSON.parse(result.text() || '{}');
207
- exports.UIAssertions.assertDataBinding(html, output, boundKeys);
208
- }
209
- catch {
210
- // If we can't parse output, skip data binding check
211
- }
212
- }
213
- return html;
214
- },
215
- // ═══════════════════════════════════════════════════════════════════
216
- // PLATFORM META ASSERTIONS
217
- // ═══════════════════════════════════════════════════════════════════
218
- /**
219
- * Assert tool result has correct meta keys for OpenAI platform.
220
- * Verifies openai/* keys are present and ui/*, frontmcp/* keys are absent.
221
- * @param result - The tool result wrapper
222
- * @throws Error if meta keys don't match OpenAI expectations
223
- */
224
- assertOpenAIMeta(result) {
225
- exports.UIAssertions.assertPlatformMeta(result, 'openai');
226
- },
227
- /**
228
- * Assert tool result has correct meta keys for ext-apps platform (SEP-1865).
229
- * Verifies ui/* keys are present and openai/*, frontmcp/* keys are absent.
230
- * @param result - The tool result wrapper
231
- * @throws Error if meta keys don't match ext-apps expectations
232
- */
233
- assertExtAppsMeta(result) {
234
- exports.UIAssertions.assertPlatformMeta(result, 'ext-apps');
235
- },
236
- /**
237
- * Assert tool result has correct meta keys for FrontMCP platforms (Claude, Cursor, etc.).
238
- * Verifies frontmcp/* + ui/* keys are present and openai/* keys are absent.
239
- * @param result - The tool result wrapper
240
- * @throws Error if meta keys don't match FrontMCP expectations
241
- */
242
- assertFrontmcpMeta(result) {
243
- exports.UIAssertions.assertPlatformMeta(result, 'claude');
244
- },
245
- /**
246
- * Assert tool result has correct meta keys for a specific platform.
247
- * @param result - The tool result wrapper
248
- * @param platform - The platform type to check for
249
- * @throws Error if meta keys don't match platform expectations
250
- */
251
- assertPlatformMeta(result, platform) {
252
- const meta = result.raw._meta;
253
- if (!meta) {
254
- throw new Error(`Expected tool result to have _meta with platform meta for "${platform}"`);
255
- }
256
- const expectedPrefixes = (0, platform_types_1.getToolCallMetaPrefixes)(platform);
257
- const forbiddenPrefixes = (0, platform_types_1.getForbiddenMetaPrefixes)(platform);
258
- const metaKeys = Object.keys(meta);
259
- // Check for expected prefixes
260
- const hasExpectedPrefix = metaKeys.some((key) => expectedPrefixes.some((prefix) => key.startsWith(prefix)));
261
- if (!hasExpectedPrefix) {
262
- throw new Error(`Expected _meta to have keys with prefixes [${expectedPrefixes.join(', ')}] for platform "${platform}", ` +
263
- `but found: [${metaKeys.join(', ')}]`);
264
- }
265
- // Check for forbidden prefixes
266
- const forbiddenKeys = metaKeys.filter((key) => forbiddenPrefixes.some((prefix) => key.startsWith(prefix)));
267
- if (forbiddenKeys.length > 0) {
268
- throw new Error(`Expected _meta NOT to have keys [${forbiddenKeys.join(', ')}] for platform "${platform}" ` +
269
- `(forbidden prefixes: [${forbiddenPrefixes.join(', ')}])`);
270
- }
271
- },
272
- /**
273
- * Assert that no cross-namespace pollution exists in meta.
274
- * @param result - The tool result wrapper
275
- * @param expectedNamespace - The namespace that SHOULD be present
276
- * @throws Error if other namespaces are found
277
- */
278
- assertNoMixedNamespaces(result, expectedNamespace) {
279
- const meta = result.raw._meta;
280
- if (!meta) {
281
- throw new Error(`Expected tool result to have _meta with namespace "${expectedNamespace}"`);
282
- }
283
- const metaKeys = Object.keys(meta);
284
- const wrongKeys = metaKeys.filter((key) => !key.startsWith(expectedNamespace));
285
- if (wrongKeys.length > 0) {
286
- throw new Error(`Expected _meta to ONLY have keys with namespace "${expectedNamespace}", ` +
287
- `but found: [${wrongKeys.join(', ')}]`);
288
- }
289
- },
290
- /**
291
- * Assert that _meta has the correct MIME type for a platform.
292
- * @param result - The tool result wrapper
293
- * @param platform - The platform type to check for
294
- * @throws Error if MIME type doesn't match platform expectations
295
- */
296
- assertPlatformMimeType(result, platform) {
297
- const meta = result.raw._meta;
298
- const expectedMimeType = (0, platform_types_1.getPlatformMimeType)(platform);
299
- if (!meta) {
300
- throw new Error(`Expected tool result to have _meta with MIME type for platform "${platform}"`);
301
- }
302
- // Determine which key to check based on platform
303
- let mimeTypeKey;
304
- switch (platform) {
305
- case 'openai':
306
- mimeTypeKey = 'openai/mimeType';
307
- break;
308
- case 'ext-apps':
309
- mimeTypeKey = 'ui/mimeType';
310
- break;
311
- default:
312
- mimeTypeKey = 'frontmcp/mimeType';
313
- }
314
- const actualMimeType = meta[mimeTypeKey];
315
- if (actualMimeType !== expectedMimeType) {
316
- throw new Error(`Expected _meta["${mimeTypeKey}"] to be "${expectedMimeType}" for platform "${platform}", ` +
317
- `but got "${actualMimeType}"`);
318
- }
319
- },
320
- /**
321
- * Assert that _meta has HTML in the correct platform-specific key.
322
- * @param result - The tool result wrapper
323
- * @param platform - The platform type to check for
324
- * @returns The HTML string
325
- * @throws Error if HTML is missing or in wrong key
326
- */
327
- assertPlatformHtml(result, platform) {
328
- const meta = result.raw._meta;
329
- if (!meta) {
330
- throw new Error(`Expected tool result to have _meta with platform HTML for "${platform}"`);
331
- }
332
- // Determine which key to check based on platform
333
- let htmlKey;
334
- switch (platform) {
335
- case 'openai':
336
- htmlKey = 'openai/html';
337
- break;
338
- case 'ext-apps':
339
- htmlKey = 'ui/html';
340
- break;
341
- default:
342
- htmlKey = 'frontmcp/html';
343
- }
344
- const html = meta[htmlKey];
345
- if (typeof html !== 'string' || html.length === 0) {
346
- throw new Error(`Expected _meta["${htmlKey}"] to contain HTML for platform "${platform}", ` +
347
- `but ${html === undefined ? 'key not found' : `got ${typeof html}`}`);
348
- }
349
- return html;
350
- },
351
- /**
352
- * Comprehensive platform meta validation.
353
- * @param result - The tool result wrapper
354
- * @param platform - The platform type to validate for
355
- * @returns The platform-specific HTML string
356
- * @throws Error if any platform-specific validation fails
357
- */
358
- assertValidPlatformMeta(result, platform) {
359
- // 1. Check correct namespace keys
360
- exports.UIAssertions.assertPlatformMeta(result, platform);
361
- // 2. Check MIME type
362
- exports.UIAssertions.assertPlatformMimeType(result, platform);
363
- // 3. Get and return HTML
364
- return exports.UIAssertions.assertPlatformHtml(result, platform);
365
- },
366
- };
367
- //# sourceMappingURL=ui-assertions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ui-assertions.js","sourceRoot":"","sources":["../../../src/ui/ui-assertions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAIH,+DAAoH;AAEpH,iGAAiG;AACjG,sEAAsE;AAEtE,sEAAsE;AACtE,mBAAmB;AACnB,sEAAsE;AAEtE;;;GAGG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC;AAED,sEAAsE;AACtE,gBAAgB;AAChB,sEAAsE;AAEtE;;;GAGG;AACU,QAAA,YAAY,GAAG;IAC1B;;;;;OAKG;IACH,gBAAgB,CAAC,MAAyB;QACxC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,KAA4C,CAAC;QAErE,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QAE7B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACtF,CAAC;QAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,4CAA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CAAC;QAC7F,CAAC;QAED,iDAAiD;QACjD,IAAI,OAAe,CAAC;QACpB,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,QAAQ;gBACX,OAAO,GAAG,aAAa,CAAC;gBACxB,MAAM;YACR,KAAK,UAAU;gBACb,OAAO,GAAG,SAAS,CAAC;gBACpB,MAAM;YACR;gBACE,OAAO,GAAG,eAAe,CAAC;QAC9B,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAE3B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CACb,mBAAmB,OAAO,oCAAoC,QAAQ,KAAK;gBACzE,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,OAAO,IAAI,EAAE,EAAE,CACvE,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,uBAAuB,CAAC,MAAyB,EAAE,QAA0B;QAC3E,kCAAkC;QAClC,oBAAY,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAElD,qBAAqB;QACrB,oBAAY,CAAC,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEtD,yBAAyB;QACzB,OAAO,oBAAY,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3D,CAAC;CACF,CAAC","sourcesContent":["/**\n * @file ui-assertions.ts\n * @description UI-specific assertion helpers for testing tool UI responses\n *\n * The metadata keys used in these assertions align with the UIMetadata interface\n * from @frontmcp/ui/adapters. Key fields include:\n * - `ui/html`: Inline rendered HTML (universal)\n * - `ui/mimeType`: MIME type for the HTML content\n * - `openai/outputTemplate`: Resource URI for widget template (OpenAI)\n * - `openai/widgetAccessible`: Whether widget can invoke tools (OpenAI)\n *\n * @see {@link https://docs.agentfront.dev/docs/servers/tools#tool-ui | Tool UI Documentation}\n *\n * @example\n * ```typescript\n * import { UIAssertions } from '@frontmcp/testing';\n *\n * const result = await client.tools.call('my-tool', {});\n * const html = UIAssertions.assertRenderedUI(result);\n * UIAssertions.assertXssSafe(html);\n * UIAssertions.assertDataBinding(html, result.json(), ['location', 'temperature']);\n * ```\n */\n\nimport type { ToolResultWrapper } from '../client/mcp-test-client.types';\nimport type { TestPlatformType } from '../platform/platform-types';\nimport { getForbiddenMetaPrefixes, getToolCallMetaPrefixes, getPlatformMimeType } from '../platform/platform-types';\n\n// Type-only reference: Metadata keys used below align with UIMetadata from @frontmcp/ui/adapters\n// This is an optional peer dependency, so we don't import it directly\n\n// ═══════════════════════════════════════════════════════════════════\n// HELPER FUNCTIONS\n// ═══════════════════════════════════════════════════════════════════\n\n/**\n * Escape special regex metacharacters in a string.\n * This prevents user-provided tag/class names from being interpreted as regex patterns.\n */\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n// ═══════════════════════════════════════════════════════════════════\n// UI ASSERTIONS\n// ═══════════════════════════════════════════════════════════════════\n\n/**\n * UI-specific assertion helpers.\n * Use these for imperative-style assertions with detailed error messages.\n */\nexport const UIAssertions = {\n /**\n * Assert tool result has valid rendered UI HTML.\n * @param result - The tool result wrapper\n * @returns The rendered HTML string\n * @throws Error if no UI HTML found or if mdx-fallback detected\n */\n assertRenderedUI(result: ToolResultWrapper): string {\n const meta = result.raw._meta as Record<string, unknown> | undefined;\n\n if (!meta) {\n throw new Error('Expected tool result to have _meta, but _meta is undefined');\n }\n\n const html = meta['ui/html'];\n\n if (!html) {\n throw new Error('Expected tool result to have ui/html in _meta, but it is missing');\n }\n\n if (typeof html !== 'string') {\n throw new Error(`Expected ui/html to be a string, but got ${typeof html}`);\n }\n\n if (html.includes('mdx-fallback')) {\n throw new Error(\n 'Got mdx-fallback instead of rendered HTML - MDX/React rendering failed. ' +\n 'Check that @mdx-js/mdx is installed and the template syntax is valid.',\n );\n }\n\n return html;\n },\n\n /**\n * Assert HTML contains all expected bound values from tool output.\n * @param html - The rendered HTML string\n * @param output - The tool output object\n * @param keys - Array of keys whose values should appear in the HTML\n * @throws Error if any expected value is missing from the HTML\n */\n assertDataBinding(html: string, output: Record<string, unknown>, keys: string[]): void {\n const missingKeys: string[] = [];\n\n for (const key of keys) {\n const value = output[key];\n if (value === undefined || value === null) {\n continue; // Skip undefined/null values\n }\n\n const stringValue = String(value);\n if (!html.includes(stringValue)) {\n missingKeys.push(`${key}=\"${stringValue}\"`);\n }\n }\n\n if (missingKeys.length > 0) {\n throw new Error(\n `Expected HTML to contain bound values for: ${missingKeys.join(', ')}. ` + 'Data binding may have failed.',\n );\n }\n },\n\n /**\n * Assert HTML is XSS-safe (no scripts, event handlers, or javascript: URIs).\n * @param html - The rendered HTML string\n * @throws Error if potential XSS vulnerabilities are detected\n */\n assertXssSafe(html: string): void {\n const vulnerabilities: string[] = [];\n\n if (/<script[\\s>]/i.test(html)) {\n vulnerabilities.push('<script> tag detected');\n }\n\n if (/\\son\\w+\\s*=/i.test(html)) {\n vulnerabilities.push('inline event handler detected (onclick, onerror, etc.)');\n }\n\n if (/javascript:/i.test(html)) {\n vulnerabilities.push('javascript: URI detected');\n }\n\n if (vulnerabilities.length > 0) {\n throw new Error(`Potential XSS vulnerabilities found: ${vulnerabilities.join('; ')}`);\n }\n },\n\n /**\n * Assert HTML has proper structure (not escaped raw content).\n * @param html - The rendered HTML string\n * @throws Error if HTML appears to be raw/unrendered content\n */\n assertProperHtmlStructure(html: string): void {\n // Check for escaped HTML entities that suggest content wasn't rendered\n if (html.includes('&lt;') && html.includes('&gt;')) {\n throw new Error(\n 'HTML contains escaped HTML entities (&lt;, &gt;) - content was likely not rendered. ' +\n 'Check that the template is being processed correctly.',\n );\n }\n\n // Check that there's at least one HTML tag\n if (!/<[a-z]/i.test(html)) {\n throw new Error('HTML contains no HTML tags - content may be plain text or rendering failed.');\n }\n },\n\n /**\n * Assert HTML contains a specific element.\n * @param html - The rendered HTML string\n * @param tag - The HTML tag name to look for\n * @throws Error if the element is not found\n */\n assertContainsElement(html: string, tag: string): void {\n // Escape regex metacharacters to prevent user input from breaking the regex\n const regex = new RegExp(`<${escapeRegex(tag)}[\\\\s>]`, 'i');\n if (!regex.test(html)) {\n throw new Error(`Expected HTML to contain <${tag}> element`);\n }\n },\n\n /**\n * Assert HTML contains a specific CSS class.\n * @param html - The rendered HTML string\n * @param className - The CSS class name to look for\n * @throws Error if the class is not found\n */\n assertHasCssClass(html: string, className: string): void {\n // Escape regex metacharacters to prevent user input from breaking the regex\n const classRegex = new RegExp(`class(?:Name)?\\\\s*=\\\\s*[\"'][^\"']*\\\\b${escapeRegex(className)}\\\\b[^\"']*[\"']`, 'i');\n if (!classRegex.test(html)) {\n throw new Error(`Expected HTML to have CSS class \"${className}\"`);\n }\n },\n\n /**\n * Assert HTML does NOT contain specific content.\n * Useful for verifying custom components were rendered, not left as raw tags.\n * @param html - The rendered HTML string\n * @param content - The content that should NOT appear\n * @throws Error if the content is found\n */\n assertNotContainsRaw(html: string, content: string): void {\n if (html.includes(content)) {\n throw new Error(\n `HTML contains raw content \"${content}\" - this component may not have been rendered. ` +\n 'Check that all custom components are properly passed to the renderer.',\n );\n }\n },\n\n /**\n * Assert that widget metadata is present in the result.\n * Checks for ui/html, openai/outputTemplate, or ui/mimeType.\n * @param result - The tool result wrapper\n * @throws Error if widget metadata is missing\n */\n assertWidgetMetadata(result: ToolResultWrapper): void {\n const meta = result.raw._meta as Record<string, unknown> | undefined;\n\n if (!meta) {\n throw new Error('Expected tool result to have _meta with widget metadata');\n }\n\n // Check for any widget-related metadata fields (aligned with toHaveWidgetMetadata matcher)\n const hasUiHtml = Boolean(meta['ui/html']);\n const hasOutputTemplate = Boolean(meta['openai/outputTemplate']);\n const hasMimeType = Boolean(meta['ui/mimeType']);\n\n if (!hasUiHtml && !hasOutputTemplate && !hasMimeType) {\n throw new Error('Expected _meta to have widget metadata (ui/html, openai/outputTemplate, or ui/mimeType)');\n }\n },\n\n /**\n * Comprehensive UI validation that runs all checks.\n * @param result - The tool result wrapper\n * @param boundKeys - Optional array of output keys to check for data binding\n * @returns The rendered HTML string\n * @throws Error if any validation fails\n */\n assertValidUI(result: ToolResultWrapper, boundKeys?: string[]): string {\n // 1. Get and validate HTML exists\n const html = UIAssertions.assertRenderedUI(result);\n\n // 2. Check HTML structure\n UIAssertions.assertProperHtmlStructure(html);\n\n // 3. Check XSS safety\n UIAssertions.assertXssSafe(html);\n\n // 4. Check data binding if keys provided\n if (boundKeys && boundKeys.length > 0) {\n try {\n const output = JSON.parse(result.text() || '{}');\n UIAssertions.assertDataBinding(html, output, boundKeys);\n } catch {\n // If we can't parse output, skip data binding check\n }\n }\n\n return html;\n },\n\n // ═══════════════════════════════════════════════════════════════════\n // PLATFORM META ASSERTIONS\n // ═══════════════════════════════════════════════════════════════════\n\n /**\n * Assert tool result has correct meta keys for OpenAI platform.\n * Verifies openai/* keys are present and ui/*, frontmcp/* keys are absent.\n * @param result - The tool result wrapper\n * @throws Error if meta keys don't match OpenAI expectations\n */\n assertOpenAIMeta(result: ToolResultWrapper): void {\n UIAssertions.assertPlatformMeta(result, 'openai');\n },\n\n /**\n * Assert tool result has correct meta keys for ext-apps platform (SEP-1865).\n * Verifies ui/* keys are present and openai/*, frontmcp/* keys are absent.\n * @param result - The tool result wrapper\n * @throws Error if meta keys don't match ext-apps expectations\n */\n assertExtAppsMeta(result: ToolResultWrapper): void {\n UIAssertions.assertPlatformMeta(result, 'ext-apps');\n },\n\n /**\n * Assert tool result has correct meta keys for FrontMCP platforms (Claude, Cursor, etc.).\n * Verifies frontmcp/* + ui/* keys are present and openai/* keys are absent.\n * @param result - The tool result wrapper\n * @throws Error if meta keys don't match FrontMCP expectations\n */\n assertFrontmcpMeta(result: ToolResultWrapper): void {\n UIAssertions.assertPlatformMeta(result, 'claude');\n },\n\n /**\n * Assert tool result has correct meta keys for a specific platform.\n * @param result - The tool result wrapper\n * @param platform - The platform type to check for\n * @throws Error if meta keys don't match platform expectations\n */\n assertPlatformMeta(result: ToolResultWrapper, platform: TestPlatformType): void {\n const meta = result.raw._meta as Record<string, unknown> | undefined;\n\n if (!meta) {\n throw new Error(`Expected tool result to have _meta with platform meta for \"${platform}\"`);\n }\n\n const expectedPrefixes = getToolCallMetaPrefixes(platform);\n const forbiddenPrefixes = getForbiddenMetaPrefixes(platform);\n const metaKeys = Object.keys(meta);\n\n // Check for expected prefixes\n const hasExpectedPrefix = metaKeys.some((key) => expectedPrefixes.some((prefix) => key.startsWith(prefix)));\n\n if (!hasExpectedPrefix) {\n throw new Error(\n `Expected _meta to have keys with prefixes [${expectedPrefixes.join(', ')}] for platform \"${platform}\", ` +\n `but found: [${metaKeys.join(', ')}]`,\n );\n }\n\n // Check for forbidden prefixes\n const forbiddenKeys = metaKeys.filter((key) => forbiddenPrefixes.some((prefix) => key.startsWith(prefix)));\n\n if (forbiddenKeys.length > 0) {\n throw new Error(\n `Expected _meta NOT to have keys [${forbiddenKeys.join(', ')}] for platform \"${platform}\" ` +\n `(forbidden prefixes: [${forbiddenPrefixes.join(', ')}])`,\n );\n }\n },\n\n /**\n * Assert that no cross-namespace pollution exists in meta.\n * @param result - The tool result wrapper\n * @param expectedNamespace - The namespace that SHOULD be present\n * @throws Error if other namespaces are found\n */\n assertNoMixedNamespaces(result: ToolResultWrapper, expectedNamespace: string): void {\n const meta = result.raw._meta as Record<string, unknown> | undefined;\n\n if (!meta) {\n throw new Error(`Expected tool result to have _meta with namespace \"${expectedNamespace}\"`);\n }\n\n const metaKeys = Object.keys(meta);\n const wrongKeys = metaKeys.filter((key) => !key.startsWith(expectedNamespace));\n\n if (wrongKeys.length > 0) {\n throw new Error(\n `Expected _meta to ONLY have keys with namespace \"${expectedNamespace}\", ` +\n `but found: [${wrongKeys.join(', ')}]`,\n );\n }\n },\n\n /**\n * Assert that _meta has the correct MIME type for a platform.\n * @param result - The tool result wrapper\n * @param platform - The platform type to check for\n * @throws Error if MIME type doesn't match platform expectations\n */\n assertPlatformMimeType(result: ToolResultWrapper, platform: TestPlatformType): void {\n const meta = result.raw._meta as Record<string, unknown> | undefined;\n const expectedMimeType = getPlatformMimeType(platform);\n\n if (!meta) {\n throw new Error(`Expected tool result to have _meta with MIME type for platform \"${platform}\"`);\n }\n\n // Determine which key to check based on platform\n let mimeTypeKey: string;\n switch (platform) {\n case 'openai':\n mimeTypeKey = 'openai/mimeType';\n break;\n case 'ext-apps':\n mimeTypeKey = 'ui/mimeType';\n break;\n default:\n mimeTypeKey = 'frontmcp/mimeType';\n }\n\n const actualMimeType = meta[mimeTypeKey];\n\n if (actualMimeType !== expectedMimeType) {\n throw new Error(\n `Expected _meta[\"${mimeTypeKey}\"] to be \"${expectedMimeType}\" for platform \"${platform}\", ` +\n `but got \"${actualMimeType}\"`,\n );\n }\n },\n\n /**\n * Assert that _meta has HTML in the correct platform-specific key.\n * @param result - The tool result wrapper\n * @param platform - The platform type to check for\n * @returns The HTML string\n * @throws Error if HTML is missing or in wrong key\n */\n assertPlatformHtml(result: ToolResultWrapper, platform: TestPlatformType): string {\n const meta = result.raw._meta as Record<string, unknown> | undefined;\n\n if (!meta) {\n throw new Error(`Expected tool result to have _meta with platform HTML for \"${platform}\"`);\n }\n\n // Determine which key to check based on platform\n let htmlKey: string;\n switch (platform) {\n case 'openai':\n htmlKey = 'openai/html';\n break;\n case 'ext-apps':\n htmlKey = 'ui/html';\n break;\n default:\n htmlKey = 'frontmcp/html';\n }\n\n const html = meta[htmlKey];\n\n if (typeof html !== 'string' || html.length === 0) {\n throw new Error(\n `Expected _meta[\"${htmlKey}\"] to contain HTML for platform \"${platform}\", ` +\n `but ${html === undefined ? 'key not found' : `got ${typeof html}`}`,\n );\n }\n\n return html;\n },\n\n /**\n * Comprehensive platform meta validation.\n * @param result - The tool result wrapper\n * @param platform - The platform type to validate for\n * @returns The platform-specific HTML string\n * @throws Error if any platform-specific validation fails\n */\n assertValidPlatformMeta(result: ToolResultWrapper, platform: TestPlatformType): string {\n // 1. Check correct namespace keys\n UIAssertions.assertPlatformMeta(result, platform);\n\n // 2. Check MIME type\n UIAssertions.assertPlatformMimeType(result, platform);\n\n // 3. Get and return HTML\n return UIAssertions.assertPlatformHtml(result, platform);\n },\n};\n"]}