/** * Reading the module roster for the health-coverage check. * * Split out from `health-coverage.ts` so that the decision — which modules * count as unobserved — stays pure and testable, while the query that feeds it * lives here. See Rule 2.3. */ import type { DbClient } from '../../db/client'; import { modules } from '../../db/schema'; import type { ModuleManifest } from '../../manifest/schema'; import { CONTROL_PLANE_MODULE_ID } from '../deployed-systems'; import { loadModuleHealthCadences } from './health-cadence'; import type { ModuleCoverageInput } from './health-coverage'; export function loadModuleCoverage(db: DbClient): ModuleCoverageInput[] { // Coverage now asks the same question the sweep asks — "what is this module's // effective cadence" — rather than "does an enabled monitor row exist". The // row's `enabled` column is `builtin_check`-only, so reading it here would // have reported a module as watched that the sweep had stopped scheduling. const cadences = loadModuleHealthCadences(db); return db .select({ id: modules.id, state: modules.state, manifestData: modules.manifestData }) .from(modules) .all() .map((module) => { const manifest = module.manifestData as ModuleManifest; return { id: module.id, state: module.state, // The control plane is verifiable without declaring a hook, and that // is the point rather than an exemption: celilo runs `runFleetChecks` // for it directly (`controlPlaneHealthChecks`), which asks eight // questions where its old hook asked two. The hook was deleted because // it could not answer them from inside the jail — it reported a // present database missing (celilo#1225). Reading only the manifest // here would raise a coverage warning about the best-observed module // in the fleet. hasHealthCheckHook: Boolean(manifest.hooks?.health_check) || module.id === CONTROL_PLANE_MODULE_ID, cadence: cadences.get(module.id)?.cadence ?? null, }; }); }