Skip to content

chore(ci): start the Postgres that is already in the routine image, so the loop can run integration specs #663

Closed

Description

@Ardnived

Summary

The loop's routine environment has PostgreSQL 16 installed — /usr/lib/postgresql/16/bin/
carries initdb, pg_ctl and postgres. It is simply not on $PATH and no cluster is running, so
DATABASE_URL is unset and 127.0.0.1:5432 refuses. Starting it takes about fifteen seconds and no
network access.

Until it is started, the 66 *.int.spec.ts files cannot run during a routine run: the lean gate
silently covers less than CI does, and the loop finds out after pushing. On
#660 it rewrote an assertion in tests/int/user-message-screening.int.spec.ts and
shipped it reasoned from documented behaviour rather than observed, flagging in the PR description:
"This is the one change most likely to turn CI red."

Nothing untested has shipped. CI provisions postgres:18 as a service
(.github/workflows/ci.yml:19–35) and all 113 test files passed on that PR. This is a
self-verification gap, not a coverage gap — which is why it is Medium rather than High.

⚠ An earlier version of this ticket said the environment had no Postgres and proposed installing
one.
That was inferred from an unset DATABASE_URL and a refused connection, which are equally
consistent with "nothing has been started". Measured 2026-08-31, in a routine run; see the comment
thread.

Approach

Start the cluster before the gate runs, and make its absence loud rather than silent.

  1. Start the bundled Postgres, lazily. Roughly:

    export PATH=/usr/lib/postgresql/16/bin:$PATH
    id postgres >/dev/null 2>&1 || useradd -m postgres   # postgres refuses to run as root
    su postgres -c "initdb -D /tmp/pgdata -U postgres --auth=trust"
    su postgres -c "pg_ctl -D /tmp/pgdata -l /tmp/pg.log start"
    su postgres -c "psql -U postgres -c \"ALTER USER postgres WITH PASSWORD 'postgres'\""
    su postgres -c "createdb -U postgres payload_test"

    That yields exactly DEFAULT_TEST_DATABASE_URL
    (postgresql://postgres:postgres@localhost:5432/payload_test, tests/utils/postgresTestPool.ts),
    which is the same string CI's service container provides — so no test config changes.

    Lazy, not unconditional: a run that touches no tests/int/** should not pay the ~15s. The
    container is ephemeral, so this is per-run setup, not a one-time provision.

  2. Make the absence loud. check.sh should detect no reachable database and report a named
    skipped lane rather than falling through quietly. A gate that silently covers less than it claims
    is the same defect class as fix(ci): restore Railway preview URLs, fail closed when none is found #661.

The two are complementary — start it, and make a future absence loud instead of silent, since the
image's contents are not ours to depend on forever.

Where the startup lives — the open question

The commands belong to the routine environment, not to this repo's source: they are how a
particular runner is provisioned, and a contributor running Claude Code locally already has a
database. Candidates, in rough preference order:

  • The remote environment's setup script (see the Claude Code on the web docs) — runs once per
    container, before any session, and keeps repo source clean.
  • A small script in sydevs/claude-workflow the loop invokes when it is about to run an integration
    lane, so all five repos share one copy.
  • .claude/skills/pr-prep/check.sh in this repo, which is the wrong layer but the shortest path.

Deciding this is the remaining work; the mechanics are settled.

Acceptance criteria

  • A routine run can execute tests/int/** against a real database
  • The cluster is started only when a run actually needs it
  • If no database is reachable, the gate reports a named skipped lane rather than passing quietly
  • A PR that changes an integration spec is never opened with that spec unexecuted and unmentioned

Verification checklist

  • In a routine run, .claude/skills/pr-prep/check.sh reports the integration lane as run, with a spec count
  • Deliberately break one assertion in tests/int/regions.int.spec.ts on a scratch branch; the loop's own gate goes red before CI does
  • With no cluster running, check.sh exits naming the skipped lane rather than reporting success
  • A routine run that touches no integration spec does not start Postgres
  • CI still shows the full spec count

Notes

Found on #660, which is merged and green. First worked around on
#666, where the cluster was started by hand mid-run.

Distinct from the two open smoke-lane tickets, which look similar but are not the same defect:
#661 is about the Railway preview smoke lane skipping on most PRs, and
#662 about how its admin is seeded. This one is the local integration lane inside
the loop's own runner. The common thread is worth noting though: three separate lanes that report
success while running less than they appear to.

Activity

  1. added theissue type on Aug 31, 2026
  2. Ardnived commented on Aug 31, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Revise this ticket. We don't want to refuse to modify integration tests, we also don't want to consume a lot of tickets installing Postgres in Claude Routines. If Claude Routines doesn't have a way to already provision Postgres on run, then we need to look for another method, or accept that integration tests will always be tested in CI (at least when run in Claude Routines as opposed to locally running Claude Code).

  3. sydevs-bot commented on Aug 31, 2026

    @sydevs-bot
    Contributor

    The premise was wrong, and the fix costs nothing: PostgreSQL 16 is already installed in the routine image. It just isn't on $PATH and no cluster is running. No install, no Docker, no network.

    I ran the integration lane in this routine before writing this:

    $ ls /usr/lib/postgresql/16/bin/          # initdb, pg_ctl, postgres — all present
    $ initdb -D /tmp/pgdata -U postgres --auth=trust && pg_ctl -D /tmp/pgdata start
    $ createdb payload_test
    $ pnpm exec vitest run tests/int/atlas-sitemap.int.spec.ts --config ./vitest.config.mts
      Test Files  1 passed (1)
           Tests  17 passed (17)
        Duration  13.54s
    

    That is DEFAULT_TEST_DATABASE_URL unchanged — postgresql://postgres:postgres@localhost:5432/payload_test, the same string CI's service container provides — so nothing in the test config has to know where it is running.

    So all three of your constraints are satisfied at once: option 3 is dropped, no ticket budget goes on installing anything, and integration tests stop being CI-only in routines. I've rewritten the ticket accordingly.

    Two caveats, both real:

    • postgres refuses to run as root, and the routine runs as root, so the cluster has to start under a separate account (useradd postgres + su). That is the only fiddly part, and it is four lines.
    • The container is ephemeral, so this is per-run setup, not a one-time provision. ~15s of startup — worth it against 66 spec files, but it should be lazy rather than unconditional. A run that touches no tests/int/** should not pay it.
    Why the ticket said the opposite, and what that says about the next such claim

    The original was written from DATABASE_URL being unset and 127.0.0.1:5432 refusing a connection — both true — and concluded no Postgres was available. Those two observations are consistent with "nothing is installed" and equally consistent with "nothing has been started", and the ticket did not distinguish them. Checking /usr/lib/postgresql/ would have.

    This is the same shape as the finding in SahajAtlasWeb's .claude/rules/tests.md about Cloudflare's in-progress window: an absence observed at one layer is not evidence of absence at the layer below. Worth checking the filesystem before concluding a capability is missing.

    It also means the two claims in the ticket's Summary were not equally true. "The loop cannot run integration specs" was wrong. "It shipped an assertion in tests/int/user-message-screening.int.spec.ts reasoned from documented behaviour rather than observed" was correct and remains the reason the ticket exists — that spec was genuinely never executed before it was pushed on #660.

    This is already paying for itself in this run. I opened #666 an hour ago flagging that I could not verify onInit against the 66 integration suites; with the cluster up, that lane is running now and I will report the result on that PR rather than leaving it to CI.

    Leaving the ticket assigned to me: it now has a known, cheap implementation, and the change belongs in the routine's setup rather than in this repo's source — so the next step is deciding where that four-line startup lives, which is the open question below.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  4. changed the title [-]chore(ci): the loop cannot run integration specs — no Postgres in its environment[/-] [+]chore(ci): start the Postgres that is already in the routine image, so the loop can run integration specs[/+] on Aug 31, 2026
  5. Ardnived commented on Aug 31, 2026

    @Ardnived
    ContributorAuthor

    Resolved — the decision the ticket was waiting on is made: the Postgres bring-up lives in the routine environment's setup script, not in this repo. It is environment provisioning, and the environment is where it now sits.

    The validated script (from this ticket's own investigation: the image ships Postgres 16 off $PATH with no cluster; initdb + pg_ctl as the postgres user yields exactly DEFAULT_TEST_DATABASE_URL, and the integration lane then runs unmodified — 67 files, 1135 tests, green) is documented in claude-workflow/docs/routine-setup.md §4, merged in sydevs/claude-workflow#10. The maintainer pastes it into the environment settings at claude.ai/code, which is the one step no session can perform.

    The original acceptance criteria are superseded by the rewrite this ticket already went through: option 1 (provision the database) is done as above; option 2's make-the-absence-loud remains desirable but belongs to the lean-gate script and is small enough to ride along with any future check.sh change rather than hold this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

Priority

Medium

Hold Until

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions