From 334c7d53991c3dd73f9e1c0fa26e1392046a24bc Mon Sep 17 00:00:00 2001 From: Gorka Date: Wed, 17 Jun 2026 11:45:46 -0300 Subject: [PATCH] fix(playwright): default DB DSN to the dev host for local runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit helpers/db.ts defaulted PG_BASE_URL to the Docker hostname `db:5432`, which only resolves inside the playwright compose network. The documented local flow (`npx playwright test` against the up.sh stack) runs on the dev host, where postgres is `localhost:5442` — so it died at the first DB query with `getaddrinfo ENOTFOUND db` (full-flow Step 6b), despite the README saying local works out of the box. - db.ts: default to the dev-host DSN (localhost:5442). - docker-compose.playwright.yml: set PG_BASE_URL=...@db:5432 on the test-runner so the in-network Docker suite is unchanged. --- docker-compose.playwright.yml | 4 ++++ playwright/helpers/db.ts | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docker-compose.playwright.yml b/docker-compose.playwright.yml index fb2de1d..157caf3 100644 --- a/docker-compose.playwright.yml +++ b/docker-compose.playwright.yml @@ -388,3 +388,7 @@ services: FRIENDBOT_URL: http://stellar:8000/friendbot FREIGHTER_EXTENSION_PATH: /app/freighter-extension JAEGER_QUERY_URL: http://jaeger:16686 + # In the Docker network postgres is reachable at `db:5432`. helpers/db.ts + # defaults to the dev-host DSN (localhost:5442), so the in-network run + # must override it here. + PG_BASE_URL: postgresql://admin:devpass@db:5432 diff --git a/playwright/helpers/db.ts b/playwright/helpers/db.ts index 4e2a3f0..fb187a4 100644 --- a/playwright/helpers/db.ts +++ b/playwright/helpers/db.ts @@ -8,18 +8,20 @@ * fixes that without infra changes to the container image. * * Both DBs (provider_platform_db, pay_platform_db) live on the same PG - * instance (host `db` inside the test compose network, `localhost:5442` from - * the dev host). The CLEANUP_DATABASE_URL / DISCOVERY_DATABASE_URL env vars - * default to the in-container DSN; override when running playwright off-host. + * instance — reachable at `localhost:5442` from the dev host (the documented + * `npx playwright test` flow against the up.sh stack), and at `db:5432` + * inside the playwright Docker network. The default targets the dev host so + * local runs work with no env; the Docker `test-runner` sets `PG_BASE_URL` to + * the in-network DSN. Override a single DB via `_URL` if needed. */ import { Client } from "pg"; -const DEFAULT_DSN_IN_CONTAINER = "postgresql://admin:devpass@db:5432"; +const DEFAULT_DSN_DEV_HOST = "postgresql://admin:devpass@localhost:5442"; function resolveDsn(dbName: string): string { const explicit = process.env[`${dbName.toUpperCase()}_URL`]; if (explicit) return explicit; - const base = process.env.PG_BASE_URL || DEFAULT_DSN_IN_CONTAINER; + const base = process.env.PG_BASE_URL || DEFAULT_DSN_DEV_HOST; return `${base}/${dbName}`; }