snapdrift 0.13.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 +29 -0
- package/README.md +3 -3
- package/action.yml +2 -2
- package/docs/contracts.md +21 -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 +78 -10
- package/package.json +5 -5
- package/types/visual-diff-types.d.ts +28 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.14.0 - 2026-09-21
|
|
6
|
+
|
|
7
|
+
Workspace releases this version:
|
|
8
|
+
|
|
9
|
+
- `@snapdrift/compare-core` 1.5.0 — bounded vertical row alignment and comparison
|
|
10
|
+
policy v2, with conservative coordinate fallbacks and resource limits.
|
|
11
|
+
- `@snapdrift/manifest` 1.6.0 — policy v2 validation, constants, and comparison types.
|
|
12
|
+
- `@snapdrift/adapter-fs` 1.5.0 — local policy v2 comparison and summary types.
|
|
13
|
+
- `@snapdrift/adapter-report-md` 1.4.0 — alignment and fallback details in Markdown,
|
|
14
|
+
HTML, and bounded PR comments.
|
|
15
|
+
|
|
16
|
+
Root and workspace dependency floors require these versions so upgrades receive
|
|
17
|
+
all parts of the policy v2 implementation. The dispatcher pins `576e774`, the
|
|
18
|
+
#176 merge commit on `main`, including the runtime loaded by both wrapper actions.
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
- Added opt-in comparison policy v2 with bounded vertical row alignment for
|
|
23
|
+
inserted and deleted page rows. Unchanged content that shifts after an
|
|
24
|
+
insertion remains matched; reports record aligned results and conservative
|
|
25
|
+
coordinate fallbacks. Deprecated policy v1 remains the compatibility default
|
|
26
|
+
so existing configurations are unchanged; new configurations should use v2.
|
|
27
|
+
|
|
28
|
+
- Snap-provider requests forward policy v2 and validate hosted acknowledgements
|
|
29
|
+
and alignment metadata. Hosted use requires matching Snap service support;
|
|
30
|
+
publishing this library does not deploy the hosted service.
|
|
31
|
+
|
|
3
32
|
## 0.13.0 - 2026-09-19
|
|
4
33
|
|
|
5
34
|
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.14.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.14.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@576e774845c29288a0061365e4905009533e0e01 # v0.14.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@576e774845c29288a0061365e4905009533e0e01 # v0.14.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,22 @@ 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
|
+
`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
|
+
|
|
293
301
|
When a changed item has a generated local `diffImagePath`, its PR comment cell
|
|
294
302
|
links to the uploaded report artifact (or the workflow run when no artifact URL
|
|
295
303
|
was supplied) and shows the bundle-relative path. It does not use that relative
|
|
@@ -323,8 +331,10 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
323
331
|
- Mismatch ratio is `different_pixels / total_pixels`
|
|
324
332
|
- `diff.threshold` applies per screenshot
|
|
325
333
|
- Missing captures are counted separately from drift signals
|
|
326
|
-
- Comparison policy v1 `{ "version": 1, "threshold": number }` is
|
|
327
|
-
-
|
|
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.
|
|
328
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.
|
|
329
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.
|
|
330
340
|
- `diff.mode` controls enforcement, not summary generation
|
|
@@ -373,6 +383,11 @@ The comparator reports this condition with the stable error code
|
|
|
373
383
|
dimensions in the error message. The ceiling that was exceeded is included too,
|
|
374
384
|
since a caller may raise it per call.
|
|
375
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
|
+
|
|
376
391
|
`32 × 1024 × 1024` is the *default* ceiling, not an algorithm property. The cost
|
|
377
392
|
is dominated by the decoded images: both RGBA inputs (4 bytes per pixel each) are
|
|
378
393
|
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.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
|
@@ -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,66 @@ 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
|
+
outputStart += segment.length;
|
|
230
|
+
if (hasBaseline) baselineStart += segment.length;
|
|
231
|
+
if (hasCurrent) currentStart += segment.length;
|
|
232
|
+
}
|
|
233
|
+
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
234
|
}
|
|
183
235
|
|
|
184
236
|
/**
|
|
@@ -221,12 +273,17 @@ function comparisonFromCapture(capture) {
|
|
|
221
273
|
return isComparisonMetadata(candidate) ? candidate : undefined;
|
|
222
274
|
}
|
|
223
275
|
|
|
276
|
+
/** @param {ComparisonMetadata} comparison @param {ComparisonPolicy} expected */
|
|
277
|
+
function comparisonMatchesPolicy(comparison, expected) {
|
|
278
|
+
return expected.version === 2 ? comparison.policyVersion === 2 : comparison.policyVersion === undefined;
|
|
279
|
+
}
|
|
280
|
+
|
|
224
281
|
/** @param {unknown} actual @param {ComparisonPolicy} expected @param {string} context */
|
|
225
282
|
function assertComparisonPolicyAcknowledged(actual, expected, context) {
|
|
226
|
-
if (!isComparisonPolicy(actual) || actual.threshold !== expected.threshold) {
|
|
283
|
+
if (!isComparisonPolicy(actual) || actual.version !== expected.version || actual.threshold !== expected.threshold) {
|
|
227
284
|
throw new SnapUpgradeRequiredError(
|
|
228
|
-
`${context} did not acknowledge comparisonPolicy
|
|
229
|
-
'Upgrade the Snap server before enabling
|
|
285
|
+
`${context} did not acknowledge comparisonPolicy v${expected.version} with threshold ${expected.threshold}. ` +
|
|
286
|
+
'Upgrade the Snap server before enabling this comparison policy.'
|
|
230
287
|
);
|
|
231
288
|
}
|
|
232
289
|
}
|
|
@@ -2247,7 +2304,18 @@ export class SnapProvider {
|
|
|
2247
2304
|
expected.routePath,
|
|
2248
2305
|
expected.viewport,
|
|
2249
2306
|
`Snap capture "${expected.routeId}" is missing complete comparison metadata; ` +
|
|
2250
|
-
|
|
2307
|
+
`upgrade the Snap server and diff Lambda before enabling comparisonPolicy v${comparisonPolicy.version}.`
|
|
2308
|
+
);
|
|
2309
|
+
continue;
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
if (comparisonPolicy && comparison && !comparisonMatchesPolicy(comparison, comparisonPolicy)) {
|
|
2313
|
+
addError(
|
|
2314
|
+
expected.routeId,
|
|
2315
|
+
expected.routePath,
|
|
2316
|
+
expected.viewport,
|
|
2317
|
+
`Snap capture "${expected.routeId}" returned comparison metadata for a different policy than v${comparisonPolicy.version}; ` +
|
|
2318
|
+
'upgrade the Snap server and diff Lambda before enabling this comparison policy.'
|
|
2251
2319
|
);
|
|
2252
2320
|
continue;
|
|
2253
2321
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snapdrift",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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.5.0",
|
|
107
|
+
"@snapdrift/adapter-report-md": "^1.4.0",
|
|
108
|
+
"@snapdrift/compare-core": "^1.5.0",
|
|
109
|
+
"@snapdrift/manifest": "^1.6.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,22 @@ 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;
|
|
34
58
|
}
|
|
35
59
|
|
|
36
60
|
export interface VisualRegressionRouteConfig {
|
|
@@ -52,6 +76,7 @@ export interface VisualRegressionConfig {
|
|
|
52
76
|
diff: {
|
|
53
77
|
threshold: number;
|
|
54
78
|
mode: 'report-only' | 'fail-on-changes' | 'fail-on-incomplete' | 'strict';
|
|
79
|
+
/** Deprecated v1 remains the compatibility default; new configurations should use v2. */
|
|
55
80
|
comparisonPolicy?: ComparisonPolicy;
|
|
56
81
|
};
|
|
57
82
|
selection?: VisualRegressionSelectionConfig;
|
|
@@ -110,7 +135,7 @@ export interface SnapRunMetadata {
|
|
|
110
135
|
runId: string;
|
|
111
136
|
projectId: string;
|
|
112
137
|
purpose: 'baseline' | 'capture' | 'diff';
|
|
113
|
-
/** Exact comparison policy acknowledged by Snap for
|
|
138
|
+
/** Exact comparison policy acknowledged by Snap; v1 is deprecated for compatibility. */
|
|
114
139
|
comparisonPolicy?: ComparisonPolicy;
|
|
115
140
|
/** CI source branch for hosted baseline runs; omitted for ordinary diff runs. */
|
|
116
141
|
refBranch?: string;
|
|
@@ -194,6 +219,7 @@ export interface VisualDiffSummary {
|
|
|
194
219
|
errors: VisualDiffErrorItem[];
|
|
195
220
|
captureCompatibility?: import('@snapdrift/manifest').CaptureCompatibility;
|
|
196
221
|
dimensionChanges: VisualDiffDimensionItem[];
|
|
222
|
+
/** The exact policy used for the comparison; v1 is deprecated and retained for compatibility. */
|
|
197
223
|
comparisonPolicy?: ComparisonPolicy;
|
|
198
224
|
message?: string;
|
|
199
225
|
/** Link to the provider's run detail page. Set by SnapProvider during diff(); undefined for LocalProvider. */
|