Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ the per-shot output when piped, `--no-progress` the summary on a terminal.
| `dom sel` | On both sides and unchanged in style or position, so its own pixels changed (an image or canvas). |
| `(re-parented)` | After a `dom` entry: paired across a structure change, so its properties may not be the cause. |
| `1 accepted` | That many of the shot's changes are accepted; the rest are new. |
| `findings: N repeated on 2+ routes` | After the routes: the same `dom` entry, text line or element-less band delta (`band -24px`) on two or more routes, once per line with `×N routes` and where (`/a@1440,375`, then `+N routes`), most widespread first, accepted ones aside. Top 20; `summary.findings` in results.json has them all. One cause behind many rows: fix it once. A selector names an element per page, so the same path may be a different element on another route: check one crop. |
| `computed: N findings` | With `--computed`: each `key prop left→right` once, with the routes and widths it was seen at; `dom identical`: the markup matches apart from asset hashes and generated class names, so look at CSS or script. See [below](#computed-styles---computed). |
| `crops …` | Up to 3 PNGs per comparison, bands first, relative to `results.json`. Left is on top or on the left, and the change is boxed in red. |
| `ERROR …` | Unmeasured, which is neither a pass nor a fail. Exits 3. |
Expand Down Expand Up @@ -262,8 +263,9 @@ identical or accepted, amber when it differs but doesn't fail (at or above `--th
red when it fails or errored; a route takes its worst width's colour. Without a threshold
any difference fails, so there is no amber. The summary on top counts routes, shots,
differing shots, errors, accepted and stale accepted; gives the mean and the worst score,
linked to its card; and lists only the differing shots, by route. With `--computed`, the
style findings sit collapsed under it. Then a card per shot, lowest score first.
linked to its card; and lists only the differing shots, by route. Findings repeated on two
or more routes, and with `--computed` the style findings, sit collapsed under it. Then a
card per shot, lowest score first.

## evidence.html

Expand Down Expand Up @@ -341,6 +343,7 @@ pulls a route), scores rounded down to four decimals (so a shot that differs nev
"differing": 1, // shots with any differing pixel, accepted ones aside
"accepted": 0, // shots whose every difference was accepted
"stale": [], // accepted entries the run measured but didn't see
"findings": [], // { finding, selector?, at: [{ url, widths }] }, seen on 2+ routes
"computed": [] // --computed: { key, prop, values: [left, right], at: [{ url, widths }] }
}
}
Expand Down
5 changes: 3 additions & 2 deletions skills/renderdiff/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ Pixels decide the score and the exit code in every mode.
3. **Change, run all routes at default widths, read each row in this order**: `ERROR` →
`failed` (a missing stylesheet or font explains the whole row: fix, rerun) → `text` →
`h`/`w`, `band`, `aligned`, `line` → `dom` (`sel prop l→r` is a computed value: find the
*rule*) → `computed:` → `Read` the `crops` for what `dom` doesn't explain (multi-width row:
widest and narrowest). Every token: § Output.
*rule*) → `findings:` (one cause on many routes: fix it once) → `computed:` → `Read` the
`crops` for what `dom` doesn't explain (multi-width row: widest and narrowest). Every
token: § Output.
4. **Decide every band, region, line and text line:**

| It is | Do |
Expand Down
7 changes: 5 additions & 2 deletions skills/renderdiff/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ accepted: /blog
dom -nav > a[href="/pricing"] "Pricing"
crops about.1440.c1.png
@375 ERROR HTTP 404 at http://localhost:3001/about
findings: … (a change seen on 2+ routes)
computed: … (with --computed, see below)
renderdiff: 1 of 3 routes differ (1 of 15 shots), 1 error, worst 97.41% /about@1440 — …/results.json
```
Expand Down Expand Up @@ -85,6 +86,7 @@ on stderr: `✗ 2 routes differ (10 shots).` (`below 97.00%` with `--threshold`)
| `unstable 1,204px` | Pixels that kept changing between shots of the same load on one origin (ticker, carousel, video with `--no-freeze-video`). Painted out on both sides, excluded from the score; the route is never clean. Large: a big area went unmeasured, look at the magenta in the full shots. |
| `1 accepted` | That many of the shot's bands and regions are accepted; the rest are new. `dom` names only the new. |
| `text +"x" -"y"` | Lines of visible text only on the left (`+`) / right (`-`), added first. Up to three, then `(+N more)`. Masked elements are left out. |
| `findings: N repeated on 2+ routes` | After the routes: each `dom` entry, text line or element-less `band -24px` seen on 2+ routes once, `×N routes /a@1440,375 …`, most widespread first, accepted aside; top 20, all in `summary.findings`. One cause: fix it once. The same selector can be a different element per route: check one crop. |

**`dom` entries** (left first, `;`-separated)

Expand Down Expand Up @@ -314,8 +316,9 @@ For scripts and drilling into one route; the loop doesn't need it. One result pe
`computedError`.
- **`summary`:** `compared`, `errors`, `mean` and `worst` (accepted shots aside),
`belowThreshold`, `differing` (unaccepted shots with any differing pixel; without
`--threshold`, any exits 1), `accepted`, `stale`, and with `--computed` `computed` (each
change once with `at: [{ url, widths }]`).
`--threshold`, any exits 1), `accepted`, `stale`, `findings` (each `dom` entry, text line
or element-less band on 2+ routes once: `finding`, `selector?`, `at: [{ url, widths }]`),
and with `--computed` `computed` (each change once with `at: [{ url, widths }]`).
- **`meta`:** origins, widths, threshold, `clock`, block patterns, hidden selectors, mask
reasons, `browser` (`chromium`, or `chrome` after a fallback), storage state file names,
`config` hash, `rightReplayedFrom`, `freezeVideo`, `platform`, `rerun` (`{ rerun, reused }` or
Expand Down
30 changes: 17 additions & 13 deletions src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ export function diffSnapshots(
const computedOf = (rs: RouteResult[]) =>
rs.filter((r): r is ComparedResult => r.status === "compared" && !!r.computed);

export function addAt(at: Finding["at"], r: RouteResult) {
const url = name(r);
const seen = at.find((a) => a.url === url);
if (seen) seen.widths.push(r.width);
else at.push({ url, widths: [r.width] });
}

/** Every change across routes and widths, one per (key, property, values), most widespread first. */
export function groupFindings(results: RouteResult[]): Finding[] {
const out = new Map<string, Finding>();
Expand All @@ -202,22 +209,25 @@ export function groupFindings(results: RouteResult[]): Finding[] {
const id = `${c.key}\0${c.prop}\0${c.values.join("\0")}`;
const f = out.get(id) ?? { ...c, at: [] };
out.set(id, f);
const url = name(r);
const at = f.at.find((a) => a.url === url);
if (at) at.widths.push(r.width);
else f.at.push({ url, widths: [r.width] });
addAt(f.at, r);
}
}
const shots = (f: Finding) => f.at.reduce((n, a) => n + a.widths.length, 0);
return [...out.values()].sort((a, b) => shots(b) - shots(a) || a.key.localeCompare(b.key));
}

/** Findings shown in the console summary; results.json has them all. */
const SHOWN = 20;
export const SHOWN = 20;
const AT_ROUTES = 3;
/** Unmatched routes, and keys per route, in the console summary. */
const UNMATCHED_SHOWN = 5;

export const fmtAt = (at: Finding["at"]) =>
at
.slice(0, AT_ROUTES)
.map((a) => `${a.url}@${a.widths.join(",")}`)
.join(" ") + (at.length > AT_ROUTES ? ` +${at.length - AT_ROUTES} routes` : "");

/** The console block: dom per route, then one line per finding, `left→right` like `dom`. */
export function fmtComputed(results: RouteResult[], routes: string[]): string[] {
const rows = results.filter(
Expand All @@ -243,14 +253,8 @@ export function fmtComputed(results: RouteResult[], routes: string[]): string[]
(differs.length ? `, differs ${differs.join(" ")}, so findings there are hints` : "") +
(failed.length ? `; snapshot failed on ${failed.join(" ")}` : ""),
];
for (const f of findings.slice(0, SHOWN)) {
const at = f.at
.slice(0, AT_ROUTES)
.map((a) => `${a.url}@${a.widths.join(",")}`)
.join(" ");
const more = f.at.length > AT_ROUTES ? ` +${f.at.length - AT_ROUTES} routes` : "";
out.push(` ${f.key} ${f.prop} ${f.values.join("→")} ${at}${more}`);
}
for (const f of findings.slice(0, SHOWN))
out.push(` ${f.key} ${f.prop} ${f.values.join("→")} ${fmtAt(f.at)}`);
if (findings.length > SHOWN) out.push(` (+${findings.length - SHOWN} more in results.json)`);
const cut = computedOf(rows).filter((r) => r.computed!.truncated);
if (cut.length)
Expand Down
67 changes: 66 additions & 1 deletion src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import fs from "node:fs";
import path from "node:path";
import sharp from "sharp";
import type { Accepted } from "./accept.ts";
import { fmtComputed, groupFindings, type ComputedDiff, type Finding } from "./computed.ts";
import {
addAt,
fmtAt,
fmtComputed,
groupFindings,
SHOWN,
type ComputedDiff,
type Finding,
} from "./computed.ts";
import type { Band, Box, Region, TextDiff } from "./compare.ts";
import { CONTEXT_OPTIONS, name, type Sides } from "./config.ts";
import type { ElementDiff } from "./locate.ts";
Expand Down Expand Up @@ -137,17 +145,66 @@ export interface Summary {
accepted: number;
/** Accepted differences for a measured route and width that weren't seen: prune them. */
stale: Accepted[];
/** Each pixel finding seen on two or more routes, once, with the routes and widths it was seen at. */
findings: PixelFinding[];
/** With `--computed`: each style change once, with the routes and widths it was seen at. */
computed?: Finding[];
}

/** An element change, text line or element-less band delta, as the summary prints it. */
export interface PixelFinding {
finding: string;
selector?: string;
at: Finding["at"];
}

/** The shape of `results.json`, written to the out dir on every run. */
export interface Results {
meta: RunMeta;
results: RouteResult[];
summary: Summary;
}

/** Unaccepted findings that repeat on two or more routes, most widespread first. */
export function pixelFindings(results: RouteResult[]): PixelFinding[] {
const out = new Map<string, PixelFinding>();
for (const r of results) {
if (r.status !== "compared" || r.accepted) continue;
const tokens = new Map<string, string | undefined>();
for (const g of [...(r.bands ?? []), ...r.regions]) {
if (g.accepted) continue;
for (const e of g.elements ?? []) tokens.set(fmtElements([e]), e.selector);
if ("side" in g && !g.elements?.length)
tokens.set(`band ${g.side === "left" ? "+" : "-"}${g.h}px`, undefined);
}
for (const t of r.text.added) tokens.set(`+"${t}"`, undefined);
for (const t of r.text.removed) tokens.set(`-"${t}"`, undefined);
for (const [finding, selector] of tokens) {
const f = out.get(finding) ?? { finding, ...(selector ? { selector } : {}), at: [] };
out.set(finding, f);
addAt(f.at, r);
}
}
const shots = (f: PixelFinding) => f.at.reduce((n, a) => n + a.widths.length, 0);
return [...out.values()]
.filter((f) => f.at.length >= 2)
.sort(
(a, b) =>
b.at.length - a.at.length || shots(b) - shots(a) || a.finding.localeCompare(b.finding),
);
}

/** The console block: one line per repeated finding, then where it was seen. */
export function fmtPixelFindings(results: RouteResult[]): string[] {
const findings = pixelFindings(results);
if (!findings.length) return [];
const out = [`findings: ${findings.length} repeated on 2+ routes`];
for (const f of findings.slice(0, SHOWN))
out.push(` ${f.finding} ×${f.at.length} routes ${fmtAt(f.at)}`);
if (findings.length > SHOWN) out.push(` (+${findings.length - SHOWN} more in results.json)`);
return out;
}

/** Sort ascending by score; surface the mean and the worst (lowest-scoring) row. */
export function stats(rows: ComparedResult[]) {
const sorted = [...rows].sort((a, b) => a.score - b.score);
Expand Down Expand Up @@ -197,6 +254,7 @@ export function writeResults(
differing: open.filter((r) => r.diffPixels > 0).length,
accepted: compared.filter((r) => r.accepted).length,
stale,
findings: pixelFindings(results),
...(compared.some((r) => "computed" in r) ? { computed: groupFindings(results) } : {}),
},
};
Expand Down Expand Up @@ -261,6 +319,7 @@ function summary(results: RouteResult[], meta: RunMeta, stale: Accepted[]): stri
const byRoute = Map.groupBy(stats(differing).sorted, name);
const routes = [...new Set(results.map(name))];
const computed = fmtComputed(results, routes);
const repeated = fmtPixelFindings(results);
return `<section class="summary">
<p class="counts">
${count(routes.length, "route(s)")}
Expand Down Expand Up @@ -289,6 +348,12 @@ ${
.join("\n")}</ul>`
: `<p class="good">No differing shots.</p>`
}
${
repeated.length
? `<details><summary>Findings: ${repeated[0]!.slice("findings: ".length)}</summary>
<pre class="computed">${esc(repeated.slice(1).join("\n"))}</pre></details>`
: ""
}
${
computed.length
? `<details><summary>Computed styles: ${groupFindings(results).length} finding(s)</summary>
Expand Down
9 changes: 8 additions & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { fmtBand, fmtElements, fmtFailed, fmtLine, fmtRegion, pct, signed } from "./format.ts";
import {
fails,
fmtPixelFindings,
stats,
writeReport,
writeResults,
Expand Down Expand Up @@ -790,6 +791,8 @@ function summarize(
for (const e of errors) console.log(` ${name(e)}@${e.width}: ${e.error}`);
}

const repeated = fmtPixelFindings(results);
if (repeated.length) console.log(`\n${repeated.join("\n")}`);
const computed = fmtComputed(results, routes);
if (computed.length) console.log(`\n${computed.join("\n")}`);
const varies = fmtVaries(results, routes);
Expand Down Expand Up @@ -886,7 +889,11 @@ export function compact(
}
if (accepted.length) out.unshift(`accepted: ${accepted.join(" ")}`);
if (clean.length) out.unshift(`clean: ${clean.join(" ")}`);
out.push(...fmtComputed(results, routes), ...fmtVaries(results, routes));
out.push(
...fmtPixelFindings(results),
...fmtComputed(results, routes),
...fmtVaries(results, routes),
);
const all = results.filter((r): r is ComparedResult => r.status === "compared");
const compared = all.filter((r) => !r.accepted);
const shots = compared.filter((r) => r.diffPixels > 0).length;
Expand Down
36 changes: 36 additions & 0 deletions tests/visual/controls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ test("results.json carries the run meta and a summary that matches the report",
Number((summary.worst!.score * 100).toFixed(2)) / 100,
Math.min(...report.cards.map((c) => c.score)),
);
// Each control is a different change, so none groups with another.
assert.deepEqual(summary.findings, [], context(run));
assert.doesNotMatch(run.stdout, /^findings:/m);
});

test("piped stdout is one compact summary: no clean routes, widths collapsed, a verdict", () => {
Expand Down Expand Up @@ -526,6 +529,39 @@ test("a threshold the run clears does not fail it", async () => {
assert.equal(r.code, 0, context(r));
});

test("a finding repeated on two routes is listed once, with every route and width", async () => {
const r = await runCli(
renderdiffArgs({
left: site.left,
right: site.right,
// The fixture server routes on the path, so both are /nav.
routes: ["/nav", "/nav?again"],
widths: WIDTHS,
}),
);
assert.equal(r.code, 1, context(r));
const at = [
{ url: "/nav", widths: WIDTHS },
{ url: "/nav?again", widths: WIDTHS },
];
assert.deepEqual(
results(r.outDir).summary.findings,
[
{ finding: '-"Pricing"', at },
{ finding: '-a[href="#pricing"] "Pricing"', selector: 'a[href="#pricing"]', at },
],
context(r),
);
assert.match(r.stdout, /^findings: 2 repeated on 2\+ routes$/m);
assert.ok(
r.stdout.includes(
'\n -a[href="#pricing"] "Pricing" ×2 routes /nav@1440,375 /nav?again@1440,375\n',
),
context(r),
);
assert.match(r.report()!, /Findings: 2 repeated/);
});

test("--computed names the changed rule's property, once across widths, and the dom verdict", async () => {
const r = await runCli([
...renderdiffArgs({
Expand Down
Loading