snapdrift 0.9.0 → 0.10.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 +26 -0
- package/README.md +3 -3
- package/action.yml +2 -2
- package/actions/comment/action.yml +6 -0
- package/actions/compare/action.yml +6 -0
- package/actions/pr-diff/action.yml +10 -3
- package/actions/stage/action.yml +7 -1
- package/docs/contracts.md +19 -2
- package/docs/integration-guide.md +19 -9
- package/docs/local-cli.md +15 -1
- package/docs/workflow-templates/refresh-baseline-on-merge.yml +1 -1
- package/lib/cli.mjs +15 -11
- package/lib/provider.mjs +19 -10
- package/lib/report.mjs +3 -2
- package/lib/snap-provider.mjs +495 -428
- package/package.json +5 -5
- package/types/visual-diff-types.d.ts +28 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0 - 2026-09-10
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- **PR diff artifacts remain reviewable from GitHub comments** — generated local
|
|
8
|
+
diff paths are now linked to the authenticated Actions artifact (or workflow
|
|
9
|
+
run fallback) instead of being emitted as broken relative image URLs. Hosted
|
|
10
|
+
legacy captures also retain their reported dimensions and pixel denominator
|
|
11
|
+
when v1 comparison metadata is absent.
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- **Unequal-dimension comparisons** — `@snapdrift/compare-core` now exposes
|
|
16
|
+
`compareImages()` for top-left-aligned union-canvas comparisons while the
|
|
17
|
+
existing strict APIs remain unchanged. Updated local and hosted providers
|
|
18
|
+
explicitly request comparison policy v1, record comparison dimensions and the
|
|
19
|
+
geometric union denominator, stage a generated diff PNG, and render it in
|
|
20
|
+
Markdown, HTML, and PR reports. Low-level public adapter calls remain strict
|
|
21
|
+
unless they opt in with `diff.comparisonPolicy`. Legacy dimension shifts remain
|
|
22
|
+
in `dimensionChanges[]`; completed v1 dimension changes are `changed[]` signals
|
|
23
|
+
and do not fail `fail-on-incomplete` alone.
|
|
24
|
+
|
|
25
|
+
- **Workspace packages** — publish `@snapdrift/manifest` 1.4.0,
|
|
26
|
+
`@snapdrift/compare-core` 1.1.0, `@snapdrift/adapter-report-md` 1.2.0, and
|
|
27
|
+
`@snapdrift/adapter-fs` 1.2.0 before activating the updated hosted Snap client.
|
|
28
|
+
|
|
3
29
|
## 0.9.0 - 2026-09-09
|
|
4
30
|
|
|
5
31
|
### Fixes
|
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.10.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.10.0
|
|
64
64
|
with:
|
|
65
65
|
mode: pr-diff
|
|
66
66
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -116,7 +116,7 @@ Start with `report-only` while baselines settle. Move to `fail-on-changes` or st
|
|
|
116
116
|
- Full-page capture only
|
|
117
117
|
- Viewport presets: `desktop` (1440×900) and `mobile` (390×844), or custom `{ "width": number, "height": number }`
|
|
118
118
|
- One global `diff.threshold`
|
|
119
|
-
-
|
|
119
|
+
- Unequal dimensions remain strict by default; local updated clients may opt in with `diff.comparisonPolicy: { "version": 1, "threshold": number }`
|
|
120
120
|
- 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))
|
|
121
121
|
- Hosted Snap baselines publish only from the default branch and always include the complete configured route set
|
|
122
122
|
|
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@80d61b668942dd87c33cf51598623a904becf82f # v0.10.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@80d61b668942dd87c33cf51598623a904becf82f # v0.10.0
|
|
169
169
|
with:
|
|
170
170
|
github-token: ${{ inputs.github-token }}
|
|
171
171
|
repo-config-path: ${{ inputs.repo-config-path }}
|
|
@@ -24,6 +24,10 @@ inputs:
|
|
|
24
24
|
description: Artifact label to include in the comment.
|
|
25
25
|
required: false
|
|
26
26
|
default: ''
|
|
27
|
+
artifact-url:
|
|
28
|
+
description: Authenticated URL to the uploaded report artifact.
|
|
29
|
+
required: false
|
|
30
|
+
default: ''
|
|
27
31
|
repo-config-path:
|
|
28
32
|
description: Path to the SnapDrift config file (needed for provider-aware comment rendering).
|
|
29
33
|
required: false
|
|
@@ -58,6 +62,7 @@ runs:
|
|
|
58
62
|
VISUAL_DIFF_SUMMARY_PATH: ${{ inputs.summary-path }}
|
|
59
63
|
VISUAL_DIFF_RUN_URL: ${{ inputs.run-url }}
|
|
60
64
|
VISUAL_DIFF_ARTIFACT_NAME: ${{ inputs.artifact-name }}
|
|
65
|
+
VISUAL_DIFF_ARTIFACT_URL: ${{ inputs.artifact-url }}
|
|
61
66
|
INPUT_PR_NUMBER: ${{ inputs.pr-number }}
|
|
62
67
|
REPO_CONFIG_PATH: ${{ inputs.repo-config-path }}
|
|
63
68
|
MAX_CHANGED_ROWS: ${{ inputs.max-changed-rows }}
|
|
@@ -105,6 +110,7 @@ runs:
|
|
|
105
110
|
const maxErrorRows = Number(process.env.MAX_ERROR_ROWS) || 10;
|
|
106
111
|
const body = provider.buildCommentBody(summary, {
|
|
107
112
|
artifactName: process.env.VISUAL_DIFF_ARTIFACT_NAME || '',
|
|
113
|
+
artifactUrl: process.env.VISUAL_DIFF_ARTIFACT_URL || '',
|
|
108
114
|
runUrl,
|
|
109
115
|
maxChangedRows,
|
|
110
116
|
maxErrorRows
|
|
@@ -67,6 +67,9 @@ outputs:
|
|
|
67
67
|
markdown-path:
|
|
68
68
|
description: Absolute path to the generated summary markdown file.
|
|
69
69
|
value: ${{ steps.compare.outputs.markdown_path }}
|
|
70
|
+
diff-images-dir:
|
|
71
|
+
description: Absolute path to generated local diff PNGs.
|
|
72
|
+
value: ${{ steps.compare.outputs.diff_images_dir }}
|
|
70
73
|
status:
|
|
71
74
|
description: Computed SnapDrift status.
|
|
72
75
|
value: ${{ steps.compare.outputs.status }}
|
|
@@ -133,6 +136,7 @@ runs:
|
|
|
133
136
|
const resolvedOutDir = path.resolve(process.env.OUT_DIR || 'qa-artifacts/snapdrift/drift/current');
|
|
134
137
|
const resolvedSummaryPath = path.resolve(process.env.SUMMARY_PATH || path.join(resolvedOutDir, 'summary.json'));
|
|
135
138
|
const resolvedMarkdownPath = path.resolve(process.env.MARKDOWN_PATH || path.join(resolvedOutDir, 'summary.md'));
|
|
139
|
+
const resolvedDiffImagesDir = path.join(resolvedOutDir, 'diffs');
|
|
136
140
|
|
|
137
141
|
await runDriftCheckCli({
|
|
138
142
|
configPath: process.env.REPO_CONFIG_PATH || undefined,
|
|
@@ -143,6 +147,7 @@ runs:
|
|
|
143
147
|
baselineRunDir: process.env.BASELINE_RUN_DIR || undefined,
|
|
144
148
|
currentRunDir: process.env.CURRENT_RUN_DIR || undefined,
|
|
145
149
|
outDir: resolvedOutDir,
|
|
150
|
+
diffImagesDir: resolvedDiffImagesDir,
|
|
146
151
|
summaryPath: resolvedSummaryPath,
|
|
147
152
|
markdownPath: resolvedMarkdownPath,
|
|
148
153
|
routeIds: splitCommaList(process.env.ROUTE_IDS),
|
|
@@ -155,6 +160,7 @@ runs:
|
|
|
155
160
|
const outputs = [
|
|
156
161
|
`summary_path=${resolvedSummaryPath}`,
|
|
157
162
|
`markdown_path=${resolvedMarkdownPath}`,
|
|
163
|
+
`diff_images_dir=${resolvedDiffImagesDir}`,
|
|
158
164
|
`status=${summary.status || ''}`,
|
|
159
165
|
`changed_screenshots=${summary.changedScreenshots || 0}`,
|
|
160
166
|
`matched_screenshots=${summary.matchedScreenshots || 0}`,
|
|
@@ -459,6 +459,7 @@ runs:
|
|
|
459
459
|
const resolvedOutDir = path.resolve('qa-artifacts/snapdrift/drift/current');
|
|
460
460
|
const resolvedSummaryPath = path.join(resolvedOutDir, 'summary.json');
|
|
461
461
|
const resolvedMarkdownPath = path.join(resolvedOutDir, 'summary.md');
|
|
462
|
+
const resolvedDiffImagesDir = path.join(resolvedOutDir, 'diffs');
|
|
462
463
|
|
|
463
464
|
const captureOptions = {
|
|
464
465
|
configPath: process.env.REPO_CONFIG_PATH || undefined,
|
|
@@ -475,7 +476,8 @@ runs:
|
|
|
475
476
|
baselineSourceSha: process.env.BASELINE_SOURCE_SHA || undefined,
|
|
476
477
|
currentResultsPath: process.env.CURRENT_RESULTS_PATH || undefined,
|
|
477
478
|
currentManifestPath: process.env.CURRENT_MANIFEST_PATH || undefined,
|
|
478
|
-
currentRunDir: process.env.CURRENT_SCREENSHOTS_ROOT || undefined
|
|
479
|
+
currentRunDir: process.env.CURRENT_SCREENSHOTS_ROOT || undefined,
|
|
480
|
+
diffImagesDir: resolvedDiffImagesDir
|
|
479
481
|
};
|
|
480
482
|
|
|
481
483
|
const diffed = await diffWithPolicy({
|
|
@@ -615,6 +617,7 @@ runs:
|
|
|
615
617
|
CURRENT_MANIFEST_PATH: ${{ steps.compare.outputs.current_manifest_file || steps.capture.outputs.manifest_file }}
|
|
616
618
|
BASELINE_SCREENSHOTS_DIR: ${{ steps.baseline_paths.outputs.screenshots_dir }}
|
|
617
619
|
CURRENT_SCREENSHOTS_ROOT: ${{ steps.compare.outputs.current_screenshots_root || steps.capture.outputs.screenshots_root }}
|
|
620
|
+
DIFF_IMAGES_DIR: ${{ steps.compare.outputs.diff_images_dir }}
|
|
618
621
|
run: |
|
|
619
622
|
node --input-type=module <<'EOF'
|
|
620
623
|
import fs from 'node:fs/promises';
|
|
@@ -635,13 +638,15 @@ runs:
|
|
|
635
638
|
baselineManifestPath: process.env.BASELINE_MANIFEST_PATH || undefined,
|
|
636
639
|
currentManifestPath: process.env.CURRENT_MANIFEST_PATH || undefined,
|
|
637
640
|
baselineScreenshotsDir: process.env.BASELINE_SCREENSHOTS_DIR || undefined,
|
|
638
|
-
currentScreenshotsDir: currentScreenshotsRoot ? path.join(currentScreenshotsRoot, 'screenshots') : undefined
|
|
641
|
+
currentScreenshotsDir: currentScreenshotsRoot ? path.join(currentScreenshotsRoot, 'screenshots') : undefined,
|
|
642
|
+
diffImagesDir: process.env.DIFF_IMAGES_DIR || undefined
|
|
639
643
|
});
|
|
640
644
|
|
|
641
645
|
await fs.appendFile(process.env.GITHUB_OUTPUT, `bundle_dir=${result.bundleDir}\n`);
|
|
642
646
|
EOF
|
|
643
647
|
|
|
644
|
-
-
|
|
648
|
+
- id: upload
|
|
649
|
+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
|
645
650
|
with:
|
|
646
651
|
name: ${{ steps.context.outputs.artifact_name }}
|
|
647
652
|
retention-days: ${{ inputs.artifact-retention-days }}
|
|
@@ -663,6 +668,7 @@ runs:
|
|
|
663
668
|
PR_NUMBER: ${{ steps.context.outputs.pr_number }}
|
|
664
669
|
SUMMARY_PATH: ${{ steps.compare.outputs.summary_path || steps.capture.outputs.summary_path || steps.skipped_baseline.outputs.summary_path || steps.skipped_scope.outputs.summary_path }}
|
|
665
670
|
ARTIFACT_NAME: ${{ steps.context.outputs.artifact_name }}
|
|
671
|
+
ARTIFACT_URL: ${{ steps.upload.outputs.artifact-url }}
|
|
666
672
|
RUN_URL: ${{ steps.context.outputs.run_url }}
|
|
667
673
|
REPO_CONFIG_PATH: ${{ inputs.repo-config-path }}
|
|
668
674
|
MAX_CHANGED_ROWS: ${{ inputs.max-changed-rows }}
|
|
@@ -727,6 +733,7 @@ runs:
|
|
|
727
733
|
const maxErrorRows = Number(process.env.MAX_ERROR_ROWS) || 10;
|
|
728
734
|
const body = provider.buildCommentBody(summary, {
|
|
729
735
|
artifactName: process.env.ARTIFACT_NAME || '',
|
|
736
|
+
artifactUrl: process.env.ARTIFACT_URL || '',
|
|
730
737
|
runUrl: process.env.RUN_URL || '',
|
|
731
738
|
maxChangedRows,
|
|
732
739
|
maxErrorRows
|
package/actions/stage/action.yml
CHANGED
|
@@ -57,6 +57,10 @@ inputs:
|
|
|
57
57
|
description: Current screenshots dir for diff artifact staging.
|
|
58
58
|
required: false
|
|
59
59
|
default: ''
|
|
60
|
+
diff-images-dir:
|
|
61
|
+
description: Local diff PNG directory for diff artifact staging.
|
|
62
|
+
required: false
|
|
63
|
+
default: ''
|
|
60
64
|
|
|
61
65
|
outputs:
|
|
62
66
|
bundle-dir:
|
|
@@ -91,6 +95,7 @@ runs:
|
|
|
91
95
|
CURRENT_MANIFEST_PATH: ${{ inputs.current-manifest-path }}
|
|
92
96
|
BASELINE_SCREENSHOTS_DIR: ${{ inputs.baseline-screenshots-dir }}
|
|
93
97
|
CURRENT_SCREENSHOTS_DIR: ${{ inputs.current-screenshots-dir }}
|
|
98
|
+
DIFF_IMAGES_DIR: ${{ inputs.diff-images-dir }}
|
|
94
99
|
run: |
|
|
95
100
|
node --input-type=module <<'EOF'
|
|
96
101
|
import fs from 'node:fs/promises';
|
|
@@ -113,7 +118,8 @@ runs:
|
|
|
113
118
|
baselineManifestPath: process.env.BASELINE_MANIFEST_PATH || undefined,
|
|
114
119
|
currentManifestPath: process.env.CURRENT_MANIFEST_PATH || undefined,
|
|
115
120
|
baselineScreenshotsDir: process.env.BASELINE_SCREENSHOTS_DIR || undefined,
|
|
116
|
-
currentScreenshotsDir: process.env.CURRENT_SCREENSHOTS_DIR || undefined
|
|
121
|
+
currentScreenshotsDir: process.env.CURRENT_SCREENSHOTS_DIR || undefined,
|
|
122
|
+
diffImagesDir: process.env.DIFF_IMAGES_DIR || undefined
|
|
117
123
|
});
|
|
118
124
|
|
|
119
125
|
await fs.appendFile(process.env.GITHUB_OUTPUT, `bundle_dir=${result.bundleDir}\n`);
|
package/docs/contracts.md
CHANGED
|
@@ -40,6 +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 }` | Optional local opt-in to top-left-aligned unequal-dimension comparison; absent preserves strict legacy dimension handling |
|
|
43
44
|
|
|
44
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.
|
|
45
46
|
|
|
@@ -154,6 +155,7 @@ The pull request drift bundle contains:
|
|
|
154
155
|
| `current/results.json` | Current capture results |
|
|
155
156
|
| `current/manifest.json` | Current manifest |
|
|
156
157
|
| `current/screenshots/*.png` | Current images |
|
|
158
|
+
| `diffs/*.png` | Generated v1 diff images for changed screenshots |
|
|
157
159
|
|
|
158
160
|
## Screenshot manifest shape
|
|
159
161
|
|
|
@@ -208,6 +210,18 @@ The pull request drift bundle contains:
|
|
|
208
210
|
| Field | Type | Description |
|
|
209
211
|
|:------|:-----|:------------|
|
|
210
212
|
| `dashboardUrl` | `string?` | Snap dashboard URL for the run (set by `SnapProvider`; omitted by `LocalProvider`) |
|
|
213
|
+
| `comparisonPolicy` | `{ "version": 1, "threshold": number }?` | Exact v1 comparison policy used by the local adapter when opted in |
|
|
214
|
+
|
|
215
|
+
When v1 comparison is enabled, each affected `changed[]` item may also contain
|
|
216
|
+
`comparison` with `baseline`, `current`, and `canvas` `{ width, height }`
|
|
217
|
+
objects, `dimensionsChanged`, and the effective `totalPixels` denominator. A
|
|
218
|
+
local changed item with a generated image contains `diffImagePath`, relative to
|
|
219
|
+
the diff output bundle (for example `diffs/home.png`).
|
|
220
|
+
|
|
221
|
+
When a changed item has a generated local `diffImagePath`, its PR comment cell
|
|
222
|
+
links to the uploaded report artifact (or the workflow run when no artifact URL
|
|
223
|
+
was supplied) and shows the bundle-relative path. It does not use that relative
|
|
224
|
+
path as a GitHub-hosted image URL.
|
|
211
225
|
|
|
212
226
|
### Status values
|
|
213
227
|
|
|
@@ -237,7 +251,9 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
237
251
|
- Mismatch ratio is `different_pixels / total_pixels`
|
|
238
252
|
- `diff.threshold` applies per screenshot
|
|
239
253
|
- Missing captures are counted separately from drift signals
|
|
240
|
-
-
|
|
254
|
+
- Without `diff.comparisonPolicy`, dimension mismatches skip pixel comparison and land in `dimensionChanges[]`.
|
|
255
|
+
- With the exact v1 policy `{ "version": 1, "threshold": number }`, 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. Dimension changes land in `changed[]` with comparison metadata and a generated local diff image.
|
|
256
|
+
- For v1, `diff.comparisonPolicy.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.
|
|
241
257
|
- `diff.mode` controls enforcement, not summary generation
|
|
242
258
|
|
|
243
259
|
## Drift modes
|
|
@@ -246,7 +262,7 @@ Additional missing-baseline fields: `baselineAvailable`, `currentResultsPath`.
|
|
|
246
262
|
|:-----|:-------------------|
|
|
247
263
|
| `report-only` | Never |
|
|
248
264
|
| `fail-on-changes` | `changedScreenshots > 0` |
|
|
249
|
-
| `fail-on-incomplete` | Errors
|
|
265
|
+
| `fail-on-incomplete` | Errors or missing captures occur; a completed v1 dimension comparison alone does not fail |
|
|
250
266
|
| `strict` | Any drift or incomplete comparison appears |
|
|
251
267
|
|
|
252
268
|
A summary with `status: "skipped"` — or any summary carrying no `diff.mode` —
|
|
@@ -547,6 +563,7 @@ Snap's server-side notification posting should render the same template from the
|
|
|
547
563
|
| Field | Type | Description |
|
|
548
564
|
|:------|:-----|:------------|
|
|
549
565
|
| `artifactName` | `string?` | PR diff artifact label |
|
|
566
|
+
| `artifactUrl` | `string?` | Authenticated GitHub Actions artifact URL for diff links |
|
|
550
567
|
| `runUrl` | `string?` | GitHub Actions run URL (adds `[View run]` link) |
|
|
551
568
|
| `dashboardUrl` | `string?` | Snap dashboard URL (adds `[View in dashboard →]` link; SnapProvider only) |
|
|
552
569
|
| `maxChangedRows` | `number` | Max drift-signal rows before truncation (default 20) |
|
|
@@ -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.10.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.10.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.10.0` with `mode: baseline` | `ranacseruet/snapdrift/actions/baseline@v0.10.0` |
|
|
90
|
+
| `ranacseruet/snapdrift@v0.10.0` with `mode: pr-diff` | `ranacseruet/snapdrift/actions/pr-diff@v0.10.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.10.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.10.0
|
|
174
174
|
with:
|
|
175
175
|
mode: pr-diff
|
|
176
176
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -281,7 +281,8 @@ The `pr-diff` wrapper composes the following low-level steps. They're still avai
|
|
|
281
281
|
`error`, while `missing` remains the intentional first-baseline result
|
|
282
282
|
- `actions/stage` — assemble the baseline or diff bundle for upload
|
|
283
283
|
- `actions/enforce` — evaluate the summary against `diff.mode` and fail when required
|
|
284
|
-
- `actions/comment` — upsert a PR comment from a summary (provider-aware)
|
|
284
|
+
- `actions/comment` — upsert a PR comment from a summary (provider-aware); pass
|
|
285
|
+
`artifact-url` from `upload-artifact` when local diff PNGs are present
|
|
285
286
|
|
|
286
287
|
The two wrapper actions that orchestrate the full pipeline are `actions/baseline` (publish) and `actions/pr-diff` (drift detection). They are the primary integration points.
|
|
287
288
|
|
|
@@ -309,7 +310,12 @@ See the [Local CLI guide](local-cli.md) for full command reference, flags, direc
|
|
|
309
310
|
|
|
310
311
|
## Refresh the baseline automatically
|
|
311
312
|
|
|
312
|
-
After an intentional layout change
|
|
313
|
+
After an intentional layout change merges, the baseline can be republished as
|
|
314
|
+
usual. Legacy local comparisons still require like-for-like dimensions; an
|
|
315
|
+
updated local client may opt into the exact
|
|
316
|
+
`diff.comparisonPolicy: { "version": 1, "threshold": number }` contract to
|
|
317
|
+
compare unequal frames on a union canvas and keep the dimension metadata in the
|
|
318
|
+
report.
|
|
313
319
|
|
|
314
320
|
Use the provided workflow template to refresh the baseline automatically on every push to your default branch (i.e. every merge):
|
|
315
321
|
|
|
@@ -337,7 +343,11 @@ Grant `issues: write` and `pull-requests: write` to the job.
|
|
|
337
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.
|
|
338
344
|
|
|
339
345
|
**Screenshots have different dimensions**
|
|
340
|
-
SnapDrift reports this as a dimension
|
|
346
|
+
Without `diff.comparisonPolicy`, SnapDrift reports this as a legacy dimension
|
|
347
|
+
shift and skips pixel comparison. With the exact v1 policy, it compares the
|
|
348
|
+
top-left-aligned union canvas, records the route in `changed[]`, and writes a
|
|
349
|
+
local diff PNG; refresh the baseline after an intentional change when you want
|
|
350
|
+
future runs to return to equal-size comparisons.
|
|
341
351
|
|
|
342
352
|
**A route appears in `errors[]`**
|
|
343
353
|
Capture failed before comparison. Confirm the app is fully ready and reachable before SnapDrift runs.
|
package/docs/local-cli.md
CHANGED
|
@@ -225,6 +225,7 @@ After running `capture` and `diff` with default paths:
|
|
|
225
225
|
summary.json # structured drift summary
|
|
226
226
|
summary.md # human-readable markdown report
|
|
227
227
|
report.html # self-contained HTML report with side-by-side images
|
|
228
|
+
diffs/ # v1 generated diff PNGs, when comparisonPolicy is enabled
|
|
228
229
|
```
|
|
229
230
|
|
|
230
231
|
Add `.snapdrift/` to your `.gitignore` to keep local run output out of version control.
|
|
@@ -271,7 +272,7 @@ Comparing against baseline ...
|
|
|
271
272
|
Report: .snapdrift/diff/report.html
|
|
272
273
|
```
|
|
273
274
|
|
|
274
|
-
**Incomplete run** (errors, missing captures, or dimension shifts):
|
|
275
|
+
**Incomplete run** (errors, missing captures, or legacy dimension shifts):
|
|
275
276
|
|
|
276
277
|
```
|
|
277
278
|
❌ SnapDrift — incomplete
|
|
@@ -289,6 +290,19 @@ The `Missing`, `Errors`, and `Dim diff` lines only print when their count is gre
|
|
|
289
290
|
|
|
290
291
|
The `report.html` path is printed whenever the status is anything other than `clean`; pass `--open` to also launch it in your default browser.
|
|
291
292
|
|
|
293
|
+
To compare unequal local screenshot dimensions, add the exact opt-in policy to
|
|
294
|
+
`diff`:
|
|
295
|
+
|
|
296
|
+
```json
|
|
297
|
+
"comparisonPolicy": { "version": 1, "threshold": 0.01 }
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
The v1 report includes the baseline, current, and union-canvas dimensions in
|
|
301
|
+
`summary.md` and `report.html`, and stores changed-route diff PNGs under
|
|
302
|
+
`.snapdrift/diff/diffs/`. A completed dimension comparison is a normal changed
|
|
303
|
+
signal, so `fail-on-incomplete` does not fail solely because its dimensions
|
|
304
|
+
differ; `fail-on-changes` and `strict` still enforce it.
|
|
305
|
+
|
|
292
306
|
---
|
|
293
307
|
|
|
294
308
|
## Environment variables
|
package/lib/cli.mjs
CHANGED
|
@@ -430,21 +430,24 @@ export async function runDiffCommand(opts) {
|
|
|
430
430
|
const markdownPath = path.join(opts.diffDir, 'summary.md');
|
|
431
431
|
const htmlPath = path.join(opts.diffDir, 'report.html');
|
|
432
432
|
|
|
433
|
+
const diffOptions = /** @type {import('../types/visual-diff-types').ProviderDiffOptions & { diffImagesDir: string }} */ ({
|
|
434
|
+
configPath: opts.configPath,
|
|
435
|
+
routeIds: opts.routes.length > 0 ? opts.routes : undefined,
|
|
436
|
+
baselineResultsPath,
|
|
437
|
+
baselineManifestPath,
|
|
438
|
+
currentResultsPath: currentCapture.resultsPath,
|
|
439
|
+
currentManifestPath: currentCapture.manifestPath,
|
|
440
|
+
baselineRunDir: opts.baselineDir,
|
|
441
|
+
currentRunDir: currentCapture.screenshotsRoot,
|
|
442
|
+
diffImagesDir: path.join(opts.diffDir, 'diffs')
|
|
443
|
+
});
|
|
444
|
+
|
|
433
445
|
const diffed = await diffWithPolicy({
|
|
434
446
|
provider: captured.providerName === 'local' ? createProvider('local') : provider,
|
|
435
447
|
providerName: captured.providerName,
|
|
436
448
|
localScreenshots: captured.localScreenshots,
|
|
437
449
|
captureOptions,
|
|
438
|
-
diffOptions
|
|
439
|
-
configPath: opts.configPath,
|
|
440
|
-
routeIds: opts.routes.length > 0 ? opts.routes : undefined,
|
|
441
|
-
baselineResultsPath,
|
|
442
|
-
baselineManifestPath,
|
|
443
|
-
currentResultsPath: currentCapture.resultsPath,
|
|
444
|
-
currentManifestPath: currentCapture.manifestPath,
|
|
445
|
-
baselineRunDir: opts.baselineDir,
|
|
446
|
-
currentRunDir: currentCapture.screenshotsRoot
|
|
447
|
-
},
|
|
450
|
+
diffOptions,
|
|
448
451
|
onSkip: () =>
|
|
449
452
|
process.stdout.write('Visual regression skipped (Snap unavailable, warn-and-skip mode).\n'),
|
|
450
453
|
onFallback: () => process.stdout.write('Falling back to local provider for the diff...\n'),
|
|
@@ -461,7 +464,8 @@ export async function runDiffCommand(opts) {
|
|
|
461
464
|
|
|
462
465
|
const html = await generateHtmlReport(summary, {
|
|
463
466
|
baselineRunDir: opts.baselineDir,
|
|
464
|
-
currentRunDir
|
|
467
|
+
currentRunDir,
|
|
468
|
+
diffRunDir: opts.diffDir
|
|
465
469
|
});
|
|
466
470
|
|
|
467
471
|
await Promise.all([
|
package/lib/provider.mjs
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import { runBaselineCapture, generateDriftReport, stageArtifacts } from '@snapdrift/adapter-fs';
|
|
3
|
+
import { loadSnapdriftConfig, runBaselineCapture, generateDriftReport, stageArtifacts } from '@snapdrift/adapter-fs';
|
|
4
4
|
import { buildReportCommentBody } from '@snapdrift/adapter-report-md';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
SnapProvider,
|
|
7
|
+
SnapApiError,
|
|
8
|
+
SnapUpgradeRequiredError,
|
|
9
|
+
SnapUnavailableError,
|
|
10
|
+
SnapFallbackError,
|
|
11
|
+
SnapSkipError,
|
|
12
|
+
isLocalBaseUrl
|
|
13
|
+
} from './snap-provider.mjs';
|
|
6
14
|
|
|
7
15
|
/** @typedef {import('../types/visual-diff-types').VisualProvider} VisualProvider */
|
|
8
16
|
/** @typedef {import('../types/visual-diff-types').ProviderCaptureOptions} CaptureOptions */
|
|
@@ -35,7 +43,12 @@ export class LocalProvider {
|
|
|
35
43
|
* @returns {Promise<DiffResult>}
|
|
36
44
|
*/
|
|
37
45
|
async diff(options) {
|
|
38
|
-
|
|
46
|
+
const { config } = await loadSnapdriftConfig(options.configPath);
|
|
47
|
+
const comparisonPolicy = config.diff.comparisonPolicy ?? {
|
|
48
|
+
version: 1,
|
|
49
|
+
threshold: config.diff.threshold
|
|
50
|
+
};
|
|
51
|
+
return generateDriftReport({ ...options, comparisonPolicy });
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
/**
|
|
@@ -55,8 +68,7 @@ export class LocalProvider {
|
|
|
55
68
|
*/
|
|
56
69
|
async fetchLatestBaseline(_options) {
|
|
57
70
|
throw new Error(
|
|
58
|
-
'LocalProvider.fetchLatestBaseline is not yet implemented. ' +
|
|
59
|
-
'Use the pr-diff action for baseline resolution, or wait for a future release.'
|
|
71
|
+
'LocalProvider.fetchLatestBaseline is not yet implemented. ' + 'Use the pr-diff action for baseline resolution, or wait for a future release.'
|
|
60
72
|
);
|
|
61
73
|
}
|
|
62
74
|
|
|
@@ -113,12 +125,9 @@ const PROVIDER_FACTORIES = {
|
|
|
113
125
|
export function createProvider(providerName, config) {
|
|
114
126
|
const factory = PROVIDER_FACTORIES[providerName];
|
|
115
127
|
if (!factory) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
`Unknown SnapDrift provider: "${providerName}". ` +
|
|
118
|
-
`Available providers: ${Object.keys(PROVIDER_FACTORIES).join(', ')}.`
|
|
119
|
-
);
|
|
128
|
+
throw new Error(`Unknown SnapDrift provider: "${providerName}". ` + `Available providers: ${Object.keys(PROVIDER_FACTORIES).join(', ')}.`);
|
|
120
129
|
}
|
|
121
130
|
return factory(config);
|
|
122
131
|
}
|
|
123
132
|
|
|
124
|
-
export { SnapProvider, SnapApiError, SnapUnavailableError, SnapFallbackError, SnapSkipError, isLocalBaseUrl };
|
|
133
|
+
export { SnapProvider, SnapApiError, SnapUpgradeRequiredError, SnapUnavailableError, SnapFallbackError, SnapSkipError, isLocalBaseUrl };
|
package/lib/report.mjs
CHANGED
|
@@ -26,14 +26,15 @@ async function defaultImageReader(runDir, imagePath) {
|
|
|
26
26
|
* @param {{
|
|
27
27
|
* baselineRunDir?: string,
|
|
28
28
|
* currentRunDir?: string,
|
|
29
|
+
* diffRunDir?: string,
|
|
29
30
|
* imageReader?: (runDir: string, imagePath: string) => Promise<string | null>
|
|
30
31
|
* }} [options]
|
|
31
32
|
* @returns {Promise<string>}
|
|
32
33
|
*/
|
|
33
34
|
export async function generateHtmlReport(summary, options = {}) {
|
|
34
35
|
const enrichedOptions = { ...options };
|
|
35
|
-
if (!enrichedOptions.imageReader && (options.baselineRunDir || options.currentRunDir)) {
|
|
36
|
+
if (!enrichedOptions.imageReader && (options.baselineRunDir || options.currentRunDir || options.diffRunDir)) {
|
|
36
37
|
enrichedOptions.imageReader = defaultImageReader;
|
|
37
38
|
}
|
|
38
39
|
return _generateHtmlReport(summary, enrichedOptions);
|
|
39
|
-
}
|
|
40
|
+
}
|