snapdrift 0.16.0 → 0.16.1

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 CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.16.1 - 2026-10-27
6
+
7
+ Workspace releases this version:
8
+
9
+ - `@snapdrift/compare-core` 1.7.0 — new public `readPngDimensions` export (PNG IHDR width/height without decoding pixels).
10
+ - `@snapdrift/adapter-fs` 1.7.1 — local capture reads screenshot dimensions from the PNG header instead of fully decoding every PNG, and now depends on `@snapdrift/compare-core ^1.7.0` for that reader.
11
+
12
+ `@snapdrift/manifest` stays 1.8.0 and `@snapdrift/adapter-report-md` stays 1.4.0. Root floors move to `@snapdrift/compare-core ^1.7.0` and `@snapdrift/adapter-fs ^1.7.1`; the previous `adapter-fs` 1.7.0 and `compare-core` 1.6.0 do not satisfy them, so installing `snapdrift` 0.16.1 always gets the shared reader. The dispatcher pins `1cbf629`, the #195 merge commit on `main`, which is the newest commit touching `actions/` and includes the shell-only Playwright install.
13
+
14
+ ### Performance
15
+
16
+ - Hybrid (`provider: "snap"` with a local `baseUrl`) capture uploads screenshots to Snap with up to 4 routes in flight instead of one at a time, and stops starting new uploads after the first failure.
17
+ - The latest-baseline lookup for hybrid diff runs now starts before local capture and overlaps with it.
18
+ - Local Playwright capture reads screenshot width/height from the PNG header instead of fully decoding every PNG, which no longer blocks the event loop for all in-flight routes. A corrupt PNG body is no longer detected at capture time; a buffer without a valid PNG signature or IHDR chunk still fails the route.
19
+ - GitHub Actions install only Playwright's Chromium headless shell (`playwright install --with-deps --only-shell chromium`) instead of full Chromium plus the shell. Capture already launches with `headless: true`, which uses the shell, so rendering is unchanged. Measured on `node:22-bookworm` with Playwright 1.63.0: install 22s -> 15s, browser cache 662 MB -> 269 MB, identical browser version and screenshot bytes.
20
+ - Capture and upload phases log their duration (`Captured N route(s) in Xs`, `Uploaded N screenshot(s) to Snap in Xs`).
21
+
22
+ ### Features
23
+
24
+ - `@snapdrift/compare-core` exports `readPngDimensions(buffer)`, which reads width/height from a PNG's IHDR chunk without decoding pixels and returns `undefined` for a buffer that is too short, lacks the PNG signature, does not start with IHDR, or declares a zero or above-2^31-1 dimension.
25
+
26
+ ### Refactors
27
+
28
+ - Local capture (`@snapdrift/adapter-fs`) and the Snap baseline export (`lib/snap-provider.mjs`) now use the shared `readPngDimensions` instead of their own copies. The Snap baseline export is slightly stricter than before: an exported image whose header is not a valid IHDR (or declares a zero dimension) falls back to the viewport descriptor's dimensions instead of being recorded with the header's values. Requires the `@snapdrift/compare-core` release that adds the export; dependency floors are raised at release time. Closes #194.
29
+
5
30
  ## 0.16.0 - 2026-10-05
6
31
 
7
32
  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.16.0
51
+ uses: ranacseruet/snapdrift@v0.16.1
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.16.0
63
+ uses: ranacseruet/snapdrift@v0.16.1
64
64
  with:
65
65
  mode: pr-diff
66
66
  github-token: ${{ secrets.GITHUB_TOKEN }}
package/action.yml CHANGED
@@ -155,7 +155,7 @@ runs:
155
155
  - name: SnapDrift baseline
156
156
  id: baseline
157
157
  if: inputs.mode == 'baseline'
158
- uses: ranacseruet/snapdrift/actions/baseline@8e827952c33415ba2d8f1fdab944d519534013a6 # v0.16.0
158
+ uses: ranacseruet/snapdrift/actions/baseline@1cbf62965475bc856218ce46eb46dccf7c05326f # v0.16.1
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@8e827952c33415ba2d8f1fdab944d519534013a6 # v0.16.0
168
+ uses: ranacseruet/snapdrift/actions/pr-diff@1cbf62965475bc856218ce46eb46dccf7c05326f # v0.16.1
169
169
  with:
170
170
  github-token: ${{ inputs.github-token }}
171
171
  repo-config-path: ${{ inputs.repo-config-path }}
@@ -90,7 +90,7 @@ runs:
90
90
  if: (steps.config.outputs.provider != 'snap' && (steps.config.outputs.capture_engine != 'snap' || steps.config.outputs.is_local_base_url == 'true')) || steps.config.outputs.on_unavailable == 'fallback-local' || steps.config.outputs.snap_local_capture == 'true'
91
91
  shell: bash
92
92
  run: |
93
- "$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps chromium
93
+ "$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps --only-shell chromium
94
94
 
95
95
  - id: capture
96
96
  shell: bash
@@ -48,7 +48,7 @@ runs:
48
48
  - name: Install Playwright Chromium
49
49
  shell: bash
50
50
  run: |
51
- "$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps chromium
51
+ "$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps --only-shell chromium
52
52
 
53
53
  - id: capture
54
54
  shell: bash
@@ -273,7 +273,7 @@ runs:
273
273
  if: steps.scope.outputs.should_run == 'true' && ((steps.config.outputs.provider != 'snap' && (steps.config.outputs.capture_engine != 'snap' || steps.config.outputs.is_local_base_url == 'true')) || steps.config.outputs.on_unavailable == 'fallback-local' || steps.config.outputs.snap_local_capture == 'true')
274
274
  shell: bash
275
275
  run: |
276
- "$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps chromium
276
+ "$ACTION_ROOT/node_modules/.bin/playwright" install --with-deps --only-shell chromium
277
277
 
278
278
  - id: capture
279
279
  if: steps.scope.outputs.should_run == 'true'
package/docs/contracts.md CHANGED
@@ -43,7 +43,7 @@ SnapDrift reads runtime behavior from `.github/snapdrift.json` by default.
43
43
  | `snap.onUnavailable` | `string` | Behavior when Snap is unreachable: `"fail"` (default), `"warn-and-skip"`, or `"fallback-local"` |
44
44
  | `diff.comparisonPolicy` | `{ "version": 1 \| 2, "threshold": number }` | Optional explicit comparison policy. Deprecated v1 remains the compatibility default; new configurations should use v2 for bounded vertical row alignment. `threshold` must match `diff.threshold` |
45
45
 
46
- When `capture: "snap"` is set (or overridden via `SNAPDRIFT_CAPTURE_ENGINE=snap`), SnapDrift routes baseline and diff captures to Snap Cloud's batch screenshot API (`POST /v1/screenshots`) instead of launching local Chromium via Playwright. Rendered PNGs are downloaded in parallel and diffed locally via `@snapdrift/compare-core`. This requires a public or preview `baseUrl` (loopback and private network URLs like `localhost`, `127.0.0.1`, `::1` are rejected) and an API key (configured in `snap.apiKeyEnv` / `snap.apiKey` or via `SNAP_API_KEY`). When `capture: "snap"` is used with a remote `baseUrl`, GitHub Actions wrapper actions (`actions/baseline`, `actions/pr-diff`) skip the `playwright install --with-deps chromium` step, accelerating CI workflows.
46
+ When `capture: "snap"` is set (or overridden via `SNAPDRIFT_CAPTURE_ENGINE=snap`), SnapDrift routes baseline and diff captures to Snap Cloud's batch screenshot API (`POST /v1/screenshots`) instead of launching local Chromium via Playwright. Rendered PNGs are downloaded in parallel and diffed locally via `@snapdrift/compare-core`. This requires a public or preview `baseUrl` (loopback and private network URLs like `localhost`, `127.0.0.1`, `::1` are rejected) and an API key (configured in `snap.apiKeyEnv` / `snap.apiKey` or via `SNAP_API_KEY`). When `capture: "snap"` is used with a remote `baseUrl`, GitHub Actions wrapper actions (`actions/baseline`, `actions/pr-diff`) skip the `playwright install --with-deps --only-shell chromium` step, accelerating CI workflows.
47
47
 
48
48
  When `provider: "snap"` is set, the `snap` block is required. Exactly one of `snap.apiKeyEnv` or `snap.apiKey` must be present. `snap.apiKey` accepts `${VAR}` interpolation (for example `"${SNAP_API_KEY}"`); the referenced environment variable must be set at runtime or the config loader throws.
49
49
 
@@ -553,6 +553,8 @@ Publication sends `publicationMode: "complete"` and the source run id both as to
553
553
 
554
554
  If `baseUrl` resolves to a local address (see [`isLocalBaseUrl`](#islocalbaseurl-detection) below), SnapDrift runs Playwright on the runner to render the page and uploads the resulting screenshots to Snap. This is necessary whenever your `baseUrl` is a server only the runner can reach (the common case) — Snap's render worker cannot reach a `127.0.0.1` or `localhost` server.
555
555
 
556
+ In the hybrid path, the latest-baseline lookup for diff runs starts before local capture so it overlaps with rendering, and the per-route capture-create and `local-result` uploads run with up to 4 routes in flight. The first failed upload stops further uploads and fails the capture. Local screenshot dimensions come from the PNG header (signature and IHDR are validated; pixel data is not decoded at capture time).
557
+
556
558
  The hybrid path is transparent to the user: the same provider factory picks it, and the output `results.json` carries `provider: "snap"` plus `captureMode: "local-upload"` so downstream consumers can tell which path produced the run. The action's `Install Playwright Chromium` step is gated on this hybrid, so a `provider: "snap"` config with a remote `baseUrl` will not download Playwright Chromium.
557
559
 
558
560
  ### API contract
@@ -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.16.0
49
+ uses: ranacseruet/snapdrift@v0.16.1
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.16.0
74
+ uses: ranacseruet/snapdrift@v0.16.1
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.16.0` with `mode: baseline` | `ranacseruet/snapdrift/actions/baseline@v0.16.0` |
90
- | `ranacseruet/snapdrift@v0.16.0` with `mode: pr-diff` | `ranacseruet/snapdrift/actions/pr-diff@v0.16.0` |
89
+ | `ranacseruet/snapdrift@v0.16.1` with `mode: baseline` | `ranacseruet/snapdrift/actions/baseline@v0.16.1` |
90
+ | `ranacseruet/snapdrift@v0.16.1` with `mode: pr-diff` | `ranacseruet/snapdrift/actions/pr-diff@v0.16.1` |
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.16.0
133
+ uses: ranacseruet/snapdrift@v0.16.1
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.16.0
173
+ uses: ranacseruet/snapdrift@v0.16.1
174
174
  with:
175
175
  mode: pr-diff
176
176
  github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -289,7 +289,7 @@ When your application deploys preview URLs (e.g., Vercel, Netlify, Cloudflare Pa
289
289
  ```
290
290
 
291
291
  ### Why use `capture: "snap"`?
292
- - **Skips Playwright Installation in CI:** The GitHub Actions wrapper actions (`actions/baseline` and `actions/pr-diff`) detect `capture: "snap"` with a remote `baseUrl` and skip `playwright install --with-deps chromium`, saving 45–90 seconds per workflow run.
292
+ - **Skips Playwright Installation in CI:** The GitHub Actions wrapper actions (`actions/baseline` and `actions/pr-diff`) detect `capture: "snap"` with a remote `baseUrl` and skip `playwright install --with-deps --only-shell chromium`, saving 45–90 seconds per workflow run.
293
293
  - **Parallel Cloud Rendering:** Snap Cloud renders full-page screenshots concurrently via its batch API (`POST /v1/screenshots`).
294
294
  - **Local Diff Engine:** Screenshots are downloaded and diffed locally on the runner with `@snapdrift/compare-core`, keeping full artifact bundles and PR comments in GitHub Actions without requiring hosted project configuration.
295
295
 
@@ -82,7 +82,7 @@ jobs:
82
82
 
83
83
  - name: Publish SnapDrift baseline
84
84
  if: steps.baseline_candidate.outputs.current == 'true'
85
- uses: ranacseruet/snapdrift@v0.16.0
85
+ uses: ranacseruet/snapdrift@v0.16.1
86
86
  with:
87
87
  mode: baseline
88
88
  repo-config-path: .github/snapdrift.json
@@ -9,7 +9,7 @@ import path from 'node:path';
9
9
 
10
10
  import { makeMarkdown, buildReportCommentBody } from '@snapdrift/adapter-report-md';
11
11
  import { loadSnapdriftConfig, runBaselineCapture } from '@snapdrift/adapter-fs';
12
- import { COMPARISON_FALLBACK_REASONS, COMPARISON_ROW_KINDS } from '@snapdrift/compare-core';
12
+ import { COMPARISON_FALLBACK_REASONS, COMPARISON_ROW_KINDS, readPngDimensions } from '@snapdrift/compare-core';
13
13
  import {
14
14
  selectConfiguredRoutes,
15
15
  splitCommaList,
@@ -47,6 +47,9 @@ const BINARY_REQUEST_TIMEOUT_MS = 120 * 1000;
47
47
  const POLL_INTERVAL_MS = 2000;
48
48
  const MAX_OPERATION_DURATION_MS = 10 * 60 * 1000;
49
49
  const MAX_STABLE_INCOMPLETE_POLLS = 30;
50
+ // Local-capture uploads are independent per route; a small pool hides round-trip
51
+ // latency without flooding the API or holding many base64 images in memory.
52
+ const LOCAL_UPLOAD_CONCURRENCY = 4;
50
53
  const BASELINE_RUN_SUCCESS_STATUS = 'new';
51
54
  const BASELINE_CAPTURE_SUCCESS_STATUS = 'new';
52
55
  const TERMINAL_CAPTURE_STATUSES = new Set(['new', 'diffed', 'error']);
@@ -64,6 +67,35 @@ function formatDuration(milliseconds) {
64
67
  return `${seconds} seconds`;
65
68
  }
66
69
 
70
+ /**
71
+ * Runs `task` over `items` with at most `limit` in flight. Stops starting new
72
+ * work after the first failure and rejects with that first error, so a failed
73
+ * upload does not keep fanning requests out to Snap.
74
+ *
75
+ * @template T
76
+ * @param {T[]} items
77
+ * @param {number} limit
78
+ * @param {(item: T) => Promise<void>} task
79
+ * @returns {Promise<void>}
80
+ */
81
+ async function runWithConcurrency(items, limit, task) {
82
+ let next = 0;
83
+ /** @type {{ error: unknown } | undefined} */
84
+ let failure;
85
+ const worker = async () => {
86
+ while (!failure && next < items.length) {
87
+ const item = items[next++];
88
+ try {
89
+ await task(item);
90
+ } catch (error) {
91
+ failure ??= { error };
92
+ }
93
+ }
94
+ };
95
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
96
+ if (failure) throw failure.error;
97
+ }
98
+
67
99
  const OPERATION_LIMIT_TEXT = formatDuration(MAX_OPERATION_DURATION_MS);
68
100
 
69
101
  /** @returns {number} A monotonic timestamp in milliseconds. */
@@ -653,7 +685,6 @@ function getPackageVersion() {
653
685
  }
654
686
 
655
687
  const TAR_BLOCK_SIZE = 512;
656
- const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
657
688
 
658
689
  /**
659
690
  * Parse a plain ustar-style tar archive (512-byte headers, bodies padded to
@@ -696,20 +727,6 @@ function parseTarEntries(archive) {
696
727
  return entries;
697
728
  }
698
729
 
699
- /**
700
- * Read the pixel dimensions from a PNG's IHDR chunk. Returns null when the
701
- * bytes are not a PNG (e.g. a JPEG export) or are too short.
702
- *
703
- * @param {Buffer} bytes
704
- * @returns {{ width: number, height: number } | null}
705
- */
706
- function readPngDimensions(bytes) {
707
- if (bytes.length < 24 || !bytes.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) {
708
- return null;
709
- }
710
- return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) };
711
- }
712
-
713
730
  /**
714
731
  * @param {string | undefined} json
715
732
  * @returns {any}
@@ -1886,6 +1903,14 @@ export class SnapProvider {
1886
1903
  * @returns {Promise<CaptureResult>}
1887
1904
  */
1888
1905
  async #captureLocalAndUpload(options) {
1906
+ // The latest-baseline lookup is read-only and independent of the screenshots,
1907
+ // so start it now and let it overlap with local capture. Its own deadline keeps
1908
+ // capture time out of the Snap operation budget. A rejection is held until we
1909
+ // await it below, so a capture failure first never leaves an unhandled one.
1910
+ const baselineLookup =
1911
+ options.purpose === 'diff' ? this.#resolveLatestBaselineId() : Promise.resolve(/** @type {string | null} */ (null));
1912
+ baselineLookup.catch(() => {});
1913
+
1889
1914
  const localCapture = await this.#localCaptureFn({
1890
1915
  configPath: options.configPath,
1891
1916
  routeIds: options.routeIds,
@@ -1915,7 +1940,7 @@ export class SnapProvider {
1915
1940
  // omit the baselineId. Captures then settle to "new" server-side (no
1916
1941
  // comparison), and publishBaseline harvests their object keys. A diff run
1917
1942
  // attaches the latest baseline so the backend can compare against it.
1918
- const baselineId = options.purpose === 'diff' ? await this.#resolveLatestBaselineId(operation) : null;
1943
+ const baselineId = await baselineLookup;
1919
1944
 
1920
1945
  const runResponse = await this.#request(
1921
1946
  'POST',
@@ -1950,7 +1975,8 @@ export class SnapProvider {
1950
1975
  assertComparisonPolicyAcknowledged(runResponse?.comparisonPolicy, options.comparisonPolicy, 'Snap local-upload run creation');
1951
1976
  }
1952
1977
 
1953
- for (const { route, manifestEntry } of uploads) {
1978
+ const uploadStartedAt = Date.now();
1979
+ await runWithConcurrency(uploads, LOCAL_UPLOAD_CONCURRENCY, async ({ route, manifestEntry }) => {
1954
1980
  const captureId = `cap_${crypto.randomUUID().replace(/-/g, '').slice(0, 24)}`;
1955
1981
  const viewportDescriptor = resolveViewportDescriptor(route.viewport);
1956
1982
 
@@ -1986,7 +2012,8 @@ export class SnapProvider {
1986
2012
  this.#generateIdempotencyKey(),
1987
2013
  operation
1988
2014
  );
1989
- }
2015
+ });
2016
+ process.stderr.write(`[SnapDrift] Uploaded ${uploads.length} screenshot(s) to Snap in ${((Date.now() - uploadStartedAt) / 1000).toFixed(1)}s.\n`);
1990
2017
 
1991
2018
  const snapResults = {
1992
2019
  ...localResults,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snapdrift",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SnapDrift captures, compares, and reports UI drift for Playwright-based app checks.",
@@ -103,9 +103,9 @@
103
103
  "registry": "https://registry.npmjs.org"
104
104
  },
105
105
  "dependencies": {
106
- "@snapdrift/adapter-fs": "^1.7.0",
106
+ "@snapdrift/adapter-fs": "^1.7.1",
107
107
  "@snapdrift/adapter-report-md": "^1.4.0",
108
- "@snapdrift/compare-core": "^1.6.0",
108
+ "@snapdrift/compare-core": "^1.7.0",
109
109
  "@snapdrift/manifest": "^1.8.0",
110
110
  "js-yaml": "^5.4.0",
111
111
  "playwright": "^1.59.1",