Require DB connection string, drop hardcoded localhost fallback - #370
Conversation
… fallback Previously src/server.ts silently fell back to a hardcoded 'mongodb://localhost:27017/intercom-manager' when neither DB_CONNECTION_STRING nor MONGODB_CONNECTION_STRING was set, risking a silent misconfiguration in production. The manager now fails fast at startup (via validateRequiredEnv) with a clear error and exit code 1 when no DB connection string is provided. The localhost default is kept for local dev in .env.example/docker-compose, not in production code. Closes #225 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Code ReviewVerdict: Needs Changes Summary: The change is focused, well-motivated, and correctly removes the silent localhost fallback with good regression tests for the primary failure path. There is no Blocking defect, but a cluster of three Warnings — an inconsistency between how validation and construction treat an empty connection string, unhandled startup rejections, and a missing BlockingNone. Warnings
Suggestions
Domain NoteNot applicable — server startup / DB manager construction only. |
…or handling Use logical-OR instead of nullish coalescing when building the DB connection string so an empty DB_CONNECTION_STRING falls through to MONGODB_CONNECTION_STRING, matching the falsy check in validateRequiredEnv(). Wrap the startServer() entrypoint in a catch so synchronous throws and rejections during startup log a fatal error and exit cleanly. Add the standard ./log jest mock and a regression test for the empty-string fallthrough case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
code-reviewer verdict: LGTM (re-review at All three prior Needs-Changes warnings verified resolved:
Fresh pass: no straggler localhost defaults in production code, DB-manager construction correctly gated behind validation, TypeScript clean. Non-blocking nits only. CI green (lint/pretty/ts/unittests). Merging via --admin. |
Summary
mongodb://localhost:27017/intercom-managerfallback insrc/server.tsthat silently masked a missing DB configuration in production.validateRequiredEnv(): it logsMissing required environment variable: DB_CONNECTION_STRINGand exits with code 1 when neitherDB_CONNECTION_STRINGnorMONGODB_CONNECTION_STRINGis set.startServer()so it runs only after env validation, mirroring howSMB_ADDRESSis already handled..env.example(and documented inreadme.md), not in production code.MONGODB_CONNECTION_STRINGname.Closes #225
Test plan
npm test)npm run typecheck)npm run lint)🤖 Generated with Claude Code