/** * Health-coverage's view of the control plane (celilo#1225). * * `celilo-mgmt` declares no `health_check` hook, and that is deliberate: celilo * runs `runFleetChecks` for it directly, which asks eight questions where the * hook asked two. The hook was deleted because it could not answer them from * inside the jail — it reported a present database missing and failed the * deploy. * * Without the carve-out here, the module best observed by celilo would be the * one celilo warns is unobservable. That warning would be both false and * unfixable, since the fix it names — add a health_check hook — is the thing * that was removed on purpose. */ import { afterEach, beforeEach, describe, expect, test } from 'bun:test'; import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import type { DbClient } from '../../db/client'; import { modules } from '../../db/schema'; import { setupTestDatabaseAt } from '../../test-utils/database'; import { resetTestDbPath } from '../../test-utils/db-path'; import { CONTROL_PLANE_MODULE_ID } from '../deployed-systems'; import { loadModuleCoverage } from './coverage-source'; import { healthCoverageFailingKeys } from './health-coverage'; describe('health coverage and the control plane', () => { let dir: string; let db: DbClient; beforeEach(async () => { dir = mkdtempSync(join(tmpdir(), 'cov-')); const dbPath = join(dir, 'celilo.db'); process.env.CELILO_DB_PATH = dbPath; db = await setupTestDatabaseAt(dbPath); }); afterEach(() => { db.$client.close(); resetTestDbPath(); try { rmSync(dir, { recursive: true, force: true }); } catch { /* ignore */ } }); function installModule(id: string, manifestData: Record): void { db.insert(modules) .values({ id, name: id, version: '1.0.0', state: 'INSTALLED', sourcePath: `/modules/${id}`, manifestData, }) .run(); } test('the control plane counts as verifiable despite declaring no hook', () => { installModule(CONTROL_PLANE_MODULE_ID, { id: CONTROL_PLANE_MODULE_ID, hooks: {} }); const coverage = loadModuleCoverage(db); const controlPlane = coverage.find((m) => m.id === CONTROL_PLANE_MODULE_ID); expect(controlPlane?.hasHealthCheckHook).toBe(true); // The finding that must NOT be raised — the one whose remedy is to add // back the hook this change deleted. const failing = healthCoverageFailingKeys(coverage); const neverVerified = failing.filter((f) => f.message.includes('can never be verified')); expect(neverVerified).toHaveLength(0); }); test('an ordinary module with no hook is still reported unobservable', () => { // The carve-out is for the control plane alone. If it leaked to every // module, the check would stop finding anything and look healthy. installModule('homebridge', { id: 'homebridge', hooks: {} }); const failing = healthCoverageFailingKeys(loadModuleCoverage(db)); const messages = failing.map((f) => f.message); expect( messages.some((m) => m.includes('homebridge') && m.includes('can never be verified')), ).toBe(true); }); });