mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
- scripts/worktree.mjs: provision() aplica migrate + db:seed:minimal nos bancos dev e test (paridade com a CI, que roda o par antes do e2e); --no-migrate pula os dois (o seed depende do catálogo migrado); fallback sem Docker também migra+seeda o teqo/teqo_test compartilhado (com warning de sobrescrita dos pins). - Guard de regressão tests/e2e/seedParity.setup.e2e.spec.ts no projeto setup: falha cedo com mensagem clara se o banco de teste não estiver seedado; evidência = users do seed (MINIMAL_CAMPAIGN_USERS), não os pins de priority — o cleanup dos fixtures e2e reseta priority por round-robin persistente. - scripts/lib/test-affected-core.mjs: scripts/worktree.mjs em HIGH_RISK_EXACT. - Docs: AGENTS.md, skill local-database, CHANGELOG-AGENTS.md, impl plan. Closes #584
71 lines
2.9 KiB
TypeScript
71 lines
2.9 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
import { getPayload } from 'payload'
|
|
|
|
import { MINIMAL_CAMPAIGN_USERS } from '../../scripts/lib/seed-minimal-manifest.mjs'
|
|
import config from '../../src/payload.config.js'
|
|
|
|
/**
|
|
* OPS28 — parity guard between the worktree provisioning and CI.
|
|
*
|
|
* CI runs `pnpm migrate && pnpm db:seed:minimal` before e2e; worktrees
|
|
* provisioned by `pnpm worktree next`/`plan` now do the same (OPS28). This
|
|
* spec pins the outcome on the TEST DATABASE: if the seed is missing, the
|
|
* suite fails here with a clear message instead of red specs that "work in
|
|
* CI" (the exact pattern TECH-DEBT row 19 calls out as masking real failures).
|
|
*
|
|
* The check is the seed's INDELIBLE evidence, deliberately NOT the
|
|
* municipality priority pins: the e2e fixture cleanup resets `priority` on
|
|
* the municipalities it touches (round-robin over the catalog with a
|
|
* persistent sequence), so after repeated suite runs against the same
|
|
* worktree database a pin can legitimately be back to `normal` — that is
|
|
* not "seed missing". The seed's campaign users (synthetic, stable email /
|
|
* username, created only by `db:seed:minimal`, never deleted by the e2e
|
|
* cleanup, which owns only rows the fixtures created) cannot die that way:
|
|
* their presence is exactly "the minimal seed ran here".
|
|
*
|
|
* Runs in the `setup` Playwright project (matches `setup.e2e.spec.ts`), which
|
|
* the `campaign` project depends on: a failure here skips the dependent
|
|
* projects with this message instead of running a confusing suite.
|
|
*/
|
|
|
|
const SEED_MISSING_MESSAGE =
|
|
'O seed mínimo não foi aplicado neste banco de teste. Rode `pnpm migrate && pnpm db:seed:minimal` ' +
|
|
'(worktrees provisionados pelo `pnpm worktree next`/`plan` já fazem isso; um banco migrado cru ' +
|
|
'não tem nenhum dado do seed).'
|
|
|
|
test('test database carries the minimal seed (run pnpm migrate && pnpm db:seed:minimal)', async () => {
|
|
expect(MINIMAL_CAMPAIGN_USERS.length).toBeGreaterThan(0)
|
|
|
|
let payload
|
|
try {
|
|
payload = await getPayload({ config })
|
|
} catch (error) {
|
|
// A never-migrated database fails on schema access, not on missing rows —
|
|
// surface the same actionable message instead of a raw PG error.
|
|
throw new Error(
|
|
`${SEED_MISSING_MESSAGE}\n(detalhe: o banco pode nem estar migrado — ${
|
|
error instanceof Error ? error.message : String(error)
|
|
})`,
|
|
)
|
|
}
|
|
try {
|
|
for (const user of MINIMAL_CAMPAIGN_USERS) {
|
|
const { docs } = await payload.find({
|
|
collection: 'campaignUser',
|
|
where: user.email
|
|
? { email: { equals: user.email } }
|
|
: { username: { equals: user.username } },
|
|
depth: 0,
|
|
limit: 1,
|
|
pagination: false,
|
|
})
|
|
const found = docs[0]
|
|
expect(
|
|
found,
|
|
`Usuário do seed ${user.email ?? user.username} ausente no banco de teste — ${SEED_MISSING_MESSAGE}`,
|
|
).toBeDefined()
|
|
}
|
|
} finally {
|
|
await payload.db.destroy?.()
|
|
}
|
|
})
|