issue-136: Implement src/env.ts with unit tests (MONGODB_URI resolution) #154
No reviewers
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills!154
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-136/implement-src-env-ts-with-unit-tests-mongodb-uri-r"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
136: Implement src/env.ts with unit tests (MONGODB_URI resolution)
Implements 136.
Generated in 6m 08s.
Review findings
Let me look at the postgres env.ts for reference and check the dotenv version installed:Now I have full context. The three findings are clear:
dotenv.configapproach — reword.originalcaptured but never restored inafterEach— restore/delete it.DOTENV_KEY/.env.vaultis intentionally dropped (dotenv 16.6.1'sconfig()supports vaults;parse()does not).Let me apply the fixes:Let me verify the edits and check the root project for gate commands:The diff looks correct. Now let me run the gates —
bun test,tsc --noEmitin the extension, and the repo-rootnpm test:All gates pass:bun testinextensions/mongodb(66 pass / 0 fail),bunx tsc --noEmit(exit 0), and repo-rootnpm test(58 pass / 0 fail). No lint tooling is configured in the repo (no eslint config or lint script), so that gate is not applicable.All three findings were feasible and resolved in this single pass:
extensions/postgres/env.ts" to "Based onextensions/postgres/env.ts, but parses viadotenv.parse(notdotenv.config)" so future "cleanup" back todotenv.configis not invited.process.env.MONGODB_URIcapture to describe scope and restored/deleted it inafterEach, so a regression that mutatesprocess.envcan no longer leak state into later tests.DOTENV_KEY/.env.vaulthandling (present indotenv.config, dropped bydotenv.parse) is intentionally not supported by the mongodb loader.Review Findings — 136
Summary
The change reworks
extensions/mongodb/src/env.ts'sloadEnvFile()to read.envviafs.readFileSync+dotenv.parseinside a try/catch (removing theprocess.envmutation side effect of the previousdotenv.config({ path })approach) and adds three unit tests covering unreadable-.envbehavior, non-mutation ofprocess.env, and mixed-case nestedMONGODB_URIlookup. All gates ran and passed:bun testinextensions/mongodb(66 pass / 0 fail),bunx tsc --noEmit(the extension'scheckscript, exit 0), and the repo-rootnpm test(58 pass / 0 fail). No lint tooling is configured anywhere in the repo (no eslint config or lint script), so the lint gate is not applicable. The change meets the issue's stated scope and the Phase 1.1 test checklist inextensions/mongodb/docs/IMPLEMENTATION_PLAN.md; only minor documentation/consistency and test-hygiene nits remain.All three findings were remediated in this pass: the JSDoc now says the module is "Based on" (not "Mirrors") the postgres loader and explains the
dotenv.parsevsdotenv.configdivergence plus the intentional drop ofDOTENV_KEY/.env.vault; and theprocess.env.MONGODB_URIcapture is now restored/deleted inafterEach. The follow-up suggestion to alignextensions/postgres/env.tsremains a candidate for a separate issue.Critical
(none)
High
(none)
Medium
extensions/mongodb/src/env.ts:8— The JSDoc still says the module "Mirrorsextensions/postgres/env.ts", but the implementation now deliberately diverges:extensions/postgres/env.tsstill usesdotenv.config({ path }), which populatesprocess.env, while this change usesdotenv.parsespecifically to avoid that mutation. Repo docs (README.md, DESIGN.md, IMPLEMENTATION_PLAN.md) also repeatedly describe the mongodb extension as "mirroring" the postgres extension, so the comment is misleading and invites a future "cleanup" back todotenv.configthat would reintroduce the exactprocess.envmutation this issue removes. Suggested fix: reword the JSDoc, e.g. "Based onextensions/postgres/env.ts, but parses viadotenv.parse(notdotenv.config) so loading the project's.envnever mutatesprocess.env", and consider a follow-up issue to alignextensions/postgres/env.tswith the same approach.Low
extensions/mongodb/src/env.test.ts:75— Test hygiene:process.env.MONGODB_URIis captured intooriginalbut never restored or deleted inafterEach. If a future regression makesloadEnvFilemutateprocess.env, this test fails and leavesMONGODB_URIset for the remainder of the test process, potentially masking/affecting later tests. Suggested fix: inafterEach, restore/delete the variable (e.g.delete process.env.MONGODB_URIor set it back tooriginal).extensions/mongodb/src/env.ts:19— Subtle behavior change vs. the previous implementation worth documenting:dotenv.config({ path })honoredDOTENV_KEY/.env.vaultwhenDOTENV_KEYwas set in the environment, whereasdotenv.parsereads the plain.envfile directly and ignores the vault path. This repo does not use dotenv vaults, so there is no practical impact, but the JSDoc note about "approaches the issue specifies" does not mention that vault/DOTENV_KEYhandling is dropped. Suggested fix: add a one-line note in the JSDoc (or README) thatDOTENV_KEY/.env.vaultis intentionally not supported by the mongodb extension's loader.