test(gateway): cross-user isolation teardown retries DB after setup failure #1193

Open
opened 2026-08-13 01:58:28 +00:00 by Ghost · 0 comments

Defect

apps/gateway/src/__tests__/cross-user-isolation.test.ts intends to skip when PostgreSQL is unavailable, but beforeAll assigns handle = createDb() before the first query. If connection/authentication then fails, dbAvailable remains false and tests skip, while afterAll sees a truthy handle and performs the full cleanup query sequence anyway.

Observed during an isolated exact-head review: an inherited ambient DATABASE_URL had invalid credentials. Setup caught the authentication failure as designed, then teardown retried DELETE and failed the entire Gateway suite. This also means an ad-hoc test shell can unexpectedly attempt whatever database its ambient environment names.

Required behavior

  • An unavailable/unauthorized setup leaves teardown with zero database queries.
  • Cleanup runs only after fixture creation reached a proven state.
  • A partially-created fixture cleans only safely-known state and closes the handle.
  • Tests never infer permission to use an ambient database silently; the required test database route is explicit and documented.
  • Connection/auth failures remain credential-safe and do not echo DSNs.

Acceptance

  1. Behavior-first regression reproduces setup failure after handle construction and proves zero teardown query attempts.
  2. Success path still cleans all fixed fixture rows and closes exactly once.
  3. Partial-setup failure has deterministic cleanup/close semantics.
  4. Full Gateway CI remains terminal green with the canonical disposable CI PostgreSQL service.
  5. Independent review verifies no production code or isolation assertions were weakened.

This issue records a test-harness safety/reliability defect. It does not authorize connecting to a host, daemon, shared, or production database.

## Defect `apps/gateway/src/__tests__/cross-user-isolation.test.ts` intends to skip when PostgreSQL is unavailable, but `beforeAll` assigns `handle = createDb()` before the first query. If connection/authentication then fails, `dbAvailable` remains false and tests skip, while `afterAll` sees a truthy handle and performs the full cleanup query sequence anyway. Observed during an isolated exact-head review: an inherited ambient `DATABASE_URL` had invalid credentials. Setup caught the authentication failure as designed, then teardown retried `DELETE` and failed the entire Gateway suite. This also means an ad-hoc test shell can unexpectedly attempt whatever database its ambient environment names. ## Required behavior - An unavailable/unauthorized setup leaves teardown with zero database queries. - Cleanup runs only after fixture creation reached a proven state. - A partially-created fixture cleans only safely-known state and closes the handle. - Tests never infer permission to use an ambient database silently; the required test database route is explicit and documented. - Connection/auth failures remain credential-safe and do not echo DSNs. ## Acceptance 1. Behavior-first regression reproduces setup failure after handle construction and proves zero teardown query attempts. 2. Success path still cleans all fixed fixture rows and closes exactly once. 3. Partial-setup failure has deterministic cleanup/close semantics. 4. Full Gateway CI remains terminal green with the canonical disposable CI PostgreSQL service. 5. Independent review verifies no production code or isolation assertions were weakened. This issue records a test-harness safety/reliability defect. It does not authorize connecting to a host, daemon, shared, or production database.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaicstack/stack#1193