Coverage for src/governed_harness/metrics/summary.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-12 16:06 +0000

1"""The overall status of the period shown at the top of the HTML report. 

2 

3The rule is explicit and deterministic: it reads only numbers the report already holds and 

4compares each with zero. It is an aid to read the report, never a quality certification: it 

5says nothing about the code, only that no run of the period shows one of the four signals 

6below (see ``docs/es/reporte-de-metricas.md``).""" 

7 

8from __future__ import annotations 

9 

10from typing import Any 

11 

12STATUS_CLEAR = "CLEAR" 

13STATUS_ATTENTION = "ATTENTION" 

14STATUS_NO_DATA = "NO_DATA" 

15 

16# (condition id, label, where the count comes from) 

17CONDITIONS: tuple[tuple[str, str], ...] = ( 

18 ("blockedRuns", "Runs stopped (blocked outside a decision)"), 

19 ("rejectedRuns", "Runs rejected by a person"), 

20 ("openBlockingFindings", "HIGH or CRITICAL findings in runs that did not close"), 

21 ("openFailedGates", "Runs that did not close whose latest gate failed"), 

22) 

23 

24 

25def period_status(counts: dict[str, int], runs: int) -> dict[str, Any]: 

26 """``NO_DATA`` without runs; ``ATTENTION`` when any condition count is above zero; 

27 ``CLEAR`` otherwise. Each condition is reported with its count so the reader sees why.""" 

28 conditions = [ 

29 {"id": key, "label": label, "count": counts[key], "met": counts[key] == 0} 

30 for key, label in CONDITIONS 

31 ] 

32 if runs == 0: 

33 status = STATUS_NO_DATA 

34 elif all(item["met"] for item in conditions): 

35 status = STATUS_CLEAR 

36 else: 

37 status = STATUS_ATTENTION 

38 return { 

39 "status": status, 

40 "rule": ( 

41 "ATTENTION when any condition count is above zero, CLEAR when all are zero, " 

42 "NO_DATA without runs. Derived from the records of the period only; not a " 

43 "quality certification." 

44 ), 

45 "conditions": conditions, 

46 "waitingDecision": counts.get("waitingDecision", 0), 

47 } 

48 

49 

50__all__ = ["CONDITIONS", "STATUS_ATTENTION", "STATUS_CLEAR", "STATUS_NO_DATA", "period_status"]