test: decouple R2/D1 bindings from wrangler.toml (forks that drop R2 keep green CI)#6
Merged
Merged
Conversation
…2 keep green CI R2 is optional in production (wrangler.toml [[r2_buckets]] may be removed — env.ts BUCKET?), but the Vitest pool read bindings straight from wrangler.toml (configPath). A fork that followed the 'remove R2' comment got env.BUCKET === undefined and 10 storage-suite tests failed, even though the deployed Worker degraded gracefully. Our own CI never caught it because the committed wrangler.toml keeps the R2 binding. Declare DB + BUCKET via miniflare options instead, so the harness owns the binding shape (code contract) while compatibility_date/flags + vars still come from wrangler.toml. R2-absent runtime behavior stays covered by the existing env.BUCKET=undefined tests; clarify smoke.test.ts/env.d.ts on why R2 is always present in tests. Verified by commenting out [[r2_buckets]] locally: pre-fix 10 failures reproduced the fork's CI; post-fix 179/179 pass with and without R2.
This was referenced Jun 8, 2026
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.
Problem
R2 is optional in production —
wrangler.toml's[[r2_buckets]]block carries a comment saying it can be removed, andenv.tstypesBUCKET?accordingly. But the Vitest pool read bindings straight fromwrangler.toml(wrangler: { configPath: "./wrangler.toml" }). A fork that followed the "remove R2" instruction gotenv.BUCKET === undefined, and 10 storage-suite tests failed — even though the deployed Worker degraded gracefully.Our own CI never caught this because the committed
wrangler.tomlkeeps the R2 binding, so we never exercised the path we tell forkers to take. (Reported by a downstream fork; confirmed by reproducing locally.)Fix
Declare the Worker's bindings (
DB,BUCKET) viaminiflareoptions invitest.config.tsinstead of relying onwrangler.tomlfor them:Rationale: binding shape is a code contract (
srcreferencesenv.DB/env.BUCKET), so the test harness should own it — not the deployment-specific, fork-editablewrangler.toml.compatibility_date/compatibility_flags+[vars]still come fromwrangler.toml(preserves prod-fidelity).miniflareoptions take precedence over and merge with the wrangler config, so this is conflict-free whenwrangler.tomlalso defines the bindings.The R2-absent runtime path stays covered by the existing
env.BUCKET = undefinedtests (settle / retention / upload / admin). Added clarifying comments tosmoke.test.tsandenv.d.tsexplaining why R2 is always present in tests.Verification
Reproduced the fork's exact failure by commenting out
[[r2_buckets]]locally:env.BUCKETundefined) — matches the fork's CI.Independent review (Codex) confirmed the diagnosis and that
miniflare.r2Bucketsis the correct option with safe merge semantics.