Repository navigation
refactor(seeds): provision the preview admin at deploy, not from tests - #666
Conversation
Closes #662. A preview's Postgres volume outlives its deploys, so an admin created once by `first-register` in the smoke run kept the password THAT run used — the credential became a property of the database rather than of the current secret, and rotating `PREVIEW_ADMIN_PASSWORD` orphaned every already-seeded preview. `onInit` now reconciles the admin on every boot of a preview environment, after the migrations the Postgres adapter applies. `ensureAdmin` collapses to a login, and the 403 special-case that reported the orphaned state goes with it. The gate is three conditions and each excludes a place this must never run: on Railway at all (so local dev, CI and both test lanes are inert — CI genuinely holds the password as a secret), not production (by Railway's environment name, never NODE_ENV, since previews run NODE_ENV=production), and a password present (pre-2026-08-27 environments never receive one and stay out of scope). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-666 environment in sahajcloud
1 service not affected by this PR
|
|
Correction to the description: I could run the integration lane after all, and it passes. 67 files, 1135 tests, green. The claim above — "this environment has no PostgreSQL" — was wrong, and I found out while revising #663 an hour later. PostgreSQL 16 is already installed in the routine image ( So the one thing this PR could not verify locally — that adding The reasoning in the description still holds (the gate returns on its first line off Railway), but it is now measured rather than argued. What that leaves for review is narrower than the description implies. Only the smoke half is still unverifiable from here, and it remains the half that proves the feature works at all — this PR's Railway preview must log in with no I have rewritten #663 around the corrected finding; the ticket is now about starting the Postgres that is already there, not installing one. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
CI is green, and you should not read that as this PR being verified. The smoke lane skipped.
So what is actually established: the change is sound in isolation and disturbs nothing — 1502 unit and 1135 integration tests pass, on CI and locally. What is not established: that a Railway preview boots, runs Whether that needs action from you depends on something I cannot see: if this branch has no Railway preview environment at all, there is nothing to fix and the verification simply has to happen after merge (or on a preview created by hand). If a preview did deploy and discovery missed it, that is #661 biting. The discovery step's own log says which. Handing this back to you either way — the four deploy-dependent boxes in the checklist are unchanged, and the first one ( 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Correcting my last comment: a preview DID deploy, successfully. The smoke lane skipped because the preview has no public URL — which means this needs a Railway configuration check, not a wait-and-see. I said discovery "found no preview". Railway's own events arrived afterwards and say otherwise: Three independent signals agree on why it was still not usable:
So discovery behaved correctly given its input. The gap is upstream: this preview environment appears to have no public domain assigned. That is distinct from #661 — which is about the lane skipping silently once there is no URL — though the two compound, and #661 is exactly why the job still went green. What I'd check first: whether PR preview environments in the ⚠ One honest limit on the evidence: the 404 proves those two guessed hostnames do not exist, not that no domain exists — Railway could be using a different scheme or a custom domain. The empty Web column and the domain-less status description are what make me confident rather than the probe alone. Nothing about the code in this PR changed; it remains green on lint, typecheck, typecheck:tests and the full unit + integration suite, locally and on CI. What is still unproven is the same one thing: that a preview boots, runs 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…ew-admin-seed # Conflicts: # AGENTS.md
Closes #662.
A preview now reconciles its admin on every deploy, so rotating
PREVIEW_ADMIN_PASSWORDtakes effect on the next deploy instead of orphaning the environment.ensureAdminin the smoke helper collapses to a login, and the 403 special-case that existed to explain the orphaned state goes with it.The gate is three conditions, and each one excludes a place this must never run:
NODE_ENV)The middle one is the trap worth naming: Railway previews run
NODE_ENV=production, which is exactly what once sent preview mail through Resend to real addresses. This readsisProductionDeployment(), the same Railway environment-name check the email adapter and the storage guard already make.The first one is the one that is easy to get wrong here. CI genuinely holds
PREVIEW_ADMIN_PASSWORDas a secret, so a gate reading only the password would provision an admin into the integration lane's database on everypnpm test:int.tests/unit/preview-admin-gate.spec.tscovers that case by name.⚠ What I could not verify, and you should know before merging
I cannot run the integration lane — this environment has no PostgreSQL (
127.0.0.1:5432refuses,DATABASE_URLunset). That is the gap #663 was filed for, and it matters more than usual here because this PR touchessrc/payload.config.ts, which every integration suite boots.What that leaves unproven locally: that adding
onInitdoes not disturb the ~66 integration suites. The gate is proven inert off-Railway by unit test andonInitreturns on its first line there, so the expected blast radius is zero — but CI is the first thing that actually runs it.The smoke lane is also unverifiable from here, and it is the half that proves the feature works at all. Its first run against this PR's Railway preview is the real test: it must log in with no
first-registerfallback left to save it.Design decisions, and the three library behaviours I read out of `node_modules` rather than assumed
Why
onInitrather than apreDeployCommand. The ticket said "predeploy step".onInitis the same in-process pattern this repo already uses for migrations (prodMigrations), it runs after them, and it needs no assumptions about what the Railpack deploy image contains —pnpm startruns.next/standalone/server.js, which carries only traced production deps, so atsxscript in a predeploy hook is a bet on tooling that may not be there.Why
src/plugins/previewAdmin/.src/plugins/is defined as "modules registered inpayload.config.ts", whichonInitis.src/lib/was wrong on its own rule — one consumer means it is not shared.Three things read from the installed Payload source, because getting any of them wrong produces a row that cannot authenticate:
payload.updatewithdata.passworddoes hash it —collections/operations/utilities/update.js:239runsgeneratePasswordSaltHashand deletes the plaintext. This is why the ticket's "local API, never raw SQL" instruction is load-bearing._verified: truemust be passed explicitly. The Managers collection configuresauth.verify, andauth/operations/login.js:184refuses a login while_verified === false.create.js:183preserves a suppliedtrue(Boolean(result._verified) || false), so passing it works;first-registerused to set it implicitly and a plaincreatedoes not.loginAttempts/lockUntilare real base fields (auth/baseFields/accountLock.js), so the reconcile clears them. A rotated secret means the smoke lane has been failing to log in, andmaxLoginAttempts: 5locks the account after five — fixing the password without clearing the lock would leave it shut for another ten minutes.It never throws. A preview that cannot seed still boots and serves; the smoke lane's login is what reports the problem. Failing the deploy would take a whole preview down over a test credential.
One consequence I did not design for but should flag: Railway sets
RAILWAY_ENVIRONMENTat build time as well as runtime, so if anything initialises Payload duringnext buildon a preview, the reconcile runs there too. It is an idempotent upsert, so this is harmless — but it means the[previewAdmin]log line may appear twice in a deploy.Every assertion in the new spec was made to fail before being kept, per
.claude/rules/tests.md:Gates run locally:
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(1502 passed, was 1502 + 5 new = 114 files). The integration and smoke lanes are CI's, for the reason above.Verification checklist for you
The ticket's checklist is mostly things only a real deploy can answer:
[previewAdmin] created …orreconciled …linePREVIEW_ADMIN_PASSWORD, redeploy this preview, confirm smoke still passes — the failure mode this removes[previewAdmin]line at allgrep -rn "first-register" tests/returns nothing🤖 Generated with Claude Code
https://claude.ai/code/session_01HgTsT7Qp7vZsZDfvAenWLd
Generated by Claude Code