Skip to content

ci(storybook): make Visual Diff safe to require - #856

Merged
bntvllnt merged 7 commits into
mainfrom
ci/visual-gate-required
Dec 3, 2026
Merged

bntvllnt merged 7 commits into
mainfrom
ci/visual-gate-required

Conversation

@bntvllnt

@bntvllnt bntvllnt commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #736

Summary

Follow-up to #854, so that Visual Diff can be marked as a required check.

  • Always reports. The pull_request trigger no longer has a paths filter. A new first job, Visual Changes (changes), lists the PR's changed files (its merge commit against the base, using git diff --name-only, with no new action) and checks them against the base commit's copy of packages/ui/scripts/visual-diff/visual-paths.sh, so a PR cannot loosen the list that judges it. If the base has no copy, as on today's main, every job runs with a warning. Files are listed with --no-renames -z, so a file moved out of a visual path still counts, and names git would put in quotes (non-ASCII, newlines) are matched as they are. If nothing visual changed, every Storybook job is skipped and Visual Diff passes straight away with a notice. Otherwise it works as before: every shard must finish, exit 3 (a story failed to render) still fails even with the label, and exit 1 needs visual-change-approved. If the changed files cannot be listed or the base cannot be fetched, every job runs. If the script exits with anything other than 0 or 1, the job fails, and Visual Diff fails with it.
  • Wider path list. The old filter plus pnpm-lock.yaml, root package.json, pnpm-workspace.yaml (overrides and catalogs), .node-version, packages/ui/package.json, tailwind.config.ts, postcss.config.mjs, playwright-ct.config.ts, playwright/** (CT harness and Tailwind content) tsconfig.json, and packages/design/** (src/design-tokens.stories.tsx imports packages/design/tokens.json). The list is kept in one script, so the push trigger no longer has a duplicate paths copy: on main the same job checks the pushed range. The old copy had the same gaps (point 2 of the review).
  • CODEOWNERS. .github/CODEOWNERS covers .github/workflows/, itself, packages/ui/scripts/visual-diff/, packages/ui/.storybook/, packages/ui/playwright/ and playwright-ct.config.ts. The owner is bntvllnt, the repo's admin. The vllnt org has no teams. CODEOWNERS only enforces a review if "Require review from Code Owners" is turned on. Until then, a PR can still change its own copy of storybook.yml or run.mjs without that review. visual-paths.sh is already read from the base.
  • Docs: the PR playbook ("Visual diff (CI)") and AGENTS.md describe when the jobs run and who owns the gate.

Owner steps (after merge)

  1. Branch protection on main: turn on Require review from Code Owners.
  2. Add Visual Diff to the required status checks. Its context name is Visual Diff. Today the only required check is Privacy Guard.

Type of change

  • chore — tooling / CI / deps

Test plan

  • actionlint .github/workflows/storybook.yml: only the SC2034 warning that is already on main (i unused in the test-runner wait loop).
  • bash -n on visual-paths.sh. Stdin cases: docs-only gives exit 1; tailwind.config.ts, pnpm-lock.yaml, .node-version, src/**, .storybook/** and the workflow give exit 0; packages/ui-native/**, apps/registry/package.json and packages/ui/README.md give exit 1; empty input gives exit 1; a last line with no newline is still read.
  • Local simulation of the changes step on real merge commits: docs-only gives visual=false, tailwind.config.ts gives visual=true, and a push with an all-zero before warns and gives visual=true.
  • CI proofs on this PR (below)

Review fixes (head 3523138e)

An independent review of e8b12fbe found three ways a visual change could pass without screenshots, plus a PR judging itself with its own copy of the script. All four are fixed in 5aba914e; the docs follow in 3523138e. origin/main was merged in and had nothing new.

Local repro. The exact changes step script, taken from each commit's workflow, was run on PR-style merge commits (parent 1 = base, parent 2 = one throwaway change):

Case Before (e8b12fbe) After (5aba914e)
git mv packages/ui/themes/presets.css docs/brand-old.css visual=false ✗ visual=true (matched packages/ui/themes/presets.css)
new packages/ui/src/ünïcode.stories.tsx visual=false ✗ visual=true (matched the unquoted name)
edit packages/design/tokens.json visual=false ✗ visual=true
PR adds exit 1 to its own visual-paths.sh, plus a src edit visual=false ✗ visual=true (the base copy judged)
docs-only (docs/agents/LANES.md) visual=false visual=false (script exit 1)
base without the script (origin/main today) — warning, visual=true
base script exits 2 — the step fails, so Visual Diff fails ("did not finish")
push with an all-zero before — warning, visual=true

actionlint shows only the SC2034 warning that is already on main, and bash -n visual-paths.sh passes.

CI proofs (on e8b12fbe, before the review fixes)

Every PR that contains this change also changes storybook.yml and visual-paths.sh, and both are visual paths. So for (a) and (b), a throwaway commit first removed those two entries from the list. The rest of the logic was left unchanged.

Proof Head Run Result
(a) docs-only diff (list narrowed) 2bc7860a 47169166340 Visual Changes: visual=false (8 s). Visual Diff: success in 2 s with the notice "No file that can change rendered pixels changed…". Builds, tests and all 8 shards: skipped.
(b) + comment in packages/ui/tailwind.config.ts 196d872c 47169382156 Visual Changes printed only packages/ui/tailwind.config.ts, so visual=true. All 8 shards ran. Visual Diff: success (a comment changes no pixels).
(c) + Badge default padding px-2.5 → px-4, no label 98f15911 47173758421 Shards: success. Visual Diff: failure, 1708 same and 222 changed, "Shots differ from the base build…", exit 1.

e8b12fbe reverts all three throwaways. Its tree is identical to e59cc961, the real change. The label was never applied.

Not exercised in CI: the case where changes fails, so that Visual Diff reports "did not finish" and fails; and a push to main, which diffs before..HEAD and counts the push as visual when before cannot be fetched. That fallback was checked locally with an all-zero before.

The throwaway commits and the revert used --no-verify. The hook runs react-doctor on staged .ts files, and this worktree has no node_modules while the host load is around 20. The real commit e59cc961 went through the hook; it had no staged TS, so the hook did nothing.

Breaking changes

None. PRs that change no visual path now show skipped Storybook jobs and a passing Visual Diff, where before the workflow did not run at all.

Drop the pull_request paths filter so the Visual Diff check always reports
and can be required. A Visual Changes job checks the diff against
visual-paths.sh, which also covers dependencies, Tailwind, PostCSS, CT config
and .node-version; with nothing visual, Visual Diff passes at once. Add
CODEOWNERS for the workflows and the visual-diff scripts.
Reverts the Badge padding change, the tailwind.config.ts comment and the
narrowed visual path list used for the CI proofs.
List changed files with --no-renames -z so a move out of a visual path and
names git would quote are both seen, read them NUL-separated, run the base
commit's visual-paths.sh so a PR cannot loosen its own gate (no base copy
runs everything), and add packages/design for tokens.json.
@bntvllnt
bntvllnt merged commit e60b561 into main Dec 3, 2026
31 checks passed
@bntvllnt
bntvllnt deleted the ci/visual-gate-required branch December 3, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant