包文件→ .shtukbase/packages/testing/checks/t01_risk_covered.ts
checks/t01_risk_covered.ts
38 行, 2.0 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // QTS-R01. A serious live risk (impact 4–5, or likelihood × impact ≥ 12; state category arriving or working) is
- // covered by a test of the quality tests in «pending» or «active» (category working or done) whose `risks` names
- // it, or by a decision about the risk (`decision`). Without the risks collection the norm holds.
- import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
- import { main } from '../../collections/checks/lib/runner.ts';
- import { addr, fld, has, live, num, refs } from '../../quality/checks/lib/qlib.ts';
- 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"' };
- /** Impact 4–5, or likelihood × impact ≥ 12. */
- export function serious(fm: Record<string, unknown>): boolean {
- const l = num(fm.likelihood) ?? 0, i = num(fm.impact) ?? 0;
- return i >= 4 || l * i >= 12;
- }
- /** Risk path → the codes of the tests that cover it (pending or active). */
- export function coveringTests(p: Project): Map<string, string[]> {
- const out = new Map<string, string[]>();
- const f = fld(p, 'QTEST', 'RISK', 'risks');
- for (const t of p.records('QTEST')) {
- if (!['working', 'done'].includes(p.category(t, 'QTEST') ?? '')) continue;
- for (const r of refs(p, t, f, 'RISK')) out.set(r, [...(out.get(r) ?? []), p.label(t, 'QTEST')]);
- }
- return out;
- }
- export function check(p: Project, res: Result): void {
- if (!res.part('risks', p.need('RISK'))) return;
- const risks = p.records('RISK').filter((r) => live(p, r, 'RISK') && serious(r.fm));
- res.scope = risks.map((r) => addr(r.id));
- const tests = coveringTests(p);
- for (const r of risks)
- if (!tests.has(r.id) && !has(r, 'decision'))
- 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`,
- 'create a quality test with risks pointing to this risk or record a decision about the risk (decision)', 'uncovered');
- }
- if (import.meta.main) main({ RULE, check });