Repository navigation
Description
Problem
src/tests/testDbHelper.helper.ts and src/tests/helpers/testHelpers.ts both export setupTestDatabase, but return different shapes, seed different data, and choose opposite foreign-key defaults. Other suites repeat open, PRAGMAs, migrations, override, and teardown by hand. Selecting a helper can therefore change the database semantics incidentally.
Importing the helpers also reaches the eager bootstrap tracked in #432; helper consolidation alone must not be presented as fixing that separate issue.
Proposed change
- Provide one low-level disposable SQLite factory with a consistent returned context and explicit foreign-key/migration options. Keep fixture seeding separate: callers request members, committee members, Species, or Submissions via named builders.
- Preserve each existing suite's intended constraint mode during migration by spelling it out. Production currently does not enforce foreign keys; tests intentionally using enforcement should remain supported. Do not silently flip all tests to ON or OFF.
- Reuse the existing lifecycle fixtures and invariant helpers for valid states. Retain intentional raw SQL for migration tests and impossible-state regression cases, with those choices visible at the call site.
- Centralize cleanup and migration setup, close resources on failed setup, and surface unexpected teardown errors rather than hiding them globally.
- Migrate callers incrementally and remove compatibility wrappers only once unused. Keep historical-migration helpers capable of selecting a migration cutoff.
Acceptance criteria and tests
- One implementation owns ordinary in-memory database creation, migration execution, and teardown.
- Fixture builders do not unexpectedly create members or change connection settings.
- Existing suites retain their intended foreign-key behavior and historical migration cases remain possible.
- Tests demonstrate fresh independent fixture data, setup-failure cleanup, and a constraint violation in ON mode versus the explicitly supported OFF mode.
- After Open and migrate the database on first use, not on import #432, importing fixture helpers creates/migrates no configured on-disk database.
- Tests/docs import one supported API; no duplicate same-named setup helpers remain.
- Run the migrated database/lifecycle/migration suites, then the regular test suite and typecheck/lint.
Boundaries
Global connection overrides still prevent safe concurrent suites within one process. Do not enable same-process parallel database tests as part of this cleanup. #476 concerns production-like staging fixtures and remains separate from local disposable test infrastructure.
Review baseline
Source review at 78e0f1b2ff157e289c237d533f1406302d95118e. Repository typechecking and the focused specialty-award/level-progress tests passed during the review; these are not reproductions of the new failure scenarios above. Full database and E2E suites were not run.
Related proposals from this review
- Separate Portal app construction from listeners and background-job startup #539: Separate Portal app construction from listeners and background-job startup
Activity
test: consolidate disposable SQLite setup and explicit fixtures (#553)