teqo/tests/int/assertTestDatabase.int.spec.ts
Francisco Solla 8125334401 feat(worktree): ambientes isolados por worktree — porta própria, bancos próprios, migrations no provision
pnpm worktree next [--go] [--no-migrate] agora provisiona um ambiente
determinístico por worktree: slot = parte numérica do código da Issue
(C15→15; hash sem dígitos; bump em colisão entre worktrees vivos), dev
server em 3100+slot, bancos teqo_wt<slot> / teqo_wt<slot>_test no
container compartilhado (-p teqo) com a cadeia de migrations aplicada;
escreve .env.local + .env.test.local (gitignored, marcador gerado; envs
manuais nunca sobrescritos) e copia PAYLOAD_SECRET/Blob/VAPID do main.
kill remove o worktree e dropa os bancos gerados (WITH FORCE, best-effort).

Suites leem .env.test.local depois de .env.test (vitest.setup /
playwright / db-doctor / gate-ci espelham o layering) e
assertTestDatabase aceita teqo_test ou teqo_<worktree>_test em localhost
só (fail-closed preservado). db:start/db:stop fixam -p teqo (um
container de qualquer diretório); max_connections 200→400. Sem Docker
(Cursor Cloud): degrada ao compartilhado com aviso.

Derivação pura em scripts/lib/worktree-env.mjs (unit-tested); fluxo
validado end-to-end: provision → migrate → 598/598 int no banco do
worktree → kill sem resíduo.
2026-08-08 11:33:07 -03:00

33 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { assertTestDatabase } from '../helpers/assertTestDatabase'
describe('assertTestDatabase', () => {
it.each([
'postgresql://teqo:teqo@localhost:5432/teqo_test',
'postgresql://teqo:teqo@localhost:5432/teqo_wt15_test',
'postgresql://teqo:teqo@127.0.0.1:5432/teqo_test',
'postgresql://teqo:teqo@127.0.0.1:5432/teqo_wt164_test',
'postgresql://teqo:teqo@[::1]:5432/teqo_test',
])('accepts the local test database at %s', (databaseUrl) => {
expect(() => assertTestDatabase(databaseUrl)).not.toThrow()
})
it.each([
'postgresql://teqo:teqo@localhost:5432/other_test',
'postgresql://teqo:teqo@localhost:5432/teqo',
'postgresql://teqo:teqo@localhost:5432/teqo_wt15',
'postgresql://teqo:teqo@localhost:5432/teqo_test_extra',
'postgresql://teqo:teqo@localhost:5432/teqo_Test_test',
'postgresql://teqo:teqo@db.example.com:5432/teqo_test',
'postgresql://teqo:teqo@neon.example.com:5432/teqo_wt15_test',
'postgres://teqo:teqo@localhost:5432/teqo_test',
'https://localhost/teqo_test',
'postgresql+srv://teqo:teqo@localhost:5432/teqo_test',
'postgresql://teqo:teqo@localhost:5432/teqo_test/extra',
'not-a-url',
undefined,
])('rejects unsafe database URL %s', (databaseUrl) => {
expect(() => assertTestDatabase(databaseUrl)).toThrow()
})
})