http2: implement internalBinding('http2') for the vendored node test shim (+2 upstream tests) - #34499
Draft
cirospaciari wants to merge 3 commits into
Draft
http2: implement internalBinding('http2') for the vendored node test shim (+2 upstream tests)#34499cirospaciari wants to merge 3 commits into
cirospaciari wants to merge 3 commits into
Conversation
`internal/test/binding` threw for "http2", so every vendored node http2 test gated on `--expose-internals` died on the import instead of running. Add the case, backed by real state where Bun has it: - `constants` is the public node:http2 table (all 240 keys already match node v26.3.0 exactly, verified against the v26.3.0 binary) - `nghttp2ErrorString` transcribes nghttp2's `nghttp2_strerror` - `Http2Session`/`Http2Stream` are inert stand-ins for the native handle layer Bun does not have, so a test stubbing a handle method ends up asserting Bun's real behavior instead of a native return code Vendor the two node v26.3.0 tests this unblocks, byte-identical: test-http2-binding and test-http2-respond-errors.
Collaborator
Contributor
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
This was referenced Jul 24, 2026
…binding-shim # Conflicts: # src/js/internal/test/binding.ts
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
internal/test/bindingthrewinternalBinding("http2") is not implemented in Bun, so every vendored node http2 test gated on--expose-internalsdied on the import before running a single assertion. This adds thehttp2case and vendors the two node v26.3.0 tests it unblocks.The case is backed by real state wherever Bun has it:
constantsis the publicnode:http2table. All 240 keys already match node v26.3.0 exactly — I diffed them against the v26.3.0 binary and found zero value mismatches — sotest-http2-bindingbecomes a genuine compat assertion rather than a check against a hand-written copy.nghttp2ErrorStringis a transcription of nghttp2'snghttp2_strerror, machine-diffed entry-by-entry againstdeps/nghttp2/lib/nghttp2_helper.c(42/42 keys and strings match).Http2Session/Http2Streamare inert stand-ins for the native handle layer Bun does not have (Bun's streams drive the Rust engine directly). In node these are the native classes underneath the JS ones, and the tests stub a method on them to neuter the native call. Bun has no native call to neuter, so the stub is inert and the test ends up asserting Bun's real behavior —test-http2-respond-errorsexercises the actualERR_HTTP2_HEADERS_SENT/ERR_HTTP2_INVALID_STREAMpaths inhttp2.ts.Tests added, both byte-identical to node v26.3.0:
test-http2-binding.jstest-http2-respond-errors.jsScope note
Seven other http2 tests are blocked on this same import but are not included, because they can only pass by faking node internals rather than testing Bun:
client-onconnect-errors,info-headers-errors,respond-nghttperrors,respond-with-fd-errors,server-push-stream-errorsassert that a native return code is translated into anNghttpError. Bun'srespond()/request()throw directly and there is no native return code to inject, so the shim itself would have to perform the translation the test is checking.util-headers-listneeds node'sbuildNgHeaderString(nghttp2 wire-format packing) andutil-update-options-bufferneeds node'soptionsBuffermarshalling. Bun has neither; it packs headers via its own materializer.One consequence worth knowing for future ports: because the stand-ins are unrelated to any real Bun object, a future test that stubs a method on them will silently no-op rather than fail loudly — check the stub actually took effect.
How did you verify your code works?
bun run <file>), 5/5 on repeat runs.test-http2*files: no regressions. (test-http2-socket-proxy-handler-for-has.jsflaked once under 6-way parallelism and passes 3/3 standalone; it does not referenceinternalBinding.)constantsobject identity (binding.constants === require('http2').constants) istruein both;nghttp2ErrorStringof an unknown code returns"Unknown error code"in both.binding.Http2Stream.prototype.respondleaves Bun's realServerHttp2Stream.prototype.responduntouched.internalBindingof an unknown name still throws.