8000 Consolidate SQLite test setup and make fixture/foreign-key choices explicit · Issue #540 · jra3/mulm · GitHub
[go: up one dir, main page]

Skip to content

Consolidate SQLite test setup and make fixture/foreign-key choices explicit #540

Closed

Description

@jra3

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

  1. 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.
  2. 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.
  3. 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.
  4. Centralize cleanup and migration setup, close resources on failed setup, and surface unexpected teardown errors rather than hiding them globally.
  5. 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

Activity

  1. added
    enhancementNew feature or request
    databaseDatabase schema, migrations, and data integrity
    testingTesting, test coverage, and quality assurance
    priority:mediumMedium priority - important but not urgent
    ready-for-agentFully specified, ready for an AFK agent
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseDatabase schema, migrations, and data integrityenhancementNew feature or requestpriority:mediumMedium priority - important but not urgentready-for-agentFully specified, ready for an AFK agenttestingTesting, test coverage, and quality assurance

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0