tools/visreg/run.sh re-renders every widget example the same way the pythondoc sweep did (Xvfb, import -window root, crop to window size), diffs each shot against its golden with ImageMagick RMSE (normalized, 0.5% threshold), and writes out/report.md + report.json with per-widget PASS/FAIL and diff percentages. Goldens vendored from the pythondoc sweep shots. Full run on a clean tree: 547/547 PASS, max diff 0.0%.
83 lines
3.3 KiB
Markdown
83 lines
3.3 KiB
Markdown
# Visual regression harness
|
||
|
||
One command, from the repo root:
|
||
|
||
```sh
|
||
tools/visreg/run.sh
|
||
```
|
||
|
||
It re-renders all 547 widget examples, diffs each new screenshot against
|
||
its golden, and writes `out/report.md` (+ `report.json`) with a per-widget
|
||
PASS/FAIL and the diff percentage. Exit code 0 = all pass, 1 = failures.
|
||
|
||
## How rendering works
|
||
|
||
The render path is the same one the pythondoc sweep used
|
||
(`/opt/lightgui-docs/pythondoc/drive.py`, `run_one`): each committed
|
||
example in `examples/<slug>.py` is run under Xvfb (1280x900x24, 6 workers
|
||
on displays :121–:126), left 2.5 s to settle, screenshotted with
|
||
`import -window root`, and cropped to the example window size
|
||
(`max(default_w + 32, 220)` x `max(default_h + 32, 120)`). A
|
||
`py_compile` check runs first; a traceback in the run log or an early
|
||
exit is a render failure, not a diff failure.
|
||
|
||
## How diffing works
|
||
|
||
`compare -metric RMSE golden new diff.png` (ImageMagick). The reported
|
||
number is the *normalized* RMSE as a percentage (0% = pixel-identical).
|
||
A widget PASSES when its diff is at or below the threshold
|
||
(default **0.5%**). Failing diff images are kept in `out/diffs/`
|
||
(passing ones are all-black, so they are deleted).
|
||
|
||
## Threshold calibration
|
||
|
||
Identical code does not produce bit-identical screenshots: font
|
||
rendering and anti-aliasing vary by a few pixels run to run. A threshold
|
||
is therefore required, and a false positive from anti-aliasing is a
|
||
harness bug, not a widget bug. The 0.5% default was calibrated on a
|
||
clean tree: the first full run (Dec 2, 2026) produced a 0.0% diff on
|
||
all 547 widgets — rendering under Xvfb is bit-deterministic here —
|
||
so 0.5% leaves a wide margin for font/anti-aliasing jitter while a
|
||
real drawing change moves far more pixels. If a clean-tree run ever
|
||
shows failures clustered just above the threshold, raise it in
|
||
`visreg.py` (`DEFAULT_THRESHOLD_PCT`) and re-run with `--diff-only` — do not
|
||
re-render to tune the threshold.
|
||
|
||
## Goldens
|
||
|
||
`goldens/` holds the 547 golden PNGs, vendored from the pythondoc sweep
|
||
shots (`/opt/lightgui-docs/pythondoc/work/shots/`). To bless a new set
|
||
of goldens after an intentional visual change, run the harness once,
|
||
inspect the diffs, then:
|
||
|
||
```sh
|
||
tools/visreg/run.sh --update-goldens
|
||
```
|
||
|
||
That copies the current shots over `goldens/`. Commit the updated
|
||
goldens with the code change that caused them.
|
||
|
||
## Options
|
||
|
||
```sh
|
||
tools/visreg/run.sh --diff-only # re-diff existing shots, no re-render
|
||
tools/visreg/run.sh --threshold 1.0 # FAIL above 1.0% normalized RMSE
|
||
tools/visreg/run.sh --workers 4 # fewer parallel Xvfb workers
|
||
tools/visreg/run.sh GtkButton GtkCalendar # only these widgets
|
||
tools/visreg/run.sh --render-only # render, skip diff/report
|
||
```
|
||
|
||
`VISREG_GOLDEN_DIR` / `VISREG_OUT_DIR` env vars override the golden and
|
||
output directories. `--golden-dir` / `--out-dir` flags do the same.
|
||
|
||
## Notes
|
||
|
||
- Goldens and new shots must be the same size; a size mismatch is a
|
||
FAIL with the dimensions in the reason (usually a `default_w`/`default_h`
|
||
change in the palette).
|
||
- `GtkInvisible` is invisible by design: its golden and its new shot are
|
||
both blank, so it passes with a 0% diff.
|
||
- If the codegen changes, regenerate the examples first
|
||
(`drive.py gen all` on the docs host) — this harness renders the
|
||
committed examples as-is.
|