Repository navigation
Keep local .dev.vars and .env out of the test Worker's env - #87
Merged
Merged
Conversation
Wrangler fills the vitest env from a local .dev.vars (or .env, which holds the build's GPG key), so a developer's real secrets reached the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CMCuDa11Qr39yxAQJNUXoH
davidwkeith
commented
Oct 23, 2026
davidwkeith
left a comment
Owner
Author
There was a problem hiding this comment.
Review: looks good. The change is small and correct.
parseEnvfromnode:utilneeds Node ≥ 20.12. CI uses Node 22, so that's fine.- Blanking
.dev.varskeys with""works becauseworker/mounts.tschecks!env[name]. The...localDevVarsspread comes before the fixed test values, soTOKEN_SIGNING_KEYandINTROSPECTION_TOKENstill win. - The
existsSync(".dev.vars")path is relative to the cwd. That's fine fornpm testfrom the repo root. - The CLAUDE.md note matches the code.
No blocking issues. The test check was still running when I reviewed, so I'm leaving the merge to you.
Generated by Claude Code
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://claude-affectionate-curie-3ekeg3-dwk.8k9dgysp29.workers.dev (commit 5b0a50b)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
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.
The vitest plugin hands
wrangler.jsoncto wrangler, and wrangler fills the test Worker'senvfrom a local.dev.vars, or, when there isn't one, from.env. A developer's real secrets therefore reached the tests,.env'sGPG_PRIVATE_KEYandCLOUDFLARE_API_TOKENincluded.miniflare.bindingsonly overrodeTOKEN_SIGNING_KEYandINTROSPECTION_TOKEN.vitest.config.tsnow:CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV=false, so wrangler skips.env;.dev.varsdefines, usingnode:util'sparseEnv. The plugin has no switch to skip.dev.vars, and it rejectsundefinedbinding values. An empty secret reads as unset (!env[name]inworker/mounts.ts), so the mounts behave as they do in CI.Verified: a probe test asserting
env.OWNER_TOKENis unset failed before the change withOWNER_TOKEN=leaked-ownerin.dev.vars, and separately withleaked-envin.env. Both pass after it. The full suite passes with a.dev.varspresent and without one (11 files, 71 tests), andnpm run checkreports 0 errors.CLAUDE.md's Testing bullet describes the isolation.
Generated by Claude Code