Quick task 260613-ndv — isolate local API tests to a dedicated test DB
Local apps/api integration tests ran against the devfamilysync DB, seeding thousands of throwaway users into real dev data (and causing the flaky lists.test.ts > re-populates list_shares timeout as the users table grew). This wires them to a dedicated, auto-provisioned familysync_test DB.
What changed
New apps/api/test/global-setup.ts (vitest globalSetup): when NOT in CI, root-connects to the dev MariaDB → CREATE DATABASE IF NOT EXISTS familysync_test + GRANT to the app user → applies committed Drizzle migrations → truncate-resets every table (except the migration ledger) so each run is a deterministic clean slate (no run-over-run accumulation). Root creds read from DB_ROOT_USER/DB_ROOT_PASSWORD env (dev default root), never hardcoded; GRANT identifier validated against injection.
apps/api/vitest.config.ts: wires globalSetup + a CI-gatedtest.env override forcing DB_NAME=familysync_test for local workers. Under CI the override is empty — CI keeps its own familysync service DB + db:migrate step, fully unaffected.
test/setup.ts header note + a README "Running API tests locally" section.
Verified locally
Dev familysync users unchanged (stays 3) across a full test run — dev DB no longer polluted.
familysync_test resets each run (186 → 93 users, not doubled), 10 migrated tables.
244/244 API tests pass; the previously-flaky list_shares timeout is gone.
## Quick task 260613-ndv — isolate local API tests to a dedicated test DB
Local `apps/api` integration tests ran against the **dev** `familysync` DB, seeding thousands of throwaway users into real dev data (and causing the flaky `lists.test.ts > re-populates list_shares` timeout as the users table grew). This wires them to a dedicated, auto-provisioned `familysync_test` DB.
### What changed
- **New `apps/api/test/global-setup.ts`** (vitest globalSetup): when NOT in CI, root-connects to the dev MariaDB → `CREATE DATABASE IF NOT EXISTS familysync_test` + `GRANT` to the app user → applies committed Drizzle migrations → **truncate-resets every table** (except the migration ledger) so each run is a deterministic clean slate (no run-over-run accumulation). Root creds read from `DB_ROOT_USER`/`DB_ROOT_PASSWORD` env (dev default `root`), never hardcoded; GRANT identifier validated against injection.
- **`apps/api/vitest.config.ts`**: wires `globalSetup` + a **CI-gated** `test.env` override forcing `DB_NAME=familysync_test` for local workers. Under CI the override is empty — CI keeps its own `familysync` service DB + `db:migrate` step, fully unaffected.
- `test/setup.ts` header note + a README "Running API tests locally" section.
### Verified locally
- Dev `familysync` users **unchanged (stays 3)** across a full test run — dev DB no longer polluted.
- `familysync_test` resets each run (**186 → 93 users**, not doubled), 10 migrated tables.
- **244/244 API tests pass**; the previously-flaky `list_shares` timeout is gone.
- `typecheck` exit 0; lint / format:check / md:lint / frozen-lockfile all green.
- CI unaffected by inspection: globalSetup early-returns under `CI=true` and the worker env override is empty there.
Branched off `main` (independent of the Phase 10 PR).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Update apps/api/test/setup.ts header: clarify tests run against familysync_test
(provisioned by global-setup.ts), document users-cleanup decision (intact across
tests), and note CI-vs-local env difference
- Add apps/api/README.md "Running API tests locally" section: documents the test
DB isolation, run command, DB_ROOT_PASSWORD requirement, and CI no-op behaviour
- Fix apps/api/test/global-setup.ts: switch from drizzle({ client, mode }) to
drizzle(pool, { mode }) — drizzle-orm@0.45.2 isConfig() has a tautological OR
in the `mode` branch that always returns false, causing the combined-config form
to pass the config object as the client (client.query is not a function); two-arg
form routes correctly; 244/244 tests pass against familysync_test
CREATE DATABASE IF NOT EXISTS reuses the prior run's data, so the test DB
would itself accumulate users run-over-run (the same flaky list_shares
fan-out the dev DB suffered). Truncate every table (except the drizzle
migration ledger) at globalSetup start, FK-safe, so each run is a clean
deterministic slate. Verified: familysync_test users 186 -> 93 across a run
(reset, not doubled); dev familysync untouched at 3.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Quick task 260613-ndv — isolate local API tests to a dedicated test DB
Local
apps/apiintegration tests ran against the devfamilysyncDB, seeding thousands of throwaway users into real dev data (and causing the flakylists.test.ts > re-populates list_sharestimeout as the users table grew). This wires them to a dedicated, auto-provisionedfamilysync_testDB.What changed
apps/api/test/global-setup.ts(vitest globalSetup): when NOT in CI, root-connects to the dev MariaDB →CREATE DATABASE IF NOT EXISTS familysync_test+GRANTto the app user → applies committed Drizzle migrations → truncate-resets every table (except the migration ledger) so each run is a deterministic clean slate (no run-over-run accumulation). Root creds read fromDB_ROOT_USER/DB_ROOT_PASSWORDenv (dev defaultroot), never hardcoded; GRANT identifier validated against injection.apps/api/vitest.config.ts: wiresglobalSetup+ a CI-gatedtest.envoverride forcingDB_NAME=familysync_testfor local workers. Under CI the override is empty — CI keeps its ownfamilysyncservice DB +db:migratestep, fully unaffected.test/setup.tsheader note + a README "Running API tests locally" section.Verified locally
familysyncusers unchanged (stays 3) across a full test run — dev DB no longer polluted.familysync_testresets each run (186 → 93 users, not doubled), 10 migrated tables.list_sharestimeout is gone.typecheckexit 0; lint / format:check / md:lint / frozen-lockfile all green.CI=trueand the worker env override is empty there.Branched off
main(independent of the Phase 10 PR).🤖 Generated with Claude Code
- Update apps/api/test/setup.ts header: clarify tests run against familysync_test (provisioned by global-setup.ts), document users-cleanup decision (intact across tests), and note CI-vs-local env difference - Add apps/api/README.md "Running API tests locally" section: documents the test DB isolation, run command, DB_ROOT_PASSWORD requirement, and CI no-op behaviour - Fix apps/api/test/global-setup.ts: switch from drizzle({ client, mode }) to drizzle(pool, { mode }) — drizzle-orm@0.45.2 isConfig() has a tautological OR in the `mode` branch that always returns false, causing the combined-config form to pass the config object as the client (client.query is not a function); two-arg form routes correctly; 244/244 tests pass against familysync_test1d5d23a1e0to4517432dca