snapdrift 0.12.0 → 0.14.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 +113 -0
- package/README.md +7 -3
- package/action.yml +2 -2
- package/actions/comment/action.yml +8 -37
- package/actions/pr-diff/action.yml +24 -121
- package/actions/scope/action.yml +15 -73
- package/docs/contracts.md +148 -8
- package/docs/integration-guide.md +18 -12
- package/docs/local-cli.md +67 -5
- package/docs/workflow-templates/refresh-baseline-on-merge.yml +1 -1
- package/lib/cli.mjs +4 -0
- package/lib/github-requests.mjs +134 -0
- package/lib/outage-policy.mjs +49 -14
- package/lib/provider.mjs +19 -1
- package/lib/snap-provider.mjs +80 -11
- package/package.json +6 -5
- package/types/visual-diff-types.d.ts +29 -2
package/docs/contracts.md
CHANGED
|
@@ -40,7 +40,7 @@ SnapDrift reads runtime behavior from `.github/snapdrift.json` by default.
|
|
|
40
40
|
| `snap.apiKey` | `string` | Inline API key with `${VAR}` interpolation (mutually exclusive with `snap.apiKeyEnv`) |
|
|
41
41
|
| `snap.projectId` | `string` | Snap project ID or `"auto"` (default: `"auto"`, derives from `GITHUB_REPOSITORY`) |
|
|
42
42
|
| `snap.onUnavailable` | `string` | Behavior when Snap is unreachable: `"fail"` (default), `"warn-and-skip"`, or `"fallback-local"` |
|
|
43
|
-
| `diff.comparisonPolicy` | `{ "version": 1, "threshold": number }` |
|
|
43
|
+
| `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
44
|
|
|
45
45
|
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
46
|
|
|
@@ -155,10 +155,12 @@ The pull request drift bundle contains:
|
|
|
155
155
|
| `current/results.json` | Current capture results |
|
|
156
156
|
| `current/manifest.json` | Current manifest |
|
|
157
157
|
| `current/screenshots/*.png` | Current images |
|
|
158
|
-
| `diffs/*.png` | Generated v1 diff images for changed screenshots |
|
|
158
|
+
| `diffs/*.png` | Generated v1 union or v2 aligned/fallback diff images for changed screenshots |
|
|
159
159
|
|
|
160
160
|
## Screenshot manifest shape
|
|
161
161
|
|
|
162
|
+
Minimal legacy example (new local captures also write `captureProfile`):
|
|
163
|
+
|
|
162
164
|
```json
|
|
163
165
|
{
|
|
164
166
|
"generatedAt": "2024-01-01T00:00:00.000Z",
|
|
@@ -176,6 +178,75 @@ The pull request drift bundle contains:
|
|
|
176
178
|
}
|
|
177
179
|
```
|
|
178
180
|
|
|
181
|
+
### Local capture profile v2
|
|
182
|
+
|
|
183
|
+
New local captures persist `captureProfile` with `schemaVersion: 2`. This version
|
|
184
|
+
is independent of the outer manifest schema (which defaults to 1 when omitted)
|
|
185
|
+
and comparison policy v1. The profile records:
|
|
186
|
+
|
|
187
|
+
| Field | Local capture value |
|
|
188
|
+
|:------|:--------------------|
|
|
189
|
+
| `engine`, `engineVersion` | `{ "name": "snapdrift-local", "version": "<adapter-fs version>" }`; `engineVersion` equals `engine.version` |
|
|
190
|
+
| `browser`, `browserRevision`, `playwrightVersion` | `chromium`, the running browser's `browser.version()` string, and the installed Playwright version |
|
|
191
|
+
| `platform` | `name`, `architecture`, `release`, `version` from Node's OS APIs |
|
|
192
|
+
| `locale`, `timezone` | `en-US`, `UTC` |
|
|
193
|
+
| `settings.screenshot` | `fullPage: true`, `animations: "disabled"`, `caret: "hide"`, `scale: "device"`, `omitBackground: false`, `type: "png"` |
|
|
194
|
+
| `settings.readiness` | `waitUntil: "load"`, `settleDelayMs: 300` |
|
|
195
|
+
| `settings.context` | `isolation: "fresh-context-per-attempt"`, `colorScheme: "light"`, `reducedMotion: "no-preference"`, `forcedColors: "none"`, `javaScriptEnabled: true`, `serviceWorkers: "allow"` |
|
|
196
|
+
| `settings.launch` | `headless: true`, `args: ["--disable-gpu"]` |
|
|
197
|
+
|
|
198
|
+
These are persisted metadata, not new configuration knobs. Local v2 requires
|
|
199
|
+
all listed fields with valid types/settings and matching engine version fields.
|
|
200
|
+
Fonts are **not fingerprinted**: local capture does not populate the optional
|
|
201
|
+
`fontsHash`, so a verified profile is not proof of identical installed fonts.
|
|
202
|
+
Explicit `en-US` / `UTC` replaces environment-dependent defaults and may change
|
|
203
|
+
localized text or dates; recapture affected baselines after upgrading.
|
|
204
|
+
|
|
205
|
+
### Local compatibility before pixels
|
|
206
|
+
|
|
207
|
+
Both manifests are validated after loading and before manifest entries are
|
|
208
|
+
indexed and PNGs are resolved.
|
|
209
|
+
Malformed manifests/profiles and unsupported profile schema versions (anything
|
|
210
|
+
other than omitted, 1, or 2) throw before a comparison summary is generated;
|
|
211
|
+
`report-only` does not suppress these input errors.
|
|
212
|
+
|
|
213
|
+
- Two local v2 profiles must match exactly across the full profile, including
|
|
214
|
+
extra fields. Object key order is ignored; array order and values matter.
|
|
215
|
+
There is no version tolerance: adapter, Playwright, browser, or OS updates can
|
|
216
|
+
require a baseline refresh. The reason identifies the first differing field.
|
|
217
|
+
- For each selected configured route id present in both manifests, both entries
|
|
218
|
+
must have the exact configured `path` and the same normalized viewport as the
|
|
219
|
+
config: width, height, device scale factor, mobile, and touch. Paths are not
|
|
220
|
+
URL-normalized; `baseUrl` and timestamps are not compared. Custom viewports use
|
|
221
|
+
scale 1, mobile false, touch false: 1440×900 equals `desktop`, but 390×844 does
|
|
222
|
+
not equal `mobile`. Missing entries retain their missing/error classification.
|
|
223
|
+
- A profile or route-identity mismatch adds an `errors[]` item with
|
|
224
|
+
`status: "error"` and `code: "incompatible_capture"`. That route's PNGs are
|
|
225
|
+
not resolved, read, or pixel-compared, even if they would be byte-identical.
|
|
226
|
+
The summary is `incomplete`, not product drift. With compatible identity,
|
|
227
|
+
changed full-page raster dimensions remain normal union-canvas `changed[]`
|
|
228
|
+
signals, independent of threshold.
|
|
229
|
+
- Missing profiles or profiles with omitted/v1 schema remain usable but
|
|
230
|
+
`unverified`, with a warning in `summary.message`; pixels can still be compared
|
|
231
|
+
after route checks. If both profiles provide `browser`, `browserRevision`,
|
|
232
|
+
`fontsHash`, `timezone`, or `locale`, a difference in any shared field is
|
|
233
|
+
incompatible. An explicit foreign `engine.name` on either side is incompatible
|
|
234
|
+
even when the other profile is absent. Legacy engine versions alone do not
|
|
235
|
+
establish verified compatibility.
|
|
236
|
+
|
|
237
|
+
`summary.captureCompatibility` contains profile-level `status` (`verified`,
|
|
238
|
+
`unverified`, or `incompatible`) and an optional `reason`. It is **not** an
|
|
239
|
+
aggregate route status: profiles can be `verified` while route path/viewport
|
|
240
|
+
checks produce `incompatible_capture` errors. Unverified alone does not make a
|
|
241
|
+
run incomplete or fail enforcement.
|
|
242
|
+
|
|
243
|
+
Refresh the baseline using the [existing CLI or baseline action](local-cli.md#refreshing-or-acknowledging-local-baselines)
|
|
244
|
+
in the intended capture environment. For intentional nonblocking acknowledgement,
|
|
245
|
+
set `diff.mode` to `report-only`: it preserves incompatibility errors and never
|
|
246
|
+
overrides compatibility to compare pixels. `fail-on-incomplete` and `strict`
|
|
247
|
+
fail on those errors; `fail-on-changes` does not fail on incompatibility alone
|
|
248
|
+
but still fails if other comparable routes changed.
|
|
249
|
+
|
|
179
250
|
## Summary shape
|
|
180
251
|
|
|
181
252
|
```json
|
|
@@ -209,15 +280,24 @@ The pull request drift bundle contains:
|
|
|
209
280
|
|
|
210
281
|
| Field | Type | Description |
|
|
211
282
|
|:------|:-----|:------------|
|
|
283
|
+
| `captureCompatibility` | `{ status, reason? }?` | Local profile-level compatibility: `verified`, `unverified`, or `incompatible`; route identity errors are separate |
|
|
212
284
|
| `dashboardUrl` | `string?` | Snap dashboard URL for the run (set by `SnapProvider`; omitted by `LocalProvider`) |
|
|
213
|
-
| `comparisonPolicy` | `{ "version": 1, "threshold": number }?` | Effective
|
|
285
|
+
| `comparisonPolicy` | `{ "version": 1 \| 2, "threshold": number }?` | Effective comparison policy used by the adapter (deprecated v1 is synthesized from `diff.threshold` when not configured) |
|
|
214
286
|
|
|
215
|
-
When
|
|
287
|
+
When a policy comparison is applied, each affected `changed[]` item may also contain
|
|
216
288
|
`comparison` with `baseline`, `current`, and `canvas` `{ width, height }`
|
|
217
289
|
objects, `dimensionsChanged`, and the effective `totalPixels` denominator. A
|
|
218
290
|
local changed item with a generated image contains `diffImagePath`, relative to
|
|
219
291
|
the diff output bundle (for example `diffs/home.png`).
|
|
220
292
|
|
|
293
|
+
Policy v2 comparison metadata additionally includes `policyVersion: 2` and
|
|
294
|
+
`mode`. An aligned result has `mode: "vertical-aligned"` and a compact
|
|
295
|
+
`rowMapping` describing matched, changed, inserted, and deleted row runs. A
|
|
296
|
+
`mode: "coordinate-fallback"` result includes `fallbackReason` when widths,
|
|
297
|
+
ignore regions, ambiguity, or the alignment resource limit prevent safe row
|
|
298
|
+
alignment. The aligned canvas may be taller than either source image because
|
|
299
|
+
inserted and deleted rows each occupy an output row.
|
|
300
|
+
|
|
221
301
|
When a changed item has a generated local `diffImagePath`, its PR comment cell
|
|
222
302
|
links to the uploaded report artifact (or the workflow run when no artifact URL
|
|
223
303
|
was supplied) and shows the bundle-relative path. It does not use that relative
|
|
@@ -247,11 +327,14 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
247
327
|
|
|
248
328
|
## Drift semantics
|
|
249
329
|
|
|
250
|
-
- Screenshots are matched by `id
|
|
330
|
+
- Screenshots are matched by `id`; local profile and configured path/normalized viewport compatibility are checked before pixels (see [Local compatibility before pixels](#local-compatibility-before-pixels))
|
|
251
331
|
- Mismatch ratio is `different_pixels / total_pixels`
|
|
252
332
|
- `diff.threshold` applies per screenshot
|
|
253
333
|
- Missing captures are counted separately from drift signals
|
|
254
|
-
- Comparison policy v1 `{ "version": 1, "threshold": number }` is
|
|
334
|
+
- 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. Unchanged content that moves after an insertion/deletion remains matched; inserted current rows are green, deleted baseline rows are red, and actual pixel edits are orange. Width changes, ignore regions, ambiguous 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
|
+
- 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
|
+
- 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.
|
|
255
338
|
- `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.
|
|
256
339
|
- Threshold is applied after pixel aggregation. A mismatch exactly equal to the threshold is matched; a dimension change is still a changed signal independent of ratio.
|
|
257
340
|
- `diff.mode` controls enforcement, not summary generation
|
|
@@ -260,7 +343,7 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
260
343
|
|
|
261
344
|
| Mode | Stops the run when |
|
|
262
345
|
|:-----|:-------------------|
|
|
263
|
-
| `report-only` | Never |
|
|
346
|
+
| `report-only` | Never from summary enforcement; validation/capture failures still fail |
|
|
264
347
|
| `fail-on-changes` | `changedScreenshots > 0` |
|
|
265
348
|
| `fail-on-incomplete` | Errors or missing captures occur; a completed v1 dimension comparison alone does not fail |
|
|
266
349
|
| `strict` | Any drift or incomplete comparison appears |
|
|
@@ -300,6 +383,11 @@ The comparator reports this condition with the stable error code
|
|
|
300
383
|
dimensions in the error message. The ceiling that was exceeded is included too,
|
|
301
384
|
since a caller may raise it per call.
|
|
302
385
|
|
|
386
|
+
Policy v2 uses the aligned output height for this same budget. Because an
|
|
387
|
+
inserted row and a deleted row each occupy an output row, that height can be up
|
|
388
|
+
to the sum of the baseline and current heights. If the aligned canvas exceeds
|
|
389
|
+
the budget, v2 returns `comparison_too_large` before allocating a diff image.
|
|
390
|
+
|
|
303
391
|
`32 × 1024 × 1024` is the *default* ceiling, not an algorithm property. The cost
|
|
304
392
|
is dominated by the decoded images: both RGBA inputs (4 bytes per pixel each) are
|
|
305
393
|
retained plus, when the diff image is rendered (the default), a union-sized diff
|
|
@@ -349,6 +437,14 @@ that matches the product behavior. Do not resize or crop screenshots, or lower
|
|
|
349
437
|
| Screenshot animations | `disabled` (Playwright finishes/cancels CSS animations before capture) |
|
|
350
438
|
| Capture concurrency | 5 routes per viewport (overridable via `SNAPDRIFT_CAPTURE_CONCURRENCY`)|
|
|
351
439
|
|
|
440
|
+
Local Playwright captures use a fresh browser context for every route attempt,
|
|
441
|
+
including retries. Cookies and browser storage are not shared between routes,
|
|
442
|
+
even when routes share a viewport or run serially. This also applies to Snap's
|
|
443
|
+
local-capture hybrid, not to rendering performed by the hosted service. Viewport
|
|
444
|
+
groups still run concurrently, with the configured limit applied per group.
|
|
445
|
+
Previously leaked storage may have affected existing baselines; recapture them
|
|
446
|
+
after upgrading if storage-dependent UI produces a one-time change.
|
|
447
|
+
|
|
352
448
|
## Local CLI directory layout
|
|
353
449
|
|
|
354
450
|
When using the `snapdrift` CLI, outputs are written to `.snapdrift/` by default:
|
|
@@ -541,6 +637,50 @@ The wrapper actions (`actions/baseline`, `actions/pr-diff`) and the CLI both han
|
|
|
541
637
|
request or response body is being bounded. It is not an additional public
|
|
542
638
|
error class; callers should handle the exported error classes above.
|
|
543
639
|
|
|
640
|
+
## Shared orchestration
|
|
641
|
+
|
|
642
|
+
GitHub-facing request handling is shared between the wrapper and standalone
|
|
643
|
+
actions through `lib/github-requests.mjs`. The github-script steps stay as thin
|
|
644
|
+
adapters that load the module, inject `{ github, owner, repo, context }`-style
|
|
645
|
+
inputs, and map the returned decision to step outputs:
|
|
646
|
+
|
|
647
|
+
- `fetchPullRequestFiles` paginates `pulls.listFiles` (100 per page) and
|
|
648
|
+
validates each record's `filename` before any scope decision is made.
|
|
649
|
+
- `resolveScopeDecision` is pure: renamed files contribute
|
|
650
|
+
`previous_filename`, paths are deduplicated, 3000+ records short-circuit to
|
|
651
|
+
running all routes (`changed_files_truncated`), and an empty list maps to
|
|
652
|
+
`no_changed_files`. Other reasons come from
|
|
653
|
+
`selectRoutesForChangedFiles`.
|
|
654
|
+
- `resolvePullRequestScope` composes the above with the
|
|
655
|
+
explicit-route/force-run/missing-PR shortcuts and the
|
|
656
|
+
`snapdrift_scope_check_failed` fallback warning.
|
|
657
|
+
- `upsertPullRequestReportComment` performs the marker-filtered, newest-first
|
|
658
|
+
comment upsert with duplicate deletion used by `actions/comment` and the
|
|
659
|
+
`actions/pr-diff` report step. The create-only "Capture Failed" /
|
|
660
|
+
"Baseline Lookup Failed" fallback body remains inline in `actions/pr-diff`.
|
|
661
|
+
|
|
662
|
+
The baseline resolver keeps its own module (`lib/resolve-baseline-artifact.mjs`)
|
|
663
|
+
because both actions already share it verbatim.
|
|
664
|
+
|
|
665
|
+
### Capture artifact capabilities
|
|
666
|
+
|
|
667
|
+
Providers now return `artifacts` on capture results, attached in the provider layer
|
|
668
|
+
rather than adapter-fs:
|
|
669
|
+
|
|
670
|
+
- `localScreenshots`: whether PNGs are available locally for pixel comparison.
|
|
671
|
+
- `artifactsRoot`: the capture's `screenshotsRoot` for local and Snap hybrid
|
|
672
|
+
captures (`localScreenshots: true`); `undefined` for hosted remote captures
|
|
673
|
+
(`localScreenshots: false`), even though their metadata has a local path.
|
|
674
|
+
|
|
675
|
+
`captureWithPolicy` prefers `result.artifacts` over provider-name/base-URL inference.
|
|
676
|
+
For `diffWithPolicy`, pass the capture as `captureResult` or forward its `artifacts`.
|
|
677
|
+
Precedence is the legacy `options.localScreenshots` boolean (if supplied), then
|
|
678
|
+
`options.artifacts`, then `captureResult.artifacts`, then provider/config inference.
|
|
679
|
+
The boolean overrides only `localScreenshots`; false clears `artifactsRoot`.
|
|
680
|
+
Inference remains for legacy results without a descriptor when config is supplied.
|
|
681
|
+
If no capability arguments, result descriptor, or config are supplied to
|
|
682
|
+
`diffWithPolicy`, it preserves the legacy local-screenshots default without recapture.
|
|
683
|
+
|
|
544
684
|
## Primary entrypoints
|
|
545
685
|
|
|
546
686
|
- `actions/baseline`
|
|
@@ -567,7 +707,7 @@ These are for custom orchestration only. Wrapper actions set them automatically.
|
|
|
567
707
|
| `SNAPDRIFT_BASELINE_ARTIFACT_NAME` | `compare-results.mjs` | Baseline artifact label to embed in the report |
|
|
568
708
|
| `SNAPDRIFT_BASELINE_SOURCE_SHA` | `compare-results.mjs` | Baseline source SHA to embed in the report |
|
|
569
709
|
| `SNAPDRIFT_ENFORCE_OUTCOME` | `compare-results.mjs` | Set to `0` to disable enforcement in direct CLI usage |
|
|
570
|
-
| `SNAPDRIFT_CAPTURE_CONCURRENCY` | `capture-routes.mjs` | Max concurrent route captures per viewport
|
|
710
|
+
| `SNAPDRIFT_CAPTURE_CONCURRENCY` | `capture-routes.mjs` | Max concurrent route captures per viewport group (positive integer, default `5`). Each local attempt uses a fresh browser context. Set to `1` to serialize each group without sharing storage. |
|
|
571
711
|
|
|
572
712
|
## PR comment markdown shape
|
|
573
713
|
|
|
@@ -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.14.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.14.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.14.0` with `mode: baseline` | `ranacseruet/snapdrift/actions/baseline@v0.14.0` |
|
|
90
|
+
| `ranacseruet/snapdrift@v0.14.0` with `mode: pr-diff` | `ranacseruet/snapdrift/actions/pr-diff@v0.14.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.14.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.14.0
|
|
174
174
|
with:
|
|
175
175
|
mode: pr-diff
|
|
176
176
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -309,10 +309,13 @@ See the [Local CLI guide](local-cli.md) for full command reference, flags, direc
|
|
|
309
309
|
## Refresh the baseline automatically
|
|
310
310
|
|
|
311
311
|
After an intentional layout change merges, the baseline can be republished as
|
|
312
|
-
usual. Local comparisons
|
|
313
|
-
(`{ "version": 1, "threshold": number }`)
|
|
314
|
-
when not configured — so unequal frames are
|
|
315
|
-
dimension metadata stays in the report.
|
|
312
|
+
usual. Local comparisons retain deprecated policy v1
|
|
313
|
+
(`{ "version": 1, "threshold": number }`) as the compatibility default —
|
|
314
|
+
synthesized from `diff.threshold` when not configured — so unequal frames are
|
|
315
|
+
compared on a union canvas and dimension metadata stays in the report. New
|
|
316
|
+
configurations should set `diff.comparisonPolicy.version` to `2` to opt into
|
|
317
|
+
bounded vertical row alignment; the report records aligned results and
|
|
318
|
+
coordinate fallbacks.
|
|
316
319
|
|
|
317
320
|
Use the provided workflow template to refresh the baseline automatically on every push to your default branch (i.e. every merge):
|
|
318
321
|
|
|
@@ -340,8 +343,11 @@ Grant `issues: write` and `pull-requests: write` to the job.
|
|
|
340
343
|
The Snap client never retries 4xx and never falls back, even when `onUnavailable` is set. Inspect the response body — the most common cause is a project-id mismatch between `GITHUB_REPOSITORY` (auto-derived) and the project's id on Snap.
|
|
341
344
|
|
|
342
345
|
**Screenshots have different dimensions**
|
|
343
|
-
SnapDrift compares the top-left-aligned union canvas
|
|
344
|
-
|
|
346
|
+
SnapDrift compares the top-left-aligned union canvas by default. Policy v2 can
|
|
347
|
+
align equal-width rows so unchanged content after an insertion is not painted
|
|
348
|
+
as drift; width changes, ignored regions, ambiguous rows, and resource limits
|
|
349
|
+
fall back to coordinate comparison. Either policy records the route in
|
|
350
|
+
`changed[]`, and local runs write a diff PNG. Refresh the baseline after an
|
|
345
351
|
intentional change when you want future runs to return to equal-size
|
|
346
352
|
comparisons.
|
|
347
353
|
|
package/docs/local-cli.md
CHANGED
|
@@ -203,6 +203,61 @@ The `--open` flag opens the HTML report in your default browser when the diff is
|
|
|
203
203
|
|
|
204
204
|
---
|
|
205
205
|
|
|
206
|
+
## Refreshing or acknowledging local baselines
|
|
207
|
+
|
|
208
|
+
New local manifests record a [v2 capture profile](contracts.md#local-capture-profile-v2)
|
|
209
|
+
with exact engine, Playwright/browser, OS, locale/timezone, and rendering settings.
|
|
210
|
+
Manifests are validated after loading; then, before resolving PNGs, comparison
|
|
211
|
+
checks the profiles and each selected route's id, exact configured path, and
|
|
212
|
+
normalized viewport. A mismatch produces an
|
|
213
|
+
`incompatible_capture` error and an `incomplete` summary, not a pixel drift
|
|
214
|
+
signal. Matching profiles can still have route-identity errors:
|
|
215
|
+
`summary.captureCompatibility.status` describes profiles only.
|
|
216
|
+
|
|
217
|
+
To refresh, serve the intended accepted application state using the same capture
|
|
218
|
+
environment and route config as future diffs. With `provider: "local"`, run:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
snapdrift baseline --config .github/snapdrift.json --baseline-dir .snapdrift/baseline
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
This overwrites baseline metadata and captured screenshots; `snapdrift capture`
|
|
225
|
+
with the same options is equivalent for the local provider. Capture all routes
|
|
226
|
+
for a complete replacement, without `--routes` or `SNAPDRIFT_ROUTE_IDS` scoping.
|
|
227
|
+
Then serve the candidate application state and run:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
snapdrift diff --config .github/snapdrift.json --baseline-dir .snapdrift/baseline --open
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
In CI, run the existing default-branch baseline workflow using the root action's
|
|
234
|
+
`mode: baseline` ([Quickstart](../README.md#quickstart)) or `actions/baseline`.
|
|
235
|
+
Use the same upgraded SnapDrift/action revision and runner environment for
|
|
236
|
+
baseline and PR captures, with artifact upload enabled; then rerun the PR diff.
|
|
237
|
+
A baseline captured on a different OS is not interchangeable merely because
|
|
238
|
+
both commands use Playwright.
|
|
239
|
+
|
|
240
|
+
For intentional nonblocking acknowledgement, set `diff.mode` to `report-only`
|
|
241
|
+
in the config and rerun `snapdrift diff --open`. This keeps the incompatibility
|
|
242
|
+
errors visible and **never overrides compatibility to compare pixels**; there
|
|
243
|
+
is no diff acceptance flag. `fail-on-incomplete` and `strict` fail on these
|
|
244
|
+
errors; `fail-on-changes` fails only if other comparable routes changed. Once
|
|
245
|
+
identity is compatible, a changed full-page PNG size is normal product drift,
|
|
246
|
+
not incompatibility, and fails `fail-on-changes` / `strict` even below threshold.
|
|
247
|
+
|
|
248
|
+
Legacy manifests with missing profiles or omitted/v1 profile schema remain
|
|
249
|
+
pixel-comparable after route checks, but report `unverified` with a warning.
|
|
250
|
+
Conflicting shared browser/revision, fonts hash, locale, or timezone fields, or
|
|
251
|
+
an explicit foreign engine on either side, are still incompatible. Malformed
|
|
252
|
+
manifests/profiles and unsupported profile schema versions abort comparison,
|
|
253
|
+
even in `report-only`; refresh rather than editing metadata to force a match.
|
|
254
|
+
|
|
255
|
+
Local capture now explicitly uses `en-US` and `UTC`; localized text/date changes
|
|
256
|
+
may require recapture after upgrading. Fonts are not fingerprinted, so keep
|
|
257
|
+
installed fonts consistent even when profiles are verified.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
206
261
|
## Local directory layout
|
|
207
262
|
|
|
208
263
|
After running `capture` and `diff` with default paths:
|
|
@@ -239,7 +294,7 @@ Add `.snapdrift/` to your `.gitignore` to keep local run output out of version c
|
|
|
239
294
|
| `0` | Clean — no drift above threshold, `diff.mode` is `report-only`, the command was intentionally skipped under `onUnavailable: "warn-and-skip"` (`diff`, `capture` and `baseline` all exit 0 in that case), or the command was a `capture` / `baseline` / `migrate-baselines --to local` / `init` that completed |
|
|
240
295
|
| `1` | Drift enforced — `diff.mode` caused the run to fail, a required command argument was missing, or the `--to local` engine-name check failed (see [Drift modes](../README.md#drift-modes)) |
|
|
241
296
|
|
|
242
|
-
Enforcement follows the same `diff.mode` rules as the GitHub Actions workflow. Set `"mode": "report-only"`
|
|
297
|
+
Enforcement follows the same `diff.mode` rules as the GitHub Actions workflow. Set `"mode": "report-only"` for nonblocking report inspection; capture, input-validation, and other command failures still exit 1 and can prevent report generation.
|
|
243
298
|
|
|
244
299
|
---
|
|
245
300
|
|
|
@@ -290,14 +345,21 @@ The `Missing`, `Errors`, and `Dim diff` lines only print when their count is gre
|
|
|
290
345
|
|
|
291
346
|
The `report.html` path is printed whenever the status is anything other than `clean`; pass `--open` to also launch it in your default browser.
|
|
292
347
|
|
|
293
|
-
SnapDrift
|
|
294
|
-
|
|
295
|
-
|
|
348
|
+
SnapDrift retains deprecated comparison policy v1 for compatibility unless an
|
|
349
|
+
explicit v2 policy is configured. It synthesizes v1 from `diff.threshold` when
|
|
350
|
+
`diff` does not declare one. New configurations should use v2:
|
|
296
351
|
|
|
297
352
|
```json
|
|
298
353
|
"comparisonPolicy": { "version": 1, "threshold": 0.01 }
|
|
299
354
|
```
|
|
300
355
|
|
|
356
|
+
Set `version` to `2` to enable bounded vertical row alignment for equal-width
|
|
357
|
+
captures. Reports record aligned results and conservative coordinate fallbacks:
|
|
358
|
+
|
|
359
|
+
```json
|
|
360
|
+
"comparisonPolicy": { "version": 2, "threshold": 0.01 }
|
|
361
|
+
```
|
|
362
|
+
|
|
301
363
|
The report includes the baseline, current, and union-canvas dimensions in
|
|
302
364
|
`summary.md` and `report.html`, and stores changed-route diff PNGs under
|
|
303
365
|
`.snapdrift/diff/diffs/`. A completed dimension comparison is a normal changed
|
|
@@ -310,7 +372,7 @@ differ; `fail-on-changes` and `strict` still enforce it.
|
|
|
310
372
|
|
|
311
373
|
| Variable | Applies to | Description |
|
|
312
374
|
|:---------|:-----------|:------------|
|
|
313
|
-
| `SNAPDRIFT_CAPTURE_CONCURRENCY` | `capture`, `diff` | Max concurrent route operations (positive integer, default `5`): route captures per viewport
|
|
375
|
+
| `SNAPDRIFT_CAPTURE_CONCURRENCY` | `capture`, `diff` | Max concurrent route operations (positive integer, default `5`): route captures per viewport group, and per-route resolve/compare during `diff`. Each local capture attempt uses isolated browser storage. Set to `1` to serialize captures within each viewport group, without sharing storage. |
|
|
314
376
|
| `SNAPDRIFT_CONFIG_PATH` | `capture`, `diff`, `migrate-baselines` | Override the config file path. Equivalent to `--config`. |
|
|
315
377
|
| `SNAPDRIFT_ROUTE_IDS` | `capture`, `baseline`, `diff` | Comma-separated route ids to scope to. Equivalent to `--routes`; it may not reduce a hosted baseline's complete route set. |
|
|
316
378
|
|
package/lib/cli.mjs
CHANGED
|
@@ -214,6 +214,10 @@ export function printSummary(summary) {
|
|
|
214
214
|
if (errors > 0) process.stdout.write(` Errors: ${errors}\n`);
|
|
215
215
|
if (dimensionChanges > 0) process.stdout.write(` Dim diff: ${dimensionChanges}\n`);
|
|
216
216
|
|
|
217
|
+
if (summary.captureCompatibility?.status === 'unverified' && summary.message) {
|
|
218
|
+
process.stdout.write(` Note: ${summary.message}\n`);
|
|
219
|
+
}
|
|
220
|
+
|
|
217
221
|
if (summary.changed?.length) {
|
|
218
222
|
process.stdout.write('\n Changed routes:\n');
|
|
219
223
|
for (const item of summary.changed) {
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { selectConfiguredRoutes, selectRoutesForChangedFiles, splitCommaList } from './snapdrift-config.mjs';
|
|
4
|
+
|
|
5
|
+
/** @typedef {import('../types/visual-diff-types').VisualRegressionConfig} VisualRegressionConfig */
|
|
6
|
+
/** @typedef {{ filename: string, status?: string, previous_filename?: string }} PullRequestFile */
|
|
7
|
+
/** @typedef {ReturnType<typeof selectRoutesForChangedFiles>} ScopeDecision */
|
|
8
|
+
/** @typedef {{ paginate: Function, rest: { pulls: { listFiles: Function } } }} ScopeGitHubClient */
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* paginate: Function,
|
|
12
|
+
* rest: { issues: {
|
|
13
|
+
* listComments: Function,
|
|
14
|
+
* createComment: Function,
|
|
15
|
+
* updateComment: Function,
|
|
16
|
+
* deleteComment: Function
|
|
17
|
+
* } }
|
|
18
|
+
* }} CommentGitHubClient
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{ github: ScopeGitHubClient, owner: string, repo: string, pullNumber: number }} options
|
|
23
|
+
* @returns {Promise<PullRequestFile[]>}
|
|
24
|
+
*/
|
|
25
|
+
export async function fetchPullRequestFiles({ github, owner, repo, pullNumber }) {
|
|
26
|
+
const files = await github.paginate(github.rest.pulls.listFiles, {
|
|
27
|
+
owner,
|
|
28
|
+
repo,
|
|
29
|
+
pull_number: pullNumber,
|
|
30
|
+
per_page: 100
|
|
31
|
+
});
|
|
32
|
+
if (!Array.isArray(files)) {
|
|
33
|
+
throw new Error('Malformed GitHub changed-file response: expected an array of file records.');
|
|
34
|
+
}
|
|
35
|
+
for (const [index, file] of files.entries()) {
|
|
36
|
+
if (!file || typeof file !== 'object' || typeof file.filename !== 'string' || file.filename.length === 0) {
|
|
37
|
+
throw new Error(`Malformed GitHub changed-file response: file record ${index} must include a non-empty string filename.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return files;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {{ config: VisualRegressionConfig, files: PullRequestFile[] }} options
|
|
45
|
+
* @returns {ScopeDecision}
|
|
46
|
+
*/
|
|
47
|
+
export function resolveScopeDecision({ config, files }) {
|
|
48
|
+
if (files.length >= 3000) {
|
|
49
|
+
return { shouldRun: true, reason: 'changed_files_truncated', selectedRouteIds: (config.routes || []).map((route) => route.id) };
|
|
50
|
+
}
|
|
51
|
+
const changedFiles = [...new Set(files.flatMap((file) => [
|
|
52
|
+
file.filename,
|
|
53
|
+
...(file.status === 'renamed' && typeof file.previous_filename === 'string' && file.previous_filename
|
|
54
|
+
? [file.previous_filename]
|
|
55
|
+
: [])
|
|
56
|
+
]))];
|
|
57
|
+
return selectRoutesForChangedFiles(config, changedFiles);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {{
|
|
62
|
+
* github: ScopeGitHubClient,
|
|
63
|
+
* owner: string,
|
|
64
|
+
* repo: string,
|
|
65
|
+
* config: VisualRegressionConfig,
|
|
66
|
+
* pullNumber: number,
|
|
67
|
+
* routeIds?: string,
|
|
68
|
+
* forceRun?: boolean,
|
|
69
|
+
* forceRunReason?: string,
|
|
70
|
+
* warning?: (message: string) => void
|
|
71
|
+
* }} options
|
|
72
|
+
* @returns {Promise<ScopeDecision>}
|
|
73
|
+
*/
|
|
74
|
+
export async function resolvePullRequestScope({ github, owner, repo, config, pullNumber, routeIds = '', forceRun = false, forceRunReason = 'forced', warning = (_message) => {} }) {
|
|
75
|
+
const allRouteIds = (config.routes || []).map((route) => route.id);
|
|
76
|
+
const explicitRouteIds = splitCommaList(routeIds);
|
|
77
|
+
if (explicitRouteIds.length > 0) {
|
|
78
|
+
const selected = selectConfiguredRoutes(config, explicitRouteIds);
|
|
79
|
+
return { shouldRun: true, reason: 'explicit_route_ids', selectedRouteIds: selected.selectedRouteIds };
|
|
80
|
+
}
|
|
81
|
+
if (forceRun) {
|
|
82
|
+
return { shouldRun: true, reason: forceRunReason || 'forced', selectedRouteIds: allRouteIds };
|
|
83
|
+
}
|
|
84
|
+
if (!Number.isFinite(pullNumber) || pullNumber <= 0) {
|
|
85
|
+
return { shouldRun: true, reason: 'missing_pr_number', selectedRouteIds: allRouteIds };
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const files = await fetchPullRequestFiles({ github, owner, repo, pullNumber });
|
|
89
|
+
const scope = resolveScopeDecision({ config, files });
|
|
90
|
+
if (scope.reason === 'changed_files_truncated') {
|
|
91
|
+
warning('GitHub returned the maximum 3000 changed-file records; the list may be truncated, so running all configured captures.');
|
|
92
|
+
}
|
|
93
|
+
return scope;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
warning(`Unable to inspect PR files for SnapDrift scope; running all configured captures instead. ${error.message}`);
|
|
96
|
+
return { shouldRun: true, reason: 'snapdrift_scope_check_failed', selectedRouteIds: allRouteIds };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {{
|
|
102
|
+
* github: CommentGitHubClient,
|
|
103
|
+
* owner: string,
|
|
104
|
+
* repo: string,
|
|
105
|
+
* issueNumber: number,
|
|
106
|
+
* body: string,
|
|
107
|
+
* markers: readonly string[]
|
|
108
|
+
* }} options
|
|
109
|
+
* @returns {Promise<void>}
|
|
110
|
+
*/
|
|
111
|
+
export async function upsertPullRequestReportComment({ github, owner, repo, issueNumber, body, markers }) {
|
|
112
|
+
const comments = await github.paginate(github.rest.issues.listComments, {
|
|
113
|
+
owner,
|
|
114
|
+
repo,
|
|
115
|
+
issue_number: issueNumber,
|
|
116
|
+
per_page: 100
|
|
117
|
+
});
|
|
118
|
+
const matchingComments = comments
|
|
119
|
+
.filter((comment) => comment.body && markers.some((marker) => comment.body.includes(marker)))
|
|
120
|
+
.sort((left, right) => {
|
|
121
|
+
const leftTime = new Date(left.updated_at || left.created_at).getTime();
|
|
122
|
+
const rightTime = new Date(right.updated_at || right.created_at).getTime();
|
|
123
|
+
return rightTime - leftTime;
|
|
124
|
+
});
|
|
125
|
+
const existing = matchingComments[0];
|
|
126
|
+
if (existing) {
|
|
127
|
+
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
|
|
128
|
+
} else {
|
|
129
|
+
await github.rest.issues.createComment({ owner, repo, issue_number: issueNumber, body });
|
|
130
|
+
}
|
|
131
|
+
for (const duplicate of matchingComments.slice(1)) {
|
|
132
|
+
await github.rest.issues.deleteComment({ owner, repo, comment_id: duplicate.id });
|
|
133
|
+
}
|
|
134
|
+
}
|