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>
2.0 KiB
Testing — database isolation
TL;DR
Tests run resetDb() → DROP SCHEMA public CASCADE. They MUST run against a
dedicated void_test database, never the prod void DB. This is enforced
in code (tests/helpers/setup.js throws if the resolved URL still targets
/void).
Why
The void2 Postgres cluster on 192.168.1.215 (CT 310) is shared: the prod app
(CT 311) and dev runs both use it. The dev DATABASE_URL points at the prod
void database. Before isolation, npm test wiped production data on every run
(spaces/tasks/etc. gone; migrations + the seeded companion agent re-created by
migrateUp, which masked the damage).
Setup (already done — 2026-06-01)
void_testdatabase created on the.215cluster, owned byvoid:-- run while connected to the `void` db (the `postgres` maintenance db is -- not reachable from the dev box per pg_hba.conf): CREATE DATABASE void_test OWNER void;pg_hba.confon CT 310 (/etc/postgresql/16/main/pg_hba.conf) — added a rule mirroring thevoidone, thensystemctl reload postgresql@16-main:host void_test void 192.168.1.0/24 scram-sha-256tests/helpers/setup.js(vitestsetupFiles) forces the test DB and guards against prod:- uses
TEST_DATABASE_URLif set, else derives it by swapping/void→/void_testinDATABASE_URL; - throws if the resolved URL still points at
/void.
- uses
- Dev
.envhasTEST_DATABASE_URL=postgres://void:…@192.168.1.215:5432/void_test.
Running tests
npm test # vitest; binds the pool to void_test via setup.js
resetDb() + migrateUp() rebuild void_test's schema each run. Prod void
is never touched. The guard makes a misconfiguration fail loudly instead of
silently wiping prod.
Note
.env (incl. TEST_DATABASE_URL) is git-ignored and not deployed — this is a
dev-box concern only. Prod (CT 311) never runs the test suite.