ShtukbaseStandard
包文件→ .shtukbase/packages/testing/checks/t01_risk_covered.ts

checks/t01_risk_covered.ts

38 行, 2.0 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // QTS-R01. A serious live risk (impact 4–5, or likelihood × impact ≥ 12; state category arriving or working) is
  2. // covered by a test of the quality tests in «pending» or «active» (category working or done) whose `risks` names
  3. // it, or by a decision about the risk (`decision`). Without the risks collection the norm holds.
  4. import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
  5. import { main } from '../../collections/checks/lib/runner.ts';
  6. import { addr, fld, has, live, num, refs } from '../../quality/checks/lib/qlib.ts';
  7. export const RULE = { id: 'qts-r01', title: 'A serious risk is covered by a test or a decision', scope: 'serious risks in "Open" and "Mitigated"' };
  8. /** Impact 4–5, or likelihood × impact ≥ 12. */
  9. export function serious(fm: Record<string, unknown>): boolean {
  10. const l = num(fm.likelihood) ?? 0, i = num(fm.impact) ?? 0;
  11. return i >= 4 || l * i >= 12;
  12. }
  13. /** Risk path → the codes of the tests that cover it (pending or active). */
  14. export function coveringTests(p: Project): Map<string, string[]> {
  15. const out = new Map<string, string[]>();
  16. const f = fld(p, 'QTEST', 'RISK', 'risks');
  17. for (const t of p.records('QTEST')) {
  18. if (!['working', 'done'].includes(p.category(t, 'QTEST') ?? '')) continue;
  19. for (const r of refs(p, t, f, 'RISK')) out.set(r, [...(out.get(r) ?? []), p.label(t, 'QTEST')]);
  20. }
  21. return out;
  22. }
  23. export function check(p: Project, res: Result): void {
  24. if (!res.part('risks', p.need('RISK'))) return;
  25. const risks = p.records('RISK').filter((r) => live(p, r, 'RISK') && serious(r.fm));
  26. res.scope = risks.map((r) => addr(r.id));
  27. const tests = coveringTests(p);
  28. for (const r of risks)
  29. if (!tests.has(r.id) && !has(r, 'decision'))
  30. res.hole(addr(r.id), `${p.label(r, 'RISK')}: a serious risk (likelihood ${r.fm.likelihood ?? '?'}, impact ${r.fm.impact ?? '?'}) is not covered by a test`,
  31. 'create a quality test with risks pointing to this risk or record a decision about the risk (decision)', 'uncovered');
  32. }
  33. if (import.meta.main) main({ RULE, check });