ui_guardrails 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 792f503cf353ceaa71b9e45e39a4c3f9ae9255b40f4ecf361a207048074857e8
4
- data.tar.gz: ff563d0927467149ddc42011500457c7c637db11fc9770566db64e3a0a4427e2
3
+ metadata.gz: 9f34f9ff613f4b10edd128972a3ee8b268e82fee79abc499d7554d48bf834eec
4
+ data.tar.gz: 937199143fb681851d6493dc666ce9a381d4db83b247059e00e9b0dd91b8a901
5
5
  SHA512:
6
- metadata.gz: 3eb224a5d378469571b727813ac68adcacd95576c63bade906a29e4119f9c0b28e972dbbbcf3710acbb6d7647684b14250a28b61c0a52ca65fd2c96e4f435d3a
7
- data.tar.gz: 62c132501303b6cc6bcd5ffa8bf566955fc82cf6c4ed30ea3d1ad678ff4270841a57b636daf635035a38681a2e8797ab1e0018ceb62685a144aa840dc3aed238
6
+ metadata.gz: 8e6d87b9e1bac27c0f79f941343855806c0fb3a3c55b0191cfeb1e184a0b4b5cc6b09eb88ce4df2512ac646c1572f528da269dedacc56fd269f8a4b3ac7630eb
7
+ data.tar.gz: d50217306f64e883988ad9184adde4d02e274fc8262560aeab3b8a0c9eecd573bae847006c0a3383222020ab3d9281ba96d1720ea9019f17c3491bf21fcf08e1
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Guardrails
1
+ # UI-Guardrails
2
2
 
3
3
  A Rails toolset that prevents UI drift in AI-assisted applications. Static audits over your views, components, stylesheets, JS controllers, and tokens — surfacing the kinds of inconsistencies that compound silently as an AI assistant ships code faster than design-system discipline can keep up.
4
4
 
5
5
  Built and maintained by [Meticulous](https://meticulous.com).
6
6
 
7
- **Current release:** 1.0.0 — V0 + V1 + V2 complete, published on [RubyGems.org as `ui_guardrails`](https://rubygems.org/gems/ui_guardrails). The Ruby module stays `Guardrails` (so `require "guardrails"` is unchanged) — only the gem package name on rubygems carries the `ui_` prefix, to clear RubyGems' similarity rule against the unrelated [`guard-rails`](https://rubygems.org/gems/guard-rails) gem. See [`doc/ROADMAP.md`](doc/ROADMAP.md) for status, [`CHANGELOG.md`](CHANGELOG.md) for the full naming rationale.
7
+ **Current release:** 1.2.0 — V0 + V1 + V2 complete, published on [RubyGems.org as `ui_guardrails`](https://rubygems.org/gems/ui_guardrails). The Ruby module stays `Guardrails` (so `require "guardrails"` is unchanged) — only the gem package name on rubygems carries the `ui_` prefix, to clear RubyGems' similarity rule against the unrelated [`guard-rails`](https://rubygems.org/gems/guard-rails) gem. See [`doc/ROADMAP.md`](doc/ROADMAP.md) for status, [`CHANGELOG.md`](CHANGELOG.md) for the full naming rationale.
8
8
 
9
9
  ---
10
10
 
@@ -0,0 +1,226 @@
1
+ # Visual-diff integration — research memo
2
+
3
+ > Status: research, not implementation. Closes the V2 visual-diff item's "evaluate a stable visual-regression target" prerequisite before any code lands.
4
+ >
5
+ > Last updated: 2026-05-10
6
+
7
+ ## Executive summary
8
+
9
+ **Recommendation: ship a `Guardrails::VisualDiff` parser that consumes screenshot-diff tool output, the same way `Guardrails::A11yDeep` consumes axe-core JSON.** Don't bundle Chromium / Playwright / Capybara as runtime deps — that was the constraint that originally parked this item, and it hasn't changed.
10
+
11
+ The cleanest external producers to support, in priority order:
12
+
13
+ 1. **`snap_diff-capybara`** (formerly `capybara-screenshot-diff`) — the Rails-native default. Active gem (1.12.0 released April 2026), commits baselines to git, no cloud dep. Highest fit-for-purpose.
14
+ 2. **BackstopJS** — fully OSS, clean JSON output. Worth a second adapter for non-Rails-monolith projects (the Avo dogfood pattern).
15
+ 3. **Percy / Chromatic** — SaaS, vendor-locked. Defer until a user actually asks; webhook ingestion is the integration shape if they do.
16
+
17
+ The talk narrative writes itself: **static analysis catches the source, visual diff catches what the rendered DOM does next.** Pair this with `ClassItis` — AI-generated 8-class soup looks plausible in the source but pixel-shifts the baseline once a single utility is wrong.
18
+
19
+ ---
20
+
21
+ ## The constraint that shaped A11yDeep applies here too
22
+
23
+ When deferring deep a11y in the original roadmap, the call was:
24
+
25
+ > axe-core wrapper with `--deep` mode NOT shipped — would require Capybara + headless Chrome runtime deps.
26
+
27
+ Then in 0.6.0 we shipped `A11yDeep` as a **parser** for axe JSON output: zero new runtime deps, user runs axe however they already do, Guardrails provides the merge + report + exit-code contract. The same calculus applies to visual diff. Bundling Playwright/Chromium would balloon `bundle install` for users who don't run system tests; bundling Selenium would tie us to Ruby browser-driver decay. The right move is to consume what existing tools emit.
28
+
29
+ **Acceptance criteria for any candidate tool**, in priority order:
30
+
31
+ 1. **Emits a machine-readable diff summary** — JSON, JUnit XML, or a parseable HTML/filesystem layout. We need per-scenario: name, baseline path, current path, diff path (if any), mismatch % or pass/fail, optionally the URL/component selector.
32
+ 2. **Runs without Guardrails being involved.** The user's existing test toolchain runs the tool; we ingest the output. No shelling out to `npx`, no requiring the tool be present at audit time.
33
+ 3. **OSS-friendly licensing** *or* a stable public API for SaaS tools.
34
+ 4. **Active maintenance.** Sub-12-month release cadence and >50 GitHub stars as a rough proxy.
35
+
36
+ ---
37
+
38
+ ## Per-tool brief
39
+
40
+ ### snap_diff-capybara (Rails-native) — **PRIMARY RECOMMENDATION**
41
+
42
+ - **What it is:** Ruby gem (formerly `capybara-screenshot-diff`, now maintained at `github.com/snap-diff/snap_diff-capybara` by `donv` and `jetthoughts`). Latest 1.12.0, April 2026. MIT-licensed. ~770k total downloads.
43
+ - **How it works:** `screenshot "name"` inside Capybara system tests. Baselines live at `doc/screenshots/` and are **committed to git** — UI changes get reviewed in PR like code. No external auth, no cloud.
44
+ - **Diff artifacts:**
45
+ - `*.png` baseline
46
+ - `*.diff.png` (changed pixels highlighted red)
47
+ - `*.heatmap.diff.png` (pixel-variance density)
48
+ - **`snap_diff_report.html`** — interactive multi-view dashboard
49
+ - **CI flow:** Tests fail on baseline mismatch. There's a reusable GitHub Actions workflow that uploads the HTML report and posts PR comments. Ships its own baseline-update flow.
50
+ - **Runtime:** Ruby 3.2+, any Capybara-compatible driver (Selenium / Playwright / Cuprite). libvips 8.9+ for fast comparisons, falls back to ChunkyPNG.
51
+ - **For Guardrails to consume:** the HTML report has a fixed structure, but the gem doesn't (yet) emit a top-level JSON summary. **Either:**
52
+ - **(a)** ask upstream for a `snap_diff_report.json` companion to the HTML — small ask, this is the maintained gem
53
+ - **(b)** walk `doc/screenshots/` ourselves: pair `name.png` with `name.diff.png`, treat presence of the diff file as a failing finding
54
+ - **Fit:** ★★★★★. Same ecosystem (Ruby/Rails/Capybara), no new deps for users already running system tests, baselines-in-git matches the Guardrails ethos of "the source is the source of truth."
55
+
56
+ ### BackstopJS
57
+
58
+ - **What it is:** Node CLI, MIT-licensed, actively maintained, the dominant OSS visual-regression tool outside the Storybook ecosystem.
59
+ - **How it works:** `backstop init`, `backstop test`, `backstop approve`. Configured via `backstop.json` (scenarios = URL × viewport × selector). Headless Chrome via Puppeteer or Firefox/WebKit via Playwright. All artifacts local under `backstop_data/`.
60
+ - **Output:** HTML interactive report, **JSON report**, JUnit XML, CLI text. Exit 0/1.
61
+ - **For Guardrails to consume:** The JSON report already exists and is the canonical machine-readable output. Per-scenario: name, label, mismatch percentage, pass/fail, paths to reference + test + diff images.
62
+ - **Fit:** ★★★★☆. Native machine-readable output, no SaaS dep, but Node-only — Ruby/Rails shops would have a parallel toolchain. Justifiable for the "Rails frontend that already runs JS tooling" subset (any non-trivial Rails app).
63
+
64
+ ### Playwright `toHaveScreenshot` / `toMatchSnapshot`
65
+
66
+ - **What it is:** Built-in Playwright assertion. The team that maintains Playwright also maintains Chromatic (Microsoft → Storybook acquisition), so it's becoming the de facto cross-tool snapshot mechanism.
67
+ - **How it works:** `await expect(page).toHaveScreenshot()`. Stores baselines in `__screenshots__/`. Updates via `--update-snapshots`.
68
+ - **Output:** JUnit / JSON via Playwright's reporter API; HTML report; per-test pass/fail in CI.
69
+ - **For Guardrails to consume:** Playwright JSON reporter emits a structured test-result document; each failure includes `attachments` with the diff image path. Parseable, but the schema is "Playwright test results" not "visual diff" — we'd be extracting the visual subset.
70
+ - **Fit:** ★★★☆☆. Future-proof and increasingly canonical, but the integration is heavier (have to filter Playwright results for screenshot-specific failures). Worth supporting in v2 of the adapter.
71
+
72
+ ### Percy (BrowserStack)
73
+
74
+ - **What it is:** SaaS, all builds go through Percy's cloud. Originally a standalone product, BrowserStack-acquired in 2020.
75
+ - **Ruby story:** `percy-capybara` gem exists. Latest release v5.0.0 — July 2021 — i.e. **maintenance-stale**. 4+ years without a meaningful release; the active surface is the JS SDKs.
76
+ - **Output:** Dashboard URL + per-build webhook. No local artifacts beyond the snapshot upload.
77
+ - **Pricing:** Pricing page is gated behind BrowserStack's product navigation; no clear OSS-free tier surfaced via the public site. Assume paid-only for non-trial use.
78
+ - **For Guardrails to consume:** `build-finished` webhook payload is the integration shape — but that requires a receiver, which Guardrails-the-gem isn't. Could ship a parser for the webhook JSON that users POST to their CI.
79
+ - **Fit:** ★★☆☆☆. Stale Ruby SDK, vendor-locked, no clear OSS pricing. Defer until a user asks specifically.
80
+
81
+ ### Chromatic
82
+
83
+ - **What it is:** SaaS, made by the Storybook team. The standard visual-regression for Storybook-based component libraries; expanded to Playwright + Cypress in 2024–25.
84
+ - **Ruby story:** None. JS-ecosystem only. No Lookbook integration despite Lookbook being the Rails-shaped Storybook equivalent.
85
+ - **Output:** Cloud dashboard, web API for build status, no local artifacts.
86
+ - **Pricing:** Free tier (5,000 snapshots/month, Chrome-only) — generous. Paid starts at $179/mo. "Building in the open?" OSS plan available on application.
87
+ - **Fit:** ★★☆☆☆ for Rails apps without Storybook. ★★★★☆ for ViewComponent shops who use Storybook for non-Rails components alongside. Pair-of-tools story is workable but indirect; Lookbook integration would be the missing link, and that's a Lookbook upstream ask, not a Guardrails one.
88
+
89
+ ### Honorable mentions
90
+
91
+ - **Loki** — Storybook-only, narrow audience for Rails-flavored Guardrails. Skip.
92
+ - **`reg-suit`** — Cloud or self-hosted, language-agnostic, JSON report. Reasonable BackstopJS-alternative; not common enough in Rails shops to justify a dedicated adapter at v1.
93
+
94
+ ---
95
+
96
+ ## Fit table
97
+
98
+ | Tool | OSS | Rails-native | Machine-readable output | Cloud dep | Active | Fit score |
99
+ |---|---|---|---|---|---|---|
100
+ | snap_diff-capybara | ✅ MIT | ✅ Ruby gem | 🟡 HTML report (no JSON yet) | ❌ baselines in git | ✅ active | ★★★★★ |
101
+ | BackstopJS | ✅ MIT | ❌ Node | ✅ JSON report | ❌ local FS | ✅ active | ★★★★☆ |
102
+ | Playwright snapshots | ✅ Apache | ❌ Node | ✅ JSON via reporter | ❌ local FS | ✅ active | ★★★☆☆ |
103
+ | Percy | 🔒 SaaS | 🟡 stale gem (2021) | ✅ webhook | ✅ required | 🟡 webhooks active, SDK stale | ★★☆☆☆ |
104
+ | Chromatic | 🔒 SaaS | ❌ JS-only | ✅ API | ✅ required | ✅ active | ★★☆☆☆ |
105
+
106
+ ---
107
+
108
+ ## Proposed integration shape (mirrors A11yDeep)
109
+
110
+ ```
111
+ lib/guardrails/visual_diff.rb — parser + report
112
+ lib/guardrails/visual_diff/snap_diff.rb — adapter for snap_diff-capybara
113
+ lib/guardrails/visual_diff/backstop.rb — adapter for BackstopJS JSON
114
+ spec/guardrails/visual_diff_spec.rb
115
+ spec/guardrails/visual_diff/snap_diff_spec.rb
116
+ spec/guardrails/visual_diff/backstop_spec.rb
117
+ ```
118
+
119
+ Normalized `Finding` shape (across both adapters):
120
+
121
+ ```ruby
122
+ Finding = Struct.new(
123
+ :scenario, # "homepage", "checkout_cart"
124
+ :viewport, # "desktop"; nil if not applicable
125
+ :mismatch_ratio, # Float 0.0..1.0 (or nil for snap_diff which is pass/fail)
126
+ :baseline_path, # relative path on disk
127
+ :current_path, # relative path on disk
128
+ :diff_path, # relative path to .diff.png, nil if pass
129
+ :url, # optional, BackstopJS scenarios have URLs
130
+ :selector, # optional
131
+ keyword_init: true
132
+ )
133
+ ```
134
+
135
+ Rake task (mirrors `guardrails:a11y:deep`):
136
+
137
+ ```bash
138
+ # Either auto-detect from `doc/screenshots/` (snap_diff convention) ...
139
+ bundle exec rake guardrails:visual:deep
140
+
141
+ # ... or point at an explicit producer:
142
+ SNAP_DIFF_DIR=doc/screenshots bundle exec rake guardrails:visual:deep
143
+ BACKSTOP_JSON=backstop_data/html_report/jsonReport.json bundle exec rake guardrails:visual:deep
144
+ ```
145
+
146
+ Folded into `guardrails:audit` via `VISUAL_DIFF=...` env var, same shape as `AXE_JSON`.
147
+
148
+ JSON output extends the existing audit payload:
149
+
150
+ ```json
151
+ {
152
+ "summary": { "...": "...", "visual_diff": 3 },
153
+ "visual_diff": [
154
+ { "scenario": "checkout/cart", "mismatch_ratio": 0.082,
155
+ "baseline_path": "doc/screenshots/checkout_cart.png",
156
+ "diff_path": "doc/screenshots/checkout_cart.diff.png" }
157
+ ]
158
+ }
159
+ ```
160
+
161
+ Exit-code contract: a finding's `mismatch_ratio > threshold` (configurable, default `0.0` — any diff fails) bumps the audit to exit 1. For snap_diff (pass/fail), any failure is a fail.
162
+
163
+ ---
164
+
165
+ ## What this buys the gem (and the talk)
166
+
167
+ 1. **Closes V2.** Roadmap is fully shipped on the three core items.
168
+ 2. **Talk narrative is now four layers deep:**
169
+ - *Static AST drift* (V0): the source-level mistakes.
170
+ - *Structural drift* (V2 cross-codebase + class-itis): the patterns the source shouldn't have.
171
+ - *Runtime a11y drift* (V1.6 deep a11y): what the static checks can't see.
172
+ - *Visual drift* (V2 visual-diff): what the rendered DOM does next.
173
+
174
+ AI assistants fail at each layer differently. Each Guardrails detector maps to a specific failure mode.
175
+
176
+ 3. **Same install/run story as everything else.** No new install footprint. Users keep their preferred screenshot tool; Guardrails provides the unified report.
177
+
178
+ ---
179
+
180
+ ## Open decisions for the morning
181
+
182
+ 1. **Primary adapter: snap_diff or BackstopJS?**
183
+ - My read: snap_diff-capybara, since (a) Rails-native, (b) we'd be working with the maintainers of a small focused gem who'd likely accept a JSON-output PR upstream, and (c) baselines-in-git matches Guardrails' "source is canonical" ethos.
184
+ - The risk: snap_diff doesn't currently emit JSON, so v0.8.0 might need an upstream contribution. We could ship the filesystem-walking adapter first (look at `doc/screenshots/*.diff.png`) and contribute the JSON emitter separately.
185
+
186
+ 2. **Scope: ship one adapter or two?**
187
+ - One (snap_diff) keeps the PR small and proves the pattern.
188
+ - Two (snap_diff + BackstopJS) covers the Avo / non-Rails-monolith case from day one.
189
+ - I'd ship one and tag, then add BackstopJS in a follow-up if there's signal.
190
+
191
+ 3. **Threshold default: `0.0` (any diff fails) or something more lenient?**
192
+ - A11yDeep defaulted to "any non-nil impact fails". The visual-diff equivalent is "any pixel mismatch fails" — strict, but visual diff is opt-in (you set up baselines deliberately), so strict is the right default.
193
+ - Per-call override via `VISUAL_DIFF_THRESHOLD=0.01` env or `visual_diff.threshold` in `guardrails.yml`.
194
+
195
+ 4. **Where does this surface in the Lookbook panel?**
196
+ - `ComponentReport#for` could add `visual_diff: [...]` showing per-component baseline mismatches. Pulls together: "this component drifted statically (raw_color) AND visually (3% mismatch on the desktop viewport)."
197
+ - Probably out of scope for v0.8.0 — first land the audit/CI integration, layer Lookbook in v0.9.0.
198
+
199
+ 5. **Is this 0.8.0 or 1.0.0?**
200
+ - Argument for 0.8.0: matches the pattern of every other increment.
201
+ - Argument for 1.0.0: with this shipped, all three V0–V2 column-headers are done. We could draw the "ready for serious use" line here and tag a 1.0.0.
202
+ - My read: 0.8.0 for the visual-diff feature, then a separate 1.0.0 release after dogfooding the full V2 surface against Patchvault/Talos/Forem/Avo. The 0.2.x→0.7.x cadence already moved through dogfood-driven patches; another round before 1.0.0 fits.
203
+
204
+ ---
205
+
206
+ ## Out of scope
207
+
208
+ - **Running the screenshot tool ourselves.** Not now, possibly not ever — the gem's ethos is parse-only.
209
+ - **Hosted baseline storage.** Baselines stay in the user's repo (snap_diff convention) or wherever their existing tool puts them.
210
+ - **Image-diff algorithm work.** Pixel comparison is a solved problem with multiple good libraries; we don't add value by reinventing it.
211
+ - **Real-browser rendering.** Same as the headless Chrome reasoning in A11yDeep.
212
+
213
+ ---
214
+
215
+ ## What's needed to start
216
+
217
+ If we go with snap_diff-capybara as the primary adapter:
218
+
219
+ 1. Decide if we file an upstream PR to add `snap_diff_report.json` emission, or build the filesystem-walking adapter first.
220
+ 2. Add `snap_diff-capybara` to `examples/demo/Gemfile` and seed a couple of system tests so the integration spec has something to verify against.
221
+ 3. Roughly 3 slices, mirroring the A11yDeep PR:
222
+ - Slice 1: `VisualDiff` parser + `Finding` struct + snap_diff adapter + spec
223
+ - Slice 2: rake task wiring (standalone + `guardrails:audit` fold-in) + JSON output extension
224
+ - Slice 3: docs (new `doc/VISUAL-DIFF.md` mirroring `doc/A11Y.md`) + ROADMAP + CHANGELOG → 0.8.0
225
+
226
+ Estimated scope: a single PR, comparable to 0.6.0's `A11yDeep` (~17 specs, ~400 LOC). Could be shipped same day as kick-off if no upstream blocker.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Guardrails
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ui_guardrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Athayde
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-05-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: railties
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '7.1'
18
+ version: '7.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '7.1'
25
+ version: '7.2'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: herb
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +79,7 @@ files:
80
79
  - doc/LOOKBOOK.md
81
80
  - doc/PRD.md
82
81
  - doc/PUBLISHING.md
82
+ - doc/RESEARCH-visual-diff.md
83
83
  - doc/ROADMAP.md
84
84
  - doc/UPSTREAM-snap_diff-issue-draft.md
85
85
  - doc/VISUAL-DIFF.md
@@ -125,7 +125,6 @@ metadata:
125
125
  source_code_uri: https://github.com/meticulous/guardrails
126
126
  changelog_uri: https://github.com/meticulous/guardrails/blob/main/CHANGELOG.md
127
127
  rubygems_mfa_required: 'true'
128
- post_install_message:
129
128
  rdoc_options: []
130
129
  require_paths:
131
130
  - lib
@@ -133,15 +132,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
132
  requirements:
134
133
  - - ">="
135
134
  - !ruby/object:Gem::Version
136
- version: 3.2.0
135
+ version: 3.4.0
137
136
  required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  requirements:
139
138
  - - ">="
140
139
  - !ruby/object:Gem::Version
141
140
  version: '0'
142
141
  requirements: []
143
- rubygems_version: 3.4.19
144
- signing_key:
142
+ rubygems_version: 3.6.9
145
143
  specification_version: 4
146
144
  summary: Rails toolset for preventing UI drift in AI-assisted applications.
147
145
  test_files: []