From 81f500bd29938db508391088f18aa2a4bd1c996e Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 17 Aug 2026 23:13:03 -0500 Subject: [PATCH] test(gateway): cross-user-isolation cleanup honors dbAvailable (#1275) The no-database skip path failed the file: createDb connects lazily, so on an unreachable database 'handle' is set while nothing was inserted; afterAll checked only 'handle' and its cleanup deletes threw ECONNREFUSED, failing the suite despite 28/28 tests being skipped. Caught live by the publish pipeline's verify gate (pipeline 2486, first gated publish after #1277): the gate's no-DATABASE_URL PGlite path runs 'pnpm test' without ci-postgres, cross-user-isolation hit its dead-cleanup path, verify correctly failed closed and blocked all publish steps (build/publish-npm/build-gateway skipped). Verified both paths: DATABASE_URL=dead-port -> 28 skipped, file PASSES (was the failure); live 5433 -> 28 passed. Sibling suites checked: connector-lease.postgres.integration skips at describe level (describe.skipIf) so its afterAll never runs unguarded. --- apps/gateway/src/__tests__/cross-user-isolation.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/gateway/src/__tests__/cross-user-isolation.test.ts b/apps/gateway/src/__tests__/cross-user-isolation.test.ts index 439b750e..781aba79 100644 --- a/apps/gateway/src/__tests__/cross-user-isolation.test.ts +++ b/apps/gateway/src/__tests__/cross-user-isolation.test.ts @@ -190,7 +190,13 @@ beforeEach((ctx) => { }); afterAll(async () => { - if (!handle) return; + // Cleanup only when the fixture actually installed rows. `handle` is set + // before the first query (createDb connects lazily), so on an unreachable + // database `handle` is truthy while nothing was inserted — cleanup must + // honor `dbAvailable` or the skip path fails the file with ECONNREFUSED in + // afterAll (caught live by the publish pipeline's no-DATABASE_URL verify + // step, pipeline 2486). + if (!handle || !dbAvailable) return; const db = handle.db; // Delete in dependency order (FK constraints)