Skip to content

ci: run the integration tests on Postgres - #123

Merged
bvdaakster merged 1 commit into
mainfrom
ci/postgres
Nov 28, 2026
Merged

bvdaakster merged 1 commit into
mainfrom
ci/postgres

Conversation

@bvdaakster

Copy link
Copy Markdown
Contributor

Why

Postgres is the adapter that always runs Payload's operations in a transaction, and the tests only ran on SQLite, where there are none by default. Work the plugin does outside the request's transaction only shows up on Postgres.

What

  • pnpm test:postgres runs the same vitest suite with DATABASE_ADAPTER=postgres against the server in DATABASE_URI.
  • dev/helpers/databaseAdapter.ts picks the adapter for dev/payload.config.ts and the four spec files that build their own config. On Postgres every Payload instance of a run gets its own database (pb_test_<run>_<pid>_<name>, created by Payload's adapter on connect); dev/helpers/postgresGlobalSetup.ts drops them after the run.
  • CI: a postgres job, Test (Postgres), with a postgres:16 service. No PostGIS is needed: the plugin has no point fields.
  • README, dev/README.md and dev/.env.example describe the new script.

No published source changes. @payloadcms/db-postgres was already a devDependency.

What the Postgres run found

Nine tests fail on Postgres, all from one defect in the plugin: the collection hooks of refunds, invoices and payments read and write related documents without the request they were given, so that work runs outside the request's transaction.

  • Creating a refund, or an invoice with payment set, locks the payment's row until the transaction ends (foreign key). The hook then updates that payment on another connection and waits for the transaction, which is waiting for the hook. The request hangs.
  • When a refund becomes succeeded, the hook that derives the payment's refunded / partially_refunded status does not see the refund being saved, so the payment stays succeeded.

Fixing it changes how hook failures behave inside a transaction and needs its own PR, so this one does not touch src. Instead:

  • The nine tests use testFailingOnPostgres (dev/helpers/knownPostgresDefects.ts): plain test on SQLite, test.fails on Postgres, so the Postgres job turns red as soon as the defect is fixed and the marker has to go. No assertion was changed.
  • The Postgres test connections set lock_timeout=3000, so the self-deadlock is an error after three seconds instead of a test timeout with two stuck connections.

Verified locally

Postgres 16: 275 passed, 9 expected fail (284). SQLite: 284 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_0122PV8TJ7ELGdAX7H2hdrRU

Adds pnpm test:postgres (DATABASE_ADAPTER=postgres), a database adapter helper
that gives every Payload instance of a test run its own Postgres database, a
global setup that drops them afterwards, and the CI job "Test (Postgres)" with
a postgres:16 service. Nine tests that fail on Postgres because the collection
hooks work outside the request's transaction are marked as expected failures
there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0122PV8TJ7ELGdAX7H2hdrRU
@claude

claude Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@bvdaakster
bvdaakster merged commit 188a8d8 into main Nov 28, 2026
10 checks passed
@bvdaakster
bvdaakster deleted the ci/postgres branch November 28, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant