/** * The control plane's health check (celilo#1225). * * The mapping is what these pin. The failure that made this code exist was not * a wrong assertion — the hook's `existsSync(db_path)` was a perfectly correct * question — it was a correct question asked from inside a jail that does not * bind the directory, so a present database read as absent. Nothing in a unit * test can catch that shape; what a unit test CAN hold is that every finding * reaches the operator with its status and its remediation intact, because the * unattended path is the one nobody is watching. */ import { describe, expect, test } from 'bun:test'; import { findingAsHealthCheck } from './control-plane-health'; import type { FleetFinding } from './fleet-checks'; function finding(over: Partial = {}): FleetFinding { return { id: 'dispatcher', title: 'Event dispatcher', status: 'ok', summary: 'a dispatcher is live', detail: [], remediation: null, autoFixable: false, ...over, }; } describe('findingAsHealthCheck', () => { test("ok becomes pass — celilo's vocabulary is not the health path's", () => { expect(findingAsHealthCheck(finding({ status: 'ok' })).status).toBe('pass'); expect(findingAsHealthCheck(finding({ status: 'warn' })).status).toBe('warn'); expect(findingAsHealthCheck(finding({ status: 'fail' })).status).toBe('fail'); }); test('the check is named by the finding id, so an operator can grep for it', () => { const item = findingAsHealthCheck(finding({ id: 'schema_drift' })); expect(item.name).toBe('schema_drift'); expect(item.message).toBe('a dispatcher is live'); }); test('the remediation survives the mapping', () => { // This is the line that tells an operator what to DO, and the health path // is the one that runs unattended every fifteen minutes. Dropping it here // would leave a failing check with no next step, quietly. const item = findingAsHealthCheck( finding({ status: 'fail', detail: ['no live dispatcher — heartbeat absent'], remediation: 'systemctl enable --now celilo-events.service', }), ); expect(item.details).toContain('no live dispatcher — heartbeat absent'); expect(item.details).toContain('Fix: systemctl enable --now celilo-events.service'); }); test('a healthy finding carries no empty details field', () => { expect(findingAsHealthCheck(finding()).details).toBeUndefined(); }); test('detail lines survive without a remediation', () => { const item = findingAsHealthCheck(finding({ status: 'warn', detail: ['two dispatchers'] })); expect(item.details).toBe('two dispatchers'); }); });