@andrii_kremlovskyi/playwright-traces-reader 2.5.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cli/formatters.d.ts +3 -4
- package/dist/cli/formatters.d.ts.map +1 -1
- package/dist/cli/formatters.js +13 -48
- package/dist/cli/formatters.js.map +1 -1
- package/dist/cli/helpers.d.ts +0 -1
- package/dist/cli/helpers.d.ts.map +1 -1
- package/dist/cli/helpers.js +0 -2
- package/dist/cli/helpers.js.map +1 -1
- package/dist/cli/json.d.ts +90 -10
- package/dist/cli/json.d.ts.map +1 -1
- package/dist/cli/json.js +3 -2
- package/dist/cli/json.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +6 -35
- package/dist/cli.js.map +1 -1
- package/dist/extractors.d.ts +32 -30
- package/dist/extractors.d.ts.map +1 -1
- package/dist/extractors.js +215 -175
- package/dist/extractors.js.map +1 -1
- package/dist/failureDigest.d.ts +17 -0
- package/dist/failureDigest.d.ts.map +1 -0
- package/dist/failureDigest.js +310 -0
- package/dist/failureDigest.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/parseTrace.d.ts +4 -1
- package/dist/parseTrace.d.ts.map +1 -1
- package/dist/parseTrace.js +7 -3
- package/dist/parseTrace.js.map +1 -1
- package/package.json +1 -1
- package/templates/skills/analyze-playwright-traces/SKILL.md +45 -26
package/dist/extractors.js
CHANGED
|
@@ -42,12 +42,11 @@ exports.getTraceIssues = getTraceIssues;
|
|
|
42
42
|
exports.getAttachments = getAttachments;
|
|
43
43
|
exports.extractAttachment = extractAttachment;
|
|
44
44
|
exports.extractScreenshots = extractScreenshots;
|
|
45
|
+
exports.extractFailureScreenshots = extractFailureScreenshots;
|
|
45
46
|
exports.getDomSnapshots = getDomSnapshots;
|
|
46
47
|
exports.getTimeline = getTimeline;
|
|
47
48
|
exports.getTestTitle = getTestTitle;
|
|
48
49
|
exports.getSummary = getSummary;
|
|
49
|
-
exports.getReportFailurePatterns = getReportFailurePatterns;
|
|
50
|
-
exports.summarizeReportFailurePatterns = summarizeReportFailurePatterns;
|
|
51
50
|
exports.getFailedTraceSelections = getFailedTraceSelections;
|
|
52
51
|
exports.getFailedTestSummaries = getFailedTestSummaries;
|
|
53
52
|
const fs = __importStar(require("fs"));
|
|
@@ -413,6 +412,66 @@ async function extractScreenshots(traceContext, outDir) {
|
|
|
413
412
|
}
|
|
414
413
|
return screenshots;
|
|
415
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* For each failure anchor, locates the nearest screencast frame `before`
|
|
417
|
+
* (timestamp ≤ anchor), `action` (closest in time), and `after`
|
|
418
|
+
* (timestamp ≥ anchor), writes the referenced image blobs into `outDir`, and
|
|
419
|
+
* returns the saved file names per anchor.
|
|
420
|
+
*
|
|
421
|
+
* Frames are de-duplicated by SHA1 — the same underlying image is written once
|
|
422
|
+
* and referenced by multiple roles/anchors. Returns an empty array when the
|
|
423
|
+
* trace has no screencast frames (e.g. API-only tests or capture disabled).
|
|
424
|
+
*/
|
|
425
|
+
async function extractFailureScreenshots(traceContext, anchors, outDir) {
|
|
426
|
+
const frames = await getScreenshotMetadata(traceContext);
|
|
427
|
+
if (frames.length === 0 || anchors.length === 0)
|
|
428
|
+
return [];
|
|
429
|
+
frames.sort((a, b) => a.timestamp - b.timestamp);
|
|
430
|
+
await fs.promises.mkdir(outDir, { recursive: true });
|
|
431
|
+
// SHA1 → relative file name (written once, referenced many times).
|
|
432
|
+
const writtenBySha1 = new Map();
|
|
433
|
+
const ensureWritten = async (sha1) => {
|
|
434
|
+
const cached = writtenBySha1.get(sha1);
|
|
435
|
+
if (cached !== undefined)
|
|
436
|
+
return cached;
|
|
437
|
+
const buf = await (0, parseTrace_1.getResourceBuffer)(traceContext, sha1);
|
|
438
|
+
if (!buf)
|
|
439
|
+
return null;
|
|
440
|
+
const ext = sha1.endsWith('.jpeg') ? 'jpeg' : 'png';
|
|
441
|
+
const shortSha1 = sha1.replace(/\.(jpeg|png)$/, '').slice(0, 12);
|
|
442
|
+
const fileName = `frame-${shortSha1}.${ext}`;
|
|
443
|
+
await fs.promises.writeFile(path.join(outDir, fileName), buf);
|
|
444
|
+
writtenBySha1.set(sha1, fileName);
|
|
445
|
+
return fileName;
|
|
446
|
+
};
|
|
447
|
+
const sets = [];
|
|
448
|
+
for (const anchor of anchors) {
|
|
449
|
+
let before = null;
|
|
450
|
+
let after = null;
|
|
451
|
+
let action = null;
|
|
452
|
+
let actionDistance = Number.POSITIVE_INFINITY;
|
|
453
|
+
for (const frame of frames) {
|
|
454
|
+
if (frame.timestamp <= anchor.timestamp)
|
|
455
|
+
before = frame; // frames are sorted, so the last match wins
|
|
456
|
+
if (after === null && frame.timestamp >= anchor.timestamp)
|
|
457
|
+
after = frame;
|
|
458
|
+
const distance = Math.abs(frame.timestamp - anchor.timestamp);
|
|
459
|
+
if (distance < actionDistance) {
|
|
460
|
+
actionDistance = distance;
|
|
461
|
+
action = frame;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
sets.push({
|
|
465
|
+
anchorCallId: anchor.callId,
|
|
466
|
+
anchorTitle: anchor.title,
|
|
467
|
+
anchorTimestamp: anchor.timestamp,
|
|
468
|
+
before: before ? await ensureWritten(before.sha1) : null,
|
|
469
|
+
action: action ? await ensureWritten(action.sha1) : null,
|
|
470
|
+
after: after ? await ensureWritten(after.sha1) : null,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
return sets;
|
|
474
|
+
}
|
|
416
475
|
/**
|
|
417
476
|
* Builds the post-order DFS node list for a snapshot tree (mirroring
|
|
418
477
|
* Playwright's `snapshotNodes()` in snapshotRenderer.ts). Only "real"
|
|
@@ -452,20 +511,25 @@ const VOID_TAGS = new Set([
|
|
|
452
511
|
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
453
512
|
'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
|
|
454
513
|
]);
|
|
514
|
+
/** Maximum iframe nesting depth to inline before bailing out (cycle/runaway guard). */
|
|
515
|
+
const MAX_IFRAME_DEPTH = 10;
|
|
455
516
|
/**
|
|
456
|
-
* Resolves a snapshot node tree into an HTML string.
|
|
517
|
+
* Resolves a snapshot node tree into an HTML string for a given frame.
|
|
457
518
|
*
|
|
458
|
-
* `snapshotIndex` is the 0-based index of the current snapshot in
|
|
459
|
-
* `
|
|
460
|
-
*
|
|
461
|
-
* `dfsCache` is a memoization cache shared across the entire trace-file pass to
|
|
462
|
-
* avoid rebuilding the same DFS node lists repeatedly.
|
|
519
|
+
* `snapshotIndex` is the 0-based index of the current snapshot in the frame's
|
|
520
|
+
* history. `frameId` identifies the frame so back-references resolve against the
|
|
521
|
+
* correct history and child iframes can be inlined recursively.
|
|
463
522
|
*
|
|
464
523
|
* Back-references `[[offset, nodeIdx]]` are resolved as:
|
|
465
524
|
* refIndex = snapshotIndex - offset
|
|
466
525
|
* node = snapshotNodes(frameHistory[refIndex])[nodeIdx]
|
|
526
|
+
*
|
|
527
|
+
* `<iframe>` / `<frame>` elements whose `src` is `/snapshot/<childFrameId>` are
|
|
528
|
+
* replaced with the recursively-rendered child frame HTML inlined via `srcdoc`,
|
|
529
|
+
* producing a complete, self-contained page.
|
|
467
530
|
*/
|
|
468
|
-
function resolveSnapshotNode(node, snapshotIndex,
|
|
531
|
+
function resolveSnapshotNode(node, snapshotIndex, frameId, ctx) {
|
|
532
|
+
const frameHistory = ctx.frameHistory.get(frameId) ?? [];
|
|
469
533
|
if (typeof node === 'string') {
|
|
470
534
|
return escapeHtml(node);
|
|
471
535
|
}
|
|
@@ -480,9 +544,9 @@ function resolveSnapshotNode(node, snapshotIndex, frameHistory, dfsCache) {
|
|
|
480
544
|
const refIndex = snapshotIndex - offset;
|
|
481
545
|
if (refIndex >= 0 && refIndex < frameHistory.length) {
|
|
482
546
|
const refHtml = frameHistory[refIndex];
|
|
483
|
-
const nodes = buildSnapshotNodeList(refHtml, dfsCache);
|
|
547
|
+
const nodes = buildSnapshotNodeList(refHtml, ctx.dfsCache);
|
|
484
548
|
if (nodeIdx >= 0 && nodeIdx < nodes.length) {
|
|
485
|
-
return resolveSnapshotNode(nodes[nodeIdx], refIndex,
|
|
549
|
+
return resolveSnapshotNode(nodes[nodeIdx], refIndex, frameId, ctx);
|
|
486
550
|
}
|
|
487
551
|
}
|
|
488
552
|
return `<!-- ref: [${offset}, ${nodeIdx}] unresolved -->`;
|
|
@@ -494,18 +558,70 @@ function resolveSnapshotNode(node, snapshotIndex, frameHistory, dfsCache) {
|
|
|
494
558
|
const tag = tagName.toLowerCase();
|
|
495
559
|
if (tag === 'script')
|
|
496
560
|
return ''; // not useful for AI analysis
|
|
497
|
-
const
|
|
498
|
-
?
|
|
499
|
-
|
|
561
|
+
const safeAttrs = attrs && typeof attrs === 'object' && !Array.isArray(attrs)
|
|
562
|
+
? attrs
|
|
563
|
+
: {};
|
|
564
|
+
// Inline child frames: <iframe>/<frame> with src="/snapshot/<frameId>".
|
|
565
|
+
if (tag === 'iframe' || tag === 'frame') {
|
|
566
|
+
const childFrameId = parseSnapshotFrameId(safeAttrs['src']);
|
|
567
|
+
const baseAttrs = Object.entries(safeAttrs)
|
|
568
|
+
.filter(([k]) => !k.startsWith('__playwright') && k.toLowerCase() !== 'src' && k.toLowerCase() !== 'srcdoc')
|
|
500
569
|
.map(([k, v]) => ` ${k}="${escapeAttr(String(v))}"`)
|
|
501
|
-
.join('')
|
|
502
|
-
|
|
570
|
+
.join('');
|
|
571
|
+
if (childFrameId) {
|
|
572
|
+
const childHtml = renderChildFrame(childFrameId, ctx);
|
|
573
|
+
if (childHtml !== null) {
|
|
574
|
+
return `<${tag}${baseAttrs} srcdoc="${escapeAttr(childHtml)}"></${tag}>`;
|
|
575
|
+
}
|
|
576
|
+
return `<${tag}${baseAttrs}><!-- child frame ${escapeHtml(childFrameId)} not captured for ${escapeHtml(ctx.snapshotName)} --></${tag}>`;
|
|
577
|
+
}
|
|
578
|
+
return `<${tag}${baseAttrs}></${tag}>`;
|
|
579
|
+
}
|
|
580
|
+
const attrStr = Object.entries(safeAttrs)
|
|
581
|
+
.filter(([k]) => !k.startsWith('__playwright'))
|
|
582
|
+
.map(([k, v]) => ` ${k}="${escapeAttr(String(v))}"`)
|
|
583
|
+
.join('');
|
|
503
584
|
if (VOID_TAGS.has(tag)) {
|
|
504
585
|
return `<${tag}${attrStr}>`;
|
|
505
586
|
}
|
|
506
|
-
const inner = children.map(c => resolveSnapshotNode(c, snapshotIndex,
|
|
587
|
+
const inner = children.map(c => resolveSnapshotNode(c, snapshotIndex, frameId, ctx)).join('');
|
|
507
588
|
return `<${tag}${attrStr}>${inner}</${tag}>`;
|
|
508
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* Extracts the child frameId from an iframe `src` of the form
|
|
592
|
+
* `/snapshot/<frameId>` (Playwright's capture-time rewrite). Returns null for
|
|
593
|
+
* any other value (empty, blank, or a real URL).
|
|
594
|
+
*/
|
|
595
|
+
function parseSnapshotFrameId(src) {
|
|
596
|
+
if (!src)
|
|
597
|
+
return null;
|
|
598
|
+
const prefix = '/snapshot/';
|
|
599
|
+
if (!src.startsWith(prefix))
|
|
600
|
+
return null;
|
|
601
|
+
const id = src.substring(prefix.length).trim();
|
|
602
|
+
return id.length > 0 ? id : null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Renders a child frame's snapshot (matching the current action's snapshotName)
|
|
606
|
+
* to an HTML string, recursing into its own child frames. Returns null when the
|
|
607
|
+
* frame has no snapshot for this action or when the depth/cycle guard trips.
|
|
608
|
+
*/
|
|
609
|
+
function renderChildFrame(childFrameId, ctx) {
|
|
610
|
+
if (ctx.stack.has(childFrameId))
|
|
611
|
+
return null; // cycle guard
|
|
612
|
+
if (ctx.stack.size >= MAX_IFRAME_DEPTH)
|
|
613
|
+
return null; // runaway depth guard
|
|
614
|
+
const entry = ctx.frameSnapshotsByName.get(childFrameId)?.get(ctx.snapshotName);
|
|
615
|
+
if (!entry)
|
|
616
|
+
return null;
|
|
617
|
+
ctx.stack.add(childFrameId);
|
|
618
|
+
try {
|
|
619
|
+
return resolveSnapshotNode(entry.html, entry.historyIndex, childFrameId, ctx);
|
|
620
|
+
}
|
|
621
|
+
finally {
|
|
622
|
+
ctx.stack.delete(childFrameId);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
509
625
|
function escapeHtml(s) {
|
|
510
626
|
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
511
627
|
}
|
|
@@ -527,19 +643,33 @@ function escapeAttr(s) {
|
|
|
527
643
|
async function getDomSnapshots(traceContext, options) {
|
|
528
644
|
const files = await fs.promises.readdir(traceContext.traceDir);
|
|
529
645
|
const traceFiles = files.filter(f => f.endsWith('.trace') && f !== 'test.trace').sort();
|
|
530
|
-
// Per-frame snapshot history: frameId → ordered list of raw html nodes
|
|
646
|
+
// Per-frame snapshot history: frameId → ordered list of raw html nodes (for back-refs).
|
|
531
647
|
const frameHistory = new Map();
|
|
648
|
+
// Per-frame snapshot lookup: frameId → snapshotName → entry (for inlining child frames).
|
|
649
|
+
const frameSnapshotsByName = new Map();
|
|
532
650
|
// Memoization cache for buildSnapshotNodeList — keyed by html object reference
|
|
533
651
|
const dfsCache = new Map();
|
|
534
|
-
|
|
535
|
-
|
|
652
|
+
const mainFrameRecords = [];
|
|
653
|
+
// ---- Pass 1: collect every frame snapshot (main + child iframes) ----
|
|
536
654
|
for (const traceFile of traceFiles) {
|
|
537
655
|
const filePath = path.join(traceContext.traceDir, traceFile);
|
|
538
656
|
for await (const event of (0, parseTrace_1.readNdjson)(filePath)) {
|
|
539
657
|
if (event.type !== 'frame-snapshot')
|
|
540
658
|
continue;
|
|
541
659
|
const snap = event.snapshot;
|
|
542
|
-
const { snapshotName, callId, frameId, frameUrl, pageId, viewport, timestamp, html } = snap;
|
|
660
|
+
const { snapshotName, callId, frameId, frameUrl, pageId, viewport, timestamp, html, isMainFrame } = snap;
|
|
661
|
+
// Append to per-frame history BEFORE anything else (so refs can point back to it)
|
|
662
|
+
if (!frameHistory.has(frameId))
|
|
663
|
+
frameHistory.set(frameId, []);
|
|
664
|
+
const history = frameHistory.get(frameId);
|
|
665
|
+
history.push(html);
|
|
666
|
+
const snapshotIndex = history.length - 1;
|
|
667
|
+
// Index by snapshotName so parent frames can inline this child by name.
|
|
668
|
+
if (!frameSnapshotsByName.has(frameId))
|
|
669
|
+
frameSnapshotsByName.set(frameId, new Map());
|
|
670
|
+
frameSnapshotsByName.get(frameId).set(snapshotName, { html, historyIndex: snapshotIndex });
|
|
671
|
+
if (!isMainFrame)
|
|
672
|
+
continue; // child frames are only inlined, never top-level entries
|
|
543
673
|
// Determine phase from snapshotName prefix
|
|
544
674
|
let phase;
|
|
545
675
|
if (snapshotName.startsWith('before@')) {
|
|
@@ -554,33 +684,42 @@ async function getDomSnapshots(traceContext, options) {
|
|
|
554
684
|
else {
|
|
555
685
|
continue; // unknown phase, skip
|
|
556
686
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const history = frameHistory.get(frameId);
|
|
561
|
-
history.push(html);
|
|
562
|
-
const snapshotIndex = history.length - 1;
|
|
563
|
-
// Resolve the full html to a string using the correct ref algorithm
|
|
564
|
-
const resolvedHtml = resolveSnapshotNode(html, snapshotIndex, history, dfsCache);
|
|
565
|
-
// Extract the __playwright_target__ attribute to identify the targeted element
|
|
566
|
-
const targetElement = findPlaywrightTarget(html);
|
|
567
|
-
const domSnapshot = {
|
|
568
|
-
callId,
|
|
569
|
-
phase,
|
|
570
|
-
snapshotName,
|
|
571
|
-
frameId,
|
|
572
|
-
frameUrl,
|
|
573
|
-
pageId,
|
|
574
|
-
timestamp,
|
|
575
|
-
viewport,
|
|
576
|
-
html: resolvedHtml,
|
|
577
|
-
targetElement,
|
|
578
|
-
};
|
|
579
|
-
if (!rawByCallId.has(callId))
|
|
580
|
-
rawByCallId.set(callId, new Map());
|
|
581
|
-
rawByCallId.get(callId).set(phase, domSnapshot);
|
|
687
|
+
mainFrameRecords.push({
|
|
688
|
+
callId, phase, snapshotName, frameId, frameUrl, pageId, timestamp, viewport, html, snapshotIndex,
|
|
689
|
+
});
|
|
582
690
|
}
|
|
583
691
|
}
|
|
692
|
+
// ---- Pass 2: render each main-frame snapshot, inlining child iframes ----
|
|
693
|
+
const rawByCallId = new Map();
|
|
694
|
+
for (const rec of mainFrameRecords) {
|
|
695
|
+
const ctx = {
|
|
696
|
+
frameHistory,
|
|
697
|
+
frameSnapshotsByName,
|
|
698
|
+
dfsCache,
|
|
699
|
+
snapshotName: rec.snapshotName,
|
|
700
|
+
stack: new Set([rec.frameId]),
|
|
701
|
+
};
|
|
702
|
+
const resolvedHtml = resolveSnapshotNode(rec.html, rec.snapshotIndex, rec.frameId, ctx);
|
|
703
|
+
const targetElement = findPlaywrightTarget(rec.html, {
|
|
704
|
+
...ctx,
|
|
705
|
+
stack: new Set([rec.frameId]),
|
|
706
|
+
});
|
|
707
|
+
const domSnapshot = {
|
|
708
|
+
callId: rec.callId,
|
|
709
|
+
phase: rec.phase,
|
|
710
|
+
snapshotName: rec.snapshotName,
|
|
711
|
+
frameId: rec.frameId,
|
|
712
|
+
frameUrl: rec.frameUrl,
|
|
713
|
+
pageId: rec.pageId,
|
|
714
|
+
timestamp: rec.timestamp,
|
|
715
|
+
viewport: rec.viewport,
|
|
716
|
+
html: resolvedHtml,
|
|
717
|
+
targetElement,
|
|
718
|
+
};
|
|
719
|
+
if (!rawByCallId.has(rec.callId))
|
|
720
|
+
rawByCallId.set(rec.callId, new Map());
|
|
721
|
+
rawByCallId.get(rec.callId).set(rec.phase, domSnapshot);
|
|
722
|
+
}
|
|
584
723
|
// Assemble into ActionDomSnapshots
|
|
585
724
|
let result = [];
|
|
586
725
|
for (const [callId, phases] of rawByCallId) {
|
|
@@ -628,8 +767,14 @@ async function getDomSnapshots(traceContext, options) {
|
|
|
628
767
|
}
|
|
629
768
|
return result;
|
|
630
769
|
}
|
|
631
|
-
/**
|
|
632
|
-
|
|
770
|
+
/**
|
|
771
|
+
* Recursively searches the snapshot tree for a node with __playwright_target__.
|
|
772
|
+
*
|
|
773
|
+
* When `ctx` is provided, the search also descends into child `<iframe>`/`<frame>`
|
|
774
|
+
* elements (matched by `src="/snapshot/<frameId>"`) so a target living inside a
|
|
775
|
+
* child frame is still found. Cycles and runaway depth are guarded via `ctx.stack`.
|
|
776
|
+
*/
|
|
777
|
+
function findPlaywrightTarget(node, ctx) {
|
|
633
778
|
if (!Array.isArray(node) || node.length < 2)
|
|
634
779
|
return null;
|
|
635
780
|
const attrs = node[1];
|
|
@@ -637,11 +782,32 @@ function findPlaywrightTarget(node) {
|
|
|
637
782
|
const target = attrs['__playwright_target__'];
|
|
638
783
|
if (target)
|
|
639
784
|
return target;
|
|
785
|
+
// Descend into child frames so targets inside iframes are still found.
|
|
786
|
+
if (ctx && typeof node[0] === 'string') {
|
|
787
|
+
const tag = node[0].toLowerCase();
|
|
788
|
+
if (tag === 'iframe' || tag === 'frame') {
|
|
789
|
+
const childFrameId = parseSnapshotFrameId(attrs['src']);
|
|
790
|
+
if (childFrameId && !ctx.stack.has(childFrameId) && ctx.stack.size < MAX_IFRAME_DEPTH) {
|
|
791
|
+
const entry = ctx.frameSnapshotsByName.get(childFrameId)?.get(ctx.snapshotName);
|
|
792
|
+
if (entry) {
|
|
793
|
+
ctx.stack.add(childFrameId);
|
|
794
|
+
try {
|
|
795
|
+
const found = findPlaywrightTarget(entry.html, ctx);
|
|
796
|
+
if (found)
|
|
797
|
+
return found;
|
|
798
|
+
}
|
|
799
|
+
finally {
|
|
800
|
+
ctx.stack.delete(childFrameId);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
640
806
|
}
|
|
641
807
|
for (let i = 2; i < node.length; i++) {
|
|
642
808
|
const child = node[i];
|
|
643
809
|
if (Array.isArray(child)) {
|
|
644
|
-
const found = findPlaywrightTarget(child);
|
|
810
|
+
const found = findPlaywrightTarget(child, ctx);
|
|
645
811
|
if (found)
|
|
646
812
|
return found;
|
|
647
813
|
}
|
|
@@ -717,71 +883,6 @@ function buildActionDiagnostics(networkCalls, issues) {
|
|
|
717
883
|
return rightScore - leftScore;
|
|
718
884
|
});
|
|
719
885
|
}
|
|
720
|
-
function buildReportFailurePatterns(selections) {
|
|
721
|
-
const realFailures = selections.filter(selection => selection.summary.outcome !== 'skipped');
|
|
722
|
-
const repeatedFailingRequests = new Map();
|
|
723
|
-
const repeatedIssues = new Map();
|
|
724
|
-
for (const selection of realFailures) {
|
|
725
|
-
for (const entry of selection.summary.networkCalls) {
|
|
726
|
-
if (entry.status < 400)
|
|
727
|
-
continue;
|
|
728
|
-
const signature = buildRequestPatternSignature(entry);
|
|
729
|
-
const bucket = repeatedFailingRequests.get(signature) ?? {
|
|
730
|
-
method: entry.method,
|
|
731
|
-
url: stripQuery(entry.url),
|
|
732
|
-
traces: new Set(),
|
|
733
|
-
statuses: new Set(),
|
|
734
|
-
relatedActions: new Map(),
|
|
735
|
-
};
|
|
736
|
-
bucket.traces.add(selection.traceSha1);
|
|
737
|
-
bucket.statuses.add(entry.status);
|
|
738
|
-
if (entry.relatedAction)
|
|
739
|
-
bucket.relatedActions.set(entry.relatedAction.callId, { callId: entry.relatedAction.callId, title: entry.relatedAction.title });
|
|
740
|
-
repeatedFailingRequests.set(signature, bucket);
|
|
741
|
-
}
|
|
742
|
-
for (const issue of selection.summary.issues) {
|
|
743
|
-
if (!issue.relatedAction)
|
|
744
|
-
continue;
|
|
745
|
-
const signature = buildIssuePatternSignature(issue);
|
|
746
|
-
const bucket = repeatedIssues.get(signature) ?? {
|
|
747
|
-
source: issue.source,
|
|
748
|
-
name: issue.name,
|
|
749
|
-
message: firstLine(issue.message) ?? issue.message,
|
|
750
|
-
traces: new Set(),
|
|
751
|
-
relatedActions: new Map(),
|
|
752
|
-
};
|
|
753
|
-
bucket.traces.add(selection.traceSha1);
|
|
754
|
-
bucket.relatedActions.set(issue.relatedAction.callId, { callId: issue.relatedAction.callId, title: issue.relatedAction.title });
|
|
755
|
-
repeatedIssues.set(signature, bucket);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
return {
|
|
759
|
-
repeatedFailingRequests: [...repeatedFailingRequests.entries()]
|
|
760
|
-
.map(([signature, bucket]) => ({
|
|
761
|
-
signature,
|
|
762
|
-
method: bucket.method,
|
|
763
|
-
url: bucket.url,
|
|
764
|
-
count: bucket.traces.size,
|
|
765
|
-
traceSha1s: [...bucket.traces].sort(),
|
|
766
|
-
statuses: [...bucket.statuses].sort((left, right) => left - right),
|
|
767
|
-
relatedActions: [...bucket.relatedActions.values()],
|
|
768
|
-
}))
|
|
769
|
-
.filter(pattern => pattern.count > 1)
|
|
770
|
-
.sort((left, right) => right.count - left.count),
|
|
771
|
-
repeatedIssues: [...repeatedIssues.entries()]
|
|
772
|
-
.map(([signature, bucket]) => ({
|
|
773
|
-
signature,
|
|
774
|
-
source: bucket.source,
|
|
775
|
-
name: bucket.name,
|
|
776
|
-
message: bucket.message,
|
|
777
|
-
count: bucket.traces.size,
|
|
778
|
-
traceSha1s: [...bucket.traces].sort(),
|
|
779
|
-
relatedActions: [...bucket.relatedActions.values()],
|
|
780
|
-
}))
|
|
781
|
-
.filter(pattern => pattern.count > 1)
|
|
782
|
-
.sort((left, right) => right.count - left.count),
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
886
|
async function attachmentSize(traceContext, attachment) {
|
|
786
887
|
if (attachment.sha1) {
|
|
787
888
|
const buffer = await (0, parseTrace_1.getResourceBuffer)(traceContext, attachment.sha1);
|
|
@@ -886,60 +987,6 @@ function filterNetworkEntries(entries, options) {
|
|
|
886
987
|
filtered = filtered.slice(0, options.limit);
|
|
887
988
|
return filtered;
|
|
888
989
|
}
|
|
889
|
-
function buildRequestPatternSignature(entry) {
|
|
890
|
-
try {
|
|
891
|
-
const parsed = new URL(entry.url);
|
|
892
|
-
return `${entry.method.toUpperCase()} ${normalizePathname(parsed.pathname)}`;
|
|
893
|
-
}
|
|
894
|
-
catch {
|
|
895
|
-
return `${entry.method.toUpperCase()} ${entry.url}`;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
function buildIssuePatternSignature(issue) {
|
|
899
|
-
return [
|
|
900
|
-
issue.source,
|
|
901
|
-
issue.name ?? 'Error',
|
|
902
|
-
normalizeIssueMessage(firstLine(issue.message) ?? issue.message),
|
|
903
|
-
].join(' | ');
|
|
904
|
-
}
|
|
905
|
-
function normalizePathname(pathname) {
|
|
906
|
-
const segments = pathname.split('/').filter(Boolean);
|
|
907
|
-
if (segments.length === 0)
|
|
908
|
-
return '/';
|
|
909
|
-
return `/${segments.map(normalizePathSegment).join('/')}`;
|
|
910
|
-
}
|
|
911
|
-
function normalizePathSegment(segment) {
|
|
912
|
-
if (/^\d+$/.test(segment))
|
|
913
|
-
return ':id';
|
|
914
|
-
if (/^[0-9a-f]{8,}$/i.test(segment))
|
|
915
|
-
return ':id';
|
|
916
|
-
if (/^[0-9a-f]{8}-[0-9a-f-]{27,}$/i.test(segment))
|
|
917
|
-
return ':id';
|
|
918
|
-
if (/^trace-[\w-]+$/i.test(segment))
|
|
919
|
-
return ':id';
|
|
920
|
-
return segment;
|
|
921
|
-
}
|
|
922
|
-
function normalizeIssueMessage(message) {
|
|
923
|
-
return message
|
|
924
|
-
.replace(/trace-[\w-]+/gi, ':trace')
|
|
925
|
-
.replace(/call@[\w-]+/gi, 'call@:id')
|
|
926
|
-
.replace(/\b[0-9a-f]{8,}\b/gi, ':id')
|
|
927
|
-
.replace(/\b\d+\b/g, ':n');
|
|
928
|
-
}
|
|
929
|
-
function stripQuery(urlText) {
|
|
930
|
-
try {
|
|
931
|
-
const parsed = new URL(urlText);
|
|
932
|
-
parsed.search = '';
|
|
933
|
-
parsed.hash = '';
|
|
934
|
-
return parsed.toString();
|
|
935
|
-
}
|
|
936
|
-
catch {
|
|
937
|
-
return urlText;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
function firstLine(value) {
|
|
941
|
-
return value ? value.split(/\r?\n/, 1)[0] ?? null : null;
|
|
942
|
-
}
|
|
943
990
|
/**
|
|
944
991
|
* Merges all trace event types (steps, screenshots, DOM snapshots, network
|
|
945
992
|
* calls) into a single chronologically sorted array.
|
|
@@ -1086,13 +1133,6 @@ async function getSummary(traceContext, options) {
|
|
|
1086
1133
|
: null,
|
|
1087
1134
|
};
|
|
1088
1135
|
}
|
|
1089
|
-
async function getReportFailurePatterns(reportDataDir, options) {
|
|
1090
|
-
const selections = await getFailedTraceSelections(reportDataDir, options);
|
|
1091
|
-
return buildReportFailurePatterns(selections);
|
|
1092
|
-
}
|
|
1093
|
-
function summarizeReportFailurePatterns(selections) {
|
|
1094
|
-
return buildReportFailurePatterns(selections);
|
|
1095
|
-
}
|
|
1096
1136
|
async function getFailedTraceSelections(reportDataDir, options) {
|
|
1097
1137
|
const traces = await (0, parseTrace_1.listTraces)(reportDataDir);
|
|
1098
1138
|
const meta = await (0, parseTrace_1.getReportMetadata)(reportDataDir);
|