Skip to content

fix(sdp-api): create the test database before running pnpm test#488

Open
moviendome wants to merge 5 commits into
solana-foundation:mainfrom
moviendome:fix/test-creates-test-db
Open

fix(sdp-api): create the test database before running pnpm test#488
moviendome wants to merge 5 commits into
solana-foundation:mainfrom
moviendome:fix/test-creates-test-db

Conversation

@moviendome

Copy link
Copy Markdown
Contributor

While setting up a fresh clone to keep contributing, pnpm test failed before running a single test. This chains the one missing setup step so the documented flow works, and corrects a diagnostic that pointed the wrong way.

What happens today

On a clean checkout, the documented setup:

pnpm db:postgres:up
pnpm --filter @sdp/api db:postgres:bootstrap
pnpm --filter @sdp/api test

fails right away:

Caused by: error: database "sdp_test" does not exist
Serialized Error: { severity: 'FATAL', code: '3D000', routine: 'InitPostgres' }

Every workers test file fails the same way.

Root cause

db:postgres:bootstrap creates and migrates sdp, but nothing creates sdp_test. The workers pool (vitest.workers.config.ts) binds sdp_test but doesn't create it, and the test script (pnpm test:workers && pnpm test:node) never ran the step that would. That step already exists: db:migrate:test creates and migrates sdp_test via ensureDatabaseExists. It just wasn't chained in.

What this changes

apps/sdp-api/package.json — chain the existing step into test:
"test": "pnpm db:migrate:test && pnpm test:workers && pnpm test:node"

db:migrate:test is idempotent: ensureDatabaseExists guards CREATE DATABASE behind a pg_database existence check, and migrations report "up to date" when there's nothing new. So on a machine that already has sdp_test, the chained step is a fast no-op.

Testing

Verified end to end on a fresh clone (v0.31.0):

  • before: pnpm test fails every workers file with 3D000 / "database sdp_test does not exist"
  • after: the same command creates sdp_test and runs green past the DB layer (727 passed)
  • re-run: db:migrate:test prints "Test postgres migrations are up to date" and the suite runs again with no DB error, confirming the no-op path

biome check on the changed file is clean.

CI

No CI changes needed. The fork-safe runner (scripts/run-workspace-tests.mjs) already runs db:migrate:test before the suite, so chaining it into test is a duplicate idempotent no-op there; on the Doppler path it adds the same idempotent step against the CI Postgres service. Either way it's the no-op described above, and the PR's own run exercises it.

On a fresh clone the documented setup (`pnpm db:postgres:up` +
`pnpm --filter @sdp/api db:postgres:bootstrap`) creates the `sdp`
database but never `sdp_test`. The workers pool binds `sdp_test` but
does not create it, and the `test` script never ran the step that
would, so `pnpm test` failed every workers file with Postgres
`FATAL 3D000` ("database \"sdp_test\" does not exist").

Chain the existing `db:migrate:test` into `test`. It is idempotent:
`ensureDatabaseExists` guards `CREATE DATABASE` behind a
`pg_database` existence check and migrations report "up to date", so
re-runs are a fast no-op.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

@moviendome is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the missing database setup step that caused pnpm test to fail immediately on a fresh checkout with error: database "sdp_test" does not exist. The fix chains the existing idempotent db:migrate:test step into the test script, which creates and migrates sdp_test if it doesn't already exist.

  • apps/sdp-api/package.json: test script now runs pnpm db:migrate:test before the test suites; db:migrate:test is guarded by ensureDatabaseExists so it is a fast no-op on machines that already have sdp_test.

Confidence Score: 5/5

This is a minimal, targeted fix: a single-line change that prepends an idempotent database-setup step to the test script. The underlying ensureDatabaseExists guard makes the added step safe to re-run on machines that already have the database.

The one-line change is correct, the idempotency of db:migrate:test is well-established in the codebase, and the PR description documents successful end-to-end verification on a fresh clone. No logic regressions are introduced.

No files require special attention. The sibling scripts (test:coverage, test:serial, test:watch) that bypass this fix were noted in a prior review comment.

Important Files Changed

Filename Overview
apps/sdp-api/package.json Single-line fix adding pnpm db:migrate:test && prefix to the test script; the sibling scripts test:coverage, test:serial, and test:watch still bypass this step (flagged in a previous review comment).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pnpm test] --> B[pnpm db:migrate:test]
    B --> C{sdp_test exists?}
    C -- No --> D[CREATE DATABASE sdp_test]
    D --> E[Run migrations]
    C -- Yes --> F[Migrations up to date — no-op]
    E --> G[pnpm test:workers]
    F --> G
    G --> H[pnpm test:node]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[pnpm test] --> B[pnpm db:migrate:test]
    B --> C{sdp_test exists?}
    C -- No --> D[CREATE DATABASE sdp_test]
    D --> E[Run migrations]
    C -- Yes --> F[Migrations up to date — no-op]
    E --> G[pnpm test:workers]
    F --> G
    G --> H[pnpm test:node]
Loading

Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/test-create..." | Re-trigger Greptile

@multipletwigs

Copy link
Copy Markdown
Collaborator

@moviendome sweet, thanks

@GuiBibeau

Copy link
Copy Markdown
Collaborator

working on getting this merged

@moviendome

Copy link
Copy Markdown
Contributor Author

working on getting this merged

Great! Thx 🚀

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.

4 participants