Conversation
…mock pollution
messages.test.ts uses mock.module('./connection', ...) at module-load time.
Per CLAUDE.md:131 (Bun issue oven-sh/bun#7823), mock.module() is process-
global and irreversible. When Bun pre-loads all test files in a batch, the
mock shadows the real connection module before connection.test.ts runs,
causing getDatabaseType() to always return the mocked value regardless of
DATABASE_URL.
Move connection.test.ts into its own `bun test` invocation immediately
after postgres.test.ts (which runs alone) and before the big DB/utils/
config/state batch that contains messages.test.ts. This follows the same
isolation pattern already used for command-handler, clone, postgres, and
path-validation tests.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related issues
Poem
✨ 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 |
…mock pollution (coleam00#1269) messages.test.ts uses mock.module('./connection', ...) at module-load time. Per CLAUDE.md:131 (Bun issue oven-sh/bun#7823), mock.module() is process- global and irreversible. When Bun pre-loads all test files in a batch, the mock shadows the real connection module before connection.test.ts runs, causing getDatabaseType() to always return the mocked value regardless of DATABASE_URL. Move connection.test.ts into its own `bun test` invocation immediately after postgres.test.ts (which runs alone) and before the big DB/utils/ config/state batch that contains messages.test.ts. This follows the same isolation pattern already used for command-handler, clone, postgres, and path-validation tests.
…mock pollution (coleam00#1269) messages.test.ts uses mock.module('./connection', ...) at module-load time. Per CLAUDE.md:131 (Bun issue oven-sh/bun#7823), mock.module() is process- global and irreversible. When Bun pre-loads all test files in a batch, the mock shadows the real connection module before connection.test.ts runs, causing getDatabaseType() to always return the mocked value regardless of DATABASE_URL. Move connection.test.ts into its own `bun test` invocation immediately after postgres.test.ts (which runs alone) and before the big DB/utils/ config/state batch that contains messages.test.ts. This follows the same isolation pattern already used for command-handler, clone, postgres, and path-validation tests.
Summary
packages/core/src/db/messages.test.ts:9usesmock.module('./connection', ...)at module-load time. Per CLAUDE.md test-isolation rules and oven-sh/bun#7823,mock.module()is process-global and irreversible —mock.restore()does NOT undo it.When Bun pre-loads all test files in a single batch invocation, the mock replaces the real
./connectionmodule beforeconnection.test.tseven runs. SogetDatabaseType()returns the mocked'postgresql'regardless ofDATABASE_URL, and three tests fail:connection > getDatabaseType > should return sqlite when DATABASE_URL is not setconnection > getDatabaseType > should return sqlite when DATABASE_URL is empty stringconnection > getDatabaseType > should not initialize database connectionThese are pre-existing on
dev— I hit them while working on an unrelated branch and traced the root cause.Fix
One-line
package.jsonedit: movesrc/db/connection.test.tsinto its ownbun testinvocation, immediately afterpostgres.test.ts, before the shared DB/utils/config/state batch that containsmessages.test.ts.Follows the same isolation pattern already applied to
command-handler.test.ts,clone.test.ts,postgres.test.ts, andpath-validation.test.ts.Test plan
bun --filter @archon/core test— all 355 tests pass, 0 fail (previously 3 fail)bun run validate— fully green end-to-endSummary by CodeRabbit