diff --git a/README.md b/README.md index 14142af..1689384 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ renderdiff [options] | `--sitemap[=]` | Add the paths in the right side's sitemap. Default `/sitemap.xml`; give another URL or path with `=`. | | `--dry-run` | Print the URL pairs and exit. No browser. | | `--open` | Open the report when the run finishes. | -| `--progress` | A line per shot as it finishes, then the worst scores. The default on a terminal; piped, renderdiff prints one compact summary at the end. | +| `--progress` | A line per shot as it finishes, then the worst scores. The default on a terminal; piped, renderdiff prints one compact summary at the end, and `renderdiff: n/N shots` on stderr every tenth of the run. | | `--no-progress` | The compact summary even on a terminal. | | `-h, --help` / `-v, --version` | | diff --git a/docs/case-study.md b/docs/case-study.md index 6827161..c88ec13 100644 --- a/docs/case-study.md +++ b/docs/case-study.md @@ -182,10 +182,10 @@ not verified: dark mode, hover and focus states, the open mobile menu, and the p off the end of a truncated line. - **A flaky error on this site.** About 1 shot in 15 failed with `ERROR page.addStyleTag: Loading the script 'https://cloud.umami.is/script.js' violates … - Content Security Policy`. The site's own CSP blocks its own analytics script, and that - violation seems to land on renderdiff's style injection. It moves between routes and widths - from run to run, so `--rerun-failed` usually clears it and the next run brings a new one. - The message doesn't say which side failed. + Content Security Policy`. The site's own CSP blocks its own analytics script, and + Playwright's `addStyleTag` fails on any CSP violation logged while it runs, so it hit + whichever shot the script loaded during. Since fixed: renderdiff now injects its CSS as a + constructed stylesheet. - **Shots that can't be accepted.** The two long posts end up 1px shorter on some widths (`h-1 unaligned`). Accepting is documented not to cover unaligned height changes, so these stay red forever, but `--accept` said only `accepted 353 difference(s)` and didn't mention diff --git a/docs/github-action.md b/docs/github-action.md index 061a3d6..4d49d94 100644 --- a/docs/github-action.md +++ b/docs/github-action.md @@ -38,7 +38,7 @@ To run the action twice in one job, give each run its own `out` and `artifact-na matrix, put the matrix value in `artifact-name`. The action sets up Node 24, which later steps in the job then use. -Outputs: `exit-code` (0 pass, 1 a difference or below `threshold`, 2 bad input or an origin down, 3 a route +Outputs: `exit-code` (0 pass, 1 a difference or below `threshold`, 2 bad input or an origin down (at the start or mid-run), 3 a route errored) and `results` (the path to `results.json`). A Vercel preview behind Deployment Protection answers the runner with its login page: a diff --git a/docs/output.md b/docs/output.md index 217e673..99d4a4d 100644 --- a/docs/output.md +++ b/docs/output.md @@ -343,7 +343,8 @@ with `--rerun-failed`: rerun into a new `--out` and merge again. ## results.json Written on every run, errors included, one result per line (so `grep '"url":"/about"'` -pulls a route), scores rounded down to four decimals (so a shot that differs never reads as +pulls a route; the lines sit inside one JSON document and end in commas, so parse the whole +file, not each line), scores rounded down to four decimals (so a shot that differs never reads as `1`). Paths are relative to the out dir; results are in route-then-width order. Its types (`Results` and friends) are exported from the package. diff --git a/package.json b/package.json index a6a0bf7..23e2e3e 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "typecheck": "tsc --noEmit -p tsconfig.test.json", "prepare": "tsc", "test": "node --test tests/unit/*.test.ts", - "test:visual": "node --test --test-timeout=300000 tests/visual/*.test.ts", + "test:visual": "node --test --test-timeout=600000 tests/visual/*.test.ts", "test:all": "npm test && npm run test:visual", "lint": "oxlint --deny-warnings", "format": "oxfmt src tests renderdiff.config.example.ts", diff --git a/skills/renderdiff/SKILL.md b/skills/renderdiff/SKILL.md index 9aaa891..f75a82b 100644 --- a/skills/renderdiff/SKILL.md +++ b/skills/renderdiff/SKILL.md @@ -48,6 +48,8 @@ Pixels decide the score and the exit code in every mode. *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. + Hundreds of shots take many minutes: run it in the background and watch stderr's + `renderdiff: n/N shots` lines (`--progress` for a line per shot), not the PNG count. 4. **Decide every band, region, line and text line:** | It is | Do | diff --git a/skills/renderdiff/reference.md b/skills/renderdiff/reference.md index 80d7f3d..7eaa05b 100644 --- a/skills/renderdiff/reference.md +++ b/skills/renderdiff/reference.md @@ -35,8 +35,9 @@ results.json · Gotchas. ## Output -Piped (what an agent sees), stdout is one compact summary; `--progress` prints a line per shot -instead, `--no-progress` forces the summary on a terminal. +Piped (what an agent sees), stdout is one compact summary, and stderr gets +`renderdiff: n/N shots` every tenth of the run; `--progress` prints a line per shot instead, +`--no-progress` forces the summary on a terminal. ``` Routes: 3 @@ -124,7 +125,7 @@ Report (`--open`, for a human): green from 99.5%, amber to 97%, red below. | `not an HTML page: server sent … at …` | The route is a file (PDF, image, JSON, download), not a page. Drop it from the routes. Never retried. | | `page did not render on either side (…)` | Both sides under 200 chars of text and no visible image, SVG, canvas, video, iframe or form control. Usually a failed asset or an app that never mounted. One blank side isn't refused; it scores low. | | `page did not settle: Npx unstable at …` | Over 25% of the page kept changing, on two loads. `..unsettled-a/-b.png` are the two differing frames, and the message gives the box they differ in. Mask or stop the moving part. | -| `page is Npx tall at Wpx wide, past the …px sanity ceiling …` | Taller than 57,600,000px ÷ width (never under 40,000px): a runaway layout, not a page. | +| `page is Npx tall at Wpx wide, past the …px sanity ceiling …` | Taller than 57,600,000px ÷ width (never under 40,000px): a runaway layout, not a page. A long page still compares one element with `--selector` or `@sel` (`element is …` when that element itself is past it). | | `selector "…" matched N elements on left (/a), expected 1` | Make it unique (an id, `data-test`, `>> nth=0`), or list the route once per element. | | `selector "…" has no box on …` / `is off the page on …` | Matched an element not rendered (`display: none`, zero size) or outside the page. | | `before hook failed on left: …` | The hook threw (`beforeShot hook failed …` for that hook). Never retried. | @@ -250,7 +251,7 @@ aria: identical on 2 of 3 route(s), differs /pricing | --- | --- | | 0 | No unaccepted shot differs (with `--threshold`: none scores below it) and no route errored. Unstable pixels or a failed asset alone exit 0: read their rows. | | 1 | An unaccepted shot differs (with `--threshold`: scores below it; `--threshold 0` never fails). Also on an `--accept` run for what can't be accepted. Wins over 3. | -| 2 | Bad arguments or config; an origin not responding; a bad storage state or `renderdiff.accepted.json`; an out dir holding files renderdiff didn't write; `--rerun-failed` that doesn't repeat the last run; `merge` refusing. | +| 2 | Bad arguments or config; an origin not responding, at the start or mid-run (no report is written); a bad storage state or `renderdiff.accepted.json`; an out dir holding files renderdiff didn't write; `--rerun-failed` that doesn't repeat the last run; `merge` refusing. | | 3 | A route errored (unmeasured), or the run crashed (e.g. no browser). | ## Iterating @@ -359,7 +360,8 @@ One width (the first default without `--width`), no `--selector`, no `--out`. Ex ## results.json For scripts and drilling into one route; the loop doesn't need it. One result per line, so -`grep '"url":"/about"'` pulls a route. Paths are relative to the out dir. +`grep '"url":"/about"'` pulls a route, but the lines sit inside one JSON document and end in +commas: `JSON.parse` the whole file, not each line. Paths are relative to the out dir. - **Each result:** `url`, `left`, `right`, `selector` (`{ left, right }` or null), `hook`, `width`, `status` (`compared`, or `error` with `error`, and `frames` when it did not settle); `score`, `alignedScore`, diff --git a/src/capture.ts b/src/capture.ts index 8ee179f..4d3fe7b 100644 --- a/src/capture.ts +++ b/src/capture.ts @@ -244,6 +244,13 @@ export async function prepare(page: Page, cfg: ResolvedConfig, now: number): Pro }); } +/** Not addStyleTag: it fails on any CSP violation logged meanwhile, and a

Hung page guard rail

-

The page loads normally, then spins forever as soon as a style element is added to its head. Nothing after that point can run, so the shot has to be abandoned rather than waited on.

+

The page loads normally, then spins forever as soon as a stylesheet is adopted into the document. Nothing after that point can run, so the shot has to be abandoned rather than waited on.

Notes

@@ -20,7 +20,7 @@

Notes

diff --git a/tests/fixtures/pages/hang/right.html b/tests/fixtures/pages/hang/right.html index 65b7c52..4bee672 100644 --- a/tests/fixtures/pages/hang/right.html +++ b/tests/fixtures/pages/hang/right.html @@ -6,13 +6,13 @@

Hung page guard rail

-

The page loads normally, then spins forever as soon as a style element is added to its head. Nothing after that point can run, so the shot has to be abandoned rather than waited on.

+

The page loads normally, then spins forever as soon as a stylesheet is adopted into the document. Nothing after that point can run, so the shot has to be abandoned rather than waited on.

Notes

@@ -20,7 +20,7 @@

Notes

diff --git a/tests/helpers/corpus.ts b/tests/helpers/corpus.ts index d08cc97..72d54c4 100644 --- a/tests/helpers/corpus.ts +++ b/tests/helpers/corpus.ts @@ -34,6 +34,7 @@ export const GUARDRAILS = [ "lazy-js", "lazy-grow", "consent", + "csp", "drifting", "tracker", "clock", diff --git a/tests/visual/controls.test.ts b/tests/visual/controls.test.ts index 55d4ab4..95caa31 100644 --- a/tests/visual/controls.test.ts +++ b/tests/visual/controls.test.ts @@ -78,6 +78,13 @@ test("a difference exits 1 without a threshold, and is not an error", () => { assert.deepEqual(report.errors, []); }); +test("piped, stderr counts shots in tenths, ending at the total", () => { + const counts = [...run.stderr.matchAll(/^renderdiff: (\d+)\/(\d+) shots$/gm)]; + const total = CONTROLS.length * WIDTHS.length; + assert.ok(counts.length >= 2 && counts.length <= 10, context(run)); + assert.deepEqual(counts.at(-1)!.slice(1).map(Number), [total, total], context(run)); +}); + test("every control scores below parity", () => { const parity = report.cards.filter((c) => c.diffPixels === 0); assert.deepEqual( diff --git a/tests/visual/guardrails.test.ts b/tests/visual/guardrails.test.ts index bf1aafe..5403209 100644 --- a/tests/visual/guardrails.test.ts +++ b/tests/visual/guardrails.test.ts @@ -16,6 +16,7 @@ */ import assert from "node:assert/strict"; import fs from "node:fs"; +import http from "node:http"; import path from "node:path"; import sharp from "sharp"; import { after, before, describe, test } from "node:test"; @@ -300,6 +301,41 @@ describe("consent chrome", () => { }); }); +test("a page whose CSP refuses inline styles still gets renderdiff's CSS", async () => { + const run = await capture(["/csp"]); + assert.equal(run.code, 0, context(run)); + assert.equal(cardFor(run, "/csp").diffPixels, 0, context(run)); +}); + +describe("an origin that stops responding", () => { + test("aborts the run with exit 2 and names the side", async () => { + let served = 0; + const right = http.createServer((req, res) => { + res.setHeader("content-type", "text/html"); + if (req.method !== "GET") return res.end(); + res.end("

" + "Served once. ".repeat(30) + "

"); + if (++served === 1) { + right.close(); + right.closeAllConnections(); + } + }); + await new Promise((r) => right.listen(0, "127.0.0.1", r)); + const { port } = right.address() as { port: number }; + const run = await runCli([ + ...renderdiffArgs({ + left: site.left, + right: `http://127.0.0.1:${port}`, + routes: ["/", "/consent", "/csp"], + widths: [1440], + concurrency: 1, + }), + ]); + assert.equal(run.code, 2, context(run)); + assert.match(run.stderr, /✗ right \(http:\/\/127\.0\.0\.1:\d+\) stopped responding mid-run/); + assert.equal(run.report(), null, context(run)); + }); +}); + describe("the area ceiling", () => { test("a long page is compared at a narrow width and refused at a wide one", async () => { const run = await capture(["/long"], { widths: [375, 1440] }); @@ -312,6 +348,12 @@ describe("the area ceiling", () => { assert.match(wide.error, /50000px tall at 1440px wide, past the 40000px sanity ceiling/); }); + test("a selector on a page past the ceiling compares that element", async () => { + const run = await capture(["/long @h1"]); + assert.equal(run.code, 0, context(run)); + assert.equal(cardFor(run, "/long [h1]").diffPixels, 0, context(run)); + }); + test("a width past 1440 still gets the 40,000px ceiling", async () => { const run = await capture(["/long"], { widths: [2560] }); assert.equal(run.code, 0, context(run));