@midscene/core 1.15.2-beta-20261012123219.0 → 1.15.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 (180) hide show
  1. package/dist/es/agent/action-readiness.mjs +6 -3
  2. package/dist/es/agent/action-readiness.mjs.map +1 -1
  3. package/dist/es/agent/agent.mjs +4 -2
  4. package/dist/es/agent/agent.mjs.map +1 -1
  5. package/dist/es/agent/execution-session.mjs.map +1 -1
  6. package/dist/es/agent/task-builder.mjs +35 -16
  7. package/dist/es/agent/task-builder.mjs.map +1 -1
  8. package/dist/es/agent/tasks.mjs +35 -12
  9. package/dist/es/agent/tasks.mjs.map +1 -1
  10. package/dist/es/agent/utils.mjs +1 -1
  11. package/dist/es/device/index.mjs +7 -6
  12. package/dist/es/device/index.mjs.map +1 -1
  13. package/dist/es/report-generator.mjs +30 -14
  14. package/dist/es/report-generator.mjs.map +1 -1
  15. package/dist/es/report-html-template.mjs +1 -1
  16. package/dist/es/report.mjs +121 -44
  17. package/dist/es/report.mjs.map +1 -1
  18. package/dist/es/service/index.mjs.map +1 -1
  19. package/dist/es/task-runner.mjs +22 -12
  20. package/dist/es/task-runner.mjs.map +1 -1
  21. package/dist/es/test-run-report.mjs.map +1 -1
  22. package/dist/es/test-runner/engine/case-runner.mjs +1 -1
  23. package/dist/es/test-runner/engine/case-runner.mjs.map +1 -1
  24. package/dist/es/test-runner/engine/document-runtime.mjs +42 -12
  25. package/dist/es/test-runner/engine/document-runtime.mjs.map +1 -1
  26. package/dist/es/test-runner/engine/execute-step.mjs +130 -12
  27. package/dist/es/test-runner/engine/execute-step.mjs.map +1 -1
  28. package/dist/es/test-runner/engine/index.mjs +1 -0
  29. package/dist/es/test-runner/engine/project-runtime.mjs +14 -5
  30. package/dist/es/test-runner/engine/project-runtime.mjs.map +1 -1
  31. package/dist/es/test-runner/engine/resource-operations.mjs +286 -35
  32. package/dist/es/test-runner/engine/resource-operations.mjs.map +1 -1
  33. package/dist/es/test-runner/engine/result-metadata.mjs +21 -0
  34. package/dist/es/test-runner/engine/result-metadata.mjs.map +1 -0
  35. package/dist/es/test-runner/engine/run-collected-case.mjs +30 -9
  36. package/dist/es/test-runner/engine/run-collected-case.mjs.map +1 -1
  37. package/dist/es/test-runner/engine/run-workflow-document.mjs +57 -10
  38. package/dist/es/test-runner/engine/run-workflow-document.mjs.map +1 -1
  39. package/dist/es/test-runner/errors.mjs +26 -13
  40. package/dist/es/test-runner/errors.mjs.map +1 -1
  41. package/dist/es/test-runner/execution-record.mjs +2 -0
  42. package/dist/es/test-runner/execution-record.mjs.map +1 -1
  43. package/dist/es/test-runner/index.mjs +3 -0
  44. package/dist/es/test-runner/reporting/agent-report.mjs +2 -7
  45. package/dist/es/test-runner/reporting/agent-report.mjs.map +1 -1
  46. package/dist/es/test-runner/reporting/merge-report.mjs +207 -6
  47. package/dist/es/test-runner/reporting/merge-report.mjs.map +1 -1
  48. package/dist/es/test-runner/reporting/metrics.mjs +77 -0
  49. package/dist/es/test-runner/reporting/metrics.mjs.map +1 -0
  50. package/dist/es/test-runner/reporting/sanitize.mjs +92 -16
  51. package/dist/es/test-runner/reporting/sanitize.mjs.map +1 -1
  52. package/dist/es/test-runner/reporting/test-plan.mjs +56 -0
  53. package/dist/es/test-runner/reporting/test-plan.mjs.map +1 -0
  54. package/dist/es/test-runner/reporting/test-run-report.mjs +208 -21
  55. package/dist/es/test-runner/reporting/test-run-report.mjs.map +1 -1
  56. package/dist/es/types.mjs.map +1 -1
  57. package/dist/es/utils.mjs +1 -1
  58. package/dist/es/yaml/legacy-yaml-runtime.mjs +3 -3
  59. package/dist/es/yaml/legacy-yaml-runtime.mjs.map +1 -1
  60. package/dist/lib/agent/action-readiness.js +6 -3
  61. package/dist/lib/agent/action-readiness.js.map +1 -1
  62. package/dist/lib/agent/agent.js +4 -2
  63. package/dist/lib/agent/agent.js.map +1 -1
  64. package/dist/lib/agent/execution-session.js.map +1 -1
  65. package/dist/lib/agent/task-builder.js +42 -23
  66. package/dist/lib/agent/task-builder.js.map +1 -1
  67. package/dist/lib/agent/tasks.js +35 -12
  68. package/dist/lib/agent/tasks.js.map +1 -1
  69. package/dist/lib/agent/utils.js +1 -1
  70. package/dist/lib/device/index.js +7 -6
  71. package/dist/lib/device/index.js.map +1 -1
  72. package/dist/lib/report-generator.js +30 -14
  73. package/dist/lib/report-generator.js.map +1 -1
  74. package/dist/lib/report-html-template.js +1 -1
  75. package/dist/lib/report.js +121 -44
  76. package/dist/lib/report.js.map +1 -1
  77. package/dist/lib/service/index.js.map +1 -1
  78. package/dist/lib/task-runner.js +22 -12
  79. package/dist/lib/task-runner.js.map +1 -1
  80. package/dist/lib/test-run-report.js.map +1 -1
  81. package/dist/lib/test-runner/engine/case-runner.js +1 -1
  82. package/dist/lib/test-runner/engine/case-runner.js.map +1 -1
  83. package/dist/lib/test-runner/engine/document-runtime.js +41 -11
  84. package/dist/lib/test-runner/engine/document-runtime.js.map +1 -1
  85. package/dist/lib/test-runner/engine/execute-step.js +131 -10
  86. package/dist/lib/test-runner/engine/execute-step.js.map +1 -1
  87. package/dist/lib/test-runner/engine/index.js +9 -2
  88. package/dist/lib/test-runner/engine/index.js.map +1 -1
  89. package/dist/lib/test-runner/engine/project-runtime.js +13 -4
  90. package/dist/lib/test-runner/engine/project-runtime.js.map +1 -1
  91. package/dist/lib/test-runner/engine/resource-operations.js +319 -38
  92. package/dist/lib/test-runner/engine/resource-operations.js.map +1 -1
  93. package/dist/lib/test-runner/engine/result-metadata.js +58 -0
  94. package/dist/lib/test-runner/engine/result-metadata.js.map +1 -0
  95. package/dist/lib/test-runner/engine/run-collected-case.js +29 -8
  96. package/dist/lib/test-runner/engine/run-collected-case.js.map +1 -1
  97. package/dist/lib/test-runner/engine/run-workflow-document.js +57 -10
  98. package/dist/lib/test-runner/engine/run-workflow-document.js.map +1 -1
  99. package/dist/lib/test-runner/errors.js +42 -23
  100. package/dist/lib/test-runner/errors.js.map +1 -1
  101. package/dist/lib/test-runner/execution-record.js +2 -0
  102. package/dist/lib/test-runner/execution-record.js.map +1 -1
  103. package/dist/lib/test-runner/index.js +88 -16
  104. package/dist/lib/test-runner/index.js.map +1 -1
  105. package/dist/lib/test-runner/node/index.js +2 -2
  106. package/dist/lib/test-runner/reporting/agent-report.js +2 -7
  107. package/dist/lib/test-runner/reporting/agent-report.js.map +1 -1
  108. package/dist/lib/test-runner/reporting/merge-report.js +207 -6
  109. package/dist/lib/test-runner/reporting/merge-report.js.map +1 -1
  110. package/dist/lib/test-runner/reporting/metrics.js +114 -0
  111. package/dist/lib/test-runner/reporting/metrics.js.map +1 -0
  112. package/dist/lib/test-runner/reporting/sanitize.js +94 -15
  113. package/dist/lib/test-runner/reporting/sanitize.js.map +1 -1
  114. package/dist/lib/test-runner/reporting/test-plan.js +90 -0
  115. package/dist/lib/test-runner/reporting/test-plan.js.map +1 -0
  116. package/dist/lib/test-runner/reporting/test-run-report.js +208 -21
  117. package/dist/lib/test-runner/reporting/test-run-report.js.map +1 -1
  118. package/dist/lib/types.js.map +1 -1
  119. package/dist/lib/utils.js +1 -1
  120. package/dist/lib/yaml/legacy-yaml-runtime.js +2 -2
  121. package/dist/lib/yaml/legacy-yaml-runtime.js.map +1 -1
  122. package/dist/types/agent/action-readiness.d.ts +1 -1
  123. package/dist/types/agent/action-readiness.d.ts.map +1 -1
  124. package/dist/types/agent/agent.d.ts +1 -1
  125. package/dist/types/agent/agent.d.ts.map +1 -1
  126. package/dist/types/agent/execution-session.d.ts +1 -1
  127. package/dist/types/agent/execution-session.d.ts.map +1 -1
  128. package/dist/types/agent/task-builder.d.ts +4 -2
  129. package/dist/types/agent/task-builder.d.ts.map +1 -1
  130. package/dist/types/agent/tasks.d.ts +3 -0
  131. package/dist/types/agent/tasks.d.ts.map +1 -1
  132. package/dist/types/device/index.d.ts +3 -3
  133. package/dist/types/device/index.d.ts.map +1 -1
  134. package/dist/types/report-generator.d.ts +4 -2
  135. package/dist/types/report-generator.d.ts.map +1 -1
  136. package/dist/types/report.d.ts.map +1 -1
  137. package/dist/types/service/index.d.ts +2 -2
  138. package/dist/types/service/index.d.ts.map +1 -1
  139. package/dist/types/task-runner.d.ts +1 -1
  140. package/dist/types/task-runner.d.ts.map +1 -1
  141. package/dist/types/test-run-report.d.ts +157 -8
  142. package/dist/types/test-run-report.d.ts.map +1 -1
  143. package/dist/types/test-runner/engine/document-runtime.d.ts.map +1 -1
  144. package/dist/types/test-runner/engine/execute-step.d.ts +1 -0
  145. package/dist/types/test-runner/engine/execute-step.d.ts.map +1 -1
  146. package/dist/types/test-runner/engine/index.d.ts +1 -0
  147. package/dist/types/test-runner/engine/index.d.ts.map +1 -1
  148. package/dist/types/test-runner/engine/project-runtime.d.ts.map +1 -1
  149. package/dist/types/test-runner/engine/resource-operations.d.ts +41 -3
  150. package/dist/types/test-runner/engine/resource-operations.d.ts.map +1 -1
  151. package/dist/types/test-runner/engine/result-metadata.d.ts +18 -0
  152. package/dist/types/test-runner/engine/result-metadata.d.ts.map +1 -0
  153. package/dist/types/test-runner/engine/run-collected-case.d.ts.map +1 -1
  154. package/dist/types/test-runner/engine/run-workflow-document.d.ts.map +1 -1
  155. package/dist/types/test-runner/engine/types.d.ts +47 -8
  156. package/dist/types/test-runner/engine/types.d.ts.map +1 -1
  157. package/dist/types/test-runner/errors.d.ts +7 -0
  158. package/dist/types/test-runner/errors.d.ts.map +1 -1
  159. package/dist/types/test-runner/execution-record.d.ts.map +1 -1
  160. package/dist/types/test-runner/index.d.ts +2 -0
  161. package/dist/types/test-runner/index.d.ts.map +1 -1
  162. package/dist/types/test-runner/node/types.d.ts +9 -1
  163. package/dist/types/test-runner/node/types.d.ts.map +1 -1
  164. package/dist/types/test-runner/parser/types.d.ts +5 -0
  165. package/dist/types/test-runner/parser/types.d.ts.map +1 -1
  166. package/dist/types/test-runner/reporting/agent-report.d.ts.map +1 -1
  167. package/dist/types/test-runner/reporting/merge-report.d.ts +1 -1
  168. package/dist/types/test-runner/reporting/merge-report.d.ts.map +1 -1
  169. package/dist/types/test-runner/reporting/metrics.d.ts +7 -0
  170. package/dist/types/test-runner/reporting/metrics.d.ts.map +1 -0
  171. package/dist/types/test-runner/reporting/sanitize.d.ts +1 -0
  172. package/dist/types/test-runner/reporting/sanitize.d.ts.map +1 -1
  173. package/dist/types/test-runner/reporting/test-plan.d.ts +8 -0
  174. package/dist/types/test-runner/reporting/test-plan.d.ts.map +1 -0
  175. package/dist/types/test-runner/reporting/test-run-report.d.ts.map +1 -1
  176. package/dist/types/test-runner/reporting/types.d.ts +6 -1
  177. package/dist/types/test-runner/reporting/types.d.ts.map +1 -1
  178. package/dist/types/types.d.ts +3 -1
  179. package/dist/types/types.d.ts.map +1 -1
  180. package/package.json +2 -2
@@ -14,7 +14,7 @@ const normalizedSecretKeys = [
14
14
  'apikey'
15
15
  ];
16
16
  const normalizedKey = (key)=>key.toLowerCase().replace(/[^a-z0-9]/g, '');
17
- const isSecretKey = (key)=>{
17
+ const isReportSecretKey = (key)=>{
18
18
  const normalized = normalizedKey(key);
19
19
  return normalizedSecretKeys.some((secret)=>normalized.includes(secret));
20
20
  };
@@ -106,7 +106,7 @@ function sanitizeReportValue(value) {
106
106
  for (const key of keys.slice(0, MAX_OBJECT_KEYS)){
107
107
  const childPath = objectPath(path, key);
108
108
  if (!consume(childPath, key)) break;
109
- if (isSecretKey(key)) {
109
+ if (isReportSecretKey(key)) {
110
110
  output[key] = '[REDACTED]';
111
111
  redactedPaths.add(childPath);
112
112
  } else output[key] = visit(current[key], childPath, depth + 1);
@@ -139,24 +139,100 @@ function sanitizeReportValue(value) {
139
139
  };
140
140
  }
141
141
  function sanitizeReportError(error) {
142
- if (error instanceof Error || 'object' == typeof error && null !== error && 'string' == typeof error.message) {
143
- const workflowLike = error;
144
- return {
145
- name: sanitizeReportText(workflowLike.name || 'Error', 200),
146
- message: sanitizeReportText(workflowLike.message || String(error)),
147
- ...'string' == typeof workflowLike.code ? {
148
- code: sanitizeReportText(workflowLike.code, 200)
142
+ const messageText = (value)=>sanitizeReportText(value.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [REDACTED]').replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi, '$1[REDACTED]@').replace(/(["']?\b(?:password|passwd|secret|token|authorization|cookie|api[_-]?key)\b["']?\s*[:=]\s*)(?:\[REDACTED\]|"[^"]*"|'[^']*'|[^\s,;}\]]+)/gi, '$1[REDACTED]'));
143
+ const ancestors = new WeakSet();
144
+ let remainingBytes = MAX_SERIALIZED_BYTES - 1024;
145
+ let nodes = 0;
146
+ const shortened = ()=>({
147
+ format: 'midscene-error',
148
+ name: 'Error',
149
+ message: '[Truncated: error cause chain]',
150
+ truncated: true
151
+ });
152
+ const visit = (current, depth)=>{
153
+ if (depth >= MAX_DEPTH || nodes++ >= 25 || remainingBytes < 4096) return shortened();
154
+ if ('object' != typeof current || null === current) return {
155
+ format: 'midscene-error',
156
+ name: 'Error',
157
+ message: messageText(String(current))
158
+ };
159
+ if (ancestors.has(current)) return shortened();
160
+ ancestors.add(current);
161
+ const source = current;
162
+ const result = {
163
+ format: 'midscene-error',
164
+ ...true === source.truncated ? {
165
+ truncated: true
149
166
  } : {},
150
- ...void 0 === workflowLike.details ? {} : {
151
- details: sanitizeReportValue(workflowLike.details)
152
- }
167
+ name: 'string' == typeof source.name ? sanitizeReportText(source.name, 200) : 'Error',
168
+ message: messageText('string' == typeof source.message ? source.message : String(current)),
169
+ ...'string' == typeof source.code ? {
170
+ code: sanitizeReportText(source.code, 200)
171
+ } : {}
153
172
  };
154
- }
173
+ remainingBytes -= stringByteLength(JSON.stringify(result)) + 128;
174
+ if (void 0 !== source.details) {
175
+ const encodedDetails = 'midscene-error' === source.format && 'object' == typeof source.details && null !== source.details && 'value' in source.details ? source.details : void 0;
176
+ const details = sanitizeReportValue(encodedDetails ? encodedDetails.value : source.details);
177
+ for (const field of [
178
+ 'redactedPaths',
179
+ 'truncatedPaths'
180
+ ]){
181
+ const paths = encodedDetails?.[field];
182
+ if (Array.isArray(paths)) details[field] = [
183
+ ...new Set([
184
+ ...details[field] ?? [],
185
+ ...paths.filter((path)=>'string' == typeof path).slice(0, 50).map((path)=>sanitizeReportText(path))
186
+ ])
187
+ ];
188
+ }
189
+ const bytes = stringByteLength(JSON.stringify(details));
190
+ if (bytes < remainingBytes - 4096) {
191
+ result.details = details;
192
+ remainingBytes -= bytes;
193
+ } else {
194
+ result.details = {
195
+ value: '[Truncated: error details size limit]',
196
+ truncatedPaths: [
197
+ '$'
198
+ ]
199
+ };
200
+ result.truncated = true;
201
+ }
202
+ }
203
+ if (void 0 !== source.cause) result.cause = visit(source.cause, depth + 1);
204
+ if (Array.isArray(source.errors)) {
205
+ result.errors = [];
206
+ for (const item of source.errors.slice(0, 10)){
207
+ if (nodes >= 25 || remainingBytes < 4096) {
208
+ result.truncated = true;
209
+ break;
210
+ }
211
+ result.errors.push(visit(item, depth + 1));
212
+ }
213
+ if (result.errors.length < source.errors.length) result.truncated = true;
214
+ }
215
+ ancestors.delete(current);
216
+ return result;
217
+ };
218
+ const result = visit(error, 0);
219
+ if (stringByteLength(JSON.stringify(result)) <= MAX_SERIALIZED_BYTES) return result;
155
220
  return {
156
- name: 'Error',
157
- message: sanitizeReportText(String(error))
221
+ format: 'midscene-error',
222
+ name: result.name,
223
+ message: result.message,
224
+ ...result.code ? {
225
+ code: result.code
226
+ } : {},
227
+ truncated: true,
228
+ cause: {
229
+ format: 'midscene-error',
230
+ name: 'Error',
231
+ message: '[Truncated: serialized error exceeded 64 KiB]',
232
+ truncated: true
233
+ }
158
234
  };
159
235
  }
160
- export { sanitizeReportError, sanitizeReportText, sanitizeReportValue };
236
+ export { isReportSecretKey, sanitizeReportError, sanitizeReportText, sanitizeReportValue };
161
237
 
162
238
  //# sourceMappingURL=sanitize.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-runner/reporting/sanitize.mjs","sources":["../../../../src/test-runner/reporting/sanitize.ts"],"sourcesContent":["import type {\n TestRunReportError,\n TestRunReportValue,\n} from '../../test-run-report';\n\nconst MAX_DEPTH = 6;\nconst MAX_STRING_LENGTH = 2_000;\nconst MAX_ARRAY_ITEMS = 50;\nconst MAX_OBJECT_KEYS = 50;\nconst MAX_SERIALIZED_BYTES = 64 * 1024;\nconst TRUNCATED_VALUE = '[Truncated: display value exceeded 64 KiB]';\n\nconst normalizedSecretKeys = [\n 'password',\n 'passwd',\n 'secret',\n 'token',\n 'authorization',\n 'cookie',\n 'apikey',\n];\n\nconst normalizedKey = (key: string): string =>\n key.toLowerCase().replace(/[^a-z0-9]/g, '');\n\nconst isSecretKey = (key: string): boolean => {\n const normalized = normalizedKey(key);\n return normalizedSecretKeys.some((secret) => normalized.includes(secret));\n};\n\nconst objectPath = (parent: string, key: string): string =>\n /^[A-Za-z_$][\\w$]*$/.test(key)\n ? `${parent}.${key}`\n : `${parent}[${JSON.stringify(key)}]`;\n\nconst stringByteLength = (value: string): number =>\n new TextEncoder().encode(value).byteLength;\n\nexport function sanitizeReportText(\n value: string,\n maximumLength = MAX_STRING_LENGTH,\n): string {\n return value.length <= maximumLength\n ? value\n : `${value.slice(0, maximumLength)}… [truncated]`;\n}\n\n/** Convert arbitrary Node input/output to a bounded, JSON-safe display value. */\nexport function sanitizeReportValue(value: unknown): TestRunReportValue {\n const truncatedPaths = new Set<string>();\n const redactedPaths = new Set<string>();\n const ancestors = new WeakSet<object>();\n let remainingBytes = MAX_SERIALIZED_BYTES;\n\n const consume = (path: string, text: string): boolean => {\n remainingBytes -= stringByteLength(text);\n if (remainingBytes >= 0) return true;\n truncatedPaths.add(path);\n return false;\n };\n\n const visit = (current: unknown, path: string, depth: number): unknown => {\n if (remainingBytes <= 0) {\n truncatedPaths.add(path);\n return '[Truncated: size limit]';\n }\n if (current === null || typeof current === 'boolean') {\n consume(path, String(current));\n return current;\n }\n if (typeof current === 'string') {\n if (current.length > MAX_STRING_LENGTH) {\n truncatedPaths.add(path);\n const shortened = `${current.slice(0, MAX_STRING_LENGTH)}… [truncated]`;\n consume(path, shortened);\n return shortened;\n }\n consume(path, current);\n return current;\n }\n if (typeof current === 'number') {\n if (Number.isFinite(current)) {\n consume(path, String(current));\n return current;\n }\n truncatedPaths.add(path);\n return `[Unsupported number: ${String(current)}]`;\n }\n if (typeof current === 'bigint') {\n truncatedPaths.add(path);\n return `[Unsupported bigint: ${String(current)}]`;\n }\n if (\n current === undefined ||\n typeof current === 'function' ||\n typeof current === 'symbol'\n ) {\n truncatedPaths.add(path);\n return `[Unsupported ${typeof current}]`;\n }\n if (depth >= MAX_DEPTH) {\n truncatedPaths.add(path);\n return '[Truncated: maximum depth]';\n }\n\n if (current instanceof Date) {\n const date = Number.isNaN(current.getTime())\n ? '[Invalid Date]'\n : current.toISOString();\n consume(path, date);\n return date;\n }\n if (ancestors.has(current)) {\n truncatedPaths.add(path);\n return '[Unsupported circular value]';\n }\n\n if (Array.isArray(current)) {\n ancestors.add(current);\n const output: unknown[] = [];\n const itemCount = Math.min(current.length, MAX_ARRAY_ITEMS);\n for (let index = 0; index < itemCount; index += 1) {\n if (remainingBytes <= 0) break;\n output.push(visit(current[index], `${path}[${index}]`, depth + 1));\n }\n if (current.length > output.length) truncatedPaths.add(path);\n ancestors.delete(current);\n return output;\n }\n\n const prototype = Object.getPrototypeOf(current);\n if (prototype !== Object.prototype && prototype !== null) {\n truncatedPaths.add(path);\n const constructorName =\n (current as { constructor?: { name?: string } }).constructor?.name ??\n 'object';\n return `[Unsupported object: ${constructorName}]`;\n }\n\n ancestors.add(current);\n const output: Record<string, unknown> = {};\n const keys = Object.keys(current as Record<string, unknown>);\n for (const key of keys.slice(0, MAX_OBJECT_KEYS)) {\n const childPath = objectPath(path, key);\n if (!consume(childPath, key)) break;\n if (isSecretKey(key)) {\n output[key] = '[REDACTED]';\n redactedPaths.add(childPath);\n } else {\n output[key] = visit(\n (current as Record<string, unknown>)[key],\n childPath,\n depth + 1,\n );\n }\n if (remainingBytes <= 0) break;\n }\n if (keys.length > Object.keys(output).length) truncatedPaths.add(path);\n ancestors.delete(current);\n return output;\n };\n\n const sanitized = visit(value, '$', 0);\n const serialized = JSON.stringify(sanitized);\n if (\n serialized === undefined ||\n stringByteLength(serialized) > MAX_SERIALIZED_BYTES\n ) {\n return { value: TRUNCATED_VALUE, truncatedPaths: ['$'] };\n }\n\n return {\n value: sanitized,\n ...(truncatedPaths.size > 0 ? { truncatedPaths: [...truncatedPaths] } : {}),\n ...(redactedPaths.size > 0 ? { redactedPaths: [...redactedPaths] } : {}),\n };\n}\n\nexport function sanitizeReportError(error: unknown): TestRunReportError {\n if (\n error instanceof Error ||\n (typeof error === 'object' &&\n error !== null &&\n typeof (error as { message?: unknown }).message === 'string')\n ) {\n const workflowLike = error as {\n name?: string;\n message: string;\n code?: unknown;\n details?: unknown;\n };\n return {\n name: sanitizeReportText(workflowLike.name || 'Error', 200),\n message: sanitizeReportText(workflowLike.message || String(error)),\n ...(typeof workflowLike.code === 'string'\n ? { code: sanitizeReportText(workflowLike.code, 200) }\n : {}),\n ...(workflowLike.details === undefined\n ? {}\n : { details: sanitizeReportValue(workflowLike.details) }),\n };\n }\n\n return {\n name: 'Error',\n message: sanitizeReportText(String(error)),\n };\n}\n"],"names":["MAX_DEPTH","MAX_STRING_LENGTH","MAX_ARRAY_ITEMS","MAX_OBJECT_KEYS","MAX_SERIALIZED_BYTES","TRUNCATED_VALUE","normalizedSecretKeys","normalizedKey","key","isSecretKey","normalized","secret","objectPath","parent","JSON","stringByteLength","value","TextEncoder","sanitizeReportText","maximumLength","sanitizeReportValue","truncatedPaths","Set","redactedPaths","ancestors","WeakSet","remainingBytes","consume","path","text","visit","current","depth","String","shortened","Number","undefined","Date","date","Array","output","itemCount","Math","index","prototype","Object","constructorName","keys","childPath","sanitized","serialized","sanitizeReportError","error","Error","workflowLike"],"mappings":"AAKA,MAAMA,YAAY;AAClB,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkB;AACxB,MAAMC,kBAAkB;AACxB,MAAMC,uBAAuB;AAC7B,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AAOC;QAAiB,gBAAgB;YAAC;SAAI;IAAC;IAGzD,OAAO;QACL,OAAO4C;QACP,GAAI5B,eAAe,IAAI,GAAG,IAAI;YAAE,gBAAgB;mBAAIA;aAAe;QAAC,IAAI,CAAC,CAAC;QAC1E,GAAIE,cAAc,IAAI,GAAG,IAAI;YAAE,eAAe;mBAAIA;aAAc;QAAC,IAAI,CAAC,CAAC;IACzE;AACF;AAEO,SAAS4B,oBAAoBC,KAAc;IAChD,IACEA,iBAAiBC,SAChB,AAAiB,YAAjB,OAAOD,SACNA,AAAU,SAAVA,SACA,AAAoD,YAApD,OAAQA,MAAgC,OAAO,EACjD;QACA,MAAME,eAAeF;QAMrB,OAAO;YACL,MAAMlC,mBAAmBoC,aAAa,IAAI,IAAI,SAAS;YACvD,SAASpC,mBAAmBoC,aAAa,OAAO,IAAIrB,OAAOmB;YAC3D,GAAI,AAA6B,YAA7B,OAAOE,aAAa,IAAI,GACxB;gBAAE,MAAMpC,mBAAmBoC,aAAa,IAAI,EAAE;YAAK,IACnD,CAAC,CAAC;YACN,GAAIA,AAAyBlB,WAAzBkB,aAAa,OAAO,GACpB,CAAC,IACD;gBAAE,SAASlC,oBAAoBkC,aAAa,OAAO;YAAE,CAAC;QAC5D;IACF;IAEA,OAAO;QACL,MAAM;QACN,SAASpC,mBAAmBe,OAAOmB;IACrC;AACF"}
1
+ {"version":3,"file":"test-runner/reporting/sanitize.mjs","sources":["../../../../src/test-runner/reporting/sanitize.ts"],"sourcesContent":["import type {\n TestRunReportError,\n TestRunReportValue,\n} from '../../test-run-report';\n\nconst MAX_DEPTH = 6;\nconst MAX_STRING_LENGTH = 2_000;\nconst MAX_ARRAY_ITEMS = 50;\nconst MAX_OBJECT_KEYS = 50;\nconst MAX_SERIALIZED_BYTES = 64 * 1024;\nconst TRUNCATED_VALUE = '[Truncated: display value exceeded 64 KiB]';\n\nconst normalizedSecretKeys = [\n 'password',\n 'passwd',\n 'secret',\n 'token',\n 'authorization',\n 'cookie',\n 'apikey',\n];\n\nconst normalizedKey = (key: string): string =>\n key.toLowerCase().replace(/[^a-z0-9]/g, '');\n\nexport const isReportSecretKey = (key: string): boolean => {\n const normalized = normalizedKey(key);\n return normalizedSecretKeys.some((secret) => normalized.includes(secret));\n};\n\nconst objectPath = (parent: string, key: string): string =>\n /^[A-Za-z_$][\\w$]*$/.test(key)\n ? `${parent}.${key}`\n : `${parent}[${JSON.stringify(key)}]`;\n\nconst stringByteLength = (value: string): number =>\n new TextEncoder().encode(value).byteLength;\n\nexport function sanitizeReportText(\n value: string,\n maximumLength = MAX_STRING_LENGTH,\n): string {\n return value.length <= maximumLength\n ? value\n : `${value.slice(0, maximumLength)}… [truncated]`;\n}\n\n/** Convert arbitrary Node input/output to a bounded, JSON-safe display value. */\nexport function sanitizeReportValue(value: unknown): TestRunReportValue {\n const truncatedPaths = new Set<string>();\n const redactedPaths = new Set<string>();\n const ancestors = new WeakSet<object>();\n let remainingBytes = MAX_SERIALIZED_BYTES;\n\n const consume = (path: string, text: string): boolean => {\n remainingBytes -= stringByteLength(text);\n if (remainingBytes >= 0) return true;\n truncatedPaths.add(path);\n return false;\n };\n\n const visit = (current: unknown, path: string, depth: number): unknown => {\n if (remainingBytes <= 0) {\n truncatedPaths.add(path);\n return '[Truncated: size limit]';\n }\n if (current === null || typeof current === 'boolean') {\n consume(path, String(current));\n return current;\n }\n if (typeof current === 'string') {\n if (current.length > MAX_STRING_LENGTH) {\n truncatedPaths.add(path);\n const shortened = `${current.slice(0, MAX_STRING_LENGTH)}… [truncated]`;\n consume(path, shortened);\n return shortened;\n }\n consume(path, current);\n return current;\n }\n if (typeof current === 'number') {\n if (Number.isFinite(current)) {\n consume(path, String(current));\n return current;\n }\n truncatedPaths.add(path);\n return `[Unsupported number: ${String(current)}]`;\n }\n if (typeof current === 'bigint') {\n truncatedPaths.add(path);\n return `[Unsupported bigint: ${String(current)}]`;\n }\n if (\n current === undefined ||\n typeof current === 'function' ||\n typeof current === 'symbol'\n ) {\n truncatedPaths.add(path);\n return `[Unsupported ${typeof current}]`;\n }\n if (depth >= MAX_DEPTH) {\n truncatedPaths.add(path);\n return '[Truncated: maximum depth]';\n }\n\n if (current instanceof Date) {\n const date = Number.isNaN(current.getTime())\n ? '[Invalid Date]'\n : current.toISOString();\n consume(path, date);\n return date;\n }\n if (ancestors.has(current)) {\n truncatedPaths.add(path);\n return '[Unsupported circular value]';\n }\n\n if (Array.isArray(current)) {\n ancestors.add(current);\n const output: unknown[] = [];\n const itemCount = Math.min(current.length, MAX_ARRAY_ITEMS);\n for (let index = 0; index < itemCount; index += 1) {\n if (remainingBytes <= 0) break;\n output.push(visit(current[index], `${path}[${index}]`, depth + 1));\n }\n if (current.length > output.length) truncatedPaths.add(path);\n ancestors.delete(current);\n return output;\n }\n\n const prototype = Object.getPrototypeOf(current);\n if (prototype !== Object.prototype && prototype !== null) {\n truncatedPaths.add(path);\n const constructorName =\n (current as { constructor?: { name?: string } }).constructor?.name ??\n 'object';\n return `[Unsupported object: ${constructorName}]`;\n }\n\n ancestors.add(current);\n const output: Record<string, unknown> = {};\n const keys = Object.keys(current as Record<string, unknown>);\n for (const key of keys.slice(0, MAX_OBJECT_KEYS)) {\n const childPath = objectPath(path, key);\n if (!consume(childPath, key)) break;\n if (isReportSecretKey(key)) {\n output[key] = '[REDACTED]';\n redactedPaths.add(childPath);\n } else {\n output[key] = visit(\n (current as Record<string, unknown>)[key],\n childPath,\n depth + 1,\n );\n }\n if (remainingBytes <= 0) break;\n }\n if (keys.length > Object.keys(output).length) truncatedPaths.add(path);\n ancestors.delete(current);\n return output;\n };\n\n const sanitized = visit(value, '$', 0);\n const serialized = JSON.stringify(sanitized);\n if (\n serialized === undefined ||\n stringByteLength(serialized) > MAX_SERIALIZED_BYTES\n ) {\n return { value: TRUNCATED_VALUE, truncatedPaths: ['$'] };\n }\n\n return {\n value: sanitized,\n ...(truncatedPaths.size > 0 ? { truncatedPaths: [...truncatedPaths] } : {}),\n ...(redactedPaths.size > 0 ? { redactedPaths: [...redactedPaths] } : {}),\n };\n}\n\nexport function sanitizeReportError(error: unknown): TestRunReportError {\n const messageText = (value: string) =>\n sanitizeReportText(\n value\n .replace(/\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [REDACTED]')\n .replace(/(https?:\\/\\/)[^\\s/@]+:[^\\s/@]+@/gi, '$1[REDACTED]@')\n .replace(\n /([\"']?\\b(?:password|passwd|secret|token|authorization|cookie|api[_-]?key)\\b[\"']?\\s*[:=]\\s*)(?:\\[REDACTED\\]|\"[^\"]*\"|'[^']*'|[^\\s,;}\\]]+)/gi,\n '$1[REDACTED]',\n ),\n );\n const ancestors = new WeakSet<object>();\n let remainingBytes = MAX_SERIALIZED_BYTES - 1024;\n let nodes = 0;\n const shortened = (): TestRunReportError => ({\n format: 'midscene-error',\n name: 'Error',\n message: '[Truncated: error cause chain]',\n truncated: true,\n });\n const visit = (current: unknown, depth: number): TestRunReportError => {\n if (depth >= MAX_DEPTH || nodes++ >= 25 || remainingBytes < 4096)\n return shortened();\n if (typeof current !== 'object' || current === null)\n return {\n format: 'midscene-error',\n name: 'Error',\n message: messageText(String(current)),\n };\n if (ancestors.has(current)) return shortened();\n ancestors.add(current);\n const source = current as {\n format?: unknown;\n truncated?: unknown;\n name?: unknown;\n message?: unknown;\n code?: unknown;\n details?: unknown;\n cause?: unknown;\n errors?: unknown;\n };\n const result: TestRunReportError = {\n format: 'midscene-error',\n ...(source.truncated === true ? { truncated: true } : {}),\n name:\n typeof source.name === 'string'\n ? sanitizeReportText(source.name, 200)\n : 'Error',\n message: messageText(\n typeof source.message === 'string' ? source.message : String(current),\n ),\n ...(typeof source.code === 'string'\n ? { code: sanitizeReportText(source.code, 200) }\n : {}),\n };\n remainingBytes -= stringByteLength(JSON.stringify(result)) + 128;\n if (source.details !== undefined) {\n // Current encoded errors may cross JSON/worker boundaries more than\n // once. An explicit format marker keeps detail values from nesting.\n const encodedDetails =\n source.format === 'midscene-error' &&\n typeof source.details === 'object' &&\n source.details !== null &&\n 'value' in source.details\n ? (source.details as TestRunReportValue)\n : undefined;\n const details = sanitizeReportValue(\n encodedDetails ? encodedDetails.value : source.details,\n );\n for (const field of ['redactedPaths', 'truncatedPaths'] as const) {\n const paths = encodedDetails?.[field];\n if (Array.isArray(paths))\n details[field] = [\n ...new Set([\n ...(details[field] ?? []),\n ...paths\n .filter((path): path is string => typeof path === 'string')\n .slice(0, 50)\n .map((path) => sanitizeReportText(path)),\n ]),\n ];\n }\n const bytes = stringByteLength(JSON.stringify(details));\n if (bytes < remainingBytes - 4096) {\n result.details = details;\n remainingBytes -= bytes;\n } else {\n result.details = {\n value: '[Truncated: error details size limit]',\n truncatedPaths: ['$'],\n };\n result.truncated = true;\n }\n }\n if (source.cause !== undefined)\n result.cause = visit(source.cause, depth + 1);\n if (Array.isArray(source.errors)) {\n result.errors = [];\n for (const item of source.errors.slice(0, 10)) {\n if (nodes >= 25 || remainingBytes < 4096) {\n result.truncated = true;\n break;\n }\n result.errors.push(visit(item, depth + 1));\n }\n if (result.errors.length < source.errors.length) result.truncated = true;\n }\n ancestors.delete(current);\n return result;\n };\n const result = visit(error, 0);\n if (stringByteLength(JSON.stringify(result)) <= MAX_SERIALIZED_BYTES)\n return result;\n return {\n format: 'midscene-error',\n name: result.name,\n message: result.message,\n ...(result.code ? { code: result.code } : {}),\n truncated: true,\n cause: {\n format: 'midscene-error',\n name: 'Error',\n message: '[Truncated: serialized error exceeded 64 KiB]',\n truncated: true,\n },\n };\n}\n"],"names":["MAX_DEPTH","MAX_STRING_LENGTH","MAX_ARRAY_ITEMS","MAX_OBJECT_KEYS","MAX_SERIALIZED_BYTES","TRUNCATED_VALUE","normalizedSecretKeys","normalizedKey","key","isReportSecretKey","normalized","secret","objectPath","parent","JSON","stringByteLength","value","TextEncoder","sanitizeReportText","maximumLength","sanitizeReportValue","truncatedPaths","Set","redactedPaths","ancestors","WeakSet","remainingBytes","consume","path","text","visit","current","depth","String","shortened","Number","undefined","Date","date","Array","output","itemCount","Math","index","prototype","Object","constructorName","keys","childPath","sanitized","serialized","sanitizeReportError","error","messageText","nodes","source","result","encodedDetails","details","field","paths","bytes","item"],"mappings":"AAKA,MAAMA,YAAY;AAClB,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkB;AACxB,MAAMC,kBAAkB;AACxB,MAAMC,uBAAuB;AAC7B,MAAMC,kBAAkB;AAExB,MAAMC,uBAAuB;IAC3B;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,gBAAgB,CAACC,MACrBA,IAAI,WAAW,GAAG,OAAO,CAAC,cAAc;AAEnC,MAAMC,oBAAoB,CAACD;IAChC,MAAME,aAAaH,cAAcC;IACjC,OAAOF,qBAAqB,IAAI,CAAC,CAACK,SAAWD,WAAW,QAAQ,CAACC;AACnE;AAEA,MAAMC,aAAa,CAACC,QAAgBL,MAClC,qBAAqB,IAAI,CAACA,OACtB,GAAGK,OAAO,CAAC,EAAEL,KAAK,GAClB,GAAGK,OAAO,CAAC,EAAEC,KAAK,SAAS,CAACN,KAAK,CAAC,CAAC;AAEzC,MAAMO,mBAAmB,CAACC,QACxB,IAAIC,cAAc,MAAM,CAACD,OAAO,UAAU;AAErC,SAASE,mBACdF,KAAa,EACbG,gBAAgBlB,iBAAiB;IAEjC,OAAOe,MAAM,MAAM,IAAIG,gBACnBH,QACA,GAAGA,MAAM,KAAK,CAAC,GAAGG,eAAe,aAAa,CAAC;AACrD;AAGO,SAASC,oBAAoBJ,KAAc;IAChD,MAAMK,iBAAiB,IAAIC;IAC3B,MAAMC,gBAAgB,IAAID;IAC1B,MAAME,YAAY,IAAIC;IACtB,IAAIC,iBAAiBtB;IAErB,MAAMuB,UAAU,CAACC,MAAcC;QAC7BH,kBAAkBX,iBAAiBc;QACnC,IAAIH,kBAAkB,GAAG,OAAO;QAChCL,eAAe,GAAG,CAACO;QACnB,OAAO;IACT;IAEA,MAAME,QAAQ,CAACC,SAAkBH,MAAcI;QAC7C,IAAIN,kBAAkB,GAAG;YAC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ACAA,OAAO,SAAS,GAAG;YACrB;QACF;QACA,IAAID,AAAiBnB,WAAjBmB,OAAO,KAAK,EACdC,OAAO,KAAK,GAAG1B,MAAMyB,OAAO,KAAK,EAAEvB,QAAQ;QAC7C,IAAIO,MAAM,OAAO,CAACgB,OAAO,MAAM,GAAG;YAChCC,OAAO,MAAM,GAAG,EAAE;YAClB,KAAK,MAAMM,QAAQP,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,IAAK;gBAC7C,IAAID,SAAS,MAAM5B,iBAAiB,MAAM;oBACxC8B,OAAO,SAAS,GAAG;oBACnB;gBACF;gBACAA,OAAO,MAAM,CAAC,IAAI,CAAC1B,MAAMgC,MAAM9B,QAAQ;YACzC;YACA,IAAIwB,OAAO,MAAM,CAAC,MAAM,GAAGD,OAAO,MAAM,CAAC,MAAM,EAAEC,OAAO,SAAS,GAAG;QACtE;QACAhC,UAAU,MAAM,CAACO;QACjB,OAAOyB;IACT;IACA,MAAMA,SAAS1B,MAAMsB,OAAO;IAC5B,IAAIrC,iBAAiBD,KAAK,SAAS,CAAC0C,YAAYpD,sBAC9C,OAAOoD;IACT,OAAO;QACL,QAAQ;QACR,MAAMA,OAAO,IAAI;QACjB,SAASA,OAAO,OAAO;QACvB,GAAIA,OAAO,IAAI,GAAG;YAAE,MAAMA,OAAO,IAAI;QAAC,IAAI,CAAC,CAAC;QAC5C,WAAW;QACX,OAAO;YACL,QAAQ;YACR,MAAM;YACN,SAAS;YACT,WAAW;QACb;IACF;AACF"}
@@ -0,0 +1,56 @@
1
+ import { sanitizeReportText, sanitizeReportValue } from "./sanitize.mjs";
2
+ function buildTestRunReportPlan(document, options = {}) {
3
+ const selected = new Set(options.selectedCaseIds ?? document.cases.map((c)=>c.caseId));
4
+ const steps = (items, phase, owner)=>items.map((step, stepIndex)=>{
5
+ const input = step.templateInput ?? step.input;
6
+ const candidate = input.prompt ?? input.script ?? input.scenario ?? input.title;
7
+ const title = 'string' == typeof candidate ? candidate : candidate && 'object' == typeof candidate && 'prompt' in candidate && 'string' == typeof candidate.prompt ? candidate.prompt : void 0;
8
+ return {
9
+ id: `${document.documentId}:${owner}:${phase}:${stepIndex}`,
10
+ phase,
11
+ stepIndex,
12
+ node: step.node,
13
+ ...title ? {
14
+ title: sanitizeReportText(title, 240)
15
+ } : {},
16
+ input: sanitizeReportValue(input),
17
+ inputMode: step.templateInput ? 'template' : 'resolved',
18
+ ...(step.meta.timeoutMs ?? options.defaultTimeoutMs) === void 0 ? {} : {
19
+ timeoutMs: step.meta.timeoutMs ?? options.defaultTimeoutMs
20
+ },
21
+ continueOnError: step.meta.continueOnError
22
+ };
23
+ });
24
+ const cases = document.cases.map((item)=>({
25
+ caseId: item.caseId,
26
+ name: item.definition.name,
27
+ caseIndex: item.caseIndex,
28
+ selected: selected.has(item.caseId),
29
+ tags: [
30
+ ...item.definition.tags ?? []
31
+ ],
32
+ ...item.definition.onFailure ? {
33
+ onFailure: item.definition.onFailure
34
+ } : {},
35
+ beforeEach: steps(document.lifecycle.beforeEach, 'beforeEach', item.caseId),
36
+ steps: steps(item.definition.steps, 'steps', item.caseId),
37
+ afterEach: steps(document.lifecycle.afterEach, 'afterEach', item.caseId)
38
+ }));
39
+ return {
40
+ documentId: document.documentId,
41
+ sourcePath: document.sourcePath,
42
+ ...document.sourceYaml ? {
43
+ sourceYaml: structuredClone(document.sourceYaml)
44
+ } : {},
45
+ retry: options.retry ?? {
46
+ scope: 'case',
47
+ count: 0
48
+ },
49
+ beforeAll: steps(document.lifecycle.beforeAll, 'beforeAll', 'document'),
50
+ cases,
51
+ afterAll: steps(document.lifecycle.afterAll, 'afterAll', 'document')
52
+ };
53
+ }
54
+ export { buildTestRunReportPlan };
55
+
56
+ //# sourceMappingURL=test-plan.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runner/reporting/test-plan.mjs","sources":["../../../../src/test-runner/reporting/test-plan.ts"],"sourcesContent":["import type {\n TestRunReportCasePlan,\n TestRunReportDocumentPlan,\n TestRunReportPlannedStep,\n TestRunReportStepPhase,\n} from '../../test-run-report';\nimport type {\n CollectedWorkflowDocument,\n NormalizedStep,\n} from '../parser/types';\nimport { sanitizeReportText, sanitizeReportValue } from './sanitize';\n\nexport function buildTestRunReportPlan(\n document: CollectedWorkflowDocument,\n options: {\n selectedCaseIds?: readonly string[];\n defaultTimeoutMs?: number;\n retry?: TestRunReportDocumentPlan['retry'];\n } = {},\n): TestRunReportDocumentPlan {\n const selected = new Set(\n options.selectedCaseIds ?? document.cases.map((c) => c.caseId),\n );\n const steps = (\n items: readonly NormalizedStep[],\n phase: TestRunReportStepPhase,\n owner: string,\n ): TestRunReportPlannedStep[] =>\n items.map((step, stepIndex) => {\n const input = step.templateInput ?? step.input;\n const candidate =\n input.prompt ?? input.script ?? input.scenario ?? input.title;\n const title =\n typeof candidate === 'string'\n ? candidate\n : candidate &&\n typeof candidate === 'object' &&\n 'prompt' in candidate &&\n typeof candidate.prompt === 'string'\n ? candidate.prompt\n : undefined;\n return {\n id: `${document.documentId}:${owner}:${phase}:${stepIndex}`,\n phase,\n stepIndex,\n node: step.node,\n ...(title ? { title: sanitizeReportText(title, 240) } : {}),\n input: sanitizeReportValue(input),\n inputMode: step.templateInput ? 'template' : 'resolved',\n ...((step.meta.timeoutMs ?? options.defaultTimeoutMs) === undefined\n ? {}\n : { timeoutMs: step.meta.timeoutMs ?? options.defaultTimeoutMs }),\n continueOnError: step.meta.continueOnError,\n };\n });\n const cases: TestRunReportCasePlan[] = document.cases.map((item) => ({\n caseId: item.caseId,\n name: item.definition.name,\n caseIndex: item.caseIndex,\n selected: selected.has(item.caseId),\n tags: [...(item.definition.tags ?? [])],\n ...(item.definition.onFailure\n ? { onFailure: item.definition.onFailure }\n : {}),\n beforeEach: steps(document.lifecycle.beforeEach, 'beforeEach', item.caseId),\n steps: steps(item.definition.steps, 'steps', item.caseId),\n afterEach: steps(document.lifecycle.afterEach, 'afterEach', item.caseId),\n }));\n return {\n documentId: document.documentId,\n sourcePath: document.sourcePath,\n ...(document.sourceYaml\n ? { sourceYaml: structuredClone(document.sourceYaml) }\n : {}),\n retry: options.retry ?? { scope: 'case', count: 0 },\n beforeAll: steps(document.lifecycle.beforeAll, 'beforeAll', 'document'),\n cases,\n afterAll: steps(document.lifecycle.afterAll, 'afterAll', 'document'),\n };\n}\n"],"names":["buildTestRunReportPlan","document","options","selected","Set","c","steps","items","phase","owner","step","stepIndex","input","candidate","title","undefined","sanitizeReportText","sanitizeReportValue","cases","item","structuredClone"],"mappings":";AAYO,SAASA,uBACdC,QAAmC,EACnCC,UAII,CAAC,CAAC;IAEN,MAAMC,WAAW,IAAIC,IACnBF,QAAQ,eAAe,IAAID,SAAS,KAAK,CAAC,GAAG,CAAC,CAACI,IAAMA,EAAE,MAAM;IAE/D,MAAMC,QAAQ,CACZC,OACAC,OACAC,QAEAF,MAAM,GAAG,CAAC,CAACG,MAAMC;YACf,MAAMC,QAAQF,KAAK,aAAa,IAAIA,KAAK,KAAK;YAC9C,MAAMG,YACJD,MAAM,MAAM,IAAIA,MAAM,MAAM,IAAIA,MAAM,QAAQ,IAAIA,MAAM,KAAK;YAC/D,MAAME,QACJ,AAAqB,YAArB,OAAOD,YACHA,YACAA,aACE,AAAqB,YAArB,OAAOA,aACP,YAAYA,aACZ,AAA4B,YAA5B,OAAOA,UAAU,MAAM,GACvBA,UAAU,MAAM,GAChBE;YACR,OAAO;gBACL,IAAI,GAAGd,SAAS,UAAU,CAAC,CAAC,EAAEQ,MAAM,CAAC,EAAED,MAAM,CAAC,EAAEG,WAAW;gBAC3DH;gBACAG;gBACA,MAAMD,KAAK,IAAI;gBACf,GAAII,QAAQ;oBAAE,OAAOE,mBAAmBF,OAAO;gBAAK,IAAI,CAAC,CAAC;gBAC1D,OAAOG,oBAAoBL;gBAC3B,WAAWF,KAAK,aAAa,GAAG,aAAa;gBAC7C,GAAKA,AAAAA,CAAAA,KAAK,IAAI,CAAC,SAAS,IAAIR,QAAQ,gBAAe,MAAOa,SACtD,CAAC,IACD;oBAAE,WAAWL,KAAK,IAAI,CAAC,SAAS,IAAIR,QAAQ,gBAAgB;gBAAC,CAAC;gBAClE,iBAAiBQ,KAAK,IAAI,CAAC,eAAe;YAC5C;QACF;IACF,MAAMQ,QAAiCjB,SAAS,KAAK,CAAC,GAAG,CAAC,CAACkB,OAAU;YACnE,QAAQA,KAAK,MAAM;YACnB,MAAMA,KAAK,UAAU,CAAC,IAAI;YAC1B,WAAWA,KAAK,SAAS;YACzB,UAAUhB,SAAS,GAAG,CAACgB,KAAK,MAAM;YAClC,MAAM;mBAAKA,KAAK,UAAU,CAAC,IAAI,IAAI,EAAE;aAAE;YACvC,GAAIA,KAAK,UAAU,CAAC,SAAS,GACzB;gBAAE,WAAWA,KAAK,UAAU,CAAC,SAAS;YAAC,IACvC,CAAC,CAAC;YACN,YAAYb,MAAML,SAAS,SAAS,CAAC,UAAU,EAAE,cAAckB,KAAK,MAAM;YAC1E,OAAOb,MAAMa,KAAK,UAAU,CAAC,KAAK,EAAE,SAASA,KAAK,MAAM;YACxD,WAAWb,MAAML,SAAS,SAAS,CAAC,SAAS,EAAE,aAAakB,KAAK,MAAM;QACzE;IACA,OAAO;QACL,YAAYlB,SAAS,UAAU;QAC/B,YAAYA,SAAS,UAAU;QAC/B,GAAIA,SAAS,UAAU,GACnB;YAAE,YAAYmB,gBAAgBnB,SAAS,UAAU;QAAE,IACnD,CAAC,CAAC;QACN,OAAOC,QAAQ,KAAK,IAAI;YAAE,OAAO;YAAQ,OAAO;QAAE;QAClD,WAAWI,MAAML,SAAS,SAAS,CAAC,SAAS,EAAE,aAAa;QAC5DiB;QACA,UAAUZ,MAAML,SAAS,SAAS,CAAC,QAAQ,EAAE,YAAY;IAC3D;AACF"}
@@ -1,3 +1,4 @@
1
+ import { sumTestRunReportMetrics } from "./metrics.mjs";
1
2
  import { sanitizeReportError, sanitizeReportText, sanitizeReportValue } from "./sanitize.mjs";
2
3
  const exactMidsceneDetailNodes = new Set([
3
4
  'aiAct',
@@ -9,16 +10,66 @@ const reportSourcesForScope = (context, scopeId)=>context.sourcesByScope.get(sco
9
10
  const addDiagnostic = (context, diagnostic)=>{
10
11
  context.diagnostics.push(diagnostic);
11
12
  };
12
- const buildStep = (step, scopeId, context, executionId)=>{
13
+ const buildStep = (step, scopeId, context, executionId, plan)=>{
14
+ const stepId = `${executionId}:${step.phase}:${step.stepIndex}`;
15
+ if ('not-run' === step.status) return {
16
+ id: stepId,
17
+ ...plan ? {
18
+ planStepId: plan.id,
19
+ title: plan.title
20
+ } : {},
21
+ phase: step.phase,
22
+ stepIndex: step.stepIndex,
23
+ node: step.node,
24
+ status: 'not-run',
25
+ notRunReason: sanitizeReportText(step.notRunReason),
26
+ ...step.blockedBy ? {
27
+ blockedBy: step.blockedBy
28
+ } : {},
29
+ continuedAfterError: step.continuedAfterError,
30
+ ...step.waitForPreviousOperationMs ? {
31
+ waitForPreviousOperationMs: step.waitForPreviousOperationMs
32
+ } : {},
33
+ input: sanitizeReportValue(step.input),
34
+ ...step.error ? {
35
+ error: sanitizeReportError(step.error)
36
+ } : {},
37
+ ...step.operations ? {
38
+ operations: {
39
+ ...step.operations,
40
+ events: [
41
+ ...step.operations.events
42
+ ]
43
+ }
44
+ } : {}
45
+ };
13
46
  const details = [];
14
47
  const unresolvedExecutionIds = [];
48
+ const usage = [];
49
+ const missingUsage = [];
15
50
  for (const trace of step.report?.traces ?? []){
51
+ context.tracedScopes.add(scopeId);
52
+ const metrics = context.executionMetrics.get(trace.executionId) ?? trace.metrics;
53
+ if (metrics) {
54
+ context.executionMetrics.set(trace.executionId, metrics);
55
+ usage.push(metrics);
56
+ }
57
+ context.expectedExecutions.add(scopedExecutionKey(scopeId, trace.executionId));
16
58
  const previousScope = context.tracedScopeByExecution.get(trace.executionId);
17
59
  if (previousScope && previousScope !== scopeId) throw new Error(`Agent execution ${trace.executionId} was traced by multiple test scopes (${previousScope}, ${scopeId}).`);
18
60
  context.tracedScopeByExecution.set(trace.executionId, scopeId);
19
61
  const detail = context.detailsByScopeAndExecution.get(scopedExecutionKey(scopeId, trace.executionId));
20
- if (detail) details.push(detail);
21
- else unresolvedExecutionIds.push(trace.executionId);
62
+ if (detail) {
63
+ details.push(detail);
64
+ context.capturedExecutions.add(scopedExecutionKey(scopeId, trace.executionId));
65
+ } else {
66
+ unresolvedExecutionIds.push(trace.executionId);
67
+ if (!metrics) {
68
+ const reason = `Model usage is unavailable for execution ${trace.executionId}.`;
69
+ missingUsage.push(reason);
70
+ context.missingMetrics.add(reason);
71
+ }
72
+ }
22
73
  }
23
74
  let agentDetailDiagnostic;
24
75
  if (unresolvedExecutionIds.length > 0) {
@@ -30,6 +81,7 @@ const buildStep = (step, scopeId, context, executionId)=>{
30
81
  message: `Agent detail could not be resolved for execution ${executionId} in test scope ${scopeId}.`,
31
82
  scopeId,
32
83
  executionId,
84
+ stepId,
33
85
  ...sources.length > 0 ? {
34
86
  sourcePaths: sources.map((source)=>source.sourcePath)
35
87
  } : {}
@@ -41,16 +93,46 @@ const buildStep = (step, scopeId, context, executionId)=>{
41
93
  code: 'agent-detail-unavailable',
42
94
  message: `No stable Agent execution reference was captured for ${step.node} in test scope ${scopeId}.`,
43
95
  scopeId,
96
+ stepId,
44
97
  ...reportSourcesForScope(context, scopeId).length > 0 ? {
45
98
  sourcePaths: reportSourcesForScope(context, scopeId).map((source)=>source.sourcePath)
46
99
  } : {}
47
100
  });
48
101
  }
102
+ const collectionErrors = step.report?.collectionErrors?.map(sanitizeReportError) ?? [];
103
+ for (const error of collectionErrors)addDiagnostic(context, {
104
+ level: 'warning',
105
+ code: 'agent-source-unavailable',
106
+ scopeId,
107
+ stepId,
108
+ error,
109
+ message: `Report collection for ${step.node}: ${error.message}`
110
+ });
111
+ const snapshots = step.report?.sources?.flatMap((source)=>source.collection ? [
112
+ source.collection
113
+ ] : []) ?? [];
114
+ const evidenceCollection = snapshots.length || collectionErrors.length || details.length || unresolvedExecutionIds.length ? {
115
+ status: collectionErrors.length || unresolvedExecutionIds.length || snapshots.some((snapshot)=>'partial' === snapshot.status) ? details.length ? 'partial' : 'unknown' : 'complete',
116
+ ...snapshots.length ? {
117
+ capturedAt: snapshots.map((snapshot)=>snapshot.capturedAt).sort().at(-1)
118
+ } : {},
119
+ ...collectionErrors.length ? {
120
+ errors: collectionErrors
121
+ } : {}
122
+ } : void 0;
123
+ if (!step.report?.traces.length && collectionErrors.length && !details.length) {
124
+ const reason = `Model usage could not be collected for step ${stepId}.`;
125
+ missingUsage.push(reason);
126
+ context.missingMetrics.add(reason);
127
+ }
49
128
  const input = step.input;
50
129
  const candidateTitle = input?.prompt ?? input?.script ?? input?.scenario ?? input?.title;
51
130
  const prompt = 'string' == typeof candidateTitle ? candidateTitle : 'object' == typeof candidateTitle && null !== candidateTitle && 'prompt' in candidateTitle && 'string' == typeof candidateTitle.prompt ? candidateTitle.prompt : void 0;
52
131
  return {
53
- id: `${executionId}:${step.phase}:${step.stepIndex}`,
132
+ id: stepId,
133
+ ...plan ? {
134
+ planStepId: plan.id
135
+ } : {},
54
136
  phase: step.phase,
55
137
  stepIndex: step.stepIndex,
56
138
  node: step.node,
@@ -59,9 +141,20 @@ const buildStep = (step, scopeId, context, executionId)=>{
59
141
  } : {},
60
142
  status: step.status,
61
143
  continuedAfterError: step.continuedAfterError,
144
+ ...step.waitForPreviousOperationMs ? {
145
+ waitForPreviousOperationMs: step.waitForPreviousOperationMs
146
+ } : {},
62
147
  startedAt: step.startedAt,
63
148
  endedAt: step.endedAt,
64
149
  durationMs: step.durationMs,
150
+ ...step.operations ? {
151
+ operations: {
152
+ ...step.operations,
153
+ events: [
154
+ ...step.operations.events
155
+ ]
156
+ }
157
+ } : {},
65
158
  input: sanitizeReportValue(step.input),
66
159
  ...step.output ? {
67
160
  output: {
@@ -81,22 +174,48 @@ const buildStep = (step, scopeId, context, executionId)=>{
81
174
  } : {},
82
175
  ...agentDetailDiagnostic ? {
83
176
  agentDetailDiagnostic
177
+ } : {},
178
+ ...usage.length || missingUsage.length ? {
179
+ metrics: sumTestRunReportMetrics(usage, missingUsage)
180
+ } : {},
181
+ ...evidenceCollection ? {
182
+ evidenceCollection: {
183
+ ...evidenceCollection,
184
+ ...missingUsage.length ? {
185
+ modelUsageUnavailable: true
186
+ } : {}
187
+ }
84
188
  } : {}
85
189
  };
86
190
  };
87
191
  const attemptReportScope = (attempt)=>attempt.reportScopeId ?? attempt.runId;
88
- const buildAttempt = (attempt, context)=>{
192
+ const buildAttempt = (attempt, context, plan)=>{
89
193
  const scopeId = attemptReportScope(attempt);
90
194
  return {
91
195
  attemptId: attempt.runId,
92
196
  attemptIndex: attempt.attemptIndex,
93
197
  status: attempt.status,
198
+ ...attempt.executionStatus ? {
199
+ executionStatus: attempt.executionStatus
200
+ } : {},
201
+ ...attempt.phases ? {
202
+ phases: attempt.phases
203
+ } : {},
204
+ ...attempt.cleanup ? {
205
+ cleanup: attempt.cleanup
206
+ } : {},
207
+ ...attempt.pendingOperations ? {
208
+ pendingOperations: attempt.pendingOperations
209
+ } : {},
210
+ ...attempt.retryDecision ? {
211
+ retryDecision: attempt.retryDecision
212
+ } : {},
94
213
  startedAt: attempt.startedAt,
95
214
  endedAt: attempt.endedAt,
96
215
  durationMs: attempt.durationMs,
97
- beforeEach: attempt.beforeEach.map((step)=>buildStep(step, scopeId, context, attempt.runId)),
98
- steps: attempt.steps.map((step)=>buildStep(step, scopeId, context, attempt.runId)),
99
- afterEach: attempt.afterEach.map((step)=>buildStep(step, scopeId, context, attempt.runId)),
216
+ beforeEach: attempt.beforeEach.map((step)=>buildStep(step, scopeId, context, attempt.runId, plan?.beforeEach[step.stepIndex])),
217
+ steps: attempt.steps.map((step)=>buildStep(step, scopeId, context, attempt.runId, plan?.steps[step.stepIndex])),
218
+ afterEach: attempt.afterEach.map((step)=>buildStep(step, scopeId, context, attempt.runId, plan?.afterEach[step.stepIndex])),
100
219
  ...attempt.executionErrors?.length ? {
101
220
  hostErrors: attempt.executionErrors.map((error)=>({
102
221
  phase: 'execution',
@@ -111,7 +230,10 @@ const buildAttempt = (attempt, context)=>{
111
230
  } : {}
112
231
  };
113
232
  };
114
- const buildCase = (outcome, context)=>({
233
+ const buildCase = (outcome, context, plan)=>({
234
+ ...plan ? {
235
+ plan
236
+ } : {},
115
237
  caseId: outcome.caseId,
116
238
  name: outcome.name,
117
239
  caseIndex: outcome.caseIndex,
@@ -121,15 +243,19 @@ const buildCase = (outcome, context)=>({
121
243
  } : {},
122
244
  attempts: (outcome.attempts ?? (outcome.run ? [
123
245
  outcome.run
124
- ] : [])).map((attempt)=>buildAttempt(attempt, context))
246
+ ] : [])).map((attempt)=>buildAttempt(attempt, context, plan))
125
247
  });
126
248
  const documentReportScope = (document)=>document.reportScopeId ?? document.documentRunId;
127
- const buildDocument = (documentId, document, cases, context)=>{
249
+ const buildDocument = (documentId, document, cases, context, plan)=>{
250
+ plan ??= document?.plan;
128
251
  const sourcePath = document?.sourcePath ?? cases[0]?.sourcePath ?? '<unknown>';
129
252
  const status = document?.status ?? (cases.some((item)=>'success' !== item.status) ? 'failed' : 'success');
130
253
  const scopeId = document ? documentReportScope(document) : void 0;
131
254
  return {
132
255
  documentId,
256
+ ...plan ? {
257
+ plan
258
+ } : {},
133
259
  ...document ? {
134
260
  logicalDocumentId: document.documentId,
135
261
  documentRunId: document.documentRunId,
@@ -139,14 +265,29 @@ const buildDocument = (documentId, document, cases, context)=>{
139
265
  } : {},
140
266
  sourcePath,
141
267
  status,
268
+ ...document?.executionStatus ? {
269
+ executionStatus: document.executionStatus
270
+ } : {},
271
+ ...document?.phases ? {
272
+ phases: document.phases
273
+ } : {},
274
+ ...document?.cleanup ? {
275
+ cleanup: document.cleanup
276
+ } : {},
277
+ ...document?.pendingOperations ? {
278
+ pendingOperations: document.pendingOperations
279
+ } : {},
280
+ ...document?.retryDecision ? {
281
+ retryDecision: document.retryDecision
282
+ } : {},
142
283
  ...document ? {
143
284
  startedAt: document.startedAt,
144
285
  endedAt: document.endedAt,
145
286
  durationMs: document.durationMs
146
287
  } : {},
147
- beforeAll: (document?.beforeAll ?? []).map((step)=>buildStep(step, scopeId, context, document.documentRunId)),
148
- cases: cases.map((outcome)=>buildCase(outcome, context)),
149
- afterAll: (document?.afterAll ?? []).map((step)=>buildStep(step, scopeId, context, document.documentRunId)),
288
+ beforeAll: (document?.beforeAll ?? []).map((step)=>buildStep(step, scopeId, context, document.documentRunId, plan?.beforeAll[step.stepIndex])),
289
+ cases: cases.map((outcome)=>buildCase(outcome, context, plan?.cases.find((item)=>item.caseId === outcome.caseId))),
290
+ afterAll: (document?.afterAll ?? []).map((step)=>buildStep(step, scopeId, context, document.documentRunId, plan?.afterAll[step.stepIndex])),
150
291
  ...document?.hostErrors?.length || document?.executionErrors?.length ? {
151
292
  hostErrors: [
152
293
  ...document?.hostErrors ?? [],
@@ -204,19 +345,22 @@ const buildProject = (project, context)=>{
204
345
  }
205
346
  const result = buildDocument(documentId, last, [
206
347
  ...outcomes.values()
207
- ], context);
348
+ ], context, project.plans?.find((plan)=>plan.documentId === last.documentId));
208
349
  if (group.length > 1) {
209
350
  result.startedAt = first.startedAt;
210
351
  result.durationMs = Math.max(0, Date.parse(last.endedAt) - Date.parse(first.startedAt));
211
352
  result.attempts = group.map((document)=>{
212
- const { cases: _cases, ...attempt } = buildDocument(documentId, document, [], context);
353
+ const { cases: _cases, ...attempt } = buildDocument(documentId, document, [], context, project.plans?.find((plan)=>plan.documentId === document.documentId));
213
354
  return attempt;
214
355
  });
215
356
  }
216
357
  return result;
217
358
  });
218
- for (const documentId of new Set(project.cases.map((outcome)=>outcome.documentId)))if (!documentCount.has(documentId)) documents.push(buildDocument(documentId, void 0, project.cases.filter((outcome)=>outcome.documentId === documentId), context));
359
+ for (const documentId of new Set(project.cases.map((outcome)=>outcome.documentId)))if (!documentCount.has(documentId)) documents.push(buildDocument(documentId, void 0, project.cases.filter((outcome)=>outcome.documentId === documentId), context, project.plans?.find((plan)=>plan.documentId === documentId)));
219
360
  return {
361
+ ...project.plans ? {
362
+ plans: project.plans
363
+ } : {},
220
364
  projectId: project.projectId,
221
365
  name: project.name,
222
366
  ...project.platform?.trim() ? {
@@ -230,6 +374,12 @@ const buildProject = (project, context)=>{
230
374
  startedAt: project.lifecycle.startedAt,
231
375
  endedAt: project.lifecycle.endedAt,
232
376
  durationMs: project.lifecycle.durationMs,
377
+ ...project.lifecycle.cleanup ? {
378
+ cleanup: project.lifecycle.cleanup
379
+ } : {},
380
+ ...project.lifecycle.pendingOperations ? {
381
+ pendingOperations: project.lifecycle.pendingOperations
382
+ } : {},
233
383
  ...project.lifecycle.setupError ? {
234
384
  setupError: sanitizeReportError(project.lifecycle.setupError)
235
385
  } : {},
@@ -286,15 +436,24 @@ function buildTestRunReportDump(result, index) {
286
436
  });
287
437
  }
288
438
  const context = {
289
- diagnostics: [],
439
+ diagnostics: (index.diagnostics ?? []).map((diagnostic)=>({
440
+ ...diagnostic,
441
+ message: sanitizeReportText(diagnostic.message)
442
+ })),
290
443
  sourcesByScope,
291
444
  detailsByScopeAndExecution,
292
- tracedScopeByExecution: new Map()
445
+ tracedScopeByExecution: new Map(),
446
+ expectedExecutions: new Set(),
447
+ capturedExecutions: new Set(),
448
+ executionMetrics: new Map(Object.entries(index.executionMetrics ?? {})),
449
+ missingMetrics: new Set(),
450
+ tracedScopes: new Set()
293
451
  };
294
452
  for (const error of result.errors ?? [])addDiagnostic(context, {
295
453
  level: 'error',
296
454
  code: 'run-infrastructure-error',
297
- message: sanitizeReportError(error).message
455
+ message: sanitizeReportError(error).message,
456
+ error: sanitizeReportError(error)
298
457
  });
299
458
  for (const source of index.sources)if (0 === source.executionIds.length) addDiagnostic(context, {
300
459
  level: 'warning',
@@ -306,10 +465,28 @@ function buildTestRunReportDump(result, index) {
306
465
  ]
307
466
  });
308
467
  const projects = result.projects.map((project)=>buildProject(project, context));
468
+ for (const diagnostic of index.diagnostics ?? [])if ('agent-source-unavailable' === diagnostic.code && (!diagnostic.scopeId || !context.tracedScopes.has(diagnostic.scopeId))) context.missingMetrics.add(diagnostic.message);
469
+ const metrics = sumTestRunReportMetrics([
470
+ ...index.sources.length || !index.executionMetrics && (index.metrics.modelCallCount || index.metrics.collection) ? [
471
+ index.capturedMetrics ?? index.metrics
472
+ ] : [],
473
+ ...[
474
+ ...context.executionMetrics.entries()
475
+ ].filter(([id])=>!index.executionMetrics?.[id]).map(([, value])=>value)
476
+ ], [
477
+ ...context.missingMetrics
478
+ ]);
309
479
  return {
310
480
  schemaVersion: 1,
311
481
  kind: 'test-runner',
312
482
  runId: result.runId,
483
+ ...result.operationLog ? {
484
+ operationLogs: [
485
+ {
486
+ ...result.operationLog
487
+ }
488
+ ]
489
+ } : {},
313
490
  status: result.status,
314
491
  startedAt: result.startedAt,
315
492
  endedAt: result.endedAt,
@@ -317,7 +494,17 @@ function buildTestRunReportDump(result, index) {
317
494
  summary: {
318
495
  ...result.summary
319
496
  },
320
- metrics: index.metrics,
497
+ metrics: {
498
+ ...metrics,
499
+ collection: {
500
+ ...metrics.collection,
501
+ expectedExecutionCount: context.expectedExecutions.size,
502
+ capturedExecutionCount: context.capturedExecutions.size
503
+ }
504
+ },
505
+ ...index.executionMetrics || context.executionMetrics.size ? {
506
+ executionMetrics: Object.fromEntries(context.executionMetrics)
507
+ } : {},
321
508
  projects,
322
509
  ...context.diagnostics.length > 0 ? {
323
510
  diagnostics: context.diagnostics