Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import net from 'node:net';
|
|
import { describe } from 'vitest';
|
|
|
|
const DB_HOST = process.env.DB_HOST || 'localhost';
|
|
const DB_PORT = Number(process.env.DB_PORT || 5432);
|
|
|
|
/**
|
|
* Probes the test database with a raw TCP connect (no credentials needed).
|
|
*/
|
|
export async function isDbReachable(
|
|
host: string = DB_HOST,
|
|
port: number = DB_PORT,
|
|
timeoutMs = 500
|
|
): Promise<boolean> {
|
|
return new Promise((resolve) => {
|
|
const socket = net.createConnection({ host, port });
|
|
const done = (value: boolean) => {
|
|
socket.removeAllListeners();
|
|
socket.destroy();
|
|
resolve(value);
|
|
};
|
|
socket.on('connect', () => done(true));
|
|
socket.on('error', () => done(false));
|
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Returns `describe` when the database is reachable, `describe.skip` when it
|
|
* is not — except in environments that declare REQUIRE_DB=1 (CI), where an
|
|
* unreachable database is a hard failure instead of a silent skip. This is
|
|
* what keeps DB-backed suites from passing vacuously in CI.
|
|
*
|
|
* Usage (top level of an integration test file):
|
|
* const describeDb = await describeWithDb();
|
|
* describeDb('my suite', () => { ... });
|
|
*/
|
|
export async function describeWithDb(): Promise<typeof describe | typeof describe.skip> {
|
|
const reachable = await isDbReachable();
|
|
if (reachable) {
|
|
return describe;
|
|
}
|
|
if (process.env.REQUIRE_DB === '1') {
|
|
throw new Error(
|
|
`REQUIRE_DB=1 but the test database at ${DB_HOST}:${DB_PORT} is unreachable. ` +
|
|
'Refusing to skip DB-backed tests in a required-DB environment.'
|
|
);
|
|
}
|
|
return describe.skip;
|
|
}
|