Skip to content

docs: correct the test-setup instructions around Postgres - #149

Merged
rrskris merged 1 commit into
mainfrom
docs/fix-postgres-test-setup
Aug 5, 2026
Merged

rrskris merged 1 commit into
mainfrom
docs/fix-postgres-test-setup

Conversation

@rrskris

@rrskris rrskris commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Closes the "phantom Postgres failure" open finding — except it was never phantom. The contributors were right and our docs were wrong.

What was believed

Two contributors — @shariqueahmad108-ship-it (#131) and @Diyaaa-12 (#123) — independently reported test_smoke.py::test_login_and_self_scan failing and needing a local Postgres. This was written off as a setup problem on their machines, on the grounds that the suite passes here with no Postgres and no Docker.

What is actually true

That "passes here" observation was an artifact of the maintainer's machine. There is a long-running Postgres on 127.0.0.1:5432, which is exactly the application default in app/database.py:7. CI passes for the same reason — ci.yml runs a postgres:16-alpine service container published on 5432.

Point DATABASE_URL at a closed port and the contributor reports reproduce exactly:

$ DATABASE_URL=postgresql://kaaval:[email protected]:55432/kaaval_db \
    KAAVAL_ADMIN_PASSWORD=test-admin-password pytest tests/test_smoke.py

E  sqlalchemy.exc.OperationalError: (psycopg2.OperationalError)
   connection to server at "127.0.0.1", port 55432 failed: Connection refused

test_smoke.py drives the real startup path — models.Base.metadata.create_all(bind=database.engine) plus tenant and admin seeding — through TestClient, so it opens a genuine connection. Its own docstring said "Requires a reachable Postgres instance" all along. CONTRIBUTING.md said the opposite.

The second trap

make db publishes Postgres on 55432 (PG_PORT ?= 55432); the application default is 5432. make test passes DATABASE_URL explicitly so it works — but the command printed in test_smoke.py's own docstring did not set it. Follow that docstring after running make db and it targets the wrong port and fails, with the database sitting right there.

Changes

  • CONTRIBUTING.md — remove the claim that the suite needs no database; name test_smoke.py as the one test that does; show the exact OperationalError so it reads as expected rather than as a broken checkout; document the port mismatch and the correct direct-pytest invocation; add a --ignore one-liner for a fully database-free run.
  • control-plane/tests/test_smoke.py — docstring now carries a DATABASE_URL that matches make db.

Docs only; no test or application behaviour changed.

Verification

KAAVAL_ADMIN_PASSWORD=... pytest              -> 131 passed
pytest tests/ --ignore=tests/test_smoke.py    -> 130 passed

Both commands in the new instructions were run as written.

Worth a follow-up

Right now a contributor without Postgres gets a red OperationalError. Making test_smoke.py skip with a clear reason when the database is unreachable — guarded by an env var set in CI so a genuinely broken CI database still fails loudly — would turn a discouraging first run into 130 passed, 1 skipped. Not included here since it changes test behaviour and CI config; happy to open it separately.

Two contributors independently reported test_smoke.py::test_login_and_self_scan
failing and needing a local Postgres. They were right, and the docs told them
otherwise.

CONTRIBUTING.md stated the suite needs "neither a cluster nor a database". That
holds for the RBAC/scoring/remediation tests but not for test_smoke.py, which
drives the real startup path (create_all + tenant/admin seeding) through
TestClient and therefore opens a real connection. Without Postgres it fails with
OperationalError: Connection refused — expected, but reading as a broken
checkout given what the page promised.

The failure was previously written off as unreproducible because it does not
reproduce on a machine that happens to run Postgres on 5432 — as this
maintainer's does, and as CI does via its postgres service container. Pointing
DATABASE_URL at a closed port reproduces the contributor reports exactly.

Second trap, also now documented: `make db` publishes on 55432 while the
application default is 5432. `make test` passes DATABASE_URL and works, but the
command in test_smoke.py's own docstring did not set it, so following the
docstring after `make db` targeted the wrong port and failed.

Document which test needs a database, show the exact error so it is recognised
as expected, give the correct direct-pytest invocation, and give a --ignore
one-liner for running everything else with no database at all.

Signed-off-by: Vamshi Krishna Santhapuri <[email protected]>
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Invigil — kaaval

Gate G5 · Grade A+ · 34/35 (97%)

All five doors open and documented

Gate Check Effort Why Fix
G4 OpenSSF Scorecard >= 7 hours score 6.8 < 7 triage the Scorecard findings (branch protection, token perms, pinned deps) to reach >=7

30 passing · 1 failing · 4 skipped · report-only

@rrskris
rrskris merged commit 8b210eb into main Aug 5, 2026
7 checks passed
@rrskris
rrskris deleted the docs/fix-postgres-test-setup branch August 5, 2026 17:47
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