Skip to content

stream: improve Web Compression spec compliance#62107

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

stream: improve Web Compression spec compliance#62107
panva wants to merge 5 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 fixesimproves 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.

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


stream: reject SharedArrayBuffer-backed chunks in web compression

Per the Compression Streams spec, chunks must be BufferSource which excludes SharedArrayBuffer-backed views. Add validation to both CompressionStream and DecompressionStream that rejects chunks backed by SharedArrayBuffer with a typed TypeError.


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 from 7ad3343 to 17679f8 Compare March 4, 2026 21:57
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.

Unskip WPT compression bad-chunks tests which now run instead of hang.

Unskip WPT compression bad-chunks tests which now run instead of hang
and mark the remaining expected failures.
@panva panva force-pushed the improve-webcompression branch from 17679f8 to 46c309e Compare March 4, 2026 21:59
Per the Compression Streams spec, chunks must be BufferSource which
excludes SharedArrayBuffer-backed views. Add validation to both
CompressionStream and DecompressionStream that rejects chunks backed
by SharedArrayBuffer with a typed TypeError.
@panva panva force-pushed the improve-webcompression branch from 161b9cf to 305ab4c Compare March 4, 2026 22:49
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 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 (9fb0878).
⚠️ Report is 5 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   206377   +65924     
  Branches    21801    39529   +17728     
==========================================
+ Hits       128694   185018   +56324     
- Misses      11536    13468    +1932     
- Partials      223     7891    +7668     
Files with missing lines Coverage Δ
lib/internal/webstreams/adapters.js 86.08% <100.00%> (+0.23%) ⬆️
lib/internal/webstreams/compression.js 100.00% <100.00%> (+2.22%) ⬆️

... and 463 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
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-rebase Add this label to allow the Commit Queue to land a PR in several commits. 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.

4 participants