Skip to content

stream: improve Web Compression spec compliance#62107

Open
panva wants to merge 4 commits intonodejs:mainfrom
panva:improve-webcompression
Open

stream: improve Web Compression spec compliance#62107
panva wants to merge 4 commits intonodejs:mainfrom
panva:improve-webcompression

Conversation

@panva
Copy link
Member

@panva panva commented Mar 4, 2026

Investigating why wpt.fyi daily runs took 26 minutes and then started taking 75 minutes last week lead me down this road.

Daily epoch synced WPTs were hanging again on test-compression, the switch to arm kicked in tools/test.py increase in timeouts (hence going from 26 to 75 minutes), and because the entire WPT subsuite errored there were no compression tests reported to wpt.fyi.

This PR updates the WPTs (some of which are no longer tentative) and improves the conformance of CompressionStream and DecompressionStream to the WHATWG Compression standard.


test: update WPT compression to ae05f5cb53

Simple WPT update


test: improve WPT report runner

Add incremental report writing after each spec completes and on worker errors so that reports survive if the process is killed before the exit handler runs.

Add bytes() method to readAsFetch() to match the Response API used by newer WPT tests.


stream: improve Web Compression spec compliance

Pass rejectGarbageAfterEnd: true to createInflateRaw() and createBrotliDecompress(), matching the behavior already in place for deflate and gzip. The Compression Streams spec treats any data following a valid compressed payload as an error.

When the underlying Node.js stream throws synchronously from write() (e.g. zlib rejects an invalid chunk type), destroy the stream so that the readable side is also errored. Without this, the readable side hangs forever waiting for data that will never arrive.

Introduce a kValidateChunk callback option in the webstreams adapter layer. Compression streams use this to validate that chunks are BufferSource instances not backed by SharedArrayBuffer, rather than monkey-patching the underlying handle's write method.

Unskip WPT compression bad-chunks tests which now run instead of hang and mark the remaining expected failures.


stream: fix brotli error handling in web compression streams

Convert brotli decompression errors to TypeError to match the Compression Streams spec, by extending handleKnownInternalErrors() in the adapters layer to recognize brotli error codes.

This replaces the manual error event handler on DecompressionStream which was redundant with the adapter's built-in error propagation.

panva added 2 commits March 4, 2026 22:37
Add incremental report writing after each spec completes and on
worker errors so that reports survive if the process is killed
before the exit handler runs.

Add bytes() method to readAsFetch() to match the Response API
used by newer WPT tests.
@panva panva added stream Issues and PRs related to the stream subsystem. web streams commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. web-standards Issues and PRs related to Web APIs labels Mar 4, 2026
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/web-standards

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Mar 4, 2026
@panva panva force-pushed the improve-webcompression branch 4 times, most recently from 305ab4c to 9fb0878 Compare March 4, 2026 22:51
@panva panva requested review from KhafraDev and anonrig March 4, 2026 23:15
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (330e3ee) to head (c28a421).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62107      +/-   ##
==========================================
- Coverage   91.62%   89.65%   -1.98%     
==========================================
  Files         337      676     +339     
  Lines      140453   206392   +65939     
  Branches    21801    39524   +17723     
==========================================
+ Hits       128694   185044   +56350     
- Misses      11536    13473    +1937     
- Partials      223     7875    +7652     
Files with missing lines Coverage Δ
lib/internal/webstreams/adapters.js 86.29% <100.00%> (+0.44%) ⬆️
lib/internal/webstreams/compression.js 100.00% <100.00%> (+2.22%) ⬆️

... and 462 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@panva panva added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 5, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 5, 2026
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@panva panva added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 5, 2026
@panva panva force-pushed the improve-webcompression branch from 9fb0878 to 2b55f7c Compare March 5, 2026 11:13
@panva panva removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 5, 2026
@panva panva force-pushed the improve-webcompression branch 2 times, most recently from 7740fc4 to 0b7f47c Compare March 5, 2026 11:42
@nodejs-github-bot

This comment was marked as outdated.

@panva panva force-pushed the improve-webcompression branch from 0b7f47c to 1dd8f13 Compare March 5, 2026 13:34
@panva
Copy link
Member Author

panva commented Mar 5, 2026

@Renegade334 done

Copy link
Member

@Renegade334 Renegade334 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to get another pair of eyes on the Transform adapter error logic, but LGTM!

@Renegade334 Renegade334 added the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 5, 2026
panva added 2 commits March 5, 2026 16:26
Pass rejectGarbageAfterEnd: true to createInflateRaw() and
createBrotliDecompress(), matching the behavior already in place
for deflate and gzip. The Compression Streams spec treats any
data following a valid compressed payload as an error.

When the underlying Node.js stream throws synchronously from
write() (e.g. zlib rejects an invalid chunk type), destroy the
stream so that the readable side is also errored. Without this,
the readable side hangs forever waiting for data that will never
arrive.

Introduce a kValidateChunk callback option in the webstreams
adapter layer. Compression streams use this to validate that
chunks are BufferSource instances not backed by SharedArrayBuffer,
replacing the previous monkey-patching of the underlying
handle's write method.

Unskip WPT compression bad-chunks tests which now run instead of
hang and mark the remaining expected failures.
Convert brotli decompression errors to TypeError to match the
Compression Streams spec, by extending handleKnownInternalErrors()
in the adapters layer to recognize brotli error codes.

This replaces the manual error event handler on DecompressionStream
which was redundant with the adapter's built-in error propagation.
@panva panva force-pushed the improve-webcompression branch from 1dd8f13 to c28a421 Compare March 5, 2026 15:26
@Renegade334 Renegade334 removed the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 5, 2026
@panva panva added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 5, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@panva panva added lts-watch-v22.x PRs that may need to be released in v22.x lts-watch-v24.x PRs that may need to be released in v24.x commit-queue Add this label to land a pull request using GitHub Actions. labels Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lts-watch-v22.x PRs that may need to be released in v22.x lts-watch-v24.x PRs that may need to be released in v24.x needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. web streams web-standards Issues and PRs related to Web APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants