файл пакета→ .shtukbase/packages/quality/checks/q02_indicator_fresh.ts
checks/q02_indicator_fresh.ts
32 строки, 1.9 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // QLT-R02. An indicator in «measuring» has a baseline, a last value and the date of the last measurement, and that
- // date is not older than two periods of its cadence (nightly — 1 day, weekly — 7 days); per-change and milestone
- // cadences have no fixed period and are not checked for age. Today is QUALITY_TODAY or the system date.
- import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
- import { main } from '../../collections/checks/lib/runner.ts';
- import { addr, day, daysBetween, has, missing, state, today } from './lib/qlib.ts';
- export const RULE = { id: 'qlt-r02', title: '"Measuring" has a baseline and a fresh measurement', scope: 'indicators in the state "Measuring"' };
- const PERIOD: Record<string, number> = { nightly: 1, weekly: 7 };
- export function check(p: Project, res: Result): void {
- const reason = p.need('IND');
- if (!res.part('indicators', reason)) return;
- const now = today();
- const recs = p.records('IND').filter((r) => state(r) === 'measuring');
- res.scope = recs.map((r) => addr(r.id));
- for (const r of recs) {
- const a = addr(r.id), name = p.label(r, 'IND');
- const gap = missing(r, ['baseline', 'current', 'lastMeasured']);
- if (gap.length) {
- res.hole(a, `${name}: "Measuring" without ${gap.join(', ')}`, 'write the baseline and the last counted measurement or return it to "Instrumented"', 'no-baseline');
- continue;
- }
- const last = day(r.fm.lastMeasured);
- const period = PERIOD[String(r.fm.cadence ?? '')];
- if (!last) res.hole(a, `${name}: lastMeasured is not a date`, 'write a date YYYY-MM-DD', 'bad-date');
- else if (period && has(r, 'cadence') && daysBetween(last, now) > 2 * period)
- res.hole(a, `${name}: gone stale — the last measurement ${last}, but it must be measured ${r.fm.cadence}`, 'make a new measurement or return the indicator to "Instrumented"', 'stale');
- }
- }
- if (import.meta.main) main({ RULE, check });