snapdrift 0.13.0 → 0.15.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 +66 -0
- package/README.md +3 -3
- package/action.yml +2 -2
- package/docs/contracts.md +25 -6
- package/docs/integration-guide.md +18 -12
- package/docs/local-cli.md +10 -3
- package/docs/workflow-templates/refresh-baseline-on-merge.yml +1 -1
- package/lib/snap-provider.mjs +85 -10
- package/package.json +5 -5
- package/types/visual-diff-types.d.ts +34 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.15.0 - 2026-09-22
|
|
6
|
+
|
|
7
|
+
Workspace releases this version:
|
|
8
|
+
|
|
9
|
+
- `@snapdrift/compare-core` 1.6.0 — vertical-offset alignment when exact row
|
|
10
|
+
matching hits its edit cap, including alpha-aware highlighting and the
|
|
11
|
+
search memory caps.
|
|
12
|
+
- `@snapdrift/manifest` 1.7.0 — `comparedOffset` on comparison row mappings.
|
|
13
|
+
- `@snapdrift/adapter-fs` 1.6.0 — depends on that compare-core so local policy
|
|
14
|
+
v2 comparisons use the offset-run engine.
|
|
15
|
+
|
|
16
|
+
`@snapdrift/adapter-report-md` stays 1.4.0. Root floors move to
|
|
17
|
+
`@snapdrift/compare-core ^1.6.0`, `@snapdrift/manifest ^1.7.0`, and
|
|
18
|
+
`@snapdrift/adapter-fs ^1.6.0`. The dispatcher pins `7b7b913`, the #179 merge
|
|
19
|
+
commit on `main`, which contains the offset-run runtime loaded by both wrapper
|
|
20
|
+
actions.
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
- Comparison policy v2, after exact row alignment hits its edit cap, maps long
|
|
25
|
+
vertical-offset runs so an insertion does not highlight the rest of a shifted
|
|
26
|
+
page. A matched row on that path was mapped and fell below the highlight
|
|
27
|
+
rule; it does not have to be byte-identical. When the compared row is one
|
|
28
|
+
pixel above or below the recorded current row, the mapping includes
|
|
29
|
+
`comparedOffset` (`-1` or `1`).
|
|
30
|
+
- Offset highlighting includes alpha. Scoring ignores fully transparent pixels
|
|
31
|
+
and treats a large opacity change as a structured mismatch, so a small alpha
|
|
32
|
+
delta stays on the offset path.
|
|
33
|
+
- The offset search rejects a page before allocating its score matrices when
|
|
34
|
+
those matrices would exceed 64 MB. It also samples every 32nd row first and
|
|
35
|
+
stops that sample once the page cannot be a correspondence, so a dissimilar
|
|
36
|
+
page falls back without scoring every offset. A dissimilar 1440×5622 pair
|
|
37
|
+
fell back in about 0.9s; scoring every offset on that pair took about 3.5s.
|
|
38
|
+
- An offset canvas that would exceed `maxPixels` falls back to coordinate
|
|
39
|
+
comparison instead of throwing. The coordinate union can still throw when it
|
|
40
|
+
itself exceeds the limit.
|
|
41
|
+
|
|
42
|
+
## 0.14.0 - 2026-09-21
|
|
43
|
+
|
|
44
|
+
Workspace releases this version:
|
|
45
|
+
|
|
46
|
+
- `@snapdrift/compare-core` 1.5.0 — bounded vertical row alignment and comparison
|
|
47
|
+
policy v2, with conservative coordinate fallbacks and resource limits.
|
|
48
|
+
- `@snapdrift/manifest` 1.6.0 — policy v2 validation, constants, and comparison types.
|
|
49
|
+
- `@snapdrift/adapter-fs` 1.5.0 — local policy v2 comparison and summary types.
|
|
50
|
+
- `@snapdrift/adapter-report-md` 1.4.0 — alignment and fallback details in Markdown,
|
|
51
|
+
HTML, and bounded PR comments.
|
|
52
|
+
|
|
53
|
+
Root and workspace dependency floors require these versions so upgrades receive
|
|
54
|
+
all parts of the policy v2 implementation. The dispatcher pins `576e774`, the
|
|
55
|
+
#176 merge commit on `main`, including the runtime loaded by both wrapper actions.
|
|
56
|
+
|
|
57
|
+
### Features
|
|
58
|
+
|
|
59
|
+
- Added opt-in comparison policy v2 with bounded vertical row alignment for
|
|
60
|
+
inserted and deleted page rows. Unchanged content that shifts after an
|
|
61
|
+
insertion remains matched; reports record aligned results and conservative
|
|
62
|
+
coordinate fallbacks. Deprecated policy v1 remains the compatibility default
|
|
63
|
+
so existing configurations are unchanged; new configurations should use v2.
|
|
64
|
+
|
|
65
|
+
- Snap-provider requests forward policy v2 and validate hosted acknowledgements
|
|
66
|
+
and alignment metadata. Hosted use requires matching Snap service support;
|
|
67
|
+
publishing this library does not deploy the hosted service.
|
|
68
|
+
|
|
3
69
|
## 0.13.0 - 2026-09-19
|
|
4
70
|
|
|
5
71
|
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.15.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.15.0
|
|
64
64
|
with:
|
|
65
65
|
mode: pr-diff
|
|
66
66
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -121,7 +121,7 @@ before pixels. Incompatible captures produce incomplete errors, not product drif
|
|
|
121
121
|
- Viewport presets: `desktop` (1440×900) and `mobile` (390×844), or custom `{ "width": number, "height": number }`
|
|
122
122
|
- Full-page comparisons are bounded to a 32 Mi-pixel union canvas; see the [screenshot size budget](docs/contracts.md#screenshot-size-budget) for viewport, device-scale, and remediation guidance
|
|
123
123
|
- One global `diff.threshold`
|
|
124
|
-
- Unequal dimensions
|
|
124
|
+
- Unequal dimensions use deprecated top-left union comparison policy v1 by default for compatibility; new configurations should opt into policy v2 with `{ "version": 2, "threshold": number }` for bounded vertical row alignment of inserted/deleted content
|
|
125
125
|
- Local provider writes artifacts to the runner filesystem; for a hosted backend with a dashboard and a shared baseline store, configure `provider: "snap"` (see the [Integration Guide](docs/integration-guide.md#hosted-snap-provider))
|
|
126
126
|
- Hosted Snap baselines publish only from the default branch and always include the complete configured route set
|
|
127
127
|
|
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@7b7b9138416fd16631c5d648b2ddfa9fe4a6a783 # v0.15.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@7b7b9138416fd16631c5d648b2ddfa9fe4a6a783 # v0.15.0
|
|
169
169
|
with:
|
|
170
170
|
github-token: ${{ inputs.github-token }}
|
|
171
171
|
repo-config-path: ${{ inputs.repo-config-path }}
|
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,7 +155,7 @@ 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
|
|
|
@@ -282,14 +282,26 @@ but still fails if other comparable routes changed.
|
|
|
282
282
|
|:------|:-----|:------------|
|
|
283
283
|
| `captureCompatibility` | `{ status, reason? }?` | Local profile-level compatibility: `verified`, `unverified`, or `incompatible`; route identity errors are separate |
|
|
284
284
|
| `dashboardUrl` | `string?` | Snap dashboard URL for the run (set by `SnapProvider`; omitted by `LocalProvider`) |
|
|
285
|
-
| `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) |
|
|
286
286
|
|
|
287
|
-
When
|
|
287
|
+
When a policy comparison is applied, each affected `changed[]` item may also contain
|
|
288
288
|
`comparison` with `baseline`, `current`, and `canvas` `{ width, height }`
|
|
289
289
|
objects, `dimensionsChanged`, and the effective `totalPixels` denominator. A
|
|
290
290
|
local changed item with a generated image contains `diffImagePath`, relative to
|
|
291
291
|
the diff output bundle (for example `diffs/home.png`).
|
|
292
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
|
+
matched offset-run was mapped and fell below the highlight rule, so its rows
|
|
297
|
+
need not be byte-identical. A segment may include `comparedOffset` of `-1` or
|
|
298
|
+
`1` when the compared current row is one pixel away from `currentStart`; output
|
|
299
|
+
row `i` was compared to current row `currentStart + i + comparedOffset`. A `mode: "coordinate-fallback"` result
|
|
300
|
+
includes `fallbackReason` when widths, ignore regions, ambiguity, or the
|
|
301
|
+
alignment resource limit prevent safe row alignment. The aligned canvas may be
|
|
302
|
+
taller than either source image because inserted and deleted rows each occupy
|
|
303
|
+
an output row.
|
|
304
|
+
|
|
293
305
|
When a changed item has a generated local `diffImagePath`, its PR comment cell
|
|
294
306
|
links to the uploaded report artifact (or the workflow run when no artifact URL
|
|
295
307
|
was supplied) and shows the bundle-relative path. It does not use that relative
|
|
@@ -323,8 +335,10 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
323
335
|
- Mismatch ratio is `different_pixels / total_pixels`
|
|
324
336
|
- `diff.threshold` applies per screenshot
|
|
325
337
|
- Missing captures are counted separately from drift signals
|
|
326
|
-
- Comparison policy v1 `{ "version": 1, "threshold": number }` is
|
|
327
|
-
-
|
|
338
|
+
- 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.
|
|
339
|
+
- 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.
|
|
340
|
+
- 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.
|
|
341
|
+
- 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.
|
|
328
342
|
- `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.
|
|
329
343
|
- 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.
|
|
330
344
|
- `diff.mode` controls enforcement, not summary generation
|
|
@@ -373,6 +387,11 @@ The comparator reports this condition with the stable error code
|
|
|
373
387
|
dimensions in the error message. The ceiling that was exceeded is included too,
|
|
374
388
|
since a caller may raise it per call.
|
|
375
389
|
|
|
390
|
+
Policy v2 uses the aligned output height for this same budget. Because an
|
|
391
|
+
inserted row and a deleted row each occupy an output row, that height can be up
|
|
392
|
+
to the sum of the baseline and current heights. If the aligned canvas exceeds
|
|
393
|
+
the budget, v2 returns `comparison_too_large` before allocating a diff image.
|
|
394
|
+
|
|
376
395
|
`32 × 1024 × 1024` is the *default* ceiling, not an algorithm property. The cost
|
|
377
396
|
is dominated by the decoded images: both RGBA inputs (4 bytes per pixel each) are
|
|
378
397
|
retained plus, when the diff image is rendered (the default), a union-sized diff
|
|
@@ -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.15.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.15.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.15.0` with `mode: baseline` | `ranacseruet/snapdrift/actions/baseline@v0.15.0` |
|
|
90
|
+
| `ranacseruet/snapdrift@v0.15.0` with `mode: pr-diff` | `ranacseruet/snapdrift/actions/pr-diff@v0.15.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.15.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.15.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
|
@@ -345,14 +345,21 @@ The `Missing`, `Errors`, and `Dim diff` lines only print when their count is gre
|
|
|
345
345
|
|
|
346
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.
|
|
347
347
|
|
|
348
|
-
SnapDrift
|
|
349
|
-
|
|
350
|
-
|
|
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:
|
|
351
351
|
|
|
352
352
|
```json
|
|
353
353
|
"comparisonPolicy": { "version": 1, "threshold": 0.01 }
|
|
354
354
|
```
|
|
355
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
|
+
|
|
356
363
|
The report includes the baseline, current, and union-canvas dimensions in
|
|
357
364
|
`summary.md` and `report.html`, and stores changed-route diff PNGs under
|
|
358
365
|
`.snapdrift/diff/diffs/`. A completed dimension comparison is a normal changed
|
package/lib/snap-provider.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import path from 'node:path';
|
|
|
10
10
|
|
|
11
11
|
import { makeMarkdown, buildReportCommentBody } from '@snapdrift/adapter-report-md';
|
|
12
12
|
import { loadSnapdriftConfig, runBaselineCapture } from '@snapdrift/adapter-fs';
|
|
13
|
+
import { COMPARISON_FALLBACK_REASONS, COMPARISON_ROW_KINDS } from '@snapdrift/compare-core';
|
|
13
14
|
import {
|
|
14
15
|
selectConfiguredRoutes,
|
|
15
16
|
splitCommaList,
|
|
@@ -148,7 +149,7 @@ function hostedDiffError(detail) {
|
|
|
148
149
|
function isComparisonPolicy(value) {
|
|
149
150
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
150
151
|
const policy = /** @type {Record<string, any>} */ (value);
|
|
151
|
-
return policy.version === 1 && typeof policy.threshold === 'number' && Number.isFinite(policy.threshold) && policy.threshold >= 0 && policy.threshold <= 1;
|
|
152
|
+
return (policy.version === 1 || policy.version === 2) && typeof policy.threshold === 'number' && Number.isFinite(policy.threshold) && policy.threshold >= 0 && policy.threshold <= 1;
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
/** @param {unknown} value @returns {value is ComparisonMetadata} */
|
|
@@ -170,15 +171,73 @@ function isComparisonMetadata(value) {
|
|
|
170
171
|
return false;
|
|
171
172
|
}
|
|
172
173
|
const [baseline, current, canvas] = dimensions;
|
|
173
|
-
|
|
174
|
+
const baseMetadataValid = (
|
|
174
175
|
typeof comparison.dimensionsChanged === 'boolean' &&
|
|
175
176
|
comparison.dimensionsChanged === (baseline.width !== current.width || baseline.height !== current.height) &&
|
|
176
|
-
canvas.width === Math.max(baseline.width, current.width) &&
|
|
177
|
-
canvas.height === Math.max(baseline.height, current.height) &&
|
|
178
177
|
Number.isInteger(comparison.totalPixels) &&
|
|
179
|
-
comparison.totalPixels >= 0
|
|
180
|
-
comparison.totalPixels <= canvas.width * canvas.height
|
|
178
|
+
comparison.totalPixels >= 0
|
|
181
179
|
);
|
|
180
|
+
if (!baseMetadataValid) return false;
|
|
181
|
+
if (comparison.policyVersion !== undefined && comparison.policyVersion !== 2) return false;
|
|
182
|
+
|
|
183
|
+
if (comparison.policyVersion !== 2) {
|
|
184
|
+
if (comparison.mode !== undefined || comparison.rowMapping !== undefined || comparison.fallbackReason !== undefined) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return (
|
|
188
|
+
canvas.width === Math.max(baseline.width, current.width) &&
|
|
189
|
+
canvas.height === Math.max(baseline.height, current.height) &&
|
|
190
|
+
comparison.totalPixels <= canvas.width * canvas.height
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (comparison.mode === 'coordinate-fallback') {
|
|
195
|
+
return (
|
|
196
|
+
comparison.rowMapping === undefined &&
|
|
197
|
+
COMPARISON_FALLBACK_REASONS.includes(comparison.fallbackReason) &&
|
|
198
|
+
canvas.width === Math.max(baseline.width, current.width) &&
|
|
199
|
+
canvas.height === Math.max(baseline.height, current.height) &&
|
|
200
|
+
comparison.totalPixels <= canvas.width * canvas.height
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (comparison.mode !== 'vertical-aligned' || comparison.fallbackReason !== undefined || !Array.isArray(comparison.rowMapping) || baseline.width !== current.width || canvas.width !== baseline.width) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
let outputStart = 0;
|
|
208
|
+
let baselineStart = 0;
|
|
209
|
+
let currentStart = 0;
|
|
210
|
+
for (const segment of comparison.rowMapping) {
|
|
211
|
+
if (!segment || !COMPARISON_ROW_KINDS.includes(segment.kind) || !Number.isInteger(segment.outputStart) || segment.outputStart !== outputStart || !Number.isInteger(segment.length) || segment.length <= 0) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const hasBaseline = segment.kind === 'matched' || segment.kind === 'changed' || segment.kind === 'deleted';
|
|
215
|
+
const hasCurrent = segment.kind === 'matched' || segment.kind === 'changed' || segment.kind === 'inserted';
|
|
216
|
+
if (hasBaseline !== (Number.isInteger(segment.baselineStart)) || hasCurrent !== (Number.isInteger(segment.currentStart))) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
if (
|
|
220
|
+
(hasBaseline && segment.baselineStart !== baselineStart) ||
|
|
221
|
+
(!hasBaseline && segment.baselineStart !== undefined) ||
|
|
222
|
+
(hasCurrent && segment.currentStart !== currentStart) ||
|
|
223
|
+
(!hasCurrent && segment.currentStart !== undefined)
|
|
224
|
+
) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
if (hasBaseline && (segment.baselineStart < 0 || segment.baselineStart + segment.length > baseline.height)) return false;
|
|
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
|
+
}
|
|
236
|
+
outputStart += segment.length;
|
|
237
|
+
if (hasBaseline) baselineStart += segment.length;
|
|
238
|
+
if (hasCurrent) currentStart += segment.length;
|
|
239
|
+
}
|
|
240
|
+
return canvas.height === outputStart && baselineStart === baseline.height && currentStart === current.height && canvas.height >= Math.max(baseline.height, current.height) && canvas.height <= baseline.height + current.height && comparison.totalPixels === canvas.width * canvas.height;
|
|
182
241
|
}
|
|
183
242
|
|
|
184
243
|
/**
|
|
@@ -221,12 +280,17 @@ function comparisonFromCapture(capture) {
|
|
|
221
280
|
return isComparisonMetadata(candidate) ? candidate : undefined;
|
|
222
281
|
}
|
|
223
282
|
|
|
283
|
+
/** @param {ComparisonMetadata} comparison @param {ComparisonPolicy} expected */
|
|
284
|
+
function comparisonMatchesPolicy(comparison, expected) {
|
|
285
|
+
return expected.version === 2 ? comparison.policyVersion === 2 : comparison.policyVersion === undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
224
288
|
/** @param {unknown} actual @param {ComparisonPolicy} expected @param {string} context */
|
|
225
289
|
function assertComparisonPolicyAcknowledged(actual, expected, context) {
|
|
226
|
-
if (!isComparisonPolicy(actual) || actual.threshold !== expected.threshold) {
|
|
290
|
+
if (!isComparisonPolicy(actual) || actual.version !== expected.version || actual.threshold !== expected.threshold) {
|
|
227
291
|
throw new SnapUpgradeRequiredError(
|
|
228
|
-
`${context} did not acknowledge comparisonPolicy
|
|
229
|
-
'Upgrade the Snap server before enabling
|
|
292
|
+
`${context} did not acknowledge comparisonPolicy v${expected.version} with threshold ${expected.threshold}. ` +
|
|
293
|
+
'Upgrade the Snap server before enabling this comparison policy.'
|
|
230
294
|
);
|
|
231
295
|
}
|
|
232
296
|
}
|
|
@@ -2247,7 +2311,18 @@ export class SnapProvider {
|
|
|
2247
2311
|
expected.routePath,
|
|
2248
2312
|
expected.viewport,
|
|
2249
2313
|
`Snap capture "${expected.routeId}" is missing complete comparison metadata; ` +
|
|
2250
|
-
|
|
2314
|
+
`upgrade the Snap server and diff Lambda before enabling comparisonPolicy v${comparisonPolicy.version}.`
|
|
2315
|
+
);
|
|
2316
|
+
continue;
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
if (comparisonPolicy && comparison && !comparisonMatchesPolicy(comparison, comparisonPolicy)) {
|
|
2320
|
+
addError(
|
|
2321
|
+
expected.routeId,
|
|
2322
|
+
expected.routePath,
|
|
2323
|
+
expected.viewport,
|
|
2324
|
+
`Snap capture "${expected.routeId}" returned comparison metadata for a different policy than v${comparisonPolicy.version}; ` +
|
|
2325
|
+
'upgrade the Snap server and diff Lambda before enabling this comparison policy.'
|
|
2251
2326
|
);
|
|
2252
2327
|
continue;
|
|
2253
2328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snapdrift",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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.
|
|
107
|
-
"@snapdrift/adapter-report-md": "^1.
|
|
108
|
-
"@snapdrift/compare-core": "^1.
|
|
109
|
-
"@snapdrift/manifest": "^1.
|
|
106
|
+
"@snapdrift/adapter-fs": "^1.6.0",
|
|
107
|
+
"@snapdrift/adapter-report-md": "^1.4.0",
|
|
108
|
+
"@snapdrift/compare-core": "^1.6.0",
|
|
109
|
+
"@snapdrift/manifest": "^1.7.0",
|
|
110
110
|
"js-yaml": "^5.4.0",
|
|
111
111
|
"playwright": "^1.59.1",
|
|
112
112
|
"pngjs": "^7.0.0"
|
|
@@ -15,11 +15,19 @@ export interface VisualRegressionSelectionConfig {
|
|
|
15
15
|
sharedExact?: string[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/** @deprecated Coordinate-based comparison policy. Retained for existing configurations; use `ComparisonPolicyV2` for new configurations. */
|
|
19
|
+
export interface ComparisonPolicyV1 {
|
|
19
20
|
version: 1;
|
|
20
21
|
threshold: number;
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
export interface ComparisonPolicyV2 {
|
|
25
|
+
version: 2;
|
|
26
|
+
threshold: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type ComparisonPolicy = ComparisonPolicyV1 | ComparisonPolicyV2;
|
|
30
|
+
|
|
23
31
|
export interface ComparisonDimensions {
|
|
24
32
|
width: number;
|
|
25
33
|
height: number;
|
|
@@ -31,6 +39,28 @@ export interface ComparisonMetadata {
|
|
|
31
39
|
canvas: ComparisonDimensions;
|
|
32
40
|
dimensionsChanged: boolean;
|
|
33
41
|
totalPixels: number;
|
|
42
|
+
policyVersion?: 2;
|
|
43
|
+
mode?: 'vertical-aligned' | 'coordinate-fallback';
|
|
44
|
+
rowMapping?: ComparisonRowMapping[];
|
|
45
|
+
fallbackReason?: ComparisonFallbackReason;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type ComparisonFallbackReason = 'width-mismatch' | 'alignment-limit' | 'ambiguous' | 'verification-failed' | 'ignore-regions';
|
|
49
|
+
export const COMPARISON_FALLBACK_REASONS: readonly ['width-mismatch', 'alignment-limit', 'ambiguous', 'verification-failed', 'ignore-regions'];
|
|
50
|
+
export type ComparisonRowKind = 'matched' | 'changed' | 'inserted' | 'deleted';
|
|
51
|
+
export const COMPARISON_ROW_KINDS: readonly ['matched', 'changed', 'inserted', 'deleted'];
|
|
52
|
+
export interface ComparisonRowMapping {
|
|
53
|
+
outputStart: number;
|
|
54
|
+
length: number;
|
|
55
|
+
kind: ComparisonRowKind;
|
|
56
|
+
baselineStart?: number;
|
|
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;
|
|
34
64
|
}
|
|
35
65
|
|
|
36
66
|
export interface VisualRegressionRouteConfig {
|
|
@@ -52,6 +82,7 @@ export interface VisualRegressionConfig {
|
|
|
52
82
|
diff: {
|
|
53
83
|
threshold: number;
|
|
54
84
|
mode: 'report-only' | 'fail-on-changes' | 'fail-on-incomplete' | 'strict';
|
|
85
|
+
/** Deprecated v1 remains the compatibility default; new configurations should use v2. */
|
|
55
86
|
comparisonPolicy?: ComparisonPolicy;
|
|
56
87
|
};
|
|
57
88
|
selection?: VisualRegressionSelectionConfig;
|
|
@@ -110,7 +141,7 @@ export interface SnapRunMetadata {
|
|
|
110
141
|
runId: string;
|
|
111
142
|
projectId: string;
|
|
112
143
|
purpose: 'baseline' | 'capture' | 'diff';
|
|
113
|
-
/** Exact comparison policy acknowledged by Snap for
|
|
144
|
+
/** Exact comparison policy acknowledged by Snap; v1 is deprecated for compatibility. */
|
|
114
145
|
comparisonPolicy?: ComparisonPolicy;
|
|
115
146
|
/** CI source branch for hosted baseline runs; omitted for ordinary diff runs. */
|
|
116
147
|
refBranch?: string;
|
|
@@ -194,6 +225,7 @@ export interface VisualDiffSummary {
|
|
|
194
225
|
errors: VisualDiffErrorItem[];
|
|
195
226
|
captureCompatibility?: import('@snapdrift/manifest').CaptureCompatibility;
|
|
196
227
|
dimensionChanges: VisualDiffDimensionItem[];
|
|
228
|
+
/** The exact policy used for the comparison; v1 is deprecated and retained for compatibility. */
|
|
197
229
|
comparisonPolicy?: ComparisonPolicy;
|
|
198
230
|
message?: string;
|
|
199
231
|
/** Link to the provider's run detail page. Set by SnapProvider during diff(); undefined for LocalProvider. */
|