test: isolate tests on void_test DB (stop resetDb wiping prod void)
resetDb() DROPs schema; dev DATABASE_URL pointed at the shared prod void DB on .215. setup.js now forces a dedicated void_test DB (TEST_DATABASE_URL or derived) and throws if it would target prod. Created void_test + pg_hba rule on CT 310. Verified: full suite green, prod void space count unchanged (2→2). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1 +1,24 @@
|
||||
import 'dotenv/config';
|
||||
|
||||
// SAFETY GUARD — tests call resetDb() which runs `DROP SCHEMA public CASCADE`.
|
||||
// The dev DATABASE_URL points at the prod "void" database on the shared .215
|
||||
// cluster, so running tests against it WIPES PRODUCTION. Force a dedicated test
|
||||
// database here, and refuse to run if we'd still be pointed at "void".
|
||||
//
|
||||
// Resolution order:
|
||||
// 1. TEST_DATABASE_URL (explicit), else
|
||||
// 2. derive from DATABASE_URL by swapping the "/void" db name for "/void_test".
|
||||
const resolved =
|
||||
process.env.TEST_DATABASE_URL ||
|
||||
(process.env.DATABASE_URL || '').replace(/\/void(\?|$)/, '/void_test$1');
|
||||
|
||||
if (!resolved || /\/void(\?|$)/.test(resolved)) {
|
||||
throw new Error(
|
||||
'Refusing to run tests: would target the prod "void" database. ' +
|
||||
'Set TEST_DATABASE_URL to a dedicated test DB (e.g. .../void_test).'
|
||||
);
|
||||
}
|
||||
|
||||
// pool.js reads process.env.DATABASE_URL on first import; this setupFile runs
|
||||
// before the test module graph loads, so the pool binds to the test DB.
|
||||
process.env.DATABASE_URL = resolved;
|
||||
|
||||
Reference in New Issue
Block a user