snapdrift 0.14.0 → 0.16.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.
- package/CHANGELOG.md +55 -0
- package/README.md +2 -2
- package/action.yml +2 -2
- package/actions/baseline/action.yml +4 -2
- package/actions/pr-diff/action.yml +4 -2
- package/docs/contracts.md +12 -5
- package/docs/integration-guide.md +32 -6
- package/docs/plans/2026-10-05-snap-cloud-batch-capture-design.md +147 -0
- package/docs/workflow-templates/refresh-baseline-on-merge.yml +1 -1
- package/lib/capture-routes.mjs +1 -1
- package/lib/snap-provider.mjs +10 -27
- package/lib/snapdrift-config.mjs +3 -1
- package/package.json +4 -4
- package/types/visual-diff-types.d.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.16.0 - 2026-10-05
|
|
6
|
+
|
|
7
|
+
Workspace releases this version:
|
|
8
|
+
|
|
9
|
+
- `@snapdrift/manifest` 1.8.0 — capture engine configuration (`capture: "playwright" | "snap"`) under `provider: "local"`, export `isLocalBaseUrl`, and recognize `snap-batch` capture profile engine.
|
|
10
|
+
- `@snapdrift/adapter-fs` 1.7.0 — Snap Cloud batch screenshot capture engine (`runSnapBatchCapture`) using POST `/v1/screenshots`, capture engine delegation in `runBaselineCapture`, and `isLocalBaseUrl` re-export.
|
|
11
|
+
|
|
12
|
+
`@snapdrift/compare-core` stays 1.6.0 and `@snapdrift/adapter-report-md` stays 1.4.0. Root floors move to `@snapdrift/manifest ^1.8.0` and `@snapdrift/adapter-fs ^1.7.0`. The dispatcher pins `8e82795`, the #191 merge commit on `main`, which includes skipping Playwright installation in composite actions when `capture: "snap"` with a remote `baseUrl`.
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- Added Snap Cloud batch screenshot capture engine (`capture: "snap"`) under `provider: "local"`. Dispatches route screenshots concurrently to Snap Cloud's batch screenshot API (`POST /v1/screenshots`), saving significant CI run time by offloading browser execution.
|
|
17
|
+
- Added automatic Playwright setup skipping in composite actions (`actions/baseline` and `actions/pr-diff`) when `capture: "snap"` is configured with a remote `baseUrl`, avoiding unnecessary browser binary downloads.
|
|
18
|
+
- Supported `SNAPDRIFT_CAPTURE_ENGINE` environment variable (`playwright` | `snap`) to override the configured capture engine at runtime.
|
|
19
|
+
- Added actionable validation rejecting loopback and local `baseUrl` (`localhost`, `127.0.0.1`, `::1`) when `capture: "snap"` is used, directing users to use `playwright` or tunnel services.
|
|
20
|
+
- Added capture profile engine validation in `@snapdrift/manifest` to recognize `snap-batch` and prevent comparing local Playwright captures against Snap Cloud batch captures.
|
|
21
|
+
- Added resilient batch capture polling with retries on transient errors (HTTP 429, 5xx on GET status polls, network errors) while safely avoiding POST retries on 5xx to prevent duplicate jobs.
|
|
22
|
+
|
|
23
|
+
## 0.15.0 - 2026-09-22
|
|
24
|
+
|
|
25
|
+
Workspace releases this version:
|
|
26
|
+
|
|
27
|
+
- `@snapdrift/compare-core` 1.6.0 — vertical-offset alignment when exact row
|
|
28
|
+
matching hits its edit cap, including alpha-aware highlighting and the
|
|
29
|
+
search memory caps.
|
|
30
|
+
- `@snapdrift/manifest` 1.7.0 — `comparedOffset` on comparison row mappings.
|
|
31
|
+
- `@snapdrift/adapter-fs` 1.6.0 — depends on that compare-core so local policy
|
|
32
|
+
v2 comparisons use the offset-run engine.
|
|
33
|
+
|
|
34
|
+
`@snapdrift/adapter-report-md` stays 1.4.0. Root floors move to
|
|
35
|
+
`@snapdrift/compare-core ^1.6.0`, `@snapdrift/manifest ^1.7.0`, and
|
|
36
|
+
`@snapdrift/adapter-fs ^1.6.0`. The dispatcher pins `7b7b913`, the #179 merge
|
|
37
|
+
commit on `main`, which contains the offset-run runtime loaded by both wrapper
|
|
38
|
+
actions.
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
- Comparison policy v2, after exact row alignment hits its edit cap, maps long
|
|
43
|
+
vertical-offset runs so an insertion does not highlight the rest of a shifted
|
|
44
|
+
page. A matched row on that path was mapped and fell below the highlight
|
|
45
|
+
rule; it does not have to be byte-identical. When the compared row is one
|
|
46
|
+
pixel above or below the recorded current row, the mapping includes
|
|
47
|
+
`comparedOffset` (`-1` or `1`).
|
|
48
|
+
- Offset highlighting includes alpha. Scoring ignores fully transparent pixels
|
|
49
|
+
and treats a large opacity change as a structured mismatch, so a small alpha
|
|
50
|
+
delta stays on the offset path.
|
|
51
|
+
- The offset search rejects a page before allocating its score matrices when
|
|
52
|
+
those matrices would exceed 64 MB. It also samples every 32nd row first and
|
|
53
|
+
stops that sample once the page cannot be a correspondence, so a dissimilar
|
|
54
|
+
page falls back without scoring every offset. A dissimilar 1440×5622 pair
|
|
55
|
+
fell back in about 0.9s; scoring every offset on that pair took about 3.5s.
|
|
56
|
+
- An offset canvas that would exceed `maxPixels` falls back to coordinate
|
|
57
|
+
comparison instead of throwing. The coordinate union can still throw when it
|
|
58
|
+
itself exceeds the limit.
|
|
59
|
+
|
|
5
60
|
## 0.14.0 - 2026-09-21
|
|
6
61
|
|
|
7
62
|
Workspace releases this version:
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ You keep ownership of checkout, build, startup, readiness, and teardown. SnapDri
|
|
|
48
48
|
|
|
49
49
|
```yaml
|
|
50
50
|
- name: SnapDrift Baseline
|
|
51
|
-
uses: ranacseruet/snapdrift@v0.
|
|
51
|
+
uses: ranacseruet/snapdrift@v0.16.0
|
|
52
52
|
with:
|
|
53
53
|
mode: baseline
|
|
54
54
|
repo-config-path: .github/snapdrift.json
|
|
@@ -60,7 +60,7 @@ With `provider: "snap"`, baseline publication is a complete, fail-closed snapsho
|
|
|
60
60
|
|
|
61
61
|
```yaml
|
|
62
62
|
- name: SnapDrift Report
|
|
63
|
-
uses: ranacseruet/snapdrift@v0.
|
|
63
|
+
uses: ranacseruet/snapdrift@v0.16.0
|
|
64
64
|
with:
|
|
65
65
|
mode: pr-diff
|
|
66
66
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package/action.yml
CHANGED
|
@@ -155,7 +155,7 @@ runs:
|
|
|
155
155
|
- name: SnapDrift baseline
|
|
156
156
|
id: baseline
|
|
157
157
|
if: inputs.mode == 'baseline'
|
|
158
|
-
uses: ranacseruet/snapdrift/actions/baseline@
|
|
158
|
+
uses: ranacseruet/snapdrift/actions/baseline@8e827952c33415ba2d8f1fdab944d519534013a6 # v0.16.0
|
|
159
159
|
with:
|
|
160
160
|
repo-config-path: ${{ inputs.repo-config-path }}
|
|
161
161
|
route-ids: ${{ inputs.route-ids }}
|
|
@@ -165,7 +165,7 @@ runs:
|
|
|
165
165
|
- name: SnapDrift pull request diff
|
|
166
166
|
id: pr-diff
|
|
167
167
|
if: inputs.mode == 'pr-diff'
|
|
168
|
-
uses: ranacseruet/snapdrift/actions/pr-diff@
|
|
168
|
+
uses: ranacseruet/snapdrift/actions/pr-diff@8e827952c33415ba2d8f1fdab944d519534013a6 # v0.16.0
|
|
169
169
|
with:
|
|
170
170
|
github-token: ${{ inputs.github-token }}
|
|
171
171
|
repo-config-path: ${{ inputs.repo-config-path }}
|
|
@@ -78,14 +78,16 @@ runs:
|
|
|
78
78
|
const outputs = [
|
|
79
79
|
`artifact_name=${config.baselineArtifactName}`,
|
|
80
80
|
`provider=${config.provider || 'local'}`,
|
|
81
|
+
`capture_engine=${process.env.SNAPDRIFT_CAPTURE_ENGINE || config.capture || 'playwright'}`,
|
|
81
82
|
`on_unavailable=${config.snap?.onUnavailable || 'fail'}`,
|
|
82
|
-
`snap_local_capture=${(config.provider || 'local') === 'snap' && isLocalBaseUrl(config.baseUrl) ? 'true' : 'false'}
|
|
83
|
+
`snap_local_capture=${(config.provider || 'local') === 'snap' && isLocalBaseUrl(config.baseUrl) ? 'true' : 'false'}`,
|
|
84
|
+
`is_local_base_url=${isLocalBaseUrl(config.baseUrl) ? 'true' : 'false'}`
|
|
83
85
|
].join('\n') + '\n';
|
|
84
86
|
await fs.appendFile(process.env.GITHUB_OUTPUT, outputs);
|
|
85
87
|
EOF
|
|
86
88
|
|
|
87
89
|
- name: Install Playwright Chromium
|
|
88
|
-
if: steps.config.outputs.provider != 'snap' || steps.config.outputs.on_unavailable == 'fallback-local' || steps.config.outputs.snap_local_capture == 'true'
|
|
90
|
+
if: (steps.config.outputs.provider != 'snap' && (steps.config.outputs.capture_engine != 'snap' || steps.config.outputs.is_local_base_url == 'true')) || steps.config.outputs.on_unavailable == 'fallback-local' || steps.config.outputs.snap_local_capture == 'true'
|
|
89
91
|
shell: bash
|
|
90
92
|
run: |
|
|
91
93
|
"$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps chromium
|
|
@@ -251,8 +251,10 @@ runs:
|
|
|
251
251
|
const { config } = await loadSnapdriftConfig(process.env.REPO_CONFIG_PATH || undefined);
|
|
252
252
|
const outputs = [
|
|
253
253
|
`provider=${config.provider || 'local'}`,
|
|
254
|
+
`capture_engine=${process.env.SNAPDRIFT_CAPTURE_ENGINE || config.capture || 'playwright'}`,
|
|
254
255
|
`on_unavailable=${config.snap?.onUnavailable || 'fail'}`,
|
|
255
|
-
`snap_local_capture=${(config.provider || 'local') === 'snap' && isLocalBaseUrl(config.baseUrl) ? 'true' : 'false'}
|
|
256
|
+
`snap_local_capture=${(config.provider || 'local') === 'snap' && isLocalBaseUrl(config.baseUrl) ? 'true' : 'false'}`,
|
|
257
|
+
`is_local_base_url=${isLocalBaseUrl(config.baseUrl) ? 'true' : 'false'}`
|
|
256
258
|
].join('\n') + '\n';
|
|
257
259
|
await fs.appendFile(process.env.GITHUB_OUTPUT, outputs);
|
|
258
260
|
EOF
|
|
@@ -268,7 +270,7 @@ runs:
|
|
|
268
270
|
exit 1
|
|
269
271
|
|
|
270
272
|
- name: Install Playwright Chromium
|
|
271
|
-
if: steps.scope.outputs.should_run == 'true' && (steps.config.outputs.provider != 'snap' || steps.config.outputs.on_unavailable == 'fallback-local' || steps.config.outputs.snap_local_capture == 'true')
|
|
273
|
+
if: steps.scope.outputs.should_run == 'true' && ((steps.config.outputs.provider != 'snap' && (steps.config.outputs.capture_engine != 'snap' || steps.config.outputs.is_local_base_url == 'true')) || steps.config.outputs.on_unavailable == 'fallback-local' || steps.config.outputs.snap_local_capture == 'true')
|
|
272
274
|
shell: bash
|
|
273
275
|
run: |
|
|
274
276
|
"$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps chromium
|
package/docs/contracts.md
CHANGED
|
@@ -32,6 +32,7 @@ SnapDrift reads runtime behavior from `.github/snapdrift.json` by default.
|
|
|
32
32
|
|
|
33
33
|
| Field | Type | Description |
|
|
34
34
|
|:------|:-----|:------------|
|
|
35
|
+
| `capture` | `string` | Capture engine for `provider: "local"`: `"playwright"` (default) or `"snap"` (Snap Cloud batch screenshot API) |
|
|
35
36
|
| `selection.sharedPrefixes` | `string[]` | Prefixes that force the full route set |
|
|
36
37
|
| `selection.sharedExact` | `string[]` | Exact files that force the full route set |
|
|
37
38
|
| `provider` | `string` | `"local"` (default) or `"snap"` for hosted backend |
|
|
@@ -42,6 +43,8 @@ SnapDrift reads runtime behavior from `.github/snapdrift.json` by default.
|
|
|
42
43
|
| `snap.onUnavailable` | `string` | Behavior when Snap is unreachable: `"fail"` (default), `"warn-and-skip"`, or `"fallback-local"` |
|
|
43
44
|
| `diff.comparisonPolicy` | `{ "version": 1 \| 2, "threshold": number }` | Optional explicit comparison policy. Deprecated v1 remains the compatibility default; new configurations should use v2 for bounded vertical row alignment. `threshold` must match `diff.threshold` |
|
|
44
45
|
|
|
46
|
+
When `capture: "snap"` is set (or overridden via `SNAPDRIFT_CAPTURE_ENGINE=snap`), SnapDrift routes baseline and diff captures to Snap Cloud's batch screenshot API (`POST /v1/screenshots`) instead of launching local Chromium via Playwright. Rendered PNGs are downloaded in parallel and diffed locally via `@snapdrift/compare-core`. This requires a public or preview `baseUrl` (loopback and private network URLs like `localhost`, `127.0.0.1`, `::1` are rejected) and an API key (configured in `snap.apiKeyEnv` / `snap.apiKey` or via `SNAP_API_KEY`). When `capture: "snap"` is used with a remote `baseUrl`, GitHub Actions wrapper actions (`actions/baseline`, `actions/pr-diff`) skip the `playwright install --with-deps chromium` step, accelerating CI workflows.
|
|
47
|
+
|
|
45
48
|
When `provider: "snap"` is set, the `snap` block is required. Exactly one of `snap.apiKeyEnv` or `snap.apiKey` must be present. `snap.apiKey` accepts `${VAR}` interpolation (for example `"${SNAP_API_KEY}"`); the referenced environment variable must be set at runtime or the config loader throws.
|
|
46
49
|
|
|
47
50
|
Changed-file scoping treats a GitHub `renamed` record as both the current
|
|
@@ -293,10 +296,14 @@ the diff output bundle (for example `diffs/home.png`).
|
|
|
293
296
|
Policy v2 comparison metadata additionally includes `policyVersion: 2` and
|
|
294
297
|
`mode`. An aligned result has `mode: "vertical-aligned"` and a compact
|
|
295
298
|
`rowMapping` describing matched, changed, inserted, and deleted row runs. A
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
299
|
+
matched offset-run was mapped and fell below the highlight rule, so its rows
|
|
300
|
+
need not be byte-identical. A segment may include `comparedOffset` of `-1` or
|
|
301
|
+
`1` when the compared current row is one pixel away from `currentStart`; output
|
|
302
|
+
row `i` was compared to current row `currentStart + i + comparedOffset`. A `mode: "coordinate-fallback"` result
|
|
303
|
+
includes `fallbackReason` when widths, ignore regions, ambiguity, or the
|
|
304
|
+
alignment resource limit prevent safe row alignment. The aligned canvas may be
|
|
305
|
+
taller than either source image because inserted and deleted rows each occupy
|
|
306
|
+
an output row.
|
|
300
307
|
|
|
301
308
|
When a changed item has a generated local `diffImagePath`, its PR comment cell
|
|
302
309
|
links to the uploaded report artifact (or the workflow run when no artifact URL
|
|
@@ -332,7 +339,7 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
332
339
|
- `diff.threshold` applies per screenshot
|
|
333
340
|
- Missing captures are counted separately from drift signals
|
|
334
341
|
- Comparison policy v1 `{ "version": 1, "threshold": number }` is deprecated but remains the compatibility default. Images are top-left aligned on a max-dimension union canvas with no scaling. Overlap pixels are compared, one-sided pixels count as changed (including transparent pixels), and empty union corners do not enter the denominator.
|
|
335
|
-
- Comparison policy v2 `{ "version": 2, "threshold": number }` is opt-in. When source widths match and no ignore regions are requested, rows are fingerprinted and aligned with a bounded Myers sequence diff.
|
|
342
|
+
- Comparison policy v2 `{ "version": 2, "threshold": number }` is opt-in. When source widths match and no ignore regions are requested, rows are fingerprinted and aligned with a bounded Myers sequence diff. If that search hits its edit cap, long vertical-offset runs are mapped instead. Inside a run, a row may be compared one pixel above or below the recorded current row when that neighbor matches. `currentStart` still consumes each current row once, so that neighbor is not a separate insertion or deletion. When the compared row differs, the segment includes `comparedOffset` of `-1` or `1`: output row `i` was compared to current row `currentStart + i + comparedOffset`. On that offset-run path, a pixel whose red, green, blue, or alpha channel differs by 32 or less stays unhighlighted, so rendering noise and soft edges remain matched. A short cluster of larger channel deltas is an orange edit. A wide band of those pixels is a local mismatch: it is highlighted in place and does not discard the rest of the page. Unmatched baseline rows are red deletions. Current rows with no baseline partner are green insertions. `matched` on this path means the row was mapped and fell below this highlight rule. Exact fingerprint matches remain byte-identical. Width changes, ignore regions, ambiguous exact-row matches, and resource limits fall back to v1 coordinate comparison and record the fallback reason. This is a raster row alignment aid, not DOM or arbitrary component matching.
|
|
336
343
|
- Both policies preserve the explicit dimension-change signal: a source height/width change remains a changed route even when the aligned mismatch ratio is at or below the threshold. Empty output corners do not enter the denominator.
|
|
337
344
|
- Local diff images are rendered with a semantic palette: orange = changed pixels, green = added or inserted pixels, red = removed or deleted pixels. Equal-dimension strict diffs (`generateDiffImage`) use orange for changed pixels and cannot contain added/removed pixels. Reports render a legend whenever a local diff image is embedded; summaries that carry only comparison metadata (Snap provider runs, which render diffs hosted-side) render no legend.
|
|
338
345
|
- `dimensionChanges[]` remains part of the summary contract but is empty for local comparisons in v1. Strict same-dimension comparison (`compareBuffers`) remains available to direct `@snapdrift/compare-core`/`comparePngs` callers that pass no policy.
|
|
@@ -46,7 +46,7 @@ SnapDrift owns route selection, capture, comparison, skipped-report generation,
|
|
|
46
46
|
|
|
47
47
|
```yaml
|
|
48
48
|
- name: SnapDrift Baseline
|
|
49
|
-
uses: ranacseruet/snapdrift@v0.
|
|
49
|
+
uses: ranacseruet/snapdrift@v0.16.0
|
|
50
50
|
with:
|
|
51
51
|
mode: baseline
|
|
52
52
|
repo-config-path: .github/snapdrift.json
|
|
@@ -71,7 +71,7 @@ Then add SnapDrift after the app is running:
|
|
|
71
71
|
|
|
72
72
|
```yaml
|
|
73
73
|
- name: SnapDrift Report
|
|
74
|
-
uses: ranacseruet/snapdrift@v0.
|
|
74
|
+
uses: ranacseruet/snapdrift@v0.16.0
|
|
75
75
|
with:
|
|
76
76
|
mode: pr-diff
|
|
77
77
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -86,8 +86,8 @@ The wrappers remain published in their own right, and are equivalent to the disp
|
|
|
86
86
|
|
|
87
87
|
| Entry point | Equivalent to |
|
|
88
88
|
|-------------|---------------|
|
|
89
|
-
| `ranacseruet/snapdrift@v0.
|
|
90
|
-
| `ranacseruet/snapdrift@v0.
|
|
89
|
+
| `ranacseruet/snapdrift@v0.16.0` with `mode: baseline` | `ranacseruet/snapdrift/actions/baseline@v0.16.0` |
|
|
90
|
+
| `ranacseruet/snapdrift@v0.16.0` with `mode: pr-diff` | `ranacseruet/snapdrift/actions/pr-diff@v0.16.0` |
|
|
91
91
|
|
|
92
92
|
Use the wrappers directly when you want to skip the dispatcher's input indirection, and the lower-level `capture`, `compare`, `scope`, `resolve-baseline`, `stage`, `comment`, and `enforce` actions when you need to orchestrate the stages yourself.
|
|
93
93
|
|
|
@@ -130,7 +130,7 @@ jobs:
|
|
|
130
130
|
done
|
|
131
131
|
|
|
132
132
|
- name: SnapDrift Report
|
|
133
|
-
uses: ranacseruet/snapdrift@v0.
|
|
133
|
+
uses: ranacseruet/snapdrift@v0.16.0
|
|
134
134
|
with:
|
|
135
135
|
mode: pr-diff
|
|
136
136
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -170,7 +170,7 @@ jobs:
|
|
|
170
170
|
done
|
|
171
171
|
|
|
172
172
|
- name: SnapDrift Report
|
|
173
|
-
uses: ranacseruet/snapdrift@v0.
|
|
173
|
+
uses: ranacseruet/snapdrift@v0.16.0
|
|
174
174
|
with:
|
|
175
175
|
mode: pr-diff
|
|
176
176
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -270,6 +270,32 @@ If you're adopting SnapDrift as a replacement for the upstream `snap/github-acti
|
|
|
270
270
|
snapdrift init --from-snap-action .github/workflows/snap.yml
|
|
271
271
|
```
|
|
272
272
|
|
|
273
|
+
## Fast CI with Snap Cloud Batch Screenshots (`capture: "snap"`)
|
|
274
|
+
|
|
275
|
+
When your application deploys preview URLs (e.g., Vercel, Netlify, Cloudflare Pages, AWS Amplify) or runs on a publicly accessible staging server during CI, you can offload screenshot rendering to Snap Cloud while keeping comparison and artifact management local (`provider: "local"`):
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"baseUrl": "https://preview-pr-123.example.com",
|
|
280
|
+
"capture": "snap",
|
|
281
|
+
"snap": {
|
|
282
|
+
"apiKeyEnv": "SNAP_API_KEY"
|
|
283
|
+
},
|
|
284
|
+
"routes": [
|
|
285
|
+
{ "id": "home-desktop", "path": "/", "viewport": "desktop" },
|
|
286
|
+
{ "id": "pricing-desktop", "path": "/pricing", "viewport": "desktop" }
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Why use `capture: "snap"`?
|
|
292
|
+
- **Skips Playwright Installation in CI:** The GitHub Actions wrapper actions (`actions/baseline` and `actions/pr-diff`) detect `capture: "snap"` with a remote `baseUrl` and skip `playwright install --with-deps chromium`, saving 45–90 seconds per workflow run.
|
|
293
|
+
- **Parallel Cloud Rendering:** Snap Cloud renders full-page screenshots concurrently via its batch API (`POST /v1/screenshots`).
|
|
294
|
+
- **Local Diff Engine:** Screenshots are downloaded and diffed locally on the runner with `@snapdrift/compare-core`, keeping full artifact bundles and PR comments in GitHub Actions without requiring hosted project configuration.
|
|
295
|
+
|
|
296
|
+
> [!NOTE]
|
|
297
|
+
> `capture: "snap"` requires a public or preview URL reachable by Snap Cloud. If `baseUrl` points to `localhost` or `127.0.0.1`, SnapDrift will fail with a clear configuration error because Snap Cloud cannot access loopback addresses. For local development or local dev servers, use `capture: "playwright"` (the default).
|
|
298
|
+
|
|
273
299
|
## Low-level actions
|
|
274
300
|
|
|
275
301
|
The `pr-diff` wrapper composes the following low-level steps. They're still available for custom orchestration but most consumers don't need to reach for them:
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Design Specification: Snap Cloud Batch Screenshot Capture Engine
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-10-05
|
|
4
|
+
**Status:** Approved
|
|
5
|
+
**Author:** Pair programming session (Antigravity & Rana)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Context & Motivation
|
|
10
|
+
|
|
11
|
+
SnapDrift currently offers two provider workflows:
|
|
12
|
+
1. **`provider: "local"`**: Executes Playwright locally on the runner to capture screenshots into PNGs, then runs pure-JS pixel comparison (`@snapdrift/compare-core`) and stores baselines in GitHub Actions artifacts.
|
|
13
|
+
2. **`provider: "snap"`**: Connects to Snap Cloud's Visual Regression service (`/v1/visual/*`), requiring a Snap project ID and hosted baseline management.
|
|
14
|
+
|
|
15
|
+
In CI workflows using `provider: "local"`, the primary speed bottleneck is running Playwright on the runner:
|
|
16
|
+
- Downloading and installing Chromium and OS dependencies (`playwright install --with-deps chromium`) adds 45–90 seconds per CI job.
|
|
17
|
+
- Headless rendering on limited CI runner CPU/RAM slows down capture of multi-route configurations.
|
|
18
|
+
|
|
19
|
+
Snap Cloud provides a public Batch Screenshot API (`POST /v1/screenshots` with `items: [...]`) capable of asynchronously capturing up to 50 URLs in parallel on hosted render workers and returning signed image URLs.
|
|
20
|
+
|
|
21
|
+
By adding a pluggable **Snap Cloud batch capture engine** to `provider: "local"`, repositories with public or preview URLs can offload screenshot rendering to Snap Cloud, skip Playwright installation in CI entirely, and continue using GitHub Actions for zero-setup baseline storage, diffing, and PR commenting.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 2. Configuration Contract
|
|
26
|
+
|
|
27
|
+
In `.github/snapdrift.json` (or inline config):
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"provider": "local",
|
|
32
|
+
"capture": "snap",
|
|
33
|
+
"baseUrl": "https://preview.example.com",
|
|
34
|
+
"routes": [
|
|
35
|
+
{ "id": "home", "path": "/", "viewport": "desktop" },
|
|
36
|
+
{ "id": "pricing", "path": "/pricing", "viewport": "mobile" }
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Schema Rules
|
|
42
|
+
- **`capture`**: Optional string. Allowed values: `"playwright"` (default) | `"snap"`. Overridable via `SNAPDRIFT_CAPTURE_ENGINE` environment variable.
|
|
43
|
+
- **Authentication**: When `capture: "snap"`, authentication uses `process.env.SNAP_API_KEY`. No project ID is required.
|
|
44
|
+
- **API URL**: Defaults internally to `https://snap.i2dev.com`.
|
|
45
|
+
- **Base URL Validation**:
|
|
46
|
+
- `isLocalBaseUrl(config.baseUrl)` evaluates loopback addresses (`localhost`, `127.0.0.1`, `::1`, `0.0.0.0`).
|
|
47
|
+
- If `baseUrl` is local and `capture: "snap"` is configured:
|
|
48
|
+
- In CLI/local development, if Playwright is available, it gracefully falls back to local Playwright with a notice, or errors if unresolvable.
|
|
49
|
+
- In CI workflows targeting public preview deployments, `baseUrl` is remote and Snap Cloud batch capture executes.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 3. Data Flow & Batch Lifecycle
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
[Selected Routes]
|
|
57
|
+
│
|
|
58
|
+
▼
|
|
59
|
+
1. Map routes to batch items (url, viewport)
|
|
60
|
+
│
|
|
61
|
+
▼
|
|
62
|
+
2. POST https://snap.i2dev.com/v1/screenshots (Bearer SNAP_API_KEY)
|
|
63
|
+
Body: { format: "png", fullPage: true, items: [...] }
|
|
64
|
+
│
|
|
65
|
+
▼ Returns { batchId, status: "queued", statusUrl }
|
|
66
|
+
3. Poll GET /v1/screenshots/:batchId every 1.5s
|
|
67
|
+
│
|
|
68
|
+
▼ status: "completed"
|
|
69
|
+
4. Download PNGs in parallel from item.imageUrl -> screenshots/<sanitizedRouteId>.png
|
|
70
|
+
│
|
|
71
|
+
▼
|
|
72
|
+
5. Inspect image dimensions and write results.json & manifest.json
|
|
73
|
+
│
|
|
74
|
+
▼
|
|
75
|
+
6. Run local pixel comparison (@snapdrift/compare-core)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Route & Viewport Mapping
|
|
79
|
+
- Viewports are resolved via `@snapdrift/manifest` presets:
|
|
80
|
+
- `"desktop"` → `{ width: 1440, height: 900 }`
|
|
81
|
+
- `"mobile"` → `{ width: 390, height: 844 }`
|
|
82
|
+
- Custom objects `{ width, height }` are passed directly.
|
|
83
|
+
- Full target URLs are constructed via `new URL(route.path, config.baseUrl).href`.
|
|
84
|
+
|
|
85
|
+
### Polling & Timeout
|
|
86
|
+
- Poll interval: 1.5 seconds.
|
|
87
|
+
- Monotonic operation deadline: 5 minutes.
|
|
88
|
+
- Stops when `status === "completed"`.
|
|
89
|
+
|
|
90
|
+
### Artifact Generation
|
|
91
|
+
- Downloaded PNGs are written to `<screenshotsRoot>/screenshots/<sanitizedRouteId>.png`.
|
|
92
|
+
- Output structure matches `runBaselineCapture`:
|
|
93
|
+
- `manifest.json`: lists screenshots with route id, path, viewport, relative imagePath, and dimensions.
|
|
94
|
+
- `results.json`: records capture metadata with engine `snap-batch`.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 4. Error Handling & Resilience
|
|
99
|
+
|
|
100
|
+
1. **Individual Route Failure in Batch**:
|
|
101
|
+
- Snap Cloud returns batches even if some URLs fail (`status: "failed"` on specific items).
|
|
102
|
+
- SnapDrift adheres to its strict baseline contract: any navigation error or HTTP failure rejects the capture to prevent committing broken states.
|
|
103
|
+
- Halts immediately with: `Route "<id>" failed cloud capture: <error.message> (<error.code>)`.
|
|
104
|
+
2. **Authentication (401)**:
|
|
105
|
+
- Fails fast with: `Missing or invalid SNAP_API_KEY for Snap Cloud batch screenshot capture.`
|
|
106
|
+
3. **Transient Server Errors (5xx)**:
|
|
107
|
+
- Retries up to 3 times with exponential backoff (1s, 2s, 4s).
|
|
108
|
+
4. **Rate Limits (429)**:
|
|
109
|
+
- Honors `Retry-After` header when available. Surfaces quota exhaustion errors clearly.
|
|
110
|
+
5. **Private Addresses (400 `unsafe_url`)**:
|
|
111
|
+
- Prevented ahead of time via early `isLocalBaseUrl` check.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 5. GitHub Actions Optimization
|
|
116
|
+
|
|
117
|
+
In `actions/baseline/action.yml` and `actions/pr-diff/action.yml`:
|
|
118
|
+
Playwright installation is skipped when `capture: "snap"` and `baseUrl` is remote:
|
|
119
|
+
|
|
120
|
+
```yaml
|
|
121
|
+
- name: Install Playwright Chromium
|
|
122
|
+
if: >
|
|
123
|
+
steps.scope.outputs.should_run == 'true' &&
|
|
124
|
+
(
|
|
125
|
+
(steps.config.outputs.provider == 'local' && steps.config.outputs.capture_engine != 'snap') ||
|
|
126
|
+
steps.config.outputs.snap_local_capture == 'true' ||
|
|
127
|
+
steps.config.outputs.on_unavailable == 'fallback-local'
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This cuts CI setup time by 45–90 seconds per run on pull requests.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 6. Testing Strategy
|
|
136
|
+
|
|
137
|
+
1. **`@snapdrift/manifest` Tests**:
|
|
138
|
+
- Validate `capture` field (`"playwright"`, `"snap"`).
|
|
139
|
+
- Rejection of invalid capture engine strings.
|
|
140
|
+
2. **`@snapdrift/adapter-fs` Tests**:
|
|
141
|
+
- Unit tests for `runSnapBatchCapture` with mocked HTTP responses:
|
|
142
|
+
- Successful batch submission, polling cycle, and image download.
|
|
143
|
+
- Propagation of single-item failure in batch.
|
|
144
|
+
- Handling 401, 429, and 5xx retries.
|
|
145
|
+
- Verification of output `manifest.json`, `results.json`, and file paths.
|
|
146
|
+
3. **Action Contract Tests**:
|
|
147
|
+
- Verify composite action YAML outputs and Playwright installation condition logic.
|
package/lib/capture-routes.mjs
CHANGED
package/lib/snap-provider.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import { execFileSync } from 'node:child_process';
|
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
5
|
import fs from 'node:fs/promises';
|
|
6
6
|
import fsSync from 'node:fs';
|
|
7
|
-
import net from 'node:net';
|
|
8
7
|
import os from 'node:os';
|
|
9
8
|
import path from 'node:path';
|
|
10
9
|
|
|
@@ -18,7 +17,8 @@ import {
|
|
|
18
17
|
VIEWPORT_PRESETS,
|
|
19
18
|
viewportHash,
|
|
20
19
|
assertUniqueRouteIdFilenames,
|
|
21
|
-
sanitizeRouteId
|
|
20
|
+
sanitizeRouteId,
|
|
21
|
+
isLocalBaseUrl
|
|
22
22
|
} from '@snapdrift/manifest';
|
|
23
23
|
|
|
24
24
|
/** @typedef {import('../types/visual-diff-types').VisualProvider} VisualProvider */
|
|
@@ -226,6 +226,13 @@ function isComparisonMetadata(value) {
|
|
|
226
226
|
}
|
|
227
227
|
if (hasBaseline && (segment.baselineStart < 0 || segment.baselineStart + segment.length > baseline.height)) return false;
|
|
228
228
|
if (hasCurrent && (segment.currentStart < 0 || segment.currentStart + segment.length > current.height)) return false;
|
|
229
|
+
if (segment.comparedOffset !== undefined) {
|
|
230
|
+
if (!hasBaseline || !hasCurrent || (segment.comparedOffset !== -1 && segment.comparedOffset !== 0 && segment.comparedOffset !== 1)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
const comparedStart = segment.currentStart + segment.comparedOffset;
|
|
234
|
+
if (comparedStart < 0 || comparedStart + segment.length > current.height) return false;
|
|
235
|
+
}
|
|
229
236
|
outputStart += segment.length;
|
|
230
237
|
if (hasBaseline) baselineStart += segment.length;
|
|
231
238
|
if (hasCurrent) currentStart += segment.length;
|
|
@@ -558,31 +565,7 @@ function baselineIdForRun(runId) {
|
|
|
558
565
|
return `bsl_${crypto.createHash('sha256').update(runId).digest('hex').slice(0, 24)}`;
|
|
559
566
|
}
|
|
560
567
|
|
|
561
|
-
|
|
562
|
-
* @param {string | undefined} baseUrl
|
|
563
|
-
* @returns {boolean}
|
|
564
|
-
*/
|
|
565
|
-
export function isLocalBaseUrl(baseUrl) {
|
|
566
|
-
if (!baseUrl) {
|
|
567
|
-
return false;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
let hostname;
|
|
571
|
-
try {
|
|
572
|
-
hostname = new URL(baseUrl).hostname.toLowerCase();
|
|
573
|
-
} catch {
|
|
574
|
-
return false;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
const normalized = hostname.replace(/^\[/, '').replace(/\]$/, '');
|
|
578
|
-
if (normalized === 'localhost' || normalized.endsWith('.localhost')) {
|
|
579
|
-
return true;
|
|
580
|
-
}
|
|
581
|
-
if (normalized === '::1' || normalized === '0.0.0.0') {
|
|
582
|
-
return true;
|
|
583
|
-
}
|
|
584
|
-
return net.isIP(normalized) === 4 && normalized.startsWith('127.');
|
|
585
|
-
}
|
|
568
|
+
export { isLocalBaseUrl };
|
|
586
569
|
|
|
587
570
|
/**
|
|
588
571
|
* @param {string} repoSlug
|
package/lib/snapdrift-config.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snapdrift",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "SnapDrift captures, compares, and reports UI drift for Playwright-based app checks.",
|
|
@@ -103,10 +103,10 @@
|
|
|
103
103
|
"registry": "https://registry.npmjs.org"
|
|
104
104
|
},
|
|
105
105
|
"dependencies": {
|
|
106
|
-
"@snapdrift/adapter-fs": "^1.
|
|
106
|
+
"@snapdrift/adapter-fs": "^1.7.0",
|
|
107
107
|
"@snapdrift/adapter-report-md": "^1.4.0",
|
|
108
|
-
"@snapdrift/compare-core": "^1.
|
|
109
|
-
"@snapdrift/manifest": "^1.
|
|
108
|
+
"@snapdrift/compare-core": "^1.6.0",
|
|
109
|
+
"@snapdrift/manifest": "^1.8.0",
|
|
110
110
|
"js-yaml": "^5.4.0",
|
|
111
111
|
"playwright": "^1.59.1",
|
|
112
112
|
"pngjs": "^7.0.0"
|
|
@@ -55,6 +55,12 @@ export interface ComparisonRowMapping {
|
|
|
55
55
|
kind: ComparisonRowKind;
|
|
56
56
|
baselineStart?: number;
|
|
57
57
|
currentStart?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Present when an offset-run row was compared one pixel above or below the
|
|
60
|
+
* recorded current row. Output row i was compared to current row
|
|
61
|
+
* `currentStart + i + comparedOffset`.
|
|
62
|
+
*/
|
|
63
|
+
comparedOffset?: -1 | 0 | 1;
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
export interface VisualRegressionRouteConfig {
|
|
@@ -81,6 +87,7 @@ export interface VisualRegressionConfig {
|
|
|
81
87
|
};
|
|
82
88
|
selection?: VisualRegressionSelectionConfig;
|
|
83
89
|
provider?: 'local' | 'snap';
|
|
90
|
+
capture?: 'playwright' | 'snap';
|
|
84
91
|
snap?: SnapConfig;
|
|
85
92
|
}
|
|
86
93
|
|
|
@@ -121,6 +128,7 @@ export interface VisualBaselineResults {
|
|
|
121
128
|
screenshotsRoot?: string;
|
|
122
129
|
routes: VisualBaselineRouteResult[];
|
|
123
130
|
passed?: boolean;
|
|
131
|
+
engine?: string;
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
/** Exact route/viewport capture identity persisted for hosted baseline validation. */
|