openvibers/openvibe.report Commits

Readiness reads the store it is given: the db check said 'store is not defined' (#75)

OP OpenVibers committed 12 days ago · 1083df0b8e · 2 files, +28 −1

app.js passed { store } to createServiceReadiness, which took no store, so
the db check threw a ReferenceError and openvibe.report answered degraded
with a working database (found 2026-11-02).

Changes

ddiff --git a/server/observability.js b/server/observability.js
iindex f8a578c..a029f18 100644
---- a/server/observability.js
++++ b/server/observability.js
@@@ -14,7 +14,7 @@
*/
const { createReadiness } = require('openvibe-shared/ready');
--function createServiceReadiness({ config, fetchImpl = globalThis.fetch, release = null }) {
++function createServiceReadiness({ config, fetchImpl = globalThis.fetch, release = null, store = null }) {
const healthOf = (name, origin) => ({
name,
required: false,
ddiff --git a/test/ready-db.test.js b/test/ready-db.test.js
nnew file mode 100644
iindex 0000000..72777e3
---- /dev/null
++++ b/test/ready-db.test.js
@@@ -0,0 +1,27 @@
++'use strict';
++/**
++ * The readiness `db` check reads the store app.js hands it. createServiceReadiness took no `store`, so the check threw
++ * "store is not defined" and openvibe.report answered degraded with a working database (2026-11-02).
++ *
++ * node test/ready-db.test.js
++ */
++const assert = require('assert');
++const { createServiceReadiness } = require('../server/observability');
++
++(async () => {
++ const config = { db: { url: 'postgres://report' }, source: 'shadow', networkUrl: 'http://127.0.0.1:1', liveUrl: 'http://127.0.0.1:1' };
++ const fetchImpl = async () => new Response(JSON.stringify({ ok: true }), { status: 200, headers: { 'content-type': 'application/json' } });
++ const run = async (store) => {
++ const r = createServiceReadiness({ config, fetchImpl, release: 'test', store });
++ const body = typeof r.run === 'function' ? await r.run() : await r.check();
++ return body.checks.db;
++ };
++ const ok = await run({ db: { value: async () => 1 } });
++ assert.strictEqual(ok.status, 'ok', JSON.stringify(ok));
++ const down = await run({ db: { value: async () => { throw new Error('connection refused'); } } });
++ assert.notStrictEqual(down.status, 'ok');
++ assert.match(String(down.error), /database did not answer: connection refused/);
++ const none = await run(null);
++ assert.match(String(none.error), /no database handle/);
++ console.log('ready db: the check reads the store it is given');
++})().catch((err) => { console.error(err); process.exit(1); });