Skip to content

fix(config): clear loadedEnvValues in resetDotenv and verify live process.env in getLoadedEnvValue - #417

Open
Pybsama wants to merge 1 commit into
AVIDS2:mainfrom
Pybsama:fix/dotenv-reset-loaded-values
Open

Pybsama wants to merge 1 commit into
AVIDS2:mainfrom
Pybsama:fix/dotenv-reset-loaded-values

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 1, 2026

Copy link
Copy Markdown

Summary

Fixes two state-tracking bugs in src/config/dotenv-loader.ts:

  1. resetDotenv() left loadedEnvValues populated: While resetDotenv() deleted injected process.env keys and cleared injectedKeys, loadedEnvFiles, and loadedEnvKeys, it did not call loadedEnvValues.clear(). After a reset (for example on dashboard config reload or project switching), getLoadedEnvValue(key) could still return stale values from a previous .env load, causing resolveDashboardKeySource() to misattribute a process environment variable to .env.
  2. getLoadedEnvValue(key) did not verify process.env[key]: Its JSDoc states "Get the value injected by .env, if the current process still has that value." Previously it returned the cached map entry unconditionally even if process.env[key] was subsequently deleted or overwritten. It now checks process.env[key] === loaded before returning the value.

Added regression tests in tests/config/dotenv-loader.test.ts.

Verification

Run locally on macOS (M1 Max):

  • npm ci
  • npm run build:workspaces — passed
  • npm run lint (tsc --noEmit) — passed
  • npm run build — passed
  • npx vitest run tests/config/ — 10 passed (10) test files, 92 passed (92) tests

AI Disclosure

Prepared with AI assistance; all changes and tests were reviewed and verified locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant