-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(sourcemap-upload): Add zstd compression support #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c313052
feat(sourcemap-upload): Add zstd compression support
BYK 8d1f331
chore(sourcemap-upload): document compression level choices
BYK dda042d
chore(sourcemap-upload): trim compression-level comments to inline on…
BYK 4e49946
fix(sourcemap-upload): address code review feedback
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { gunzipSync } from "node:zlib"; | ||
| import { | ||
| ChunkServerOptionsSchema, | ||
| encodeChunk, | ||
| pickUploadEncoding, | ||
| } from "../../../src/lib/api/sourcemaps.js"; | ||
|
|
||
| describe("pickUploadEncoding", () => { | ||
| test("prefers zstd when both zstd and gzip are advertised", () => { | ||
| expect(pickUploadEncoding(["gzip", "zstd"])).toBe("zstd"); | ||
| expect(pickUploadEncoding(["zstd", "gzip"])).toBe("zstd"); | ||
| }); | ||
|
|
||
| test("falls back to gzip when zstd is absent", () => { | ||
| expect(pickUploadEncoding(["gzip"])).toBe("gzip"); | ||
| }); | ||
|
|
||
| test("returns undefined when the server opts out of compression", () => { | ||
| expect(pickUploadEncoding([])).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("ignores unknown codecs the CLI does not implement", () => { | ||
| expect(pickUploadEncoding(["br", "deflate"])).toBeUndefined(); | ||
| expect(pickUploadEncoding(["br", "gzip"])).toBe("gzip"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("encodeChunk", () => { | ||
| const payload = Buffer.from("hello chunk-upload world".repeat(128)); | ||
|
|
||
| test("gzip encoding emits gzip magic bytes and round-trips", async () => { | ||
| const encoded = await encodeChunk(payload, "gzip"); | ||
| expect(encoded.byteLength).toBeLessThan(payload.byteLength); | ||
| // gzip magic: 1f 8b | ||
| expect(encoded[0]).toBe(0x1f); | ||
| expect(encoded[1]).toBe(0x8b); | ||
| expect(Buffer.from(gunzipSync(encoded)).equals(payload)).toBe(true); | ||
| }); | ||
|
|
||
| test("zstd encoding emits zstd magic bytes and round-trips", async () => { | ||
| const encoded = await encodeChunk(payload, "zstd"); | ||
| expect(encoded.byteLength).toBeLessThan(payload.byteLength); | ||
| // zstd magic: 28 b5 2f fd (little-endian 0xFD2FB528) | ||
| expect(encoded[0]).toBe(0x28); | ||
| expect(encoded[1]).toBe(0xb5); | ||
| expect(encoded[2]).toBe(0x2f); | ||
| expect(encoded[3]).toBe(0xfd); | ||
| const decoded = Bun.zstdDecompressSync(encoded); | ||
| expect(Buffer.from(decoded).equals(payload)).toBe(true); | ||
| }); | ||
|
|
||
| test("returns the input unchanged when no encoding is selected", async () => { | ||
| const encoded = await encodeChunk(payload, undefined); | ||
| // Plain path returns the same buffer, not a copy. | ||
| expect(encoded).toBe(payload); | ||
| }); | ||
| }); | ||
|
|
||
| describe("ChunkServerOptionsSchema", () => { | ||
| test("accepts compression: [] (server opt-out)", () => { | ||
| const result = ChunkServerOptionsSchema.safeParse({ | ||
| url: "https://example.com/api/0/organizations/o/chunk-upload/", | ||
| chunkSize: 8_388_608, | ||
| chunksPerRequest: 64, | ||
| maxRequestSize: 33_554_432, | ||
| hashAlgorithm: "sha1", | ||
| concurrency: 8, | ||
| compression: [], | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| test("accepts compression with zstd + gzip advertised", () => { | ||
| const result = ChunkServerOptionsSchema.safeParse({ | ||
| url: "https://example.com/api/0/organizations/o/chunk-upload/", | ||
| chunkSize: 8_388_608, | ||
| chunksPerRequest: 64, | ||
| maxRequestSize: 33_554_432, | ||
| hashAlgorithm: "sha1", | ||
| concurrency: 8, | ||
| compression: ["gzip", "zstd"], | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| if (result.success) { | ||
| expect(pickUploadEncoding(result.data.compression)).toBe("zstd"); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.