Some checks failed
CD / Build and push images (push) Successful in 3m16s
CI / Lint, typecheck, test (push) Successful in 3m5s
CD / Deploy to Test (push) Successful in 13s
CD / Smoke tests against Test (push) Failing after 3m35s
CD / Promote to Int (push) Has been skipped
CI / Auth e2e pack (push) Successful in 5m6s
CI / Import/export fidelity gate (push) Successful in 43s
CI / Build container images (push) Has been skipped
When the api runs against a database without the setup.completedAt marker, a global SetupGuard answers every non-exempt route with 503 setup_required; only /setup/*, health probes, and the session routes stay reachable. The wizard steps (POST /setup/admin|instance|smtp| registration|complete) write straight to their production homes; the Site Admin step signs its creator in, later steps require that session. Completing sets the marker and locks every step permanently (410, also across restarts, and not reopenable via PATCH /admin/settings). SMTP entered in the wizard is verified with a live delivery test first (failure blocks the step with the transport error as detail) and then persisted to the new env-backed secret store: a mode-600 dotenv file on the new `secrets` volume (SECRETS_FILE). Explicit container env always wins over the store; empty compose-passed strings count as unset. The mail transport now resolves lazily through SmtpConfigService so wizard changes apply without a restart. SETUP_ADMIN_* env pre-seeds the whole wizard at boot for automated deploys; a backfill migration marks instances that already have a Site Admin as completed, and seed/vitest global-setup do the same for fixture databases. The setup e2e suite provisions its own fresh database (CREATE DATABASE + migrate deploy) per run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { execFileSync } from 'node:child_process';
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
/**
|
|
* Database-backed tests run only when TEST_DATABASE_URL is set (locally:
|
|
* the compose dev db on port 5434; in CI: the postgres service container).
|
|
* This setup pushes the current Prisma schema into that database once per
|
|
* test run; tests skip themselves when the variable is absent.
|
|
*/
|
|
export default async function globalSetup(): Promise<void> {
|
|
const url = process.env.TEST_DATABASE_URL;
|
|
if (!url) return;
|
|
execFileSync(
|
|
process.execPath,
|
|
[require.resolve('prisma/build/index.js'), 'db', 'push', '--skip-generate'],
|
|
{ env: { ...process.env, DATABASE_URL: url }, stdio: 'inherit', cwd: __dirname },
|
|
);
|
|
// The shared test database counts as a configured instance — without the
|
|
// completion marker every suite would hit the first-run setup gate
|
|
// (issue #80). The setup suite provisions its own fresh database instead.
|
|
const prisma = new PrismaClient({ datasourceUrl: url });
|
|
try {
|
|
await prisma.instanceSetting.upsert({
|
|
where: { key: 'setup.completedAt' },
|
|
create: { key: 'setup.completedAt', value: new Date().toISOString() },
|
|
update: {},
|
|
});
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|