fix(conftest): isolate pytest suite from production DB #25
Reference in New Issue
Block a user
Delete Branch "fix/conftest-test-db-isolation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The pytest suite's autouse
reset_statefixture connects to the production orchestrator DB (127.0.0.1:5432) and TRUNCATEs all five tables before every test. Verified on 2026-06-26: any worker running pytest against an orchestrator copy silently wipes livework_items.Fix
db-testcompose service (127.0.0.1:5433 host / db-test:5432 container). Separate volume, separate credentials, separate database — production DB at 127.0.0.1:5432 is never touched by default._prod_safety_guard()refuses to TRUNCATE if the configured host isdbor port is 5432. Refuses withpytest.skip()+RuntimeWarningpointing at theDAMASCUS_ALLOW_TEST_RESETopt-in env var.tests/test_conftest_safety.pycovering default config, env overrides, prod-host skip, prod-port skip, opt-in path, default-runs path, constants, and module import invariants.Verification
pytest tests/test_conftest_safety.py -v→ 8 passedpytest tests/contract/ tests/unit/ -q→ 65 passed (no regressions)Deployment order (critical)
chore(compose): add db-test service) firstdocker compose up -d --force-recreate --no-deps orchestratorso it sees the newdb-testservice in its compose networkdb-testinstead of prodRollback
If a worker needs to TRUNCATE prod for a one-off diagnostic, set
DAMASCUS_ALLOW_TEST_RESET=1in its env. The guard emits aRuntimeWarningso the wipe is at least visible in the test logs.Companion to PR #22 (MCP fix, already merged) and PR #23 (db-test compose service).