ShtukbaseStandard
package file→ .shtukbase/packages/testing/checks/coverage.ts

checks/coverage.ts

28 lines, 1.6 KB.

  1. // Sensor, not a check: the coverage of live risks — seriousness, covering tests, indicators that detect the risk and
  2. // the last measurement of each. `--serious` keeps only serious risks. Always exits 0.
  3. import { Project } from '../../collections/checks/lib/speclib.ts';
  4. import { addr, day, fld, live, refs } from '../../quality/checks/lib/qlib.ts';
  5. import { coveringTests, serious } from './t01_risk_covered.ts';
  6. const p = new Project(process.cwd());
  7. const onlySerious = process.argv.includes('--serious');
  8. const tests = coveringTests(p);
  9. const fDet = fld(p, 'IND', 'RISK', 'detects');
  10. const fInd = fld(p, 'MEAS', 'IND', 'indicator');
  11. const last = new Map<string, string>();
  12. for (const m of p.records('MEAS'))
  13. for (const i of refs(p, m, fInd, 'IND')) {
  14. const d = day(m.fm.date) ?? '';
  15. if (d >= (last.get(i)?.split(' ')[0] ?? '')) last.set(i, `${d} = ${m.fm.value}`);
  16. }
  17. const rows: string[] = [];
  18. let holes = 0;
  19. for (const r of p.records('RISK').filter((x) => live(p, x, 'RISK') && (!onlySerious || serious(x.fm)))) {
  20. const inds = p.records('IND').filter((i) => p.category(i, 'IND') !== 'dropped' && refs(p, i, fDet, 'RISK').includes(r.id));
  21. const t = tests.get(r.id) ?? [];
  22. const meas = inds.map((i) => `${p.label(i, 'IND')}${last.has(i.id) ? ` (${last.get(i.id)})` : ' (no measurement)'}`);
  23. if (!t.length && !inds.length) holes++;
  24. rows.push(`${serious(r.fm) ? '!' : ' '} ${addr(r.id)} | tests: ${t.join(', ') || '—'} | indicators: ${meas.join(', ') || '—'}${r.fm.decision ? ' | decision' : ''}`);
  25. }
  26. console.log(rows.length ? rows.join('\n') : 'no live risks');
  27. console.log(`risks: ${rows.length}, without tests and indicators: ${holes} (! — serious)`);