@decocms/parity 0.33.34 → 0.33.36
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/dist/cli.js +963 -37
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -38429,7 +38429,7 @@ var CAROUSEL_STABILIZER_INIT_SCRIPT = `
|
|
|
38429
38429
|
* so the harness can log how many were stabilized.
|
|
38430
38430
|
*/
|
|
38431
38431
|
window.__parityStabilizeCarousels = function () {
|
|
38432
|
-
var counts = { swiper: 0, splide: 0, slick: 0, keenSlider: 0, generic: 0 };
|
|
38432
|
+
var counts = { swiper: 0, splide: 0, slick: 0, keenSlider: 0, generic: 0, animations: 0, media: 0 };
|
|
38433
38433
|
|
|
38434
38434
|
// 1. Swiper — most common in Deco sites. Two ways to find instances:
|
|
38435
38435
|
// - element.swiper (newer versions)
|
|
@@ -38506,7 +38506,46 @@ var CAROUSEL_STABILIZER_INIT_SCRIPT = `
|
|
|
38506
38506
|
}
|
|
38507
38507
|
} catch (_) {}
|
|
38508
38508
|
|
|
38509
|
-
// 6.
|
|
38509
|
+
// 6. Web Animations API — everything above is library-specific or
|
|
38510
|
+
// setInterval-driven, and neither reaches an animation started with
|
|
38511
|
+
// element.animate() or a CSS animation whose currentTime the page
|
|
38512
|
+
// drives. That is most modern scroll effects and a good share of
|
|
38513
|
+
// hand-rolled carousels: they slip through 1-5 entirely and land in a
|
|
38514
|
+
// different frame on each capture.
|
|
38515
|
+
//
|
|
38516
|
+
// Pinning to 0 rather than just pausing, so two captures of the same
|
|
38517
|
+
// page agree on WHICH frame, not merely that it stopped moving.
|
|
38518
|
+
// Infinite animations report a null/Infinity duration, so currentTime
|
|
38519
|
+
// is set before the pause and failures are per-animation.
|
|
38520
|
+
try {
|
|
38521
|
+
if (typeof document.getAnimations === 'function') {
|
|
38522
|
+
var anims = document.getAnimations();
|
|
38523
|
+
for (var a = 0; a < anims.length; a++) {
|
|
38524
|
+
try {
|
|
38525
|
+
anims[a].currentTime = 0;
|
|
38526
|
+
anims[a].pause();
|
|
38527
|
+
counts.animations++;
|
|
38528
|
+
} catch (_) {}
|
|
38529
|
+
}
|
|
38530
|
+
}
|
|
38531
|
+
} catch (_) {}
|
|
38532
|
+
|
|
38533
|
+
// 7. Media elements. A <video> with autoplay is a slideshow by another
|
|
38534
|
+
// name, and the screenshot's animations:disabled does not touch it.
|
|
38535
|
+
// Seek to 0 for the same reason as above.
|
|
38536
|
+
try {
|
|
38537
|
+
var media = document.querySelectorAll('video, audio');
|
|
38538
|
+
for (var m = 0; m < media.length; m++) {
|
|
38539
|
+
try {
|
|
38540
|
+
media[m].pause();
|
|
38541
|
+
if (media[m].currentTime > 0) media[m].currentTime = 0;
|
|
38542
|
+
media[m].autoplay = false;
|
|
38543
|
+
counts.media++;
|
|
38544
|
+
} catch (_) {}
|
|
38545
|
+
}
|
|
38546
|
+
} catch (_) {}
|
|
38547
|
+
|
|
38548
|
+
// 8. Set the freeze flag so future auto-advance ticks bail out (libs
|
|
38510
38549
|
// that check this flag before mutating slide index).
|
|
38511
38550
|
window.__parityCarouselStop = true;
|
|
38512
38551
|
return counts;
|
|
@@ -38520,6 +38559,8 @@ async function stabilizeCarousels(page) {
|
|
|
38520
38559
|
slick: 0,
|
|
38521
38560
|
keenSlider: 0,
|
|
38522
38561
|
generic: 0,
|
|
38562
|
+
animations: 0,
|
|
38563
|
+
media: 0,
|
|
38523
38564
|
total: 0
|
|
38524
38565
|
};
|
|
38525
38566
|
try {
|
|
@@ -38529,7 +38570,7 @@ async function stabilizeCarousels(page) {
|
|
|
38529
38570
|
});
|
|
38530
38571
|
if (!counts)
|
|
38531
38572
|
return empty;
|
|
38532
|
-
const total = (counts.swiper ?? 0) + (counts.splide ?? 0) + (counts.slick ?? 0) + (counts.keenSlider ?? 0) + (counts.generic ?? 0);
|
|
38573
|
+
const total = (counts.swiper ?? 0) + (counts.splide ?? 0) + (counts.slick ?? 0) + (counts.keenSlider ?? 0) + (counts.generic ?? 0) + (counts.animations ?? 0) + (counts.media ?? 0);
|
|
38533
38574
|
if (total > 0) {
|
|
38534
38575
|
await page.waitForTimeout(150);
|
|
38535
38576
|
}
|
|
@@ -38539,6 +38580,8 @@ async function stabilizeCarousels(page) {
|
|
|
38539
38580
|
slick: counts.slick ?? 0,
|
|
38540
38581
|
keenSlider: counts.keenSlider ?? 0,
|
|
38541
38582
|
generic: counts.generic ?? 0,
|
|
38583
|
+
animations: counts.animations ?? 0,
|
|
38584
|
+
media: counts.media ?? 0,
|
|
38542
38585
|
total
|
|
38543
38586
|
};
|
|
38544
38587
|
} catch {
|
|
@@ -38685,6 +38728,7 @@ async function newContext(browser, opts) {
|
|
|
38685
38728
|
const baseContext = VIEWPORT_PRESETS[opts.viewport];
|
|
38686
38729
|
const ctx = await browser.newContext({
|
|
38687
38730
|
...baseContext,
|
|
38731
|
+
...opts.viewportSize ? { viewport: opts.viewportSize, screen: opts.viewportSize } : {},
|
|
38688
38732
|
...opts.deviceScaleFactor != null ? { deviceScaleFactor: opts.deviceScaleFactor } : {},
|
|
38689
38733
|
recordHar: opts.harPath ? { path: opts.harPath, mode: "full", content: "omit" } : undefined,
|
|
38690
38734
|
bypassCSP: true,
|
|
@@ -53394,6 +53438,9 @@ function diffScreenshots(prodPath, candPath, heatmapPath, opts = {}) {
|
|
|
53394
53438
|
return {
|
|
53395
53439
|
width,
|
|
53396
53440
|
height,
|
|
53441
|
+
prodSize: [prod.width, prod.height],
|
|
53442
|
+
candSize: [cand.width, cand.height],
|
|
53443
|
+
cropped: prod.width !== cand.width || prod.height !== cand.height,
|
|
53397
53444
|
diffPixels,
|
|
53398
53445
|
totalPixels,
|
|
53399
53446
|
pctDiff,
|
|
@@ -74203,8 +74250,873 @@ async function mcpCommand(opts) {
|
|
|
74203
74250
|
return 0;
|
|
74204
74251
|
}
|
|
74205
74252
|
|
|
74206
|
-
// src/commands/
|
|
74253
|
+
// src/commands/heatmap.ts
|
|
74254
|
+
import { mkdirSync as mkdirSync19 } from "node:fs";
|
|
74255
|
+
import { resolve as resolve12 } from "node:path";
|
|
74207
74256
|
import chalk30 from "chalk";
|
|
74257
|
+
|
|
74258
|
+
// src/diff/hotspot-findings.ts
|
|
74259
|
+
var TYPOGRAPHY_PROPS = /^(font-family|font-weight|font-size|font-style|line-height|letter-spacing|text-transform)$/;
|
|
74260
|
+
var COLOR_PROPS = /^(color|background-color|border-color|fill|stroke)$/;
|
|
74261
|
+
var SPACING_PROPS = /^(margin|padding|gap|row-gap|column-gap)/;
|
|
74262
|
+
var SIZE_PROPS = /^(rect\.(width|height)|width|height)$/;
|
|
74263
|
+
var POSITION_PROPS = /^rect\.(offsetX|offsetY)$/;
|
|
74264
|
+
var IMAGE_TAGS = new Set(["img", "picture", "svg", "video", "canvas"]);
|
|
74265
|
+
function rankNodes(a, b) {
|
|
74266
|
+
const aExplains = a.deltas.length > 0;
|
|
74267
|
+
const bExplains = b.deltas.length > 0;
|
|
74268
|
+
if (aExplains !== bExplains)
|
|
74269
|
+
return aExplains ? -1 : 1;
|
|
74270
|
+
return a.rect.width * a.rect.height - b.rect.width * b.rect.height;
|
|
74271
|
+
}
|
|
74272
|
+
function intersects(rect, box) {
|
|
74273
|
+
return rect.x < box.x + box.width && rect.x + rect.width > box.x && rect.y < box.y + box.height && rect.y + rect.height > box.y;
|
|
74274
|
+
}
|
|
74275
|
+
function attributeHotspots(args) {
|
|
74276
|
+
const max = args.maxNodesPerHotspot ?? 3;
|
|
74277
|
+
const deltasByKey = new Map;
|
|
74278
|
+
for (const d of args.deltas) {
|
|
74279
|
+
const list = deltasByKey.get(d.key);
|
|
74280
|
+
if (list)
|
|
74281
|
+
list.push(d);
|
|
74282
|
+
else
|
|
74283
|
+
deltasByKey.set(d.key, [d]);
|
|
74284
|
+
}
|
|
74285
|
+
return args.hotspots.map((hotspot, i) => {
|
|
74286
|
+
const candidates = args.nodes.filter((n) => intersects(n.rect, hotspot)).map((n) => ({
|
|
74287
|
+
key: n.key,
|
|
74288
|
+
label: n.label,
|
|
74289
|
+
tag: n.tag,
|
|
74290
|
+
rect: n.rect,
|
|
74291
|
+
deltas: deltasByKey.get(n.key) ?? []
|
|
74292
|
+
})).sort(rankNodes).slice(0, max);
|
|
74293
|
+
const { type, because } = classify2(candidates, args.imageHostDelta ?? []);
|
|
74294
|
+
return {
|
|
74295
|
+
type,
|
|
74296
|
+
hotspot,
|
|
74297
|
+
nodes: candidates,
|
|
74298
|
+
truncated: args.truncated,
|
|
74299
|
+
summary: describe2(type, hotspot, candidates, args.imageHostDelta ?? [], because)
|
|
74300
|
+
};
|
|
74301
|
+
});
|
|
74302
|
+
}
|
|
74303
|
+
function classify2(nodes, imageHostDelta) {
|
|
74304
|
+
const deltas = nodes.flatMap((n) => n.deltas);
|
|
74305
|
+
const byKind = [
|
|
74306
|
+
["offset", POSITION_PROPS],
|
|
74307
|
+
["typography", TYPOGRAPHY_PROPS],
|
|
74308
|
+
["color", COLOR_PROPS],
|
|
74309
|
+
["size", SIZE_PROPS],
|
|
74310
|
+
["spacing", SPACING_PROPS]
|
|
74311
|
+
];
|
|
74312
|
+
for (const [type, re] of byKind) {
|
|
74313
|
+
const because = deltas.find((d) => re.test(d.prop));
|
|
74314
|
+
if (because)
|
|
74315
|
+
return { type, because };
|
|
74316
|
+
}
|
|
74317
|
+
if (imageHostDelta.length > 0 && nodes.some((n) => IMAGE_TAGS.has(n.tag))) {
|
|
74318
|
+
return { type: "image-source", because: null };
|
|
74319
|
+
}
|
|
74320
|
+
if (deltas[0])
|
|
74321
|
+
return { type: "unattributed", because: deltas[0] };
|
|
74322
|
+
return { type: "unattributed", because: null };
|
|
74323
|
+
}
|
|
74324
|
+
function nodeName(n) {
|
|
74325
|
+
if (!n.label)
|
|
74326
|
+
return n.key;
|
|
74327
|
+
return n.label === n.key ? n.label : `${n.label} (${n.key})`;
|
|
74328
|
+
}
|
|
74329
|
+
function describe2(type, hotspot, nodes, imageHostDelta, because) {
|
|
74330
|
+
const where = `at ${hotspot.x},${hotspot.y} — ${hotspot.width}×${hotspot.height}`;
|
|
74331
|
+
const owner = because ? nodes.find((n) => n.deltas.includes(because)) : undefined;
|
|
74332
|
+
const who = owner ? nodeName(owner) : nodes[0] ? nodeName(nodes[0]) : null;
|
|
74333
|
+
if (type === "offset" && because?.deltaPx != null) {
|
|
74334
|
+
const px = Math.abs(because.deltaPx);
|
|
74335
|
+
const horizontal = because.prop === "rect.offsetX";
|
|
74336
|
+
const dir = because.deltaPx < 0 ? horizontal ? "left" : "up" : horizontal ? "right" : "down";
|
|
74337
|
+
return `${who ?? "Content"} sits ${px}px further ${dir} than prod (${because.prop}: ${because.prod} → ${because.cand}) ${where}.`;
|
|
74338
|
+
}
|
|
74339
|
+
if (type === "image-source") {
|
|
74340
|
+
return `${who ?? "An image"} ${where} differs and the two sides serve images from different hosts (${imageHostDelta.join(", ")}) — recompression alone moves pixels, so this cannot reach zero until both use the same provider.`;
|
|
74341
|
+
}
|
|
74342
|
+
const delta = because;
|
|
74343
|
+
if (delta) {
|
|
74344
|
+
const arrow = `${delta.prop}: ${delta.prod} → ${delta.cand}`;
|
|
74345
|
+
const px = delta.deltaPx != null ? ` (${delta.deltaPx > 0 ? "+" : ""}${delta.deltaPx}px)` : "";
|
|
74346
|
+
return `${who} ${where}: ${arrow}${px}.`;
|
|
74347
|
+
}
|
|
74348
|
+
if (who) {
|
|
74349
|
+
return `${who} ${where} renders differently, but no box-tree delta explains it — check the computed styles and the CSS source for this node.`;
|
|
74350
|
+
}
|
|
74351
|
+
return `Difference ${where} could not be attributed to any element in the box tree — the subtree may be truncated, or the difference may sit outside it.`;
|
|
74352
|
+
}
|
|
74353
|
+
|
|
74354
|
+
// src/diff/noise-mask.ts
|
|
74355
|
+
import { readFileSync as readFileSync36, writeFileSync as writeFileSync31 } from "node:fs";
|
|
74356
|
+
import { PNG as PNG5 } from "pngjs";
|
|
74357
|
+
var DEFAULT_DILATE = 2;
|
|
74358
|
+
var MAX_MASK_COVERAGE = 0.2;
|
|
74359
|
+
function buildNoiseMask(firstPng, secondPng, dilate = DEFAULT_DILATE) {
|
|
74360
|
+
const a = PNG5.sync.read(readFileSync36(firstPng));
|
|
74361
|
+
const b = PNG5.sync.read(readFileSync36(secondPng));
|
|
74362
|
+
if (a.width !== b.width || a.height !== b.height)
|
|
74363
|
+
return null;
|
|
74364
|
+
const { width, height } = a;
|
|
74365
|
+
const raw = new Uint8Array(width * height);
|
|
74366
|
+
for (let i = 0, p = 0;i < a.data.length; i += 4, p++) {
|
|
74367
|
+
if (a.data[i] !== b.data[i] || a.data[i + 1] !== b.data[i + 1] || a.data[i + 2] !== b.data[i + 2] || a.data[i + 3] !== b.data[i + 3]) {
|
|
74368
|
+
raw[p] = 1;
|
|
74369
|
+
}
|
|
74370
|
+
}
|
|
74371
|
+
const data = dilate > 0 ? dilateMask(raw, width, height, dilate) : raw;
|
|
74372
|
+
let masked = 0;
|
|
74373
|
+
for (let p = 0;p < data.length; p++)
|
|
74374
|
+
if (data[p])
|
|
74375
|
+
masked++;
|
|
74376
|
+
const total = width * height;
|
|
74377
|
+
return { data, width, height, masked, coverage: total > 0 ? masked / total : 0 };
|
|
74378
|
+
}
|
|
74379
|
+
function dilateMask(src, width, height, radius) {
|
|
74380
|
+
const pass = (input, horizontal) => {
|
|
74381
|
+
const out = new Uint8Array(input.length);
|
|
74382
|
+
const outer = horizontal ? height : width;
|
|
74383
|
+
const inner = horizontal ? width : height;
|
|
74384
|
+
for (let o = 0;o < outer; o++) {
|
|
74385
|
+
for (let i = 0;i < inner; i++) {
|
|
74386
|
+
const idx = horizontal ? o * width + i : i * width + o;
|
|
74387
|
+
if (!input[idx])
|
|
74388
|
+
continue;
|
|
74389
|
+
const from = Math.max(0, i - radius);
|
|
74390
|
+
const to = Math.min(inner - 1, i + radius);
|
|
74391
|
+
for (let k = from;k <= to; k++) {
|
|
74392
|
+
out[horizontal ? o * width + k : k * width + o] = 1;
|
|
74393
|
+
}
|
|
74394
|
+
}
|
|
74395
|
+
}
|
|
74396
|
+
return out;
|
|
74397
|
+
};
|
|
74398
|
+
return pass(pass(src, true), false);
|
|
74399
|
+
}
|
|
74400
|
+
function applyMask(pngPath, mask, outPath) {
|
|
74401
|
+
const png = PNG5.sync.read(readFileSync36(pngPath));
|
|
74402
|
+
if (png.width !== mask.width || png.height !== mask.height) {
|
|
74403
|
+
throw new Error(`applyMask: image is ${png.width}x${png.height} but the mask is ${mask.width}x${mask.height}`);
|
|
74404
|
+
}
|
|
74405
|
+
for (let p = 0;p < mask.data.length; p++) {
|
|
74406
|
+
if (!mask.data[p])
|
|
74407
|
+
continue;
|
|
74408
|
+
const i = p * 4;
|
|
74409
|
+
png.data[i] = 0;
|
|
74410
|
+
png.data[i + 1] = 0;
|
|
74411
|
+
png.data[i + 2] = 0;
|
|
74412
|
+
png.data[i + 3] = 255;
|
|
74413
|
+
}
|
|
74414
|
+
writeFileSync31(outPath, PNG5.sync.write(png));
|
|
74415
|
+
}
|
|
74416
|
+
|
|
74417
|
+
// src/report/qa-comment.ts
|
|
74418
|
+
import { execFile } from "node:child_process";
|
|
74419
|
+
import { readFile } from "node:fs/promises";
|
|
74420
|
+
import { basename as basename4 } from "node:path";
|
|
74421
|
+
import { promisify } from "node:util";
|
|
74422
|
+
var exec = promisify(execFile);
|
|
74423
|
+
var QA_COMMENT_MARKER = "<!-- parity-qa -->";
|
|
74424
|
+
async function postQaComment(args) {
|
|
74425
|
+
const repoArgs = args.repo ? ["--repo", args.repo] : [];
|
|
74426
|
+
const uploads = new Map;
|
|
74427
|
+
const repositoryId = await ghRepositoryId(repoArgs, args.cwd);
|
|
74428
|
+
if (repositoryId) {
|
|
74429
|
+
for (const path of imagePathsToUpload(args.report)) {
|
|
74430
|
+
const url = await uploadAttachment(path, repositoryId, args.cwd);
|
|
74431
|
+
if (url)
|
|
74432
|
+
uploads.set(path, url);
|
|
74433
|
+
}
|
|
74434
|
+
}
|
|
74435
|
+
const body = buildQaComment(args.report, uploads);
|
|
74436
|
+
const existing = await findOwnComment(args.pr, repoArgs, args.cwd);
|
|
74437
|
+
if (existing) {
|
|
74438
|
+
await exec("gh", ["api", "--method", "PATCH", existing, "-f", `body=${body}`], {
|
|
74439
|
+
cwd: args.cwd,
|
|
74440
|
+
maxBuffer: 10 * 1024 * 1024
|
|
74441
|
+
});
|
|
74442
|
+
return;
|
|
74443
|
+
}
|
|
74444
|
+
await exec("gh", ["pr", "comment", args.pr, ...repoArgs, "--body", body], {
|
|
74445
|
+
cwd: args.cwd,
|
|
74446
|
+
maxBuffer: 10 * 1024 * 1024
|
|
74447
|
+
});
|
|
74448
|
+
}
|
|
74449
|
+
function imagePathsToUpload(report) {
|
|
74450
|
+
return report.viewports.filter((v) => v.verdict === "differs" && v.heatmapPath).map((v) => v.heatmapPath);
|
|
74451
|
+
}
|
|
74452
|
+
async function ghRepositoryId(repoArgs, cwd) {
|
|
74453
|
+
try {
|
|
74454
|
+
const target = repoArgs.length > 0 ? repoArgs[1] : "{owner}/{repo}";
|
|
74455
|
+
const { stdout } = await exec("gh", ["api", `repos/${target}`, "--jq", ".id"], { cwd });
|
|
74456
|
+
const id = Number.parseInt(stdout.trim(), 10);
|
|
74457
|
+
return Number.isFinite(id) ? id : null;
|
|
74458
|
+
} catch {
|
|
74459
|
+
return null;
|
|
74460
|
+
}
|
|
74461
|
+
}
|
|
74462
|
+
async function uploadAttachment(path, repositoryId, cwd) {
|
|
74463
|
+
try {
|
|
74464
|
+
const token = await githubToken(cwd);
|
|
74465
|
+
if (!token)
|
|
74466
|
+
return null;
|
|
74467
|
+
const bytes = await readFile(path);
|
|
74468
|
+
const qs = new URLSearchParams({
|
|
74469
|
+
name: basename4(path),
|
|
74470
|
+
content_type: "image/png",
|
|
74471
|
+
repository_id: String(repositoryId)
|
|
74472
|
+
});
|
|
74473
|
+
const res = await fetch(`https://uploads.github.com/user-attachments/assets?${qs}`, {
|
|
74474
|
+
method: "POST",
|
|
74475
|
+
headers: {
|
|
74476
|
+
Authorization: `Bearer ${token}`,
|
|
74477
|
+
Accept: "application/json",
|
|
74478
|
+
"Content-Type": "image/png"
|
|
74479
|
+
},
|
|
74480
|
+
body: new Uint8Array(bytes)
|
|
74481
|
+
});
|
|
74482
|
+
if (!res.ok)
|
|
74483
|
+
return null;
|
|
74484
|
+
const json = await res.json();
|
|
74485
|
+
const url = json.href ?? json.url;
|
|
74486
|
+
if (!url)
|
|
74487
|
+
return null;
|
|
74488
|
+
const head = await fetch(url, {
|
|
74489
|
+
method: "HEAD",
|
|
74490
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
74491
|
+
redirect: "manual"
|
|
74492
|
+
});
|
|
74493
|
+
return head.ok ? url : null;
|
|
74494
|
+
} catch {
|
|
74495
|
+
return null;
|
|
74496
|
+
}
|
|
74497
|
+
}
|
|
74498
|
+
async function githubToken(cwd) {
|
|
74499
|
+
const fromEnv = process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN;
|
|
74500
|
+
if (fromEnv)
|
|
74501
|
+
return fromEnv;
|
|
74502
|
+
try {
|
|
74503
|
+
return (await exec("gh", ["auth", "token"], { cwd })).stdout.trim() || null;
|
|
74504
|
+
} catch {
|
|
74505
|
+
return null;
|
|
74506
|
+
}
|
|
74507
|
+
}
|
|
74508
|
+
async function findOwnComment(pr, repoArgs, cwd) {
|
|
74509
|
+
try {
|
|
74510
|
+
const { stdout } = await exec("gh", ["pr", "view", pr, ...repoArgs, "--json", "comments"], {
|
|
74511
|
+
cwd,
|
|
74512
|
+
maxBuffer: 10 * 1024 * 1024
|
|
74513
|
+
});
|
|
74514
|
+
const parsed = JSON.parse(stdout);
|
|
74515
|
+
const mine = (parsed.comments ?? []).filter((c) => c.body?.includes(QA_COMMENT_MARKER));
|
|
74516
|
+
const last = mine[mine.length - 1];
|
|
74517
|
+
if (!last?.url)
|
|
74518
|
+
return null;
|
|
74519
|
+
const m = /github\.com\/([^/]+)\/([^/]+)\/pull\/\d+#issuecomment-(\d+)/.exec(last.url);
|
|
74520
|
+
if (!m)
|
|
74521
|
+
return null;
|
|
74522
|
+
return `repos/${m[1]}/${m[2]}/issues/comments/${m[3]}`;
|
|
74523
|
+
} catch {
|
|
74524
|
+
return null;
|
|
74525
|
+
}
|
|
74526
|
+
}
|
|
74527
|
+
var HEADLINE = {
|
|
74528
|
+
identical: "✓ approved",
|
|
74529
|
+
differs: "✗ rejected",
|
|
74530
|
+
inconclusive: "? inconclusive"
|
|
74531
|
+
};
|
|
74532
|
+
function buildQaComment(report, uploads) {
|
|
74533
|
+
const failing = report.viewports.filter((v) => v.verdict !== "identical");
|
|
74534
|
+
const lines = [
|
|
74535
|
+
QA_COMMENT_MARKER,
|
|
74536
|
+
`## Parity QA — ${HEADLINE[report.verdict]}`,
|
|
74537
|
+
"",
|
|
74538
|
+
`Zero-tolerance pixel gate · ${report.mode} mode · ${report.viewports.length} viewports · ${failing.length} not clean.`,
|
|
74539
|
+
""
|
|
74540
|
+
];
|
|
74541
|
+
if (report.reason)
|
|
74542
|
+
lines.push(`> ${report.reason}`, "");
|
|
74543
|
+
for (const v of report.viewports) {
|
|
74544
|
+
lines.push(...viewportBlock(v, uploads));
|
|
74545
|
+
}
|
|
74546
|
+
if (report.verdict !== "identical") {
|
|
74547
|
+
lines.push("**To approve, every viewport must reach 0 differing pixels.** An `inconclusive` viewport is not a pass — it means nothing was compared there.");
|
|
74548
|
+
}
|
|
74549
|
+
return lines.join(`
|
|
74550
|
+
`);
|
|
74551
|
+
}
|
|
74552
|
+
function viewportBlock(v, uploads) {
|
|
74553
|
+
if (v.verdict === "identical")
|
|
74554
|
+
return [`### ${v.label} — clean`, ""];
|
|
74555
|
+
const head = v.verdict === "differs" ? `### ${v.label} — ${(v.diffPixels ?? 0).toLocaleString("en-US")} differing pixels` : `### ${v.label} — not compared`;
|
|
74556
|
+
const out = [head, ""];
|
|
74557
|
+
if (v.reason)
|
|
74558
|
+
out.push(v.reason, "");
|
|
74559
|
+
const uploaded = v.heatmapPath ? uploads.get(v.heatmapPath) : undefined;
|
|
74560
|
+
if (uploaded)
|
|
74561
|
+
out.push(``, "");
|
|
74562
|
+
else if (v.heatmapPath && v.verdict === "differs") {
|
|
74563
|
+
out.push(`_Diff image could not be uploaded; it is on the runner at_ \`${v.heatmapPath}\``, "");
|
|
74564
|
+
}
|
|
74565
|
+
if (v.findings.length > 0) {
|
|
74566
|
+
for (const f of v.findings.slice(0, 5))
|
|
74567
|
+
out.push(`- **${f.type}** — ${f.summary}`);
|
|
74568
|
+
if (v.findings.some((f) => f.truncated)) {
|
|
74569
|
+
out.push("- _The box tree hit its size cap, so an unattributed region above is not proof that no element sits there._");
|
|
74570
|
+
}
|
|
74571
|
+
} else {
|
|
74572
|
+
for (const h of v.hotspots.slice(0, 5)) {
|
|
74573
|
+
out.push(`- Hotspot at ${h.x},${h.y} — ${h.width}×${h.height} (${h.pixelCount} px).`);
|
|
74574
|
+
}
|
|
74575
|
+
}
|
|
74576
|
+
const hosts = hostsOnlyOnOneSide(v);
|
|
74577
|
+
if (hosts.onlyProd.length > 0 || hosts.onlyCand.length > 0) {
|
|
74578
|
+
const where = [
|
|
74579
|
+
hosts.onlyProd.length ? `prod only: ${hosts.onlyProd.join(", ")}` : null,
|
|
74580
|
+
hosts.onlyCand.length ? `cand only: ${hosts.onlyCand.join(", ")}` : null
|
|
74581
|
+
].filter(Boolean).join("; ");
|
|
74582
|
+
out.push(`- Images come from different hosts (${where}). Pixel parity is unreachable until both sides use the same image provider.`);
|
|
74583
|
+
}
|
|
74584
|
+
out.push("");
|
|
74585
|
+
return out;
|
|
74586
|
+
}
|
|
74587
|
+
function hostsOnlyOnOneSide(v) {
|
|
74588
|
+
return imageHostDelta(v.prod.imageHosts, v.cand.imageHosts);
|
|
74589
|
+
}
|
|
74590
|
+
|
|
74591
|
+
// src/commands/heatmap.ts
|
|
74592
|
+
var DEFAULT_VIEWPORTS = "mobile,tablet,1024x768,desktop,1920x1080,2560x1440";
|
|
74593
|
+
var MOBILE_UA_MAX_WIDTH = 767;
|
|
74594
|
+
function parseViewports2(raw) {
|
|
74595
|
+
const entries = raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
74596
|
+
if (entries.length === 0)
|
|
74597
|
+
return "--viewports is empty";
|
|
74598
|
+
const specs = [];
|
|
74599
|
+
for (const entry of entries) {
|
|
74600
|
+
const named = parseViewport3(entry);
|
|
74601
|
+
if (named) {
|
|
74602
|
+
specs.push({ label: entry, viewport: named, size: null });
|
|
74603
|
+
continue;
|
|
74604
|
+
}
|
|
74605
|
+
const m = /^(\d{2,5})x(\d{2,5})$/.exec(entry);
|
|
74606
|
+
if (!m) {
|
|
74607
|
+
return `invalid viewport: '${entry}' (use mobile|tablet|desktop or <width>x<height>)`;
|
|
74608
|
+
}
|
|
74609
|
+
const width = Number(m[1]);
|
|
74610
|
+
const height = Number(m[2]);
|
|
74611
|
+
specs.push({
|
|
74612
|
+
label: entry,
|
|
74613
|
+
viewport: width <= MOBILE_UA_MAX_WIDTH ? "mobile" : "desktop",
|
|
74614
|
+
size: { width, height }
|
|
74615
|
+
});
|
|
74616
|
+
}
|
|
74617
|
+
return specs;
|
|
74618
|
+
}
|
|
74619
|
+
function aggregateVerdict(results) {
|
|
74620
|
+
if (results.length === 0) {
|
|
74621
|
+
return { verdict: "inconclusive", reason: "no viewport was compared" };
|
|
74622
|
+
}
|
|
74623
|
+
const differing = results.filter((r) => r.verdict === "differs");
|
|
74624
|
+
if (differing.length > 0) {
|
|
74625
|
+
const total = differing.reduce((sum, r) => sum + (r.diffPixels ?? 0), 0);
|
|
74626
|
+
return {
|
|
74627
|
+
verdict: "differs",
|
|
74628
|
+
reason: `${differing.length}/${results.length} viewports differ (${total} pixels in total): ${differing.map((r) => r.label).join(", ")}`
|
|
74629
|
+
};
|
|
74630
|
+
}
|
|
74631
|
+
const unread = results.filter((r) => r.verdict === "inconclusive");
|
|
74632
|
+
if (unread.length > 0) {
|
|
74633
|
+
return {
|
|
74634
|
+
verdict: "inconclusive",
|
|
74635
|
+
reason: `${unread.length}/${results.length} viewports could not be compared: ${unread.map((r) => `${r.label} (${r.reason ?? "no reason given"})`).join("; ")}`
|
|
74636
|
+
};
|
|
74637
|
+
}
|
|
74638
|
+
return { verdict: "identical" };
|
|
74639
|
+
}
|
|
74640
|
+
var EXIT_IDENTICAL = 0;
|
|
74641
|
+
var EXIT_DIFFERS = 1;
|
|
74642
|
+
var EXIT_INCONCLUSIVE = 2;
|
|
74643
|
+
function exitCodeFor(verdict) {
|
|
74644
|
+
if (verdict === "identical")
|
|
74645
|
+
return EXIT_IDENTICAL;
|
|
74646
|
+
if (verdict === "differs")
|
|
74647
|
+
return EXIT_DIFFERS;
|
|
74648
|
+
return EXIT_INCONCLUSIVE;
|
|
74649
|
+
}
|
|
74650
|
+
async function heatmapCommand(opts) {
|
|
74651
|
+
const specs = parseViewports2(opts.viewports);
|
|
74652
|
+
if (typeof specs === "string") {
|
|
74653
|
+
console.error(chalk30.red(specs));
|
|
74654
|
+
return EXIT_INCONCLUSIVE;
|
|
74655
|
+
}
|
|
74656
|
+
const waitMs = Number.parseInt(opts.wait, 10);
|
|
74657
|
+
if (!Number.isFinite(waitMs) || waitMs < 0) {
|
|
74658
|
+
console.error(chalk30.red(`--wait inválido: ${opts.wait}`));
|
|
74659
|
+
return EXIT_INCONCLUSIVE;
|
|
74660
|
+
}
|
|
74661
|
+
if (!isValidUrl5(opts.prod) || !isValidUrl5(opts.cand)) {
|
|
74662
|
+
console.error(chalk30.red("--prod ou --cand inválido"));
|
|
74663
|
+
return EXIT_INCONCLUSIVE;
|
|
74664
|
+
}
|
|
74665
|
+
const selector = opts.selector?.trim() || null;
|
|
74666
|
+
const candSelector = opts.candSelector?.trim() || selector;
|
|
74667
|
+
const mode = selector ? "section" : "page";
|
|
74668
|
+
mkdirSync19(opts.outDir, { recursive: true });
|
|
74669
|
+
const prefix = `heatmap-${hashSelector(`${opts.prod}|${opts.cand}|${selector ?? "page"}`)}`;
|
|
74670
|
+
const browser = await launchBrowser({ headless: true });
|
|
74671
|
+
const results = [];
|
|
74672
|
+
try {
|
|
74673
|
+
for (const spec of specs) {
|
|
74674
|
+
results.push(await compareViewportSafely(browser, {
|
|
74675
|
+
spec,
|
|
74676
|
+
prodUrl: opts.prod,
|
|
74677
|
+
candUrl: opts.cand,
|
|
74678
|
+
selector,
|
|
74679
|
+
candSelector,
|
|
74680
|
+
waitMs,
|
|
74681
|
+
outDir: opts.outDir,
|
|
74682
|
+
prefix
|
|
74683
|
+
}));
|
|
74684
|
+
}
|
|
74685
|
+
} finally {
|
|
74686
|
+
await browser.close().catch(() => {
|
|
74687
|
+
return;
|
|
74688
|
+
});
|
|
74689
|
+
}
|
|
74690
|
+
const { verdict, reason } = aggregateVerdict(results);
|
|
74691
|
+
const report = {
|
|
74692
|
+
verdict,
|
|
74693
|
+
reason,
|
|
74694
|
+
mode,
|
|
74695
|
+
prodUrl: opts.prod,
|
|
74696
|
+
candUrl: opts.cand,
|
|
74697
|
+
viewports: results
|
|
74698
|
+
};
|
|
74699
|
+
if (opts.pr) {
|
|
74700
|
+
await postQaComment({ report, pr: opts.pr, repo: opts.repo }).catch((err) => {
|
|
74701
|
+
console.error(chalk30.yellow(` aviso: não foi possível publicar no PR — ${err.message}`));
|
|
74702
|
+
});
|
|
74703
|
+
}
|
|
74704
|
+
if (opts.json)
|
|
74705
|
+
console.log(JSON.stringify(report));
|
|
74706
|
+
else
|
|
74707
|
+
printReport(report);
|
|
74708
|
+
return exitCodeFor(verdict);
|
|
74709
|
+
}
|
|
74710
|
+
async function compareViewport(browser, args) {
|
|
74711
|
+
const { spec } = args;
|
|
74712
|
+
const paths = artifactPaths(args.outDir, args.prefix, spec.label);
|
|
74713
|
+
const [prod, cand] = await Promise.all([
|
|
74714
|
+
captureSide(browser, {
|
|
74715
|
+
spec,
|
|
74716
|
+
url: args.prodUrl,
|
|
74717
|
+
selector: args.selector,
|
|
74718
|
+
waitMs: args.waitMs,
|
|
74719
|
+
outPath: paths.prod,
|
|
74720
|
+
repeatPath: paths.prodRepeat
|
|
74721
|
+
}),
|
|
74722
|
+
captureSide(browser, {
|
|
74723
|
+
spec,
|
|
74724
|
+
url: args.candUrl,
|
|
74725
|
+
selector: args.candSelector,
|
|
74726
|
+
waitMs: args.waitMs,
|
|
74727
|
+
outPath: paths.cand,
|
|
74728
|
+
repeatPath: null
|
|
74729
|
+
})
|
|
74730
|
+
]);
|
|
74731
|
+
return judgePair({
|
|
74732
|
+
spec,
|
|
74733
|
+
paths,
|
|
74734
|
+
prod: prod.side,
|
|
74735
|
+
cand: cand.side,
|
|
74736
|
+
prodRepeatScreenshot: prod.repeatScreenshot,
|
|
74737
|
+
prodRepeatError: prod.repeatError,
|
|
74738
|
+
prodBoxTree: prod.boxTree,
|
|
74739
|
+
candBoxTree: cand.boxTree
|
|
74740
|
+
});
|
|
74741
|
+
}
|
|
74742
|
+
async function compareViewportSafely(browser, args) {
|
|
74743
|
+
try {
|
|
74744
|
+
return await compareViewport(browser, args);
|
|
74745
|
+
} catch (err) {
|
|
74746
|
+
return {
|
|
74747
|
+
...emptyResult2(args.spec),
|
|
74748
|
+
verdict: "inconclusive",
|
|
74749
|
+
reason: `viewport failed to run: ${err.message}`
|
|
74750
|
+
};
|
|
74751
|
+
}
|
|
74752
|
+
}
|
|
74753
|
+
function emptyResult2(spec) {
|
|
74754
|
+
const blank = {
|
|
74755
|
+
selector: null,
|
|
74756
|
+
matches: null,
|
|
74757
|
+
rect: null,
|
|
74758
|
+
screenshot: null,
|
|
74759
|
+
imageHosts: [],
|
|
74760
|
+
devicePixelRatio: 1,
|
|
74761
|
+
fontsStatus: "unknown"
|
|
74762
|
+
};
|
|
74763
|
+
return {
|
|
74764
|
+
label: spec.label,
|
|
74765
|
+
width: spec.size?.width ?? null,
|
|
74766
|
+
height: spec.size?.height ?? null,
|
|
74767
|
+
prod: blank,
|
|
74768
|
+
cand: blank,
|
|
74769
|
+
size: { prod: null, cand: null, matched: false },
|
|
74770
|
+
diffPixels: null,
|
|
74771
|
+
pctDiff: null,
|
|
74772
|
+
noiseFloorPixels: null,
|
|
74773
|
+
maskedCoverage: null,
|
|
74774
|
+
boundingBox: null,
|
|
74775
|
+
hotspots: [],
|
|
74776
|
+
findings: [],
|
|
74777
|
+
heatmapPath: null
|
|
74778
|
+
};
|
|
74779
|
+
}
|
|
74780
|
+
function artifactPaths(outDir, prefix, label) {
|
|
74781
|
+
const at = (suffix) => resolve12(outDir, `${prefix}-${label}-${suffix}.png`);
|
|
74782
|
+
return {
|
|
74783
|
+
prod: at("prod"),
|
|
74784
|
+
prodRepeat: at("prod-repeat"),
|
|
74785
|
+
cand: at("cand"),
|
|
74786
|
+
diff: at("diff"),
|
|
74787
|
+
noise: at("noise"),
|
|
74788
|
+
prodMasked: at("prod-masked"),
|
|
74789
|
+
candMasked: at("cand-masked")
|
|
74790
|
+
};
|
|
74791
|
+
}
|
|
74792
|
+
function judgePair(args) {
|
|
74793
|
+
const { spec, paths, prod, cand } = args;
|
|
74794
|
+
const base = {
|
|
74795
|
+
label: spec.label,
|
|
74796
|
+
width: spec.size?.width ?? null,
|
|
74797
|
+
height: spec.size?.height ?? null,
|
|
74798
|
+
prod,
|
|
74799
|
+
cand,
|
|
74800
|
+
size: { prod: null, cand: null, matched: false },
|
|
74801
|
+
diffPixels: null,
|
|
74802
|
+
pctDiff: null,
|
|
74803
|
+
noiseFloorPixels: null,
|
|
74804
|
+
maskedCoverage: null,
|
|
74805
|
+
boundingBox: null,
|
|
74806
|
+
hotspots: [],
|
|
74807
|
+
findings: [],
|
|
74808
|
+
heatmapPath: null
|
|
74809
|
+
};
|
|
74810
|
+
const blocked = firstBlocker(prod, cand);
|
|
74811
|
+
if (blocked)
|
|
74812
|
+
return { ...base, verdict: "inconclusive", reason: blocked };
|
|
74813
|
+
if (!args.prodRepeatScreenshot) {
|
|
74814
|
+
return {
|
|
74815
|
+
...base,
|
|
74816
|
+
verdict: "inconclusive",
|
|
74817
|
+
reason: `prod's second capture is missing, so its noise floor is unknown and zero cannot be demanded${args.prodRepeatError ? ` (${args.prodRepeatError})` : ""}`
|
|
74818
|
+
};
|
|
74819
|
+
}
|
|
74820
|
+
let noiseFloorPixels;
|
|
74821
|
+
let maskedCoverage;
|
|
74822
|
+
let comparePaths;
|
|
74823
|
+
try {
|
|
74824
|
+
const mask = buildNoiseMask(prod.screenshot, args.prodRepeatScreenshot);
|
|
74825
|
+
if (!mask) {
|
|
74826
|
+
return {
|
|
74827
|
+
...base,
|
|
74828
|
+
verdict: "inconclusive",
|
|
74829
|
+
reason: "prod is not a stable size across two captures — the page was still growing"
|
|
74830
|
+
};
|
|
74831
|
+
}
|
|
74832
|
+
noiseFloorPixels = mask.masked;
|
|
74833
|
+
maskedCoverage = mask.coverage;
|
|
74834
|
+
if (mask.coverage > MAX_MASK_COVERAGE) {
|
|
74835
|
+
return {
|
|
74836
|
+
...base,
|
|
74837
|
+
noiseFloorPixels,
|
|
74838
|
+
maskedCoverage,
|
|
74839
|
+
verdict: "inconclusive",
|
|
74840
|
+
reason: `prod could not reproduce ${(mask.coverage * 100).toFixed(1)}% of the frame across two captures (${mask.masked} px) — too much of the page is in motion to hold the candidate to anything (noise heatmap: ${paths.noise})`
|
|
74841
|
+
};
|
|
74842
|
+
}
|
|
74843
|
+
if (mask.masked > 0) {
|
|
74844
|
+
applyMask(prod.screenshot, mask, paths.prodMasked);
|
|
74845
|
+
applyMask(cand.screenshot, mask, paths.candMasked);
|
|
74846
|
+
comparePaths = { prod: paths.prodMasked, cand: paths.candMasked };
|
|
74847
|
+
} else {
|
|
74848
|
+
comparePaths = { prod: prod.screenshot, cand: cand.screenshot };
|
|
74849
|
+
}
|
|
74850
|
+
} catch (err) {
|
|
74851
|
+
return {
|
|
74852
|
+
...base,
|
|
74853
|
+
verdict: "inconclusive",
|
|
74854
|
+
reason: `prod's self-check failed: ${err.message}`
|
|
74855
|
+
};
|
|
74856
|
+
}
|
|
74857
|
+
let diff;
|
|
74858
|
+
try {
|
|
74859
|
+
diff = diffScreenshots(comparePaths.prod, comparePaths.cand, paths.diff, {
|
|
74860
|
+
threshold: 0,
|
|
74861
|
+
maxPctDiff: 0
|
|
74862
|
+
});
|
|
74863
|
+
} catch (err) {
|
|
74864
|
+
return {
|
|
74865
|
+
...base,
|
|
74866
|
+
noiseFloorPixels,
|
|
74867
|
+
maskedCoverage,
|
|
74868
|
+
verdict: "inconclusive",
|
|
74869
|
+
reason: `could not compare the screenshots: ${err.message}`
|
|
74870
|
+
};
|
|
74871
|
+
}
|
|
74872
|
+
const size = { prod: diff.prodSize, cand: diff.candSize, matched: !diff.cropped };
|
|
74873
|
+
if (diff.cropped) {
|
|
74874
|
+
return {
|
|
74875
|
+
...base,
|
|
74876
|
+
size,
|
|
74877
|
+
noiseFloorPixels,
|
|
74878
|
+
maskedCoverage,
|
|
74879
|
+
heatmapPath: paths.diff,
|
|
74880
|
+
verdict: "inconclusive",
|
|
74881
|
+
reason: `different dimensions (prod ${fmtSize(diff.prodSize)}, cand ${fmtSize(diff.candSize)}) — the comparison would only look at the intersection`
|
|
74882
|
+
};
|
|
74883
|
+
}
|
|
74884
|
+
const analysis = analyzeHeatmapRegions(paths.diff, { minComponentPixels: 1 });
|
|
74885
|
+
return {
|
|
74886
|
+
...base,
|
|
74887
|
+
size,
|
|
74888
|
+
noiseFloorPixels,
|
|
74889
|
+
maskedCoverage,
|
|
74890
|
+
diffPixels: diff.diffPixels,
|
|
74891
|
+
pctDiff: diff.pctDiff,
|
|
74892
|
+
boundingBox: analysis.boundingBox,
|
|
74893
|
+
hotspots: analysis.hotspots,
|
|
74894
|
+
findings: explainHotspots(analysis.hotspots, prod, cand, paths, args.prodBoxTree, args.candBoxTree),
|
|
74895
|
+
heatmapPath: paths.diff,
|
|
74896
|
+
verdict: diff.diffPixels === 0 ? "identical" : "differs",
|
|
74897
|
+
reason: diff.diffPixels === 0 ? undefined : `${diff.diffPixels} differing pixels in ${analysis.hotspots.length} region(s)`
|
|
74898
|
+
};
|
|
74899
|
+
}
|
|
74900
|
+
function explainHotspots(hotspots, prod, cand, paths, prodBoxTree, candBoxTree) {
|
|
74901
|
+
if (hotspots.length === 0)
|
|
74902
|
+
return [];
|
|
74903
|
+
const p = prodBoxTree;
|
|
74904
|
+
const c = candBoxTree;
|
|
74905
|
+
const paired = p?.found && c?.found ? diffBoxTrees(p.nodes, c.nodes, { truncated: p.truncated || c.truncated }) : null;
|
|
74906
|
+
return attributeHotspots({
|
|
74907
|
+
hotspots,
|
|
74908
|
+
nodes: p?.found ? p.nodes : [],
|
|
74909
|
+
deltas: paired?.deltas ?? [],
|
|
74910
|
+
truncated: paired?.truncated ?? true,
|
|
74911
|
+
imageHostDelta: hostsOnOneSideOnly(prod.imageHosts, cand.imageHosts)
|
|
74912
|
+
});
|
|
74913
|
+
}
|
|
74914
|
+
function firstBlocker(prod, cand) {
|
|
74915
|
+
for (const [name, side] of [
|
|
74916
|
+
["prod", prod],
|
|
74917
|
+
["cand", cand]
|
|
74918
|
+
]) {
|
|
74919
|
+
if (side.error)
|
|
74920
|
+
return `${name}: ${side.error}`;
|
|
74921
|
+
if (side.matches !== null && side.matches !== 1) {
|
|
74922
|
+
return `${name}: selector '${side.selector}' matched ${side.matches} elements (must match exactly 1) — \`parity locate\` resolves which node each side means`;
|
|
74923
|
+
}
|
|
74924
|
+
if (!side.screenshot)
|
|
74925
|
+
return `${name}: no screenshot was produced`;
|
|
74926
|
+
}
|
|
74927
|
+
if (prod.devicePixelRatio !== cand.devicePixelRatio) {
|
|
74928
|
+
return `different deviceScaleFactor (prod ${prod.devicePixelRatio}x, cand ${cand.devicePixelRatio}x) — the same screen rasterised at different densities never matches pixel for pixel`;
|
|
74929
|
+
}
|
|
74930
|
+
for (const [name, side] of [
|
|
74931
|
+
["prod", prod],
|
|
74932
|
+
["cand", cand]
|
|
74933
|
+
]) {
|
|
74934
|
+
if (side.fontsStatus !== "loaded") {
|
|
74935
|
+
return `${name}: fonts were still loading (document.fonts.status = "${side.fontsStatus}")`;
|
|
74936
|
+
}
|
|
74937
|
+
}
|
|
74938
|
+
return null;
|
|
74939
|
+
}
|
|
74940
|
+
async function captureSide(browser, args) {
|
|
74941
|
+
const side = {
|
|
74942
|
+
selector: args.selector,
|
|
74943
|
+
matches: null,
|
|
74944
|
+
rect: null,
|
|
74945
|
+
screenshot: null,
|
|
74946
|
+
imageHosts: [],
|
|
74947
|
+
devicePixelRatio: 1,
|
|
74948
|
+
fontsStatus: "unknown"
|
|
74949
|
+
};
|
|
74950
|
+
let repeatScreenshot = null;
|
|
74951
|
+
let repeatError;
|
|
74952
|
+
let boxTree;
|
|
74953
|
+
const ctx = await newContext(browser, {
|
|
74954
|
+
viewport: args.spec.viewport,
|
|
74955
|
+
viewportSize: args.spec.size ?? undefined,
|
|
74956
|
+
deviceScaleFactor: 1
|
|
74957
|
+
});
|
|
74958
|
+
const page = await ctx.newPage();
|
|
74959
|
+
try {
|
|
74960
|
+
await page.goto(args.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
74961
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
74962
|
+
return;
|
|
74963
|
+
});
|
|
74964
|
+
if (args.waitMs > 0)
|
|
74965
|
+
await page.waitForTimeout(args.waitMs);
|
|
74966
|
+
await reloadIfOptionalFonts(page, args.waitMs);
|
|
74967
|
+
await waitForLayoutStable(page);
|
|
74968
|
+
await Promise.race([
|
|
74969
|
+
stabilizeCarousels(page).catch(() => {
|
|
74970
|
+
return;
|
|
74971
|
+
}),
|
|
74972
|
+
new Promise((r) => setTimeout(r, 3000))
|
|
74973
|
+
]);
|
|
74974
|
+
const scrollBudget = 30000;
|
|
74975
|
+
await Promise.race([
|
|
74976
|
+
scrollFullPage(page, scrollBudget).catch(() => {
|
|
74977
|
+
return;
|
|
74978
|
+
}),
|
|
74979
|
+
new Promise((r) => setTimeout(r, scrollBudget + 2000))
|
|
74980
|
+
]);
|
|
74981
|
+
await Promise.race([
|
|
74982
|
+
waitForSkeletonsToResolve(page, 5000).catch(() => {
|
|
74983
|
+
return;
|
|
74984
|
+
}),
|
|
74985
|
+
new Promise((r) => setTimeout(r, 5000))
|
|
74986
|
+
]);
|
|
74987
|
+
side.devicePixelRatio = await page.evaluate(() => window.devicePixelRatio);
|
|
74988
|
+
side.fontsStatus = await page.evaluate(() => document.fonts?.status ?? "unknown");
|
|
74989
|
+
if (args.selector) {
|
|
74990
|
+
const loc = page.locator(args.selector);
|
|
74991
|
+
side.matches = await loc.count();
|
|
74992
|
+
if (side.matches !== 1)
|
|
74993
|
+
return { side, repeatScreenshot };
|
|
74994
|
+
side.rect = await loc.first().boundingBox({ timeout: 3000 });
|
|
74995
|
+
const err = await captureSectionScreenshot(page, args.selector, args.outPath);
|
|
74996
|
+
if (err)
|
|
74997
|
+
side.error = err;
|
|
74998
|
+
else
|
|
74999
|
+
side.screenshot = args.outPath;
|
|
75000
|
+
} else {
|
|
75001
|
+
await page.screenshot({ path: args.outPath, fullPage: true, animations: "disabled" });
|
|
75002
|
+
side.screenshot = args.outPath;
|
|
75003
|
+
}
|
|
75004
|
+
boxTree = await readBoxTree(page, args.selector ?? "body").catch(() => {
|
|
75005
|
+
return;
|
|
75006
|
+
});
|
|
75007
|
+
side.imageHosts = await readImageHosts(page, args.selector);
|
|
75008
|
+
if (args.repeatPath && side.screenshot) {
|
|
75009
|
+
await page.waitForTimeout(600);
|
|
75010
|
+
if (args.selector) {
|
|
75011
|
+
const err = await captureSectionScreenshot(page, args.selector, args.repeatPath);
|
|
75012
|
+
if (err)
|
|
75013
|
+
repeatError = err;
|
|
75014
|
+
else
|
|
75015
|
+
repeatScreenshot = args.repeatPath;
|
|
75016
|
+
} else {
|
|
75017
|
+
await page.screenshot({ path: args.repeatPath, fullPage: true, animations: "disabled" });
|
|
75018
|
+
repeatScreenshot = args.repeatPath;
|
|
75019
|
+
}
|
|
75020
|
+
}
|
|
75021
|
+
} catch (err) {
|
|
75022
|
+
side.error = err.message;
|
|
75023
|
+
repeatError ??= err.message;
|
|
75024
|
+
} finally {
|
|
75025
|
+
await page.close().catch(() => {
|
|
75026
|
+
return;
|
|
75027
|
+
});
|
|
75028
|
+
await ctx.close().catch(() => {
|
|
75029
|
+
return;
|
|
75030
|
+
});
|
|
75031
|
+
}
|
|
75032
|
+
return { side, repeatScreenshot, repeatError, boxTree };
|
|
75033
|
+
}
|
|
75034
|
+
async function readImageHosts(page, selector) {
|
|
75035
|
+
return page.evaluate((sel) => {
|
|
75036
|
+
const root = sel ? document.querySelector(sel) : document.body;
|
|
75037
|
+
if (!root)
|
|
75038
|
+
return [];
|
|
75039
|
+
const hosts = new Set;
|
|
75040
|
+
for (const img of Array.from(root.querySelectorAll("img"))) {
|
|
75041
|
+
const urls = [img.getAttribute("src"), ...(img.getAttribute("srcset") ?? "").split(",")];
|
|
75042
|
+
for (const raw of urls) {
|
|
75043
|
+
const url = raw?.trim().split(/\s+/)[0];
|
|
75044
|
+
if (!url)
|
|
75045
|
+
continue;
|
|
75046
|
+
try {
|
|
75047
|
+
hosts.add(new URL(url, document.baseURI).host);
|
|
75048
|
+
} catch {}
|
|
75049
|
+
}
|
|
75050
|
+
}
|
|
75051
|
+
return Array.from(hosts).sort();
|
|
75052
|
+
}, selector).catch(() => []);
|
|
75053
|
+
}
|
|
75054
|
+
function hostsOnOneSideOnly(prod, cand) {
|
|
75055
|
+
const d = imageHostDelta(prod, cand);
|
|
75056
|
+
return [...d.onlyProd, ...d.onlyCand];
|
|
75057
|
+
}
|
|
75058
|
+
function fmtSize(size) {
|
|
75059
|
+
return `${size[0]}×${size[1]}`;
|
|
75060
|
+
}
|
|
75061
|
+
function isValidUrl5(s) {
|
|
75062
|
+
try {
|
|
75063
|
+
new URL(s);
|
|
75064
|
+
return true;
|
|
75065
|
+
} catch {
|
|
75066
|
+
return false;
|
|
75067
|
+
}
|
|
75068
|
+
}
|
|
75069
|
+
var MARK = {
|
|
75070
|
+
identical: chalk30.green("✓"),
|
|
75071
|
+
differs: chalk30.red("✗"),
|
|
75072
|
+
inconclusive: chalk30.yellow("?")
|
|
75073
|
+
};
|
|
75074
|
+
function printReport(report) {
|
|
75075
|
+
console.log("");
|
|
75076
|
+
console.log(chalk30.bold(` parity heatmap — ${report.mode}`));
|
|
75077
|
+
console.log(chalk30.dim(` prod: ${report.prodUrl}`));
|
|
75078
|
+
console.log(chalk30.dim(` cand: ${report.candUrl}`));
|
|
75079
|
+
console.log("");
|
|
75080
|
+
for (const v of report.viewports) {
|
|
75081
|
+
const detail = v.verdict === "identical" ? chalk30.dim("0 pixels") : v.reason ?? chalk30.dim("no detail");
|
|
75082
|
+
console.log(` ${MARK[v.verdict]} ${v.label.padEnd(12)} ${detail}`);
|
|
75083
|
+
if (v.maskedCoverage != null && v.maskedCoverage > 0) {
|
|
75084
|
+
console.log(chalk30.dim(` ${(v.maskedCoverage * 100).toFixed(1)}% of the frame excluded: prod does not reproduce those pixels`));
|
|
75085
|
+
}
|
|
75086
|
+
for (const f of v.findings.slice(0, 5)) {
|
|
75087
|
+
console.log(chalk30.dim(` [${f.type}] ${f.summary}`));
|
|
75088
|
+
}
|
|
75089
|
+
if (v.heatmapPath && v.verdict === "differs") {
|
|
75090
|
+
console.log(chalk30.dim(` ${v.heatmapPath}`));
|
|
75091
|
+
}
|
|
75092
|
+
const hosts = imageHostDelta(v.prod.imageHosts, v.cand.imageHosts);
|
|
75093
|
+
if (hosts.onlyProd.length > 0 || hosts.onlyCand.length > 0) {
|
|
75094
|
+
console.log(chalk30.yellow(` image hosts diverge — ${formatHostDelta(hosts)}`));
|
|
75095
|
+
}
|
|
75096
|
+
}
|
|
75097
|
+
console.log("");
|
|
75098
|
+
console.log(` ${MARK[report.verdict]} ${chalk30.bold(report.verdict)}${report.reason ? ` — ${report.reason}` : ""}`);
|
|
75099
|
+
console.log("");
|
|
75100
|
+
}
|
|
75101
|
+
function imageHostDelta(prod, cand) {
|
|
75102
|
+
const inProd = new Set(prod);
|
|
75103
|
+
const inCand = new Set(cand);
|
|
75104
|
+
return {
|
|
75105
|
+
onlyProd: prod.filter((h) => !inCand.has(h)).sort(),
|
|
75106
|
+
onlyCand: cand.filter((h) => !inProd.has(h)).sort()
|
|
75107
|
+
};
|
|
75108
|
+
}
|
|
75109
|
+
function formatHostDelta(d) {
|
|
75110
|
+
const parts = [];
|
|
75111
|
+
if (d.onlyProd.length)
|
|
75112
|
+
parts.push(`prod only: ${d.onlyProd.join(", ")}`);
|
|
75113
|
+
if (d.onlyCand.length)
|
|
75114
|
+
parts.push(`cand only: ${d.onlyCand.join(", ")}`);
|
|
75115
|
+
return parts.join(" · ");
|
|
75116
|
+
}
|
|
75117
|
+
|
|
75118
|
+
// src/commands/states.ts
|
|
75119
|
+
import chalk31 from "chalk";
|
|
74208
75120
|
var HOVERABLE = "a,button,summary,[role='button'],[role='menuitem'],label";
|
|
74209
75121
|
var SETTLE_RETRY_FACTOR = 4;
|
|
74210
75122
|
async function readStateEffects(page, opts) {
|
|
@@ -74425,7 +75337,7 @@ function statesVerdict(counts) {
|
|
|
74425
75337
|
async function statesCommand(opts) {
|
|
74426
75338
|
const viewport = parseViewport3(opts.viewport);
|
|
74427
75339
|
if (!viewport) {
|
|
74428
|
-
console.error(
|
|
75340
|
+
console.error(chalk31.red(`--viewport inválido: ${opts.viewport}`));
|
|
74429
75341
|
return 2;
|
|
74430
75342
|
}
|
|
74431
75343
|
const waitMs = Number.parseInt(opts.wait, 10) || 0;
|
|
@@ -74434,12 +75346,12 @@ async function statesCommand(opts) {
|
|
|
74434
75346
|
const prodSelector = opts.prodSelector?.trim() || opts.selector?.trim();
|
|
74435
75347
|
const candSelector = opts.candSelector?.trim() || opts.selector?.trim();
|
|
74436
75348
|
if (!prodSelector || !candSelector) {
|
|
74437
|
-
console.error(
|
|
75349
|
+
console.error(chalk31.red(" informe --selector (ambos os lados) ou --prod-selector e --cand-selector"));
|
|
74438
75350
|
return 2;
|
|
74439
75351
|
}
|
|
74440
75352
|
const { aliases, note: aliasNote } = resolveAliases(opts.planDir);
|
|
74441
75353
|
if (aliasNote)
|
|
74442
|
-
console.log(
|
|
75354
|
+
console.log(chalk31.dim(` ${aliasNote}`));
|
|
74443
75355
|
const browser = await launchBrowser({ headless: true });
|
|
74444
75356
|
try {
|
|
74445
75357
|
const [prodSide, candSide] = await Promise.all([
|
|
@@ -74462,7 +75374,7 @@ async function statesCommand(opts) {
|
|
|
74462
75374
|
]);
|
|
74463
75375
|
if (prodSide.baseError || candSide.baseError) {
|
|
74464
75376
|
const which = prodSide.baseError ? `prod: ${prodSide.baseError}` : `cand: ${candSide.baseError}`;
|
|
74465
|
-
console.error(
|
|
75377
|
+
console.error(chalk31.red(` não foi possível ler o componente — ${which}`));
|
|
74466
75378
|
return 2;
|
|
74467
75379
|
}
|
|
74468
75380
|
const motion = prodSide.motion.found && candSide.motion.found ? diffMotion(prodSide.motion, candSide.motion, {
|
|
@@ -74499,58 +75411,58 @@ async function statesCommand(opts) {
|
|
|
74499
75411
|
]) {
|
|
74500
75412
|
const caveat = data.settle && formatSettleCaveat(name, data.settle);
|
|
74501
75413
|
if (caveat)
|
|
74502
|
-
console.log(
|
|
75414
|
+
console.log(chalk31.yellow(` ${caveat}`));
|
|
74503
75415
|
}
|
|
74504
75416
|
console.log("");
|
|
74505
|
-
console.log(
|
|
75417
|
+
console.log(chalk31.bold(" Declared motion"));
|
|
74506
75418
|
if (!motion) {
|
|
74507
75419
|
const err = prodSide.motion.found ? candSide.motion : prodSide.motion;
|
|
74508
|
-
console.log(
|
|
75420
|
+
console.log(chalk31.yellow(` não foi possível comparar — ${"error" in err ? err.error : "?"}`));
|
|
74509
75421
|
} else {
|
|
74510
75422
|
for (const line of formatMotionDiff(motion).split(`
|
|
74511
75423
|
`))
|
|
74512
75424
|
console.log(` ${line}`);
|
|
74513
75425
|
}
|
|
74514
75426
|
console.log("");
|
|
74515
|
-
console.log(
|
|
75427
|
+
console.log(chalk31.bold(` Hover effects (${prodSide.effects.length} prod / ${candSide.effects.length} cand)`));
|
|
74516
75428
|
const nothing = effects.lost.length === 0 && effects.changed.length === 0 && effects.added.length === 0 && effects.unpaired.length === 0;
|
|
74517
75429
|
if (nothing && !exercised) {
|
|
74518
|
-
console.log(
|
|
75430
|
+
console.log(chalk31.yellow(" INCONCLUSIVE — no hover changed anything on either side, so nothing was exercised. Check the selector holds an interactive element."));
|
|
74519
75431
|
} else if (nothing) {
|
|
74520
75432
|
console.log(" clean — every hover that changes something in prod changes the same in cand");
|
|
74521
75433
|
}
|
|
74522
75434
|
for (const e of effects.lost) {
|
|
74523
|
-
console.log(
|
|
75435
|
+
console.log(chalk31.red(` LOST ${e.target}${e.label ? ` (${e.label})` : ""} — prod moves [${e.properties.join(", ")}]; cand's element was hovered and moved nothing`));
|
|
74524
75436
|
}
|
|
74525
75437
|
for (const { prod, extra, notComparable, onElement } of effects.changed) {
|
|
74526
75438
|
console.log(` DIFFERS ${prod.target}${prod.label ? ` (${prod.label})` : ""}`);
|
|
74527
75439
|
if (onElement.length) {
|
|
74528
|
-
console.log(
|
|
75440
|
+
console.log(chalk31.yellow(` prod also moves [${onElement.join(", ")}] on the element itself`));
|
|
74529
75441
|
}
|
|
74530
75442
|
if (extra.length)
|
|
74531
75443
|
console.log(` cand also moves [${extra.join(", ")}]`);
|
|
74532
75444
|
if (notComparable.length) {
|
|
74533
|
-
console.log(
|
|
75445
|
+
console.log(chalk31.dim(` not comparable: [${notComparable.join(", ")}] — prod's hover renumbered ${prod.renumberedNodes} of the changed paths, so these were read on elements that are not the same ones before and after. Bench the component, or pick a selector whose subtree the hover does not restructure.`));
|
|
74534
75446
|
}
|
|
74535
75447
|
if (onElement.length === 0 && extra.length === 0) {
|
|
74536
|
-
console.log(
|
|
75448
|
+
console.log(chalk31.dim(" nothing comparable differs."));
|
|
74537
75449
|
}
|
|
74538
75450
|
}
|
|
74539
75451
|
for (const e of effects.unpaired) {
|
|
74540
|
-
console.log(
|
|
75452
|
+
console.log(chalk31.dim(` UNPAIRED ${e.target}${e.label ? ` (${e.label})` : ""} — prod moves [${e.properties.join(", ")}]; no matching element found on the cand side (not a defect — the port may have changed the element, or it is outside --selector)`));
|
|
74541
75453
|
}
|
|
74542
75454
|
for (const e of effects.added) {
|
|
74543
75455
|
console.log(` ADDED ${e.target} — cand moves [${e.properties.join(", ")}]; prod does not`);
|
|
74544
75456
|
}
|
|
74545
75457
|
if (effects.unpaired.length > 0 && effects.lost.length === 0 && effects.changed.length === 0) {
|
|
74546
75458
|
console.log("");
|
|
74547
|
-
console.log(
|
|
75459
|
+
console.log(chalk31.yellow(` ${effects.unpaired.length} prod effect(s) had no counterpart and NOTHING paired. That is a pairing failure, not a set of defects — check --selector contains the same component on both sides, and that ported roots carry data-section.`));
|
|
74548
75460
|
}
|
|
74549
75461
|
if (prodSide.ambient > 0 || candSide.ambient > 0) {
|
|
74550
|
-
console.log(
|
|
75462
|
+
console.log(chalk31.dim(` ${prodSide.ambient} prod / ${candSide.ambient} cand node+property pair(s) were moving with no interaction (carousel, autoplaying video, anything on a timer) and were subtracted. A large count means --selector contains something animating on its own; narrow it.`));
|
|
74551
75463
|
}
|
|
74552
75464
|
if (prodSide.truncated || candSide.truncated) {
|
|
74553
|
-
console.log(
|
|
75465
|
+
console.log(chalk31.dim(" TRUNCATED — element cap hit; absence of a finding is not proof"));
|
|
74554
75466
|
}
|
|
74555
75467
|
return inconclusive || effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
74556
75468
|
} finally {
|
|
@@ -74561,7 +75473,7 @@ async function statesCommand(opts) {
|
|
|
74561
75473
|
}
|
|
74562
75474
|
|
|
74563
75475
|
// src/commands/variance.ts
|
|
74564
|
-
import
|
|
75476
|
+
import chalk32 from "chalk";
|
|
74565
75477
|
|
|
74566
75478
|
// src/diff/variance.ts
|
|
74567
75479
|
var uniq2 = (xs) => [...new Set(xs)];
|
|
@@ -74665,7 +75577,7 @@ function formatVariance(report, opts = {}) {
|
|
|
74665
75577
|
// src/commands/variance.ts
|
|
74666
75578
|
function varianceCommand(opts) {
|
|
74667
75579
|
if (opts.runIds.length < 2) {
|
|
74668
|
-
console.error(
|
|
75580
|
+
console.error(chalk32.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
|
|
74669
75581
|
return 2;
|
|
74670
75582
|
}
|
|
74671
75583
|
const budget = Number.parseFloat(opts.scoreBudget ?? "1");
|
|
@@ -74674,7 +75586,7 @@ function varianceCommand(opts) {
|
|
|
74674
75586
|
try {
|
|
74675
75587
|
runs.push(loadRun(opts.output, id));
|
|
74676
75588
|
} catch (err) {
|
|
74677
|
-
console.error(
|
|
75589
|
+
console.error(chalk32.red(` ✖ ${err.message}`));
|
|
74678
75590
|
return 2;
|
|
74679
75591
|
}
|
|
74680
75592
|
}
|
|
@@ -74683,7 +75595,7 @@ function varianceCommand(opts) {
|
|
|
74683
75595
|
console.log(JSON.stringify({ ...report, stable: isStable(report, budget), scoreBudget: budget }));
|
|
74684
75596
|
} else {
|
|
74685
75597
|
console.log("");
|
|
74686
|
-
console.log(
|
|
75598
|
+
console.log(chalk32.bold(" Score variance"));
|
|
74687
75599
|
for (const line of formatVariance(report, { scoreBudget: budget }).split(`
|
|
74688
75600
|
`)) {
|
|
74689
75601
|
console.log(` ${line}`);
|
|
@@ -74695,10 +75607,10 @@ function varianceCommand(opts) {
|
|
|
74695
75607
|
}
|
|
74696
75608
|
|
|
74697
75609
|
// src/commands/vitals.ts
|
|
74698
|
-
import { existsSync as existsSync31, readFileSync as
|
|
75610
|
+
import { existsSync as existsSync31, readFileSync as readFileSync37, writeFileSync as writeFileSync32 } from "node:fs";
|
|
74699
75611
|
import { availableParallelism } from "node:os";
|
|
74700
75612
|
import { join as join41 } from "node:path";
|
|
74701
|
-
import
|
|
75613
|
+
import chalk33 from "chalk";
|
|
74702
75614
|
import ora9 from "ora";
|
|
74703
75615
|
|
|
74704
75616
|
// src/checks/agentic-nav.ts
|
|
@@ -74996,10 +75908,10 @@ async function vitalsCommand(opts) {
|
|
|
74996
75908
|
const runId = newRunId();
|
|
74997
75909
|
const paths = createRunDir(opts.output, runId);
|
|
74998
75910
|
const t0 = Date.now();
|
|
74999
|
-
console.log(
|
|
75911
|
+
console.log(chalk33.bold(`
|
|
75000
75912
|
parity vitals ${runId}`));
|
|
75001
|
-
console.log(
|
|
75002
|
-
console.log(
|
|
75913
|
+
console.log(chalk33.dim(` prod: ${opts.prod}`));
|
|
75914
|
+
console.log(chalk33.dim(` cand: ${opts.cand}`));
|
|
75003
75915
|
const discoverSpinner = ora9("Descobrindo páginas…").start();
|
|
75004
75916
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
75005
75917
|
if (pagePaths.length === 0) {
|
|
@@ -75031,7 +75943,7 @@ async function vitalsCommand(opts) {
|
|
|
75031
75943
|
completed++;
|
|
75032
75944
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
75033
75945
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
75034
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
75946
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk33.cyan("prod") : chalk33.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
75035
75947
|
}
|
|
75036
75948
|
});
|
|
75037
75949
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
@@ -75060,7 +75972,7 @@ async function vitalsCommand(opts) {
|
|
|
75060
75972
|
}
|
|
75061
75973
|
lhCompleted++;
|
|
75062
75974
|
const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
|
|
75063
|
-
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ?
|
|
75975
|
+
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk33.cyan("prod") : chalk33.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
75064
75976
|
});
|
|
75065
75977
|
lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
|
|
75066
75978
|
}
|
|
@@ -75125,7 +76037,7 @@ async function vitalsCommand(opts) {
|
|
|
75125
76037
|
writeRunReportJson(paths.runDir, run);
|
|
75126
76038
|
const html = renderHtmlReport(run, paths.runDir);
|
|
75127
76039
|
writeRunReportHtml(paths.runDir, html);
|
|
75128
|
-
|
|
76040
|
+
writeFileSync32(join41(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
75129
76041
|
schemaVersion: "0.1",
|
|
75130
76042
|
prodUrl: opts.prod,
|
|
75131
76043
|
candUrl: opts.cand,
|
|
@@ -75138,8 +76050,8 @@ async function vitalsCommand(opts) {
|
|
|
75138
76050
|
`, "utf8");
|
|
75139
76051
|
printSummary8(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
|
|
75140
76052
|
console.log("");
|
|
75141
|
-
console.log(
|
|
75142
|
-
console.log(
|
|
76053
|
+
console.log(chalk33.dim(` → ${paths.reportHtml}`));
|
|
76054
|
+
console.log(chalk33.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
75143
76055
|
console.log("");
|
|
75144
76056
|
if (opts.open) {
|
|
75145
76057
|
const { default: open } = await import("open");
|
|
@@ -75230,14 +76142,14 @@ function parseUrlList(input) {
|
|
|
75230
76142
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
75231
76143
|
const path = input.replace(/^file:\/\//, "");
|
|
75232
76144
|
if (existsSync31(path)) {
|
|
75233
|
-
return
|
|
76145
|
+
return readFileSync37(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
75234
76146
|
}
|
|
75235
76147
|
}
|
|
75236
76148
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
75237
76149
|
}
|
|
75238
76150
|
function printSummary8(vitals, cache, scores, opportunities, agentic) {
|
|
75239
76151
|
console.log("");
|
|
75240
|
-
console.log(
|
|
76152
|
+
console.log(chalk33.bold(" Summary:"));
|
|
75241
76153
|
console.log(` ${vitals.summary}`);
|
|
75242
76154
|
console.log(` ${cache.summary}`);
|
|
75243
76155
|
if (scores.status !== "skipped")
|
|
@@ -75529,6 +76441,20 @@ program.command("check").argument("<name>", "check name (kebab-case, e.g. consol
|
|
|
75529
76441
|
json: opts.json
|
|
75530
76442
|
}));
|
|
75531
76443
|
});
|
|
76444
|
+
program.command("heatmap").description("Is the candidate PIXEL-IDENTICAL to prod — yes, no, or 'nothing was compared'. Zero tolerance, no LLM, no flag to loosen it: one differing pixel fails. Sweeps mobile→2560px so a broken breakpoint cannot hide at the one size you checked, and captures prod twice first so a page that is not identical to itself reports its own noise floor instead of blaming the candidate. Use `parity section` to find out WHY something differs; use this to decide WHETHER it does.").requiredOption("--prod <url>", "Production URL (the reference)").requiredOption("--cand <url>", "Candidate URL").option("--selector <sel>", "Compare only this section instead of the whole page. Without it the comparison is full-page.").option("--cand-selector <sel>", "Selector on the CANDIDATE side, when the ported component no longer answers to --selector. Defaults to --selector.").option("--viewports <list>", "Comma-separated. Each entry is a preset (mobile|tablet|desktop) or a literal <width>x<height>. Every entry must be clean for the run to pass.", DEFAULT_VIEWPORTS).option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--pr <number>", "Publish the verdict as a PR comment, with the diff images inline. Reporting only — a failure to publish never changes the verdict or the exit code.").option("--repo <owner/name>", "Repo for --pr. Defaults to whatever `gh` infers from the cwd.").option("--out-dir <dir>", "Where to write the screenshots and heatmaps", "./parity-output/heatmap").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
76445
|
+
process.exit(await heatmapCommand({
|
|
76446
|
+
prod: opts.prod,
|
|
76447
|
+
cand: opts.cand,
|
|
76448
|
+
selector: opts.selector,
|
|
76449
|
+
candSelector: opts.candSelector,
|
|
76450
|
+
viewports: opts.viewports,
|
|
76451
|
+
wait: opts.wait,
|
|
76452
|
+
pr: opts.pr,
|
|
76453
|
+
repo: opts.repo,
|
|
76454
|
+
outDir: opts.outDir,
|
|
76455
|
+
json: opts.json
|
|
76456
|
+
}));
|
|
76457
|
+
});
|
|
75532
76458
|
program.command("section").description("Focused prod×cand comparison of one section: HTML diff + screenshot + computed-styles diff, plus an opt-in numeric box-tree diff (--box-tree). No flags = all 3 facets. Designed for the 'in DOM but invisible' debug loop (issue #31).").requiredOption("--prod <url>", "Production URL (base, e.g. https://www.example.com)").requiredOption("--cand <url>", "Candidate URL (base, e.g. https://example.deco-cx.workers.dev)").requiredOption("--selector <sel>", "CSS selector for the section to compare").option("--cand-selector <sel>", "CSS selector on the CANDIDATE side, when the ported component no longer matches --selector (VTEX IO class names → hashed CSS Modules, data-fs-* attributes, …). Defaults to --selector.").option("--output-html", "Include the HTML diff facet (default: on if no facet flag passed)", false).option("--screenshot", "Include the screenshot facet (locator screenshot per side)", false).option("--computed-styles", "Include the computed-styles diff facet", false).option("--heatmap", "Run pixelmatch on the two screenshots and analyze diff regions (bounding box + hotspots). Implies --screenshot.", false).option("--box-tree", "Walk the selector's whole subtree on both sides and report numeric box deltas, biggest first (`margin-top: 32px → 24px -8`). Deterministic, no LLM — this is the answer to 'everything is a little off', which a pixelmatch percentage and a vision paragraph cannot give.", false).option("--css-source", "For each divergent computed-style property, resolve which CSS rule (stylesheet + selector) produced it via CDP. Useful when the LLM needs to know which file to edit.", false).option("--prompt", "Emit an LLM-ready bundle: <prefix>-bundle.json (machine-readable) + <prefix>-prompt.md (opinionated Markdown with embedded images). Implies all signals.", false).option("--llm-summary", "After building the bundle, invoke Claude (needs ANTHROPIC_API_KEY) and print a 1-paragraph 'what I understood' summary. Does NOT generate a patch. Implies --prompt.", false).option("--all", "Turn on every diagnostic facet at once (html + screenshot + computed-styles + heatmap + css-source + prompt + llm-summary) — the pixel-perfect debug shortcut formerly known as `parity fix`. Issue #415.", false).option("--no-llm", "With --all, skip the LLM call (still writes the markdown bundle). Use when offline or to avoid API costs.").option("--viewport <viewport>", "mobile | desktop | tablet", "mobile").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--out-dir <dir>", "Where to write the screenshots", "./parity-output/sections").option("--plan-dir <dir>", "Run dir holding migration-plan.json. Its component rows are the only place the prod-side spelling of a component (`site/sections/Hero/HeroBannerV2.tsx`) and the cand-side one (`HeroSlideshow`) are written down together, so reading it lets the label pass pair nodes whose markup does not agree. Without it, unlabelled nodes fall back to the structural path.").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
75533
76459
|
process.exit(await sectionCommand({
|
|
75534
76460
|
planDir: opts.planDir,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.36",
|
|
4
4
|
"description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|