Add visual regression harness for all 547 widgets

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%.
This commit is contained in:
cnmcdee committed 2026-12-02 09:10:45 +00:00
1 parent bbc284d0bb
commit bfb366c083
551 files changed
+464

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Per-run output (screenshots, logs, diffs, report). Regenerated by run.sh.
out/
+82
View File
@@ -0,0 +1,82 @@
# 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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 624 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1001 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 915 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Loaded 100 of 551 files, more files were not shown because too many files have changed in this diff. Show more