Repository navigation
Conversation
The two C_INCLUDE_PATH cases ran one after the other. Each paid a child bun start-up and a TinyCC compile under ASAN. They now run as one concurrent test.each table with a shared fixture. The child spawn stays. cc() reads C_INCLUDE_PATH and LIBRARY_PATH through the bun_core::env_var cache, which fills on the first cc() call for the life of the process. Assertions compare the whole spawn result: exact stdout, empty stderr, exit code 0. The old test only checked that stderr did not name the header. A new case links a shared library that TinyCC can only find through LIBRARY_PATH. It builds the library with the system C compiler and skips when none is installed.
|
Status: ready for review.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. WalkthroughChangesFFI environment path regression tests
Merge Risk: ⚪ Minimal · up to This localized test-only change speeds the regression test and adds coverage for header and library search paths with exact result assertions; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Full details: Title checkExplanation The title clearly describes the main change: improving the speed and coverage of the C_INCLUDE_PATH regression test. It is concise and related to the changeset, although it does not mention the added LIBRARY_PATH coverage. Full details: Description checkExplanation The description explains the problem, implementation, verification results, background, and test limitations. It does not use the exact template headings, but it provides the required information and is sufficiently complete. Comment |
There was a problem hiding this comment.
LGTM — test-only refactor that tightens assertions and adds LIBRARY_PATH coverage.
What was reviewed:
- Harness conventions:
tempDir+using,bunExe/bunEnvspread,await usingon spawns, concurrent pipe drain,test.concurrent.skipIf().each()(matches existing usage in sql-connection-socket-uaf.test.ts). - Assertion shape: combined
toEqual({stdout, stderr, exitCode})per REVIEW.md; exact stderr""replaces the loose.not.toContainchecks. - New LIBRARY_PATH case:
skipIf(isWindows || !systemCC)gate,.dylibvs.sobranch,-shared -fPICbuild with stderr surfaced on failure;systemCC!is safe under the skip guard.
Extended reasoning...
Overview
This PR touches a single file, test/regression/issue/26249.test.ts, which covers bun:ffi's cc() honoring C_INCLUDE_PATH and LIBRARY_PATH. The two near-duplicate C_INCLUDE_PATH tests are collapsed into a table-driven test.concurrent.skipIf(isWindows).each(includeCases) with shared fixtureJs() and runFixture() helpers, and a third test is added that builds a tiny shared library with the system C compiler and verifies TinyCC finds it via LIBRARY_PATH. No runtime source is touched.
Security risks
None. The change is confined to the test suite; it spawns local subprocesses in a tempDir, contacts no network, and reads no untrusted input. The system-compiler invocation is a fixed argv on a file the test itself wrote.
Level of scrutiny
Low-to-moderate. It is a mechanical test refactor plus one new coverage case, following documented harness conventions exactly (tempDir with using, bunExe/bunEnv, await using proc, Promise.all pipe drain, combined toEqual result assertion, test.concurrent for independent subprocess tests). The test.concurrent.skipIf(...).each(...) chaining already appears elsewhere in the suite, and DirectoryTree is an exported harness type. No CODEOWNERS entry covers this path.
Other factors
The header comment justifying the child-process spawn (process-wide bun_core::env_var cache) is exactly the kind of non-obvious rationale CLAUDE.md asks to keep. The new LIBRARY_PATH test is properly gated (skipIf(isWindows || !systemCC)), picks .dylib on macOS and .so otherwise, surfaces compiler stderr on build failure, and uses a unique library name to avoid colliding with system libs. The PR description includes a negative probe (renamed env vars → all three tests fail) and before/after timings. Bug hunt exited on dry_streak with no findings and no outstanding reviewer objections.
Problem
test/regression/issue/26249.test.tstook 10 s on the debian 13 x64-asan lane (build #108977). Its two tests ran in sequence, each with a child bun start-up and a TinyCC compile under ASAN.stderronly had to not contain the header name. Nothing coveredLIBRARY_PATH.Fix
C_INCLUDE_PATHcases are onetest.concurrent.eachtable with a shared fixture, so the children overlap.cc()reads both variables through thebun_core::env_varcache (src/runtime/ffi/ffi_body.rs:752). It fills on the firstcc()call and lives for the process, out of reach ofprocess.envin the test runner.toEqual: exact stdout,stderr: "",exitCode: 0. A new case links a shared library that TinyCC finds only throughLIBRARY_PATH. The system C compiler builds it, and the case skips when none is installed.bun bd test, 3 runs, local debug+ASAN: 2.80 to 2.99 s before (2 tests, 490 + 370 ms in sequence), 2.40 to 2.47 s after (3 tests, slowest 480 ms). A no-op file that importsharnesstakes 1.90 s. All three tests fail with the variables unset (Notes).Background
cc()inbun:fficompiles a C file in memory with TinyCC.library: ["name"]is-lname: TinyCC searches its library paths forlibname.so(.dylibon macOS) anddlopens it.C_INCLUDE_PATHandLIBRARY_PATHare the standard C compiler search path variables. fix(ffi): respect C_INCLUDE_PATH and LIBRARY_PATH env vars #26250 madecc()honor them (NixOS has no FHS paths).Notes
Negative probe: a copy of the file with the variables renamed (
C_INCLUDE_PATH_DISABLED,LIBRARY_PATH_DISABLED) fails all three tests underbun bd test:Wall time of
bun bd testincluding the build check: 3.58 s, 3.59 s, 3.82 s before. 3.14 s, 3.16 s, 3.21 s after.The file also passes with the release binary (
USE_SYSTEM_BUN=1 bun test, 100 ms).The compiler gate follows
test/regression/issue/29585.test.ts:Bun.which("cc") || Bun.which("clang") || Bun.which("gcc"), andskipIfwhen none is found.The fixture closes the library with
lib.close(). This frees the TinyCC state and thedlopenhandle before exit, which keeps the leak check quiet without suppressions (see #38385).The library is named
libbunffiteston purpose. A real library name such aslibmagicexists in the system library directory, which TinyCC searches beforeLIBRARY_PATH.process.envassignments in bun do not callsetenv, and the env_var cache would hold the first value anyway. So an in-process test cannot exercise these variables.no test proof · iteration 1 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/regression/issue/26249.test.ts