openvibers/openvibe-git Commits

Forge CI runs the suite on PostgreSQL too (test:pg), after a merge on the shared node (#129)

OP OpenVibers committed 12 days ago · 8be5328ec5 · 4 files, +93 −2

52 repositories have a test:pg (the suite through PostgreSQL + PgBouncer, which shows what PGlite cannot: a pooled
connection runs un-awaited work out of order); only GitHub's test-pg job ran it. After a run's tests pass, testPg
runs it: the repository's own openvibe-sdk test-services.sh starts PostgreSQL 18, PgBouncer and Valkey inside the
sandbox from the host's packages (no Docker; each sandbox has its own loopback). testPg is off by default; the shared
node sets 'main' (after a merge) so a pull request's verdict is not twice as slow, 'all' runs it everywhere. Services
that do not start are reported, not counted; a failure of the suite fails the run. test/ci-test-pg.test.js.

Changes

ddiff --git a/docs/ci.md b/docs/ci.md
iindex a670fae..5c3911c 100644
---- a/docs/ci.md
++++ b/docs/ci.md
@@@ -157,6 +157,13 @@ repositories) to `ov-node-01` (8 cores, 15 GB):
`high`, or `none`). Findings fail the run after the tests have run, and the description names them. gitleaks is
the version and checksum security.yml pins, installed at /usr/local/bin by `node-setup.sh`.
++- **The suite on PostgreSQL too** (`testPg`, 2026-11-19): a repository's `test:pg` runs after its tests pass, with
++ PostgreSQL 18, PgBouncer and Valkey started inside the sandbox by its own `openvibe-sdk/scripts/test-services.sh`
++ from the host's packages (no Docker; each sandbox has its own loopback, so runs side by side do not share ports).
++ It catches what PGlite cannot (a pooled connection runs un-awaited work out of order). The shared node runs it on
++ the default branch, after a merge (`testPg: "main"`), so a pull request's verdict is not twice as slow; `all` runs it
++ everywhere once there are more machines. Services that do not start are reported, not counted.
++
Each run's description says where the time went: `Forge runner passed in 2m 10s (install 3s from the cache, tests
2m 4s)`.
ddiff --git a/runner/config.js b/runner/config.js
iindex 52d4ba8..4669760 100644
---- a/runner/config.js
++++ b/runner/config.js
@@@ -74,6 +74,8 @@ function loadConfig(env = process.env) {
testTimeoutScale: Math.min(10, Math.max(1, Number(raw.testTimeoutScale) || 1)),
// GitHub's security workflow, in the run (runner/security.js): the secret scan and the dependency audit.
secretScan: raw.secretScan !== false,
++ // The suite on PostgreSQL too (a repository's test:pg): 'off' (default), 'main' (after a merge) or 'all'.
++ testPg: ['off', 'main', 'all'].includes(raw.testPg) ? raw.testPg : 'off',
audit: raw.audit !== false,
// Host folders shown read-only in both phases (runner/sandbox.js safeRoBinds): the node shows /opt/google (Chrome).
roBinds: Array.isArray(raw.roBinds) ? raw.roBinds.map(String).slice(0, 20) : [],
ddiff --git a/runner/run.js b/runner/run.js
iindex dc2182c..bbba74e 100644
---- a/runner/run.js
++++ b/runner/run.js
@@@ -26,6 +26,16 @@ const git = (args, cwd, timeoutMs = 180_000) => new Promise((resolve, reject) =>
});
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
++// test:pg's phase: the repository's own service script, local binaries (no Docker in the sandbox), then the suite.
++const TEST_PG_SCRIPT = [
++ 'S=node_modules/openvibe-sdk/scripts/test-services.sh',
++ '[ -f "$S" ] || { echo "test:pg: no $S"; exit 98; }',
++ 'export OV_TEST_SERVICES=local',
++ 'ENVS=$(bash "$S" up) || { echo "test:pg: the services did not start"; exit 97; }',
++ 'eval "$ENVS"',
++ 'npm run test:pg',
++].join('\n');
++
const size = (bytes) => (bytes >= 1024 ** 3 ? `${(bytes / 1024 ** 3).toFixed(1)} GB` : `${Math.round(bytes / 1024 ** 2)} MB`);
const words = (ms) => {
const s = Math.max(0, Math.round(Number(ms) / 1000));
@@@ -62,6 +72,16 @@ async function cloneAt({ dir, cloneUrl, sha, branch, log, attempts = 24, waitMs
throw new Error(`the pushed commit never reached the mirror: ${last ? last.message : sha}`);
}
++/** Whether this run runs test:pg: the repository has the script, and testPg is 'all', or 'main' on its default branch. */
++function wantsTestPg(runDir, run, job, mode) {
++ if (!mode || mode === 'off') return false;
++ if (mode === 'main' && run.branch !== ((job.repo && job.repo.default_branch) || 'main')) return false;
++ try {
++ const pkg = JSON.parse(fs.readFileSync(path.join(runDir, 'package.json'), 'utf8'));
++ return !!(pkg.scripts && pkg.scripts['test:pg']);
++ } catch { return false; }
++}
++
function createRunner({ cfg, api, log = console, clock = Date.now }) {
const say = typeof log === 'function' ? log : (...args) => log.log(...args);
const engine = detectEngine(cfg.engine);
@@@ -267,7 +287,22 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {
if (!state) {
const t1 = clock();
const test = await phase('test', installScript(commands.test, { proxy: false }), null);
-- const timing = `install ${words(installMs)}${fromCache ? ' from the cache' : ''}, tests ${words(clock() - t1)}`;
++ const testMs = clock() - t1;
++ // The suite again on PostgreSQL + PgBouncer + Valkey (the repository's test:pg), started inside the sandbox
++ // by its own openvibe-sdk test-services.sh from the host's packages: what PGlite cannot show (a pooled
++ // connection runs un-awaited work out of order). On the runs testPg says (main: after a merge).
++ let pgNote = '';
++ if (!superseded && !test.timedOut && test.code === 0 && wantsTestPg(runDir, run, job, cfg.testPg)) {
++ const t2 = clock();
++ const pg = await phase('test-pg', installScript(TEST_PG_SCRIPT, { proxy: false }), null);
++ const pgMs = clock() - t2;
++ if (pg.timedOut) problems.push(`test:pg timed out after ${words(pgMs)}`);
++ else if (pg.code === 0) pgNote = `, test:pg ${words(pgMs)}`;
++ else if (pg.code === 98) onData('test:pg: no openvibe-sdk test-services.sh in this checkout; skipped\n');
++ else if (pg.code === 97) onData('test:pg: the local PostgreSQL, PgBouncer and Valkey did not start on this runner; not counted\n');
++ else problems.push(`test:pg failed (exit ${pg.code})`);
++ }
++ const timing = `install ${words(installMs)}${fromCache ? ' from the cache' : ''}, tests ${words(testMs)}${pgNote}`;
if (superseded) state = 'superseded';
else if (test.timedOut) { state = 'timed_out'; description = `Timed out after ${words(totalMs)}`; }
else if (test.code === 0 && !problems.length) { state = 'success'; description = `Forge runner passed in ${words(clock() - started)} (${timing})`; }
@@@ -311,4 +346,4 @@ function createRunner({ cfg, api, log = console, clock = Date.now }) {
return { engine, runJob, stop };
}
--module.exports = { createRunner, cloneAt, RELAY };
++module.exports = { createRunner, cloneAt, RELAY, wantsTestPg, TEST_PG_SCRIPT };
ddiff --git a/test/ci-test-pg.test.js b/test/ci-test-pg.test.js
nnew file mode 100644
iindex 0000000..57348ef
---- /dev/null
++++ b/test/ci-test-pg.test.js
@@@ -0,0 +1,47 @@
++'use strict';
++// The forge runs a repository's test:pg (the suite on PostgreSQL + PgBouncer + Valkey) when testPg says: 'all' runs,
++// 'main' only on the default branch (after a merge), 'off' never; only where package.json has the script. The phase
++// starts the services with the repository's own openvibe-sdk script, local binaries, no Docker (2026-11-19).
++const assert = require('assert');
++const fs = require('fs');
++const os = require('os');
++const path = require('path');
++const { wantsTestPg, TEST_PG_SCRIPT } = require('../runner/run');
++const { loadConfig } = require('../runner/config');
++
++const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ov-ci-pg-'));
++try {
++ const withPg = path.join(tmp, 'with');
++ const without = path.join(tmp, 'without');
++ fs.mkdirSync(withPg); fs.mkdirSync(without);
++ fs.writeFileSync(path.join(withPg, 'package.json'), JSON.stringify({ scripts: { test: 'node test/run.js', 'test:pg': 'X_TEST_STORE=pg node test/run.js' } }));
++ fs.writeFileSync(path.join(without, 'package.json'), JSON.stringify({ scripts: { test: 'node test/run.js' } }));
++ const job = { repo: { default_branch: 'main' } };
++ const main = { branch: 'main' };
++ const branch = { branch: 'feature' };
++ assert.strictEqual(wantsTestPg(withPg, main, job, 'main'), true, 'main, after a merge');
++ assert.strictEqual(wantsTestPg(withPg, branch, job, 'main'), false, 'not a pull request branch');
++ assert.strictEqual(wantsTestPg(withPg, branch, job, 'all'), true, 'every run with all');
++ assert.strictEqual(wantsTestPg(withPg, main, job, 'off'), false);
++ assert.strictEqual(wantsTestPg(without, main, job, 'all'), false, 'no test:pg script, nothing to run');
++ assert.strictEqual(wantsTestPg(withPg, { branch: 'trunk' }, { repo: { default_branch: 'trunk' } }, 'main'), true, 'the repository\'s own default branch');
++
++ assert.match(TEST_PG_SCRIPT, /node_modules\/openvibe-sdk\/scripts\/test-services\.sh/);
++ assert.match(TEST_PG_SCRIPT, /OV_TEST_SERVICES=local/, 'local binaries: the sandbox has no Docker');
++ assert.match(TEST_PG_SCRIPT, /exit 98/, 'no script: skipped');
++ assert.match(TEST_PG_SCRIPT, /exit 97/, 'services that do not start: the runner\'s problem, not counted');
++ assert.match(TEST_PG_SCRIPT, /npm run test:pg$/);
++
++ const token = path.join(tmp, 'token');
++ fs.writeFileSync(token, 'x'.repeat(40), { mode: 0o600 });
++ const conf = path.join(tmp, 'ci.json');
++ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token }));
++ assert.strictEqual(loadConfig({ GIT_CI_CONFIG: conf }).testPg, 'off', 'off by default');
++ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token, testPg: 'main' }));
++ assert.strictEqual(loadConfig({ GIT_CI_CONFIG: conf }).testPg, 'main');
++ fs.writeFileSync(conf, JSON.stringify({ tokenFile: token, testPg: 'sometimes' }));
++ assert.strictEqual(loadConfig({ GIT_CI_CONFIG: conf }).testPg, 'off', 'an unknown value is off');
++ console.log('ci-test-pg: when test:pg runs, its script and the configuration passed');
++} finally {
++ fs.rmSync(tmp, { recursive: true, force: true });
++}