Files
clawmates/crates/cm-testkit
Omar SobhandClaude Opus 5 b58f0347e6 fix(testkit): stop leaking a database per test
`test_pool` creates a database per test and nothing ever dropped it.

Invisible on the testcontainer path — the container dies with the process
and takes them with it. But `CM_TEST_DATABASE_URL` points at a SHARED
server that outlives the run, and that is the path CI uses and the path
`.cargo/config.toml` sets for local development. So on both, every
database ever created is still there, growing with every `cargo test`.

Measured before writing the fix: **3,546 databases, 38 GB** on one
developer machine. After: 391 and 4.3 GB — the remainder being today's,
still inside the window. The docker volume went 42.3 GB to 5.7 GB.

Age comes from the NAME, not the catalogue. Postgres records no creation
time for a database, but the names are `test_<uuid-v7>` and UUIDv7 puts
its millisecond timestamp in the first 48 bits — the same property
`mission_runtime::container_name` already relies on.

Three things the tests pin down:

  - a database created just now must read as NEW, or the reaper deletes
    one a parallel test binary is still using;
  - only names we minted are reapable — `test_scratch` and `clawmates`
    survive;
  - the window outlasts any test run.

`WITH (FORCE)` because a single leftover session pins a database and the
drop otherwise silently does nothing. Best-effort throughout: a test must
never fail because housekeeping could not run.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018i9Ten1LU4jUr5d7TAWda9
2026-08-21 13:45:34 -07:00
..