-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Validate app.bundlerOptions values are objects in Bun.serve
#30446
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
Closed
Closed
Changes from all commits
Commits
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 These tests call
serve({ app: ... })in-process, but theappoption is gated behindbun.FeatureFlags.bake()(is_canary || isDebug || BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE). The CI runner only setsBUN_FEATURE_FLAG_INTERNAL_FOR_TESTINGfor the test process — the bake flag is only inharness.tsbunEnvfor spawned children — so on a non-canary release build (.buildkite/ci.mjswithcanary=0via[release]) theappblock is skipped entirely andserve()throws the generic "Bun.serve() needs either:…" error instead, failing all four new test blocks. Consider settingprocess.env.BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE = "1"at the top of this describe (the flag is read at runtime), or gating it withdescribe.skipIf.Extended reasoning...
What the bug is
The new
describe("app.bundlerOptions validation", ...)block intest/js/bun/http/bun-serve-args.test.tsinvokesserve({ app: ... })directly in the test process and asserts on specific error messages such as'app.bundlerOptions' must be an objectand'app' is missing 'framework'. However, theappoption inBun.serveis feature-flagged: when the bake flag is off, theappkey is silently ignored andserve()falls through to the generic missing-handler error. On a non-canary, non-debug release build, none of the asserted messages are ever produced and all four test blocks fail.Code path
src/bun_core/feature_flags.zig:135-138—bake()returnsenv.is_canary || env.isDebug || BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE.get().src/runtime/api/BunObject.zig:1013passesallow_bake_config = bun.FeatureFlags.bake()intoServerConfig.fromJS.src/runtime/server/ServerConfig.zig:837-841— when!opts.allow_bake_config/!bun.FeatureFlags.bake(), the entireif (try args.get(global, "app")) |...|block doesbreak :brk, sobake.UserOptions.fromJSis never called andargs.bakestaysnull.ServerConfig.zig:908-911, which throwsBun.serve() needs either:\n- A routes object\n- A fetch handler...because nofetch/routes/appwas registered.Why existing infra doesn't cover this
The flag is set in
test/harness.ts:64(BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE: "1"), but that object (bunEnv) is only used as theenvfor spawned child processes. Every existing bake test intest/bake/spawns a child via the bake harness and inheritsbunEnv, so the flag is always present there. These new tests are the first in the repo to callserve({ app: ... })in-process, so they inherit the test runner's environment instead.scripts/runner.node.mjs:1182-1202builds the env for thebun testprocess by spreading...process.envand addingBUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: "1",BUN_DEBUG_QUIET_LOGS, etc. — but notBUN_FEATURE_FLAG_EXPERIMENTAL_BAKE. These two flags are independent (env_var.zig), so the internal-testing flag does not enable bake.When it manifests
.buildkite/ci.mjs:1293-1297setscanary: 0when the commit message contains[release]or theRELEASEenv var is set, and line ~522 passes--canary=offto the build. The resulting binary hasenv.is_canary = falseandenv.isDebug = false, sobake()evaluates solely to the env var — which the runner doesn't set.skipTestsis an independent option, so the test suite still runs against this binary.Standard PR CI is unaffected because
getCanaryRevision()returns1for non-main branches (sois_canaryis true andbake()short-circuits to true), which is why this PR's own build will pass. The failure surfaces on the next release-build test job, or for anyone running the suite against a stable release binary locally.Step-by-step proof
On a release (non-canary, non-debug) binary with the runner's env:
serve({ app: { bundlerOptions: 5 } }).BunObject.zig:1013→allow_bake_config = bake() = false || false || (env var unset) = false.ServerConfig.zig:837reads the"app"property, butServerConfig.zig:838-840sees!bun.FeatureFlags.bake()and doesbreak :brk—UserOptions.fromJS(and the newisObject()check) never runs.args.bakeis stillnull, nofetch/routeswere provided →is_fetch_requiredpath atServerConfig.zig:908throws"Bun.serve() needs either:...".expect(...).toThrow("'app.bundlerOptions' must be an object")fails because the actual message is"Bun.serve() needs either:...". The same applies to thebundlerOptions.${key},.minify, and'app' is missing 'framework'assertions.Fix
Any of:
process.env.BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE = "1";at the top of the newdescribe(the flag is read viagetenvat call time, so setting it from JS beforeserve()works).describe.skipIf(...)based on the feature being unavailable.BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE: "1"to the env inscripts/runner.node.mjsalongsideBUN_FEATURE_FLAG_INTERNAL_FOR_TESTING.