package file→ .shtukbase/packages/testing/checks/coverage.ts
checks/coverage.ts
28 lines, 1.6 KB.
- // Sensor, not a check: the coverage of live risks — seriousness, covering tests, indicators that detect the risk and
- // the last measurement of each. `--serious` keeps only serious risks. Always exits 0.
- import { Project } from '../../collections/checks/lib/speclib.ts';
- import { addr, day, fld, live, refs } from '../../quality/checks/lib/qlib.ts';
- import { coveringTests, serious } from './t01_risk_covered.ts';
- const p = new Project(process.cwd());
- const onlySerious = process.argv.includes('--serious');
- const tests = coveringTests(p);
- const fDet = fld(p, 'IND', 'RISK', 'detects');
- const fInd = fld(p, 'MEAS', 'IND', 'indicator');
- const last = new Map<string, string>();
- for (const m of p.records('MEAS'))
- for (const i of refs(p, m, fInd, 'IND')) {
- const d = day(m.fm.date) ?? '';
- if (d >= (last.get(i)?.split(' ')[0] ?? '')) last.set(i, `${d} = ${m.fm.value}`);
- }
- const rows: string[] = [];
- let holes = 0;
- for (const r of p.records('RISK').filter((x) => live(p, x, 'RISK') && (!onlySerious || serious(x.fm)))) {
- const inds = p.records('IND').filter((i) => p.category(i, 'IND') !== 'dropped' && refs(p, i, fDet, 'RISK').includes(r.id));
- const t = tests.get(r.id) ?? [];
- const meas = inds.map((i) => `${p.label(i, 'IND')}${last.has(i.id) ? ` (${last.get(i.id)})` : ' (no measurement)'}`);
- if (!t.length && !inds.length) holes++;
- rows.push(`${serious(r.fm) ? '!' : ' '} ${addr(r.id)} | tests: ${t.join(', ') || '—'} | indicators: ${meas.join(', ') || '—'}${r.fm.decision ? ' | decision' : ''}`);
- }
- console.log(rows.length ? rows.join('\n') : 'no live risks');
- console.log(`risks: ${rows.length}, without tests and indicators: ${holes} (! — serious)`);