fix(test): isolate connection.test.ts to prevent mock.module() pollution#1253
Conversation
Move src/db/connection.test.ts into its own bun test invocation (batch 4),
before the batch containing workflows.test.ts. The workflows.test.ts uses
mock.module('./connection', ...) which permanently replaces the module in
Bun's process-wide cache (bun#7823), causing getDatabaseType() to always
return 'postgresql' in connection.test.ts regardless of DATABASE_URL.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Comprehensive PR ReviewPR: #1253 SummaryThis is a minimal, surgical fix that isolates Verdict: ✅
🟢 Low IssuesStale
|
The mock.module isolation documentation referenced 7 batches for @archon/core, but the actual count was already 13 before PR coleam00#1253 and is now 14 after the addition of the isolated connection.test.ts batch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
⚡ Self-Fix Report (Aggressive)Status: COMPLETE Fixes Applied (1 total)
View all fixes
Tests Added(none) Skipped (0)(none — all findings addressed) Suggested Follow-up Issues(none) Validation✅ Type check | ✅ Lint | ✅ Tests Self-fix by Archon · aggressive mode · fixes pushed to |
|
This PR looks similar to the already-merged #1269 (merged April 17, 2026). Please check whether your change is still needed — rebase on main and confirm. |
Summary
connection.test.tswas in the samebun testbatch asworkflows.test.ts. The latter callsmock.module('./connection', () => ({ getDatabaseType: () => 'postgresql' })), which permanently replaces the module in Bun's process-wide cache (oven-sh/bun#7823) —mock.restore()does NOT undo it. This causedgetDatabaseType()to always return'postgresql'inconnection.test.tsregardless ofprocess.env.DATABASE_URL, producing silent false-passes.getDatabaseType()behaves correctly for both paths.src/db/connection.test.tsis moved into its ownbun testinvocation (batch 4) that runs before the batch containingsrc/db/workflows.test.ts.UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory:
packages/core/package.jsontest scriptconnection.test.tspackages/core/package.jsontest scriptworkflows.test.tsLabel Snapshot
risk: lowsize: XStestscore:dbChange Metadata
chorecoreLinked Issue
@archon/coretest isolation section)Validation Evidence (required)
connection.test.tsto its own invocation.Security Impact (required)
Compatibility / Migration
Human Verification (required)
bun run testpasses end-to-end with the batch split in place.connection.test.tscorrectly tests both SQLite (noDATABASE_URL) and PostgreSQL paths after isolation.Side Effects / Blast Radius (required)
@archon/coretest suite only.bun run validatecatches any future batch ordering regressions.Rollback Plan (required)
git revert HEAD— one-line change, zero risk.connection.test.tsassertions fail with unexpected'postgresql'result whenDATABASE_URLis unset.Risks and Mitigations
mock.module()call must be reviewed against existing batch groupings.