starter:gate: the production full-seed check needs the guard's message; an early exit is retried
payload run can end with exit 0 and no output before Payload initializes (its bin does `void start()`; when the script's top-level await is left without live handles, Node exits). Such a run proved nothing but passed or failed the `refused !== 0` check at random. Now only "full seed refused" with a non-zero exit counts; a run without "[ipal] Plugin initialized" is inconclusive and retried up to 3 times; all three inconclusive fails the gate with that reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
40925f9331
commit
7e1f09c95a
@@ -47,6 +47,28 @@ function check(name, ok, detail = '') {
|
||||
if (!ok) {throw new Error(`gate failed: ${name}`)}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the production full seed and decides whether the guard refused it. Only the guard's own message counts:
|
||||
* an exit code alone does not, because `payload run` can end with exit 0 and no output before Payload initializes
|
||||
* (its bin does `void start()`; when the script's top-level `await getPayload()` is left with nothing that keeps the
|
||||
* event loop alive, Node simply exits). Such a run says nothing — it is retried, up to `tries` times.
|
||||
*/
|
||||
function fullSeedRefused(site, env, tries = 3) {
|
||||
for (let attempt = 1; attempt <= tries; attempt++) {
|
||||
log(`$ pnpm seed (production, no SEED_ONLY) — attempt ${attempt}/${tries}`)
|
||||
const run = spawnSync('pnpm', ['seed'], { cwd: site, encoding: 'utf8', env: { ...process.env, ...env } })
|
||||
const output = `${run.stdout ?? ''}${run.stderr ?? ''}`
|
||||
process.stdout.write(output)
|
||||
if (/full seed refused/.test(output)) {return run.status !== 0}
|
||||
if (/\[ipal\] Plugin initialized/.test(output)) {
|
||||
log(`Payload initialized but the seed was not refused (exit ${run.status})`)
|
||||
return false
|
||||
}
|
||||
log(`inconclusive: Payload never initialized (exit ${run.status}, ${output.trim() ? 'no guard message' : 'no output'})${attempt < tries ? ' — retrying' : ''}`)
|
||||
}
|
||||
throw new Error(`gate failed: the production full seed was inconclusive in all ${tries} runs — Payload never initialized, so the guard was never reached`)
|
||||
}
|
||||
|
||||
async function waitFor(url, seconds) {
|
||||
for (let i = 0; i < seconds; i++) {
|
||||
try {
|
||||
@@ -138,8 +160,7 @@ async function main() {
|
||||
sh(site, 'pnpm', ['seed'], { ...prod, SEED_ONLY: 'pages:kontakt' })
|
||||
check('targeted seed in production mode: SEED_ONLY="pages:kontakt" [SEED_DRY_RUN=1] pnpm seed', true)
|
||||
// after launch: a run without SEED_ONLY on production must be refused by the plugin's guard
|
||||
const refused = sh(site, 'pnpm', ['seed'], prod, { allowFail: true })
|
||||
check('full seed on production (no SEED_ONLY) is refused', refused !== 0)
|
||||
check('full seed on production (no SEED_ONLY) is refused', fullSeedRefused(site, prod), 'exit 1 with "full seed refused"')
|
||||
|
||||
// 6. the production server
|
||||
log(`$ pnpm start (PORT=${PORT})`)
|
||||
|
||||
Reference in New Issue
Block a user