Skip to content

Conversation

@mstange
Copy link
Contributor

@mstange mstange commented Jan 12, 2026

We have a node zlib based compression / decompression code path in gz.ts. This path is currently not exercised by our tests. But if I change our Jest environment so that it exercises the node zlib code path, there are test failures in receive-profile.test.ts, for two reasons:

  • compress / decompress were discarding the byteOffset and byteLength of the returned typed array and re-wrapping the entire underlying ArrayBuffer, including potential garbage bytes at the start or at the end. (In practice just at the end.)
  • Various places in receive-profile.test.ts were accessing .buffer on the array returned by compress(), and assuming that the buffer didn't contain any extra data beyond the Uint8Array.

So this fix removes the rewrapping, and replaces each of those .buffer accesses with a potential copy if that's needed to make sure that the ArrayBuffer doesn't contain any extra data.

A cleaner solution might be to stop using ArrayBuffer so much in these tests, but in some of them we simulate the response from a fetch() which definitely has an arrayBuffer() accessor and not a byteArray() accessor.

We were re-wrapping the Buffer into a Uint8Array but discarding
the byteOffset and byteLength, so we expanded the returned array
to include garbage data.

We can just return the Buffer itself, it is a Uint8Array.
We were assuming that the Uint8Array returned from compress() is a 
view of the entirety of its underlying ArrayBuffer. But that's not 
necessarily true. Specifically it's not true if gz.ts takes the 
"node" code path where it uses the node zlib module. We haven't 
run into this before because our jest environment has browser-like 
Worker APIs available, so we test the browser code path and the 
node path doesn't get exercised. But if I change it so that we go 
down the node path in the tests, then multiple tests in 
receive-profile.test.ts fail because we pass around compressed 
buffers with extra garbage bytes at the end.

So this fix replaces each of those `.buffer` accesses with a 
potential copy if that's needed to make sure that the ArrayBuffer 
doesn't contain any extra data.

A cleaner solution might be to stop using ArrayBuffer so much in 
these tests, but in some of them we simulate the response from a 
fetch() which definitely has an arrayBuffer() accessor and not a 
byteArray() accessor.
@mstange mstange requested a review from canova January 12, 2026 14:59
@mstange mstange self-assigned this Jan 12, 2026
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.69%. Comparing base (a0150a5) to head (c954fec).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/gz.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5753      +/-   ##
==========================================
+ Coverage   85.67%   85.69%   +0.02%     
==========================================
  Files         315      315              
  Lines       31110    31122      +12     
  Branches     8560     8564       +4     
==========================================
+ Hits        26654    26671      +17     
+ Misses       4026     4021       -5     
  Partials      430      430              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Copy link
Member

@canova canova left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@mstange mstange enabled auto-merge January 19, 2026 18:29
@mstange mstange merged commit b23085c into firefox-devtools:main Jan 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants