diff --git a/pgpm/export/__tests__/export-parity.test.ts b/pgpm/export/__tests__/export-parity.test.ts index ac87d0b494..8add047770 100644 --- a/pgpm/export/__tests__/export-parity.test.ts +++ b/pgpm/export/__tests__/export-parity.test.ts @@ -676,7 +676,7 @@ describe('export parity — SQL vs GraphQL (integration)', () => { } // Sanity: at least 105 deploy files were produced (one per sql_action) - const deployFiles = sqlPaths.filter(p => p.includes(EXTENSION_NAME) && p.includes('/deploy/')); + const deployFiles = sqlPaths.filter(p => p.startsWith(`${EXTENSION_NAME}/deploy/`)); expect(deployFiles.length).toBe(TOTAL_ACTIONS); // Cleanup diff --git a/postgres/pgsql-test/__tests__/postgres-test.seed-failures.test.ts b/postgres/pgsql-test/__tests__/postgres-test.seed-failures.test.ts new file mode 100644 index 0000000000..60833cf9e1 --- /dev/null +++ b/postgres/pgsql-test/__tests__/postgres-test.seed-failures.test.ts @@ -0,0 +1,26 @@ +process.env.LOG_SCOPE = 'pgsql-test'; + +import { seed } from '../src'; +import { getConnections } from '../src/connect'; + +jest.setTimeout(30000); + +it('fails the harness when a seed adapter throws', async () => { + await expect( + getConnections({}, [ + seed.fn(async () => { + throw new Error('DELIBERATE_SEED_FAILURE'); + }) + ]) + ).rejects.toThrow('DELIBERATE_SEED_FAILURE'); +}); + +it('fails the harness when seed SQL is invalid', async () => { + await expect( + getConnections({}, [ + seed.fn(async ({ pg }) => { + await pg.query('SELECT * FROM a_relation_that_does_not_exist'); + }) + ]) + ).rejects.toThrow(/a_relation_that_does_not_exist/); +}); diff --git a/postgres/pgsql-test/src/connect.ts b/postgres/pgsql-test/src/connect.ts index 518ff3cada..6ec7ae4d03 100644 --- a/postgres/pgsql-test/src/connect.ts +++ b/postgres/pgsql-test/src/connect.ts @@ -116,8 +116,14 @@ export const getConnections = async ( } catch (error) { // Format the error with PostgreSQL extended fields for better debugging const formatted = formatPgError(error); - process.stderr.write(`[pgsql-test] Seed error (continuing):\n${formatted}\n`); - // continue without teardown to allow caller-managed lifecycle + process.stderr.write(`[pgsql-test] Seed failed:\n${formatted}\n`); + try { + await teardown(); + } catch { + // Teardown of a database we are already abandoning: the seed error below + // is the actionable one, and hiding it behind a cleanup failure is worse. + } + throw new Error(`[pgsql-test] Seed failed:\n${formatted}`, { cause: error }); } }