Skip to content

db/connection.ts: closeDbPair/closeDbPairDeferred/closeDbDeferred lack direct unit test coverage #1751

Description

@carlos-alm

GAUNTLET (Titan phase 15 audit, rule 16) flagged that closeDbPair, closeDbPairDeferred, and closeDbDeferred have zero direct test coverage in tests/, despite being core resource-lifecycle primitives in src/db/connection.ts — a fanIn-55 file. This is exactly the kind of gap where the phase-15 resource-leak bug (openReadonlyWithNative opening the DB handle before config resolution, which could throw and leak it — see the phase-15 commit) went undetected for a long time.

Phase 15 added direct regression coverage for openReadonlyWithNative specifically (tests/unit/openReadonlyWithNative-leak.test.ts), but did not extend coverage to closeDbPair, closeDbPairDeferred, or closeDbDeferred — out of scope for that narrowly-defined commit (per sync.json's phase-15 label).

Recommendation: add direct unit tests exercising:

  • closeDbPair: both handles close in the right order (native first, then better-sqlite3); native close failure doesn't prevent the better-sqlite3 close.
  • closeDbPairDeferred: native closes immediately, better-sqlite3 close is deferred via closeDbDeferred.
  • closeDbDeferred: the advisory lock releases immediately; the handle actually closes on the next tick; flushDeferredClose() closes it synchronously before that tick if called first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions