snap_diff-capybara 0.0.1 → 2.0.0.alpha1

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +167 -0
  3. data/CODE_OF_CONDUCT.md +129 -0
  4. data/LICENSE.txt +21 -0
  5. data/Rakefile +65 -0
  6. data/capybara-screenshot-diff.gemspec +29 -0
  7. data/docs/RELEASE_PREP.md +44 -0
  8. data/docs/UPGRADING.md +475 -0
  9. data/docs/architecture.md +267 -0
  10. data/docs/ci-integration.md +238 -0
  11. data/docs/configuration.md +395 -0
  12. data/docs/docker-testing.md +24 -0
  13. data/docs/drivers.md +102 -0
  14. data/docs/framework-setup.md +87 -0
  15. data/docs/images/snap_diff_annotated.png +0 -0
  16. data/docs/images/snap_diff_web_ui.png +0 -0
  17. data/docs/migration-guide.md +286 -0
  18. data/docs/organization.md +204 -0
  19. data/docs/reporters.md +46 -0
  20. data/docs/thread_safety.md +112 -0
  21. data/gems.rb +39 -0
  22. data/lib/capybara/screenshot/diff/annotation_service.rb +7 -0
  23. data/lib/capybara/screenshot/diff/area_calculator.rb +7 -0
  24. data/lib/capybara/screenshot/diff/browser_helpers.rb +7 -0
  25. data/lib/capybara/screenshot/diff/config_legacy.rb +113 -0
  26. data/lib/capybara/screenshot/diff/cucumber.rb +3 -0
  27. data/lib/capybara/screenshot/diff/difference.rb +8 -0
  28. data/lib/capybara/screenshot/diff/drivers/base_driver.rb +9 -0
  29. data/lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb +7 -0
  30. data/lib/capybara/screenshot/diff/drivers/vips_driver.rb +7 -0
  31. data/lib/capybara/screenshot/diff/drivers.rb +9 -0
  32. data/lib/capybara/screenshot/diff/image_compare.rb +12 -0
  33. data/lib/capybara/screenshot/diff/image_preprocessor.rb +7 -0
  34. data/lib/capybara/screenshot/diff/os.rb +14 -0
  35. data/lib/capybara/screenshot/diff/region.rb +107 -0
  36. data/lib/capybara/screenshot/diff/reporters/default.rb +109 -0
  37. data/lib/capybara/screenshot/diff/screenshot_matcher.rb +7 -0
  38. data/lib/capybara/screenshot/diff/screenshoter.rb +7 -0
  39. data/lib/capybara/screenshot/diff/stable_screenshoter.rb +7 -0
  40. data/lib/capybara/screenshot/diff/utils.rb +7 -0
  41. data/lib/capybara/screenshot/diff/vcs.rb +7 -0
  42. data/lib/capybara/screenshot/diff/version.rb +15 -0
  43. data/lib/capybara/screenshot/diff.rb +3 -0
  44. data/lib/capybara-screenshot-diff.rb +3 -0
  45. data/lib/capybara_screenshot_diff/attempts_reporter.rb +7 -0
  46. data/lib/capybara_screenshot_diff/cucumber.rb +8 -0
  47. data/lib/capybara_screenshot_diff/dsl.rb +12 -0
  48. data/lib/capybara_screenshot_diff/error_with_filtered_backtrace.rb +8 -0
  49. data/lib/capybara_screenshot_diff/minitest.rb +14 -0
  50. data/lib/capybara_screenshot_diff/reporters/html.rb +7 -0
  51. data/lib/capybara_screenshot_diff/rspec.rb +8 -0
  52. data/lib/capybara_screenshot_diff/screenshot_assertion.rb +71 -0
  53. data/lib/capybara_screenshot_diff/screenshot_namer.rb +7 -0
  54. data/lib/capybara_screenshot_diff/snap.rb +7 -0
  55. data/lib/capybara_screenshot_diff/snap_manager.rb +7 -0
  56. data/lib/capybara_screenshot_diff/static.rb +9 -0
  57. data/lib/capybara_screenshot_diff.rb +50 -0
  58. data/lib/snap_diff/annotation_service.rb +84 -0
  59. data/lib/snap_diff/area_calculator.rb +56 -0
  60. data/lib/snap_diff/attempts_reporter.rb +51 -0
  61. data/lib/snap_diff/browser_helpers.rb +121 -0
  62. data/lib/snap_diff/capture/viewport.rb +40 -0
  63. data/lib/snap_diff/comparison.rb +238 -0
  64. data/lib/snap_diff/comparison_result.rb +104 -0
  65. data/lib/snap_diff/config.rb +78 -0
  66. data/lib/snap_diff/deprecation.rb +84 -0
  67. data/lib/snap_diff/driver.rb +37 -0
  68. data/lib/snap_diff/drivers/chunky_png_driver.rb +298 -0
  69. data/lib/snap_diff/drivers/vips_driver.rb +171 -0
  70. data/lib/snap_diff/drivers.rb +14 -0
  71. data/lib/snap_diff/dsl.rb +143 -0
  72. data/lib/snap_diff/error_with_filtered_backtrace.rb +32 -0
  73. data/lib/snap_diff/image_preprocessor.rb +68 -0
  74. data/lib/snap_diff/integrations/cucumber.rb +22 -0
  75. data/lib/snap_diff/integrations/minitest.rb +70 -0
  76. data/lib/snap_diff/integrations/rspec.rb +68 -0
  77. data/lib/snap_diff/legacy_shims.rb +99 -0
  78. data/lib/snap_diff/os.rb +17 -0
  79. data/lib/snap_diff/reporters/html.rb +143 -0
  80. data/lib/snap_diff/reporters/templates/report.html.erb +463 -0
  81. data/lib/snap_diff/reporting.rb +53 -0
  82. data/lib/snap_diff/screenshot_assertion.rb +143 -0
  83. data/lib/snap_diff/screenshot_matcher.rb +113 -0
  84. data/lib/snap_diff/screenshot_namer.rb +81 -0
  85. data/lib/snap_diff/screenshoter.rb +129 -0
  86. data/lib/snap_diff/snap.rb +66 -0
  87. data/lib/snap_diff/snap_manager.rb +125 -0
  88. data/lib/snap_diff/stable_screenshoter.rb +103 -0
  89. data/lib/snap_diff/static.rb +11 -0
  90. data/lib/snap_diff/utils.rb +38 -0
  91. data/lib/snap_diff/vcs.rb +35 -0
  92. data/lib/snap_diff/version.rb +5 -0
  93. data/lib/snap_diff.rb +65 -0
  94. metadata +160 -10
  95. data/README.md +0 -3
@@ -0,0 +1,267 @@
1
+ # Architecture
2
+
3
+ This document describes the internal architecture of `capybara-screenshot-diff` — how screenshots are captured, compared, and reported, and how the components fit together.
4
+
5
+ ## Overview
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────┐
9
+ │ Test Framework │
10
+ │ (Minitest / RSpec / Cucumber / Custom) │
11
+ └──────────────┬──────────────────────────────┬────────────┘
12
+ │ │
13
+ ▼ ▼
14
+ ┌──────────────────────────┐ ┌──────────────────────────┐
15
+ │ CapybaraScreenshotDiff │ │ CapybaraScreenshotDiff │
16
+ │ ::DSL (screenshot, etc) │ │ ::AssertionRegistry │
17
+ └──────────────┬───────────┘ └──────────────┬───────────┘
18
+ │ │
19
+ ▼ ▼
20
+ ┌──────────────────────────┐ ┌──────────────────────────┐
21
+ │ ScreenshotMatcher │ │ ScreenshotAssertion │
22
+ │ (capture + compare) │ │ (validate results) │
23
+ └──────┬───────────┬────────┘ └──────────────┬───────────┘
24
+ │ │ │
25
+ ▼ ▼ ▼
26
+ ┌──────────┐ ┌──────────┐ ┌──────────────────────┐
27
+ │Screenshot│ │Stable │ │ Reporters │
28
+ │er │ │Screenshot│ │ (Default / HTML / │
29
+ │ │ │er │ │ Custom) │
30
+ └─────┬────┘ └──────────┘ └──────────────────────┘
31
+
32
+
33
+ ┌──────────────────────────────────────────┐
34
+ │ ImageCompare (layered comparison) │
35
+ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
36
+ │ │1. Byte │ │2. Pixel │ │3. Region │ │
37
+ │ │ compare │ │ compare │ │ analyze │ │
38
+ │ └──────────┘ └──────────┘ └──────────┘ │
39
+ └─────────────────────┬────────────────────┘
40
+
41
+
42
+ ┌──────────────────────────────────────────┐
43
+ │ Drivers (image processing backends) │
44
+ │ ┌──────────┐ ┌──────────────────────┐ │
45
+ │ │ Vips │ │ ChunkyPNG │ │
46
+ │ │ (fast) │ │ (no native deps) │ │
47
+ │ └──────────┘ └──────────────────────┘ │
48
+ └──────────────────────────────────────────┘
49
+ ```
50
+
51
+ ## Component Breakdown
52
+
53
+ ### 1. DSL Layer (`lib/capybara_screenshot_diff/dsl.rb`)
54
+
55
+ The entry point for test code. `assert_matches_screenshot` is the primary assertion method (captures and compares). `screenshot` is a convenience wrapper with a `compare:` option — `compare: true` (default) delegates to `assert_matches_screenshot`, while `compare: false` delegates to the new `capture_screenshot` method. `capture_screenshot` takes screenshots without assertions. `assert_no_screenshot_changes` keeps its behavior but now delegates to `assert_matches_screenshot` (that redirect is part of the #191 fix). Users can safely override `screenshot` in their test classes without affecting internal gem flow.
56
+
57
+ **Flow:**
58
+ 1. Checks if screenshots are `active?` (returns `false` if disabled)
59
+ 2. Builds a full screenshot name via `ScreenshotNamer` (handles sections, groups, counters)
60
+ 3. Delegates to `ScreenshotMatcher` to capture and prepare comparison
61
+ 4. Creates a `ScreenshotAssertion` — either adds it to the thread-local registry (delayed validation) or validates immediately
62
+
63
+ ### 2. ScreenshotMatcher (`lib/capybara/screenshot/diff/screenshot_matcher.rb`)
64
+
65
+ The orchestrator that coordinates capture and comparison:
66
+
67
+ 1. **Window size check** — verifies browser window is the expected size
68
+ 2. **Area calculation** — resolves crop regions and skip areas (supports CSS selectors and coordinates)
69
+ 3. **Base screenshot checkout** — retrieves the committed baseline from git via `Vcs.checkout_vcs`
70
+ 4. **Capture** — delegates to `Screenshoter` or `StableScreenshoter` depending on `stability_time_limit`
71
+ 5. **Comparison** — creates an `ImageCompare` object (lazy — actual comparison happens on first access)
72
+ 6. **Assertion** — returns a `ScreenshotAssertion` with the comparison attached
73
+
74
+ **Key design decision:** The "new" screenshot is taken *first*, then compared against the baseline. This means if no baseline exists (first run), we skip comparison entirely and the test passes.
75
+
76
+ ### 3. Screenshoter & StableScreenshoter (`lib/capybara/screenshot/diff/screenshoter.rb`, `lib/capybara/screenshot/diff/stable_screenshoter.rb`)
77
+
78
+ **Screenshoter:** The basic capture flow:
79
+ 1. Prepares the page (blur active element, hide caret, disable animations, wait for images)
80
+ 2. Takes a browser screenshot via `Capybara.current_session.save_screenshot`
81
+ 3. Processes the screenshot (resize for retina, apply crop)
82
+
83
+ **StableScreenshoter:** Wraps `Screenshoter` with stability detection:
84
+ 1. Takes sequential screenshots at `stability_time_limit` intervals
85
+ 2. Compares consecutive attempts for byte-level equality
86
+ 3. Returns once two consecutive screenshots are identical
87
+ 4. Fails with `UnstableImage` if timeout (`wait`) is reached, generating annotated attempt images for debugging
88
+
89
+ ### 4. ImageCompare (`lib/capybara/screenshot/diff/image_compare.rb`)
90
+
91
+ The comparison engine uses a **layered optimization strategy** to balance speed and accuracy:
92
+
93
+ | Layer | Method | What it checks | Speed | When it returns |
94
+ |-------|--------|----------------|-------|-----------------|
95
+ | 1 | `quick_equal?` | File size + byte-level comparison | Fastest | Equal → `true`, Different → Layer 2 |
96
+ | 2 | `quick_equal?` continues | Dimension check + pixel comparison | Fast | Different dimensions → `false`, Same pixels → `true` |
97
+ | 3 | `processed` / `different?` | Full region analysis with tolerance | Slower | Detailed diff with region, heatmap, annotations |
98
+
99
+ **Key details:**
100
+ - `quick_equal?` is designed for fast rejection — it early-returns as soon as a difference is found
101
+ - `different?` triggers the full comparison if not already processed
102
+ - `processed` guarantees the comparison is complete and returns the result with all metadata
103
+ - `ImageCompare#analyze_difference` handles the actual pixel analysis, delegating to the driver
104
+
105
+ ### 5. Drivers (`lib/capybara/screenshot/diff/drivers/`)
106
+
107
+ Drivers abstract image processing operations. Each driver implements:
108
+
109
+ | Operation | VipsDriver | ChunkyPNGDriver |
110
+ |-----------|-----------|-----------------|
111
+ | `load_images` | Vips::Image from file | ChunkyPNG::Image from blob |
112
+ | `same_dimension?` | Compare width × height | Same |
113
+ | `same_pixels?` | Pixel-level equality | Same |
114
+ | `find_difference_region` | Difference mask → Region | Row-by-row scan → Region |
115
+ | `crop` | Vips image crop | ChunkyPNG crop |
116
+ | `save_image_to` | Vips write_to_file | PNG save |
117
+ | `filter_image_with_median` | Vips median filter | Not supported |
118
+ | `add_black_box` | Draw filled rect | No-op (handled differently) |
119
+ | `merge` | Composite images | Not applicable |
120
+ | `highlight_mask` | Conditional color overlay | Not applicable |
121
+
122
+ **Auto-detection:** `Utils.detect_available_drivers` tries to load `:vips` first (via `ruby-vips` gem), then `:chunky_png`. The `:auto` driver mode picks the first available.
123
+
124
+ ### 6. Difference Region Detection
125
+
126
+ **VipsDriver** uses a **difference mask** approach:
127
+ 1. Compute absolute difference between images: `(new - base).abs`
128
+ 2. Optional: apply perceptual color distance (CIE dE00) instead of raw RGB
129
+ 3. Project the mask to find the bounding region of non-zero pixels
130
+ 4. Return the tight bounding box of all differences
131
+
132
+ **ChunkyPNGDriver** uses **row-by-row scanning**:
133
+ 1. Scan top-to-bottom, left-to-right for first differing pixel
134
+ 2. Expand left/right boundaries within each differing row
135
+ 3. Extend bottom boundary to cover all differing rows
136
+ 4. Supports shift detection (expensive neighbor pixel search)
137
+
138
+ ### 7. SnapManager & Snap (`lib/capybara_screenshot_diff/snap_manager.rb`, `lib/capybara_screenshot_diff/snap.rb`)
139
+
140
+ **Snap** represents a single screenshot file with path management:
141
+ - `path` — the actual screenshot file
142
+ - `base_path` — the `.base.ext` VCS checkout
143
+ - `attempt_path` — stability attempt files (`.attempt_00.png`, etc.)
144
+ - Provides cleanup of diff artifacts (`.diff.png`, `.heatmap.diff.png`)
145
+
146
+ **SnapManager** is the factory and path manager:
147
+ - Creates `Snap` instances
148
+ - Handles VCS checkout of baselines
149
+ - Manages file operations (copy, move, cleanup)
150
+
151
+ ### 8. VCS (`lib/capybara/screenshot/diff/vcs.rb`)
152
+
153
+ Handles baseline retrieval from git. Uses `git show HEAD:<path>` to extract the committed version. Supports Git LFS via `git lfs smudge`. Returns `false` if the file doesn't exist in VCS (first-run scenario).
154
+
155
+ ### 9. Reporters (`lib/capybara/screenshot/diff/reporters/`)
156
+
157
+ **Default reporter:** Generates annotated diff images:
158
+ - `image.diff.png` — new screenshot with diff region outlined in red
159
+ - `image.base.diff.png` — baseline with diff region outlined in red
160
+ - `image.heatmap.diff.png` — heatmap overlay of pixel differences
161
+
162
+ **HTML reporter:** Generates an interactive dashboard (`snap_diff_report.html`) with:
163
+ - Sidebar with thumbnails and search
164
+ - 4 view modes (both/base/new/heatmap)
165
+ - Annotated toggle for showing diff outlines
166
+ - Per-image zoom with synchronized panning across side-by-side views
167
+ - Keyboard navigation and shortcuts
168
+ - Responsive layout for mobile
169
+
170
+ **Custom reporters:** Implement `record(assertions)` and `finalize` methods, then add to `CapybaraScreenshotDiff.reporters`.
171
+
172
+ ### 10. Assertion Lifecycle
173
+
174
+ ```
175
+ Test begins
176
+
177
+ ├─ setup: resize_window_if_needed
178
+
179
+ ├─ test body:
180
+ │ └─ screenshot("name")
181
+ │ ├─ ScreenshotMatcher builds assertion
182
+ │ ├─ delayed=true → add to Thread-local registry
183
+ │ └─ delayed=false → validate immediately
184
+
185
+ ├─ teardown:
186
+ │ └─ CapybaraScreenshotDiff.verify
187
+ │ ├─ iterates thread-local assertions
188
+ │ ├─ calls validate on each
189
+ │ ├─ raises ExpectationNotMet on first failure
190
+ │ └─ notifies reporters via mutex-protected snapshot
191
+
192
+ └─ at_exit:
193
+ └─ CapybaraScreenshotDiff.finalize_reporters!
194
+ ├─ Generates HTML report (if reporter registered)
195
+ └─ Prints summary
196
+ ```
197
+
198
+ ### 11. Thread Safety
199
+
200
+ | Concern | Mechanism |
201
+ |---------|-----------|
202
+ | Assertion registry | Thread-local storage (`Thread.current[:capybara_screenshot_diff_registry]`) |
203
+ | Reporter notification | Mutex-protected snapshot of reporter list before iteration |
204
+ | HTML reporter internals | Mutex protecting `@failures`, `@total`, `@finalized` |
205
+ | Screenshot naming | Per-thread `ScreenshotNamer` instance |
206
+ | Global configuration | `mattr_accessor` — must be set before tests run, not mutated during parallel execution |
207
+ | File system | Atomic `FileUtils.mv`, unique paths per screenshot name + counter, thread-safe `mkpath` |
208
+
209
+ ### 12. Configuration System
210
+
211
+ Configuration uses Ruby's `mattr_accessor` (from ActiveSupport, or pure Ruby fallback) and is organized into two namespaces:
212
+
213
+ **`Capybara::Screenshot`** — capture settings:
214
+ - `window_size`, `stability_time_limit`, `blur_active_element`, `hide_caret`, `disable_animations`
215
+ - `save_path`, `root`, `screenshot_format`, `add_driver_path`, `add_os_path`
216
+ - `enabled`, `capybara_screenshot_options`
217
+
218
+ **`Capybara::Screenshot::Diff`** — comparison settings:
219
+ - `driver`, `tolerance`, `color_distance_limit`, `perceptual_threshold`, `shift_distance_limit`
220
+ - `area_size_limit`, `skip_area`, `fail_if_new`, `fail_on_difference`, `delayed`
221
+
222
+ The `Diff.configure` block helper provides a convenient way to set both namespaces at once.
223
+
224
+ ## File Layout
225
+
226
+ ```
227
+ lib/
228
+ capybara_screenshot_diff.rb # Core module, mattr_accessor definitions
229
+ capybara/screenshot/diff.rb # Convenience require (loads minitest)
230
+ capybara_screenshot_diff/
231
+ dsl.rb # screenshot(), screenshot_group(), etc.
232
+ minitest.rb # Minitest assertions integration
233
+ rspec.rb # RSpec matcher integration
234
+ cucumber.rb # Cucumber World integration
235
+ static.rb # Non-Rails static site serving
236
+ snap_manager.rb # Screenshot file management
237
+ snap.rb # Single screenshot file abstraction
238
+ screenshot_namer.rb # Name/path generation with sections/groups
239
+ screenshot_assertion.rb # Assertion + registry objects
240
+ attempts_reporter.rb # Debug reporting for unstable captures
241
+ error_with_filtered_backtrace.rb # Error with filtered stack
242
+ reporters/
243
+ html.rb # Interactive HTML report reporter
244
+ templates/report.html.erb # HTML report template
245
+ capybara/screenshot/diff/
246
+ version.rb # VERSION constant
247
+ utils.rb # Driver detection
248
+ drivers.rb # Driver factory
249
+ drivers/
250
+ base_driver.rb # Abstract base driver
251
+ vips_driver.rb # VIPS image processing
252
+ chunky_png_driver.rb # ChunkyPNG image processing
253
+ screenshoter.rb # Basic browser screenshot capture
254
+ stable_screenshoter.rb # Stability detection wrapper
255
+ screenshot_matcher.rb # Orchestrator for capture + compare
256
+ image_compare.rb # Layered comparison engine
257
+ difference.rb # Difference result value object
258
+ image_preprocessor.rb # Pre-processing (skip areas, median filter)
259
+ area_calculator.rb # Crop/skip area coordinate resolution
260
+ region.rb # Bounding box region value object
261
+ browser_helpers.rb # DOM manipulation helpers
262
+ vcs.rb # Git baseline checkout
263
+ os.rb # OS detection
264
+ cucumber.rb # Deprecated Cucumber entry point
265
+ reporters/
266
+ default.rb # Default annotated-image reporter
267
+ ```
@@ -0,0 +1,238 @@
1
+ # CI & Non-Rails Integration
2
+
3
+ ## Non-Rails Projects (Hugo, Jekyll, Static Sites)
4
+
5
+ ```ruby
6
+ # test/test_helper.rb
7
+ require 'capybara_screenshot_diff/static'
8
+
9
+ CapybaraScreenshotDiff.serve("_site") # or "public", "build", "dist"
10
+ ```
11
+
12
+ This sets up Capybara to serve static files and configures screenshot paths automatically.
13
+
14
+ ## .gitignore Setup
15
+
16
+ See the [Quick Start section](../README.md#quick-start-5-minutes) in the README for recommended `.gitignore` patterns.
17
+
18
+ Only commit the baseline screenshots (e.g., `homepage.png`). The `.base.png`, `.diff.png`, `.heatmap.diff.png`, and report files are regenerated on every test run.
19
+
20
+ ## GitHub Actions Integration
21
+
22
+ ### 1. Enable the HTML report
23
+
24
+ Add to your test helper:
25
+
26
+ ```ruby
27
+ require 'capybara_screenshot_diff/reporters/html'
28
+ ```
29
+
30
+ ### 2. Reusable composite action (recommended)
31
+
32
+ The simplest way — one step handles artifact upload, job summary, and PR comments:
33
+
34
+ ```yaml
35
+ # .github/workflows/test.yml
36
+ jobs:
37
+ test:
38
+ runs-on: ubuntu-latest
39
+ permissions:
40
+ contents: read
41
+ pull-requests: write # Required for PR comments
42
+
43
+ steps:
44
+ - uses: actions/checkout@v6
45
+
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ bundler-cache: true
49
+
50
+ - name: Run tests
51
+ run: bundle exec rake test
52
+
53
+ - name: Upload screenshot reports
54
+ if: failure()
55
+ uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
56
+ with:
57
+ name: screenshots
58
+ pr-comment: 'true'
59
+ ```
60
+
61
+ That's it. On failure, this will:
62
+ - Upload diff images + HTML report as artifacts
63
+ - Post a PR comment with links to the inline report and full artifact download
64
+ - Add a job summary with report links (visible in the Actions UI)
65
+
66
+ #### Inputs
67
+
68
+ | Input | Default | Description |
69
+ |-------|---------|-------------|
70
+ | `name` | (required) | Artifact name prefix |
71
+ | `report-path` | `doc/screenshots` | Path to HTML report directory |
72
+ | `retention-days` | `2` | Days to retain artifacts |
73
+ | `pr-comment` | `false` | Post PR comment with report link (requires `pull-requests: write`) |
74
+
75
+ #### Outputs
76
+
77
+ | Output | Description |
78
+ |--------|-------------|
79
+ | `report-url` | Direct URL to the inline HTML report artifact |
80
+ | `report-full-url` | Direct URL to the full report artifact (with images) |
81
+
82
+ ### 3. Ruby + libvips setup action
83
+
84
+ For consistent CI environments (libvips, font antialiasing disabled), use the setup action:
85
+
86
+ ```yaml
87
+ - uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
88
+ with:
89
+ ruby-version: '4.0'
90
+ cache-apt-packages: true
91
+ ```
92
+
93
+ This installs Ruby, libvips (with apt caching), and disables font antialiasing for consistent rendering across CI runs.
94
+
95
+ #### Inputs
96
+
97
+ | Input | Default | Description |
98
+ |-------|---------|-------------|
99
+ | `ruby-version` | (required) | Ruby version to install |
100
+ | `cache-apt-packages` | `false` | Cache libvips apt packages for faster runs |
101
+ | `ruby-cache-version` | — | Bundler cache version key |
102
+
103
+ ### 4. Full example with both actions
104
+
105
+ ```yaml
106
+ jobs:
107
+ test:
108
+ runs-on: ubuntu-latest
109
+ timeout-minutes: 10
110
+ permissions:
111
+ contents: read
112
+ pull-requests: write
113
+
114
+ steps:
115
+ - uses: actions/checkout@v6
116
+
117
+ - uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
118
+ with:
119
+ ruby-version: '4.0'
120
+ cache-apt-packages: true
121
+
122
+ - run: bundle exec rake test
123
+
124
+ - uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
125
+ if: failure()
126
+ with:
127
+ name: screenshots
128
+ pr-comment: 'true'
129
+ ```
130
+
131
+ ### 5. Manual setup (without composite actions)
132
+
133
+ If you prefer full control, here's the expanded YAML:
134
+
135
+ <details>
136
+ <summary>Expand manual setup</summary>
137
+
138
+ ```yaml
139
+ jobs:
140
+ test:
141
+ runs-on: ubuntu-latest
142
+ steps:
143
+ - uses: actions/checkout@v6
144
+
145
+ - uses: ruby/setup-ruby@v1
146
+ with:
147
+ bundler-cache: true
148
+
149
+ - name: Install libvips
150
+ run: sudo apt-get install -y libvips-dev
151
+
152
+ - name: Run tests
153
+ run: bundle exec rake test
154
+
155
+ - name: Upload screenshot report
156
+ if: failure()
157
+ uses: actions/upload-artifact@v7
158
+ with:
159
+ name: screenshot-report
160
+ path: doc/screenshots/snap_diff_report.html
161
+ archive: false
162
+ retention-days: 2
163
+
164
+ - name: Upload full report with images
165
+ if: failure()
166
+ uses: actions/upload-artifact@v7
167
+ with:
168
+ name: screenshot-report-full
169
+ path: doc/screenshots/
170
+ retention-days: 2
171
+ ```
172
+
173
+ </details>
174
+
175
+ ## Update Baselines in CI
176
+
177
+ When intentional UI changes are made, baselines need to be re-recorded. You can do this locally:
178
+
179
+ ```bash
180
+ RECORD_SCREENSHOTS=1 bundle exec rake test
181
+ git add test/fixtures/screenshots/
182
+ git commit -m "chore: update screenshot baselines"
183
+ ```
184
+
185
+ Or add a workflow that maintainers can trigger manually:
186
+
187
+ <details>
188
+ <summary>Expand update-baselines workflow</summary>
189
+
190
+ ```yaml
191
+ # .github/workflows/update-baselines.yml
192
+ name: Update Screenshot Baselines
193
+
194
+ on:
195
+ workflow_dispatch:
196
+ inputs:
197
+ branch:
198
+ description: 'Branch to update baselines on'
199
+ required: true
200
+ default: 'main'
201
+
202
+ permissions:
203
+ contents: write
204
+
205
+ jobs:
206
+ update:
207
+ runs-on: ubuntu-latest
208
+ steps:
209
+ - uses: actions/checkout@v6
210
+ with:
211
+ ref: ${{ inputs.branch }}
212
+
213
+ - uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
214
+ with:
215
+ ruby-version: '4.0'
216
+ cache-apt-packages: true
217
+
218
+ - name: Record new baselines
219
+ run: RECORD_SCREENSHOTS=1 bundle exec rake test
220
+ continue-on-error: true
221
+
222
+ - name: Commit updated baselines
223
+ run: |
224
+ git config user.name "github-actions[bot]"
225
+ git config user.email "github-actions[bot]@users.noreply.github.com"
226
+ git add test/fixtures/ doc/screenshots/
227
+ git diff --staged --quiet || git commit -m "chore: update screenshot baselines"
228
+ git push
229
+ ```
230
+
231
+ </details>
232
+
233
+ **How it works:**
234
+ 1. Go to Actions → "Update Screenshot Baselines" → "Run workflow"
235
+ 2. Enter the branch name (e.g. your PR branch)
236
+ 3. The workflow records new baselines, commits, and pushes
237
+
238
+ [← Back to README](../README.md)