Repository navigation
test: cover embedded sqlite, import attributes and shared chunks in the ESM bytecode module record - #37781
test: cover embedded sqlite, import attributes and shared chunks in the ESM bytecode module record#37781robobun wants to merge 2 commits into
Conversation
Follow-up to #37677, which started building the record from what the printer emits. Three shapes repaired by that change had no test: - an embedded sqlite database (`with { type: "sqlite", embed: "true" }`), whose module body is synthesized rather than parsed, so the chunk's import.meta flag only exists if it comes from the printer; the binary segfaulted on startup before - an import attribute on a file loaded at runtime, which has to survive as host-defined fetch parameters through the per-part records; the database was parsed as JavaScript before - re-exports of an external in a file shared by two chunks, which the shared chunk hands on through its cross-chunk export suffix; the binary segfaulted on startup before All six tests fail on the released 1.4.0 and on a debug build without the fix, and pass on main.
|
Warning Review limit reached
Next review available in: 25 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
|
Updated 12:05 PM PT - Aug 12th, 2026
❌ @robobun, your commit 7964b5b has some failures in 🧪 To try this PR locally: bunx bun-pr 37781That installs a local version of the PR into your bun-37781 --bun |
|
Status: test-only follow-up to #37677, ready to merge from my side. The six new tests fail on the released 1.4.0 (two segfaults and the database-parsed-as-JavaScript error quoted in the description) and on a debug build from before that change, and pass with CI: both Buildkite builds for this PR (92957 for de63f64, 93203 for the empty retrigger 7964b5b) ran 179 of 181 jobs green, including every lane that executed the two changed files, and report no test failures (the retried tests they list are unrelated files that passed on retry). Both were marked failed only because the two |
There was a problem hiding this comment.
LGTM — test-only additions that extend existing itBundled matrices with three new ESM-bytecode module-record shapes.
What was reviewed:
- New scenarios mirror the existing
compile/EmbeddedSqliteandcompile/sqlite-filefixtures;serializedHelloDatabase()returns aBuffer, which bothfilesandruntimeFilesaccept. - Threading
runtimeFiles/setCwdthrough the matrix loop:runtimeFiles ?? {}in expectBundled handlesundefined, andsetCwd: falseis equivalent to the prior omitted value for scenarios that don't set it. ReExportExternalFromSharedChunkfollows the same shape as the neighboringReExportExternalFromSplitChunktest.
Extended reasoning...
Overview
Test-only follow-up to #37677 adding six itBundled cases (three scenarios × plain/minified) across test/bundler/bundler_compile.test.ts and test/bundler/bundler_compile_splitting.test.ts. The scenarios cover paths through the ESM bytecode ModuleInfo builder that #37677 fixed but nothing tested: a synthesized import.meta.require body (embedded sqlite), an import attribute that survives into the chunk with string-id remapping (runtime sqlite via .db + type: "sqlite"), and a shared (non-entry) split chunk whose cross-chunk export suffix must pair with imports recorded from the chunk body. The only non-test-case change is widening the scenario array's files type to BundlerTestInput["files"] and adding an optional runtimeFiles field, then passing both plus setCwd through to itBundled.
Security risks
None. No production code is touched. The tests spawn compiled binaries in temp dirs via the existing itBundled harness, use node:fs/node:path builtins and an in-memory sqlite serialization — no network, no external hosts, no auth/crypto surface.
Level of scrutiny
Low. This is additive test coverage for behavior already merged in #37677, using the exact patterns already present in the same files (compile/EmbeddedSqlite, compile/sqlite-file, ReExportExternalFromSplitChunk). I verified in expectBundled.ts that runtimeFiles accepts Buffer (what db.serialize() returns) and that Object.entries(runtimeFiles ?? {}) tolerates the undefined now passed by scenarios that don't set it. setCwd: false for those scenarios is equivalent to the previously-omitted key.
Other factors
The PR description documents that all six tests fail on 1.4.0 / a pre-#37677 debug build and pass on current main, satisfying the "prove the test fails for the right reason" bar. Each scenario carries a comment naming the specific record-builder path it exercises and why the sibling test doesn't already cover it. The bug hunter found nothing. No prior reviews to reconcile.
There was a problem hiding this comment.
LGTM — test-only additions that follow the existing itBundled patterns in both files.
What was reviewed:
- The matrix loop change is behavior-preserving for existing scenarios:
runtimeFiles: undefinedfalls through to?? {}in expectBundled.ts, andsetCwd: falseis equivalent to the previous unset value at therun.setCwd ? root : originalCwdcheck. db.serialize()returns aBuffer, which is accepted by bothBundlerTestInput["files"]andruntimeFilesin the harness type.- The new
ReExportExternalFromSharedChunkloop mirrors the adjacentReExportExternalFromSplitChunkloop exactly (same options, same minify spread pattern). - PR description confirms all six fail with
USE_SYSTEM_BUN=1and pass on current main; CI is green on all completed lanes.
Extended reasoning...
Overview
This PR adds six new test cases across two existing bundler test files as a test-only follow-up to #37677. In bundler_compile.test.ts it adds two scenarios (EmbeddedSqlite and ImportAttributeOnRuntimeFile) to the existing esmBytecodeScenarios matrix, plus a small serializedHelloDatabase() helper and an optional runtimeFiles field on the scenario type. In bundler_compile_splitting.test.ts it adds a ReExportExternalFromSharedChunk loop over [false, true] minify variants. No production code is touched.
Security risks
None. The changes are entirely within test files. The new fixtures use bun:sqlite in-memory databases, node:fs/node:path builtins, and local file I/O within the test's temp directory — no network, no external registries, no security-sensitive code paths.
Level of scrutiny
Low-to-medium. This is test-only, additive, and follows established patterns in the same files (the new sqlite scenarios mirror the existing compile/EmbeddedSqlite and compile/sqlite-file tests further down the file; the shared-chunk test mirrors the adjacent ReExportExternalFromSplitChunk loop). The one non-trivial change — threading runtimeFiles/setCwd through the matrix loop — was checked against expectBundled.ts: runtimeFiles ?? {} at line 1581 and run.setCwd ? root : originalCwd at line 1744 make undefined and false behave identically to the previous omission, so existing scenarios are unaffected.
Other factors
The PR description documents that each of the six new tests fails with USE_SYSTEM_BUN=1 (segfaults / parse-as-JS error) and on a debug build predating #37677, and passes on current main — satisfying the repo's "prove the test fails for the right reason" requirement. The self-review comment reports CI green on all 179 completed test jobs. The files type widening from Record<string, string> to BundlerTestInput["files"] is required because db.serialize() returns a Buffer, and the harness already accepts it. Comments on each scenario explain the specific code path being exercised, which matches the file's existing convention. The bug hunting system found no issues.
|
Closing this PR because it has been inactive for more than 90 days. |
Problem
--compile --bytecode --format=esmchunk's module record from what the printer emits. Three shapes it repairs had no test.panic(main thread): Segmentation fault at address 0x0. The module body is synthesized, not parsed, so the record'simport.metaflag was false.error: Expected ";" but found "format"atdata.db:1:8. The attribute's string id was not remapped for the chunk, so the database was parsed as JavaScript.node:fsre-export shared by two chunks under--splitting:panic(main thread): Segmentation fault at address 0x8. The record had the chunk's exports but not the imports they came from.Fix
runtimeFiles, written next to the binary and used as its cwd, for a database that is not embedded.USE_SYSTEM_BUN=1and on a debug build ofda3851e5(ASAN SEGV, orImports different between parseFromSourceCode and fallbackParse), and pass on current main.Background
--compile --bytecode --format=esmeach chunk ships as JSC bytecode plus a module record (imports, exports, attributes,import.metause). JSC links from the record, not the source, so a record that disagrees with the printed code fails at startup.embed: "true"on a sqlite import copies the database into the binary and synthesizes the module body (import.meta.require(...)); without it the import stays a statement and the file is opened at runtime.--splitting, a file used by both the entry and animport()ed module is hoisted into a shared chunk, whose bindings leave through a cross-chunkexport { ... }suffix rather than an entry point tail.import.metaflag is not compared, so its absence shows only as the crash.no test proof · iteration 3 · Platform-specific test-only change; deferring to CI.
Original description
Test-only follow-up to #37677, which made
--compile --bytecode --format=esmbuild each chunk's module record from what the printer emits. Reviewing that change afterwards turned up three shapes it repairs that nothing tests. On the released 1.4.0 they fail like this:Why each one is a distinct path through the record:
EmbeddedSqlite(ESM bytecode matrix, plain and minified): the embedded database is a module whose body the bundler synthesizes (import.meta.require(...)), so it never goes through the parser and the old per-sourcehas_import_metaflag was false for it. The record now gets the flag from the printer when it printsimport.meta; without it JSC runs the module without animport.metabinding and crashes inllint_op_get_by_id. The debug cross-check does not compare this flag, so the crash is the only signal.ImportAttributeOnRuntimeFile(matrix, plain and minified): an attribute on a file that stays an import statement is recorded as host-defined fetch parameters, i.e. a string id thatModuleInfo::appendhas to remap like any other slot. The entry imports a helper that itself importsnode:path/node:fs, so the helper's part is appended first and the entry's ids differ between its own part and the chunk..dbwas chosen because the extension does not imply the sqlite loader, so the recorded attribute is what selects it. The matrix gained optionalruntimeFilesfor this (the binary then runs with that directory as cwd, likecompile/sqlite-file).ReExportExternalFromSharedChunk(bundler_compile_splitting.test.ts, plain and minified):ReExportExternalFromSplitChunkfrom bundler: build the ESM bytecode module record from what the printer emits #37677 reaches the re-exporting file only throughimport(), so it is an entry chunk and its exports go through the entry point tail. Hereentry.tsand the lazy chunk both import it, so its code is hoisted into a shared chunk whose bindings leave through the cross-chunkexport { readFileSync, fsns }suffix; the record has to pair that suffix with theimportstatements recorded from the chunk body (one named import, one namespace import). This is also the only test where a non-entry chunk's record is built.Verification
All six fail with
USE_SYSTEM_BUN=1(the errors above) and on a debug build ofda3851e5(the two sqlite-embed variants with the ASAN SEGV, the other four withImports different between parseFromSourceCode and fallbackParse), and pass withbun bd teston current main. The existingcompile/EmbeddedSqlite(no bytecode) passes on both, which is what pins the crash to the record.