mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 03:14:09 +00:00
The three `*.audit.test.ts` files from #195 are real PostgreSQL regressions, but each one guards itself with a `skip` when its fixture URL is absent, so a CI run without a database reported them as skipped and still exited 0. Add a `Database Audit Tests` job that starts a disposable PostgreSQL 16 service, sets `TEST_INGEST_DATABASE_URL` and `TEST_BACKFILL_DATABASE_URL`, and runs exactly the three files one at a time. Every file's TAP stream is piped through `backend/scripts/assert-audit-tests-ran.mjs`, which fails the job when any test is skipped, failed, cancelled or missing, so a dropped service or an unset variable can no longer turn the audit into a green no-op. Plain PostgreSQL is deliberate: the audit-high fixture refuses a database where the timescaledb extension is installed, because the extension's own `timescaledb_experimental.policies` view trips its stray-table guard. The job therefore exercises the plain-PostgreSQL branch of `installChunkCatalog`, which the fixture explicitly supports. The job prints the server version it reached (host/port/database only, never the fixture password) and keeps the TAP output as an artifact on failure. Depends on #195 for the test files themselves; the job fails with an explicit `::error` naming #195 while they are absent rather than passing.
89 lines
3.3 KiB
JavaScript
89 lines
3.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Guard against database-backed audit tests silently skipping.
|
|
*
|
|
* The `.audit.test.ts` files only run when a loopback fixture database is
|
|
* supplied; without it they report `# SKIP` and node:test still exits 0. That
|
|
* makes a missing or misconfigured CI service indistinguishable from a green
|
|
* run, so every invocation of these files is piped through this check.
|
|
*
|
|
* Usage: node scripts/assert-audit-tests-ran.mjs <tap-file> [label] [--min-tests=N]
|
|
*
|
|
* Exits non-zero when the TAP stream shows any skip, todo, cancelled or failed
|
|
* test, when the counts disagree, or when fewer than `--min-tests` tests ran.
|
|
*/
|
|
import { readFileSync } from 'node:fs';
|
|
|
|
const args = process.argv.slice(2);
|
|
const minTestsArg = args.find((arg) => arg.startsWith('--min-tests='));
|
|
const positional = args.filter((arg) => !arg.startsWith('--'));
|
|
const [tapPath, label = tapPath] = positional;
|
|
const minTests = minTestsArg ? Number(minTestsArg.split('=')[1]) : 1;
|
|
|
|
if (!tapPath) {
|
|
console.error('usage: assert-audit-tests-ran.mjs <tap-file> [label] [--min-tests=N]');
|
|
process.exit(2);
|
|
}
|
|
if (!Number.isInteger(minTests) || minTests < 1) {
|
|
console.error(`invalid --min-tests value: ${minTestsArg}`);
|
|
process.exit(2);
|
|
}
|
|
|
|
let tap;
|
|
try {
|
|
tap = readFileSync(tapPath, 'utf8');
|
|
} catch (error) {
|
|
console.error(`${label}: no TAP output at ${tapPath} (${error.code ?? error.message})`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const lines = tap.split('\n');
|
|
const summary = new Map();
|
|
for (const line of lines) {
|
|
const match = /^#\s+(tests|pass|fail|cancelled|skipped|todo)\s+(\d+)\s*$/.exec(line);
|
|
if (match) summary.set(match[1], Number(match[2]));
|
|
}
|
|
|
|
const required = ['tests', 'pass', 'fail', 'skipped'];
|
|
const missing = required.filter((key) => !summary.has(key));
|
|
if (missing.length > 0) {
|
|
console.error(`${label}: TAP stream has no summary (missing ${missing.join(', ')}); the runner did not complete`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const tests = summary.get('tests');
|
|
const pass = summary.get('pass');
|
|
const fail = summary.get('fail');
|
|
const skipped = summary.get('skipped');
|
|
const cancelled = summary.get('cancelled') ?? 0;
|
|
const todo = summary.get('todo') ?? 0;
|
|
|
|
const problems = [];
|
|
if (skipped > 0) problems.push(`${skipped} test(s) skipped — the audit fixture database was not usable`);
|
|
if (todo > 0) problems.push(`${todo} test(s) marked todo`);
|
|
if (cancelled > 0) problems.push(`${cancelled} test(s) cancelled`);
|
|
if (fail > 0) problems.push(`${fail} test(s) failed`);
|
|
if (pass !== tests) problems.push(`pass (${pass}) does not equal tests (${tests})`);
|
|
if (tests < minTests) problems.push(`only ${tests} test(s) ran, expected at least ${minTests}`);
|
|
|
|
const skipReasons = lines.filter((line) => /^ok\s+\d+\s+.*#\s*(SKIP|TODO)/i.test(line));
|
|
if (skipReasons.length > 0) {
|
|
console.error(`${label}: skipped/todo entries:`);
|
|
for (const line of skipReasons) console.error(` ${line.trim()}`);
|
|
}
|
|
|
|
const failed = lines.filter((line) => /^not ok\s+\d+/.test(line));
|
|
if (failed.length > 0) {
|
|
console.error(`${label}: failing entries:`);
|
|
for (const line of failed) console.error(` ${line.trim()}`);
|
|
}
|
|
|
|
const counts = `tests=${tests} pass=${pass} fail=${fail} skipped=${skipped} cancelled=${cancelled} todo=${todo}`;
|
|
if (problems.length > 0) {
|
|
console.error(`${label}: ${counts}`);
|
|
for (const problem of problems) console.error(` - ${problem}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`${label}: ${counts}`);
|