risk-nexus/tools/coverage.py
tegwick a05ca6822b RISK-WP-0005 finished: the seven gaps closed
T01 fix tracking now reads the owner's workplan file and found two
findings the register should have known about. T02 incident and external
report intake, the latter routed since the address is not ours to create.
T03 the production transition defined by what is held rather than what
was announced. T04 the README stops claiming a surface. T05 escalation
carries a delivery state and is raised once when unacknowledged. T06
checked_by and a heartbeat, so a 1q rung cannot silently mean nobody
looked. T07 coverage: 7 of 117 repos have ever appeared in a finding.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 08:34:30 +02:00

65 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""What has never been looked at.
RISK-WP-0005-T07, deliberately minimal. The register knows what was reported.
Without this it has no view of what was never assessed, so a system with zero
findings is indistinguishable from a system nobody has examined — while
RISK-N-0003 records that every repo which *has* examined its own boundary this
month found a defect.
This does not assess anything and does not grade anyone. It counts.
"""
from __future__ import annotations
import json
import urllib.error
import urllib.request
import register_lib as lib
HUB = "http://127.0.0.1:8000/repos/"
def repos() -> list[dict] | None:
for url in (HUB, "http://127.0.0.1:8000/repos"):
try:
with urllib.request.urlopen(url, timeout=8) as r:
data = json.load(r)
return data if isinstance(data, list) else data.get("items", [])
except (urllib.error.URLError, TimeoutError, json.JSONDecodeError, OSError):
continue
return None
def main() -> int:
all_repos = repos()
seen: dict[str, list[str]] = {}
for f in lib.findings():
for key in (f.get("system"), f.get("fix_owner"), f.get("reported_by")):
if key and isinstance(key, str):
seen.setdefault(key, []).append(f["id"])
print("Coverage — what the register has heard from\n")
print(f" systems that have produced or carried a finding: {len(seen)}")
for name in sorted(seen):
print(f" {name}: {', '.join(sorted(set(seen[name])))}")
if all_repos is None:
print("\n Hub unreachable — the denominator is unknown, which is the whole point of this report.")
return 0
names = {r.get("slug") for r in all_repos if r.get("slug")}
unheard = sorted(names - set(seen))
print(f"\n registered repos: {len(names)}")
print(f" never appeared in any finding: {len(unheard)}")
print("\n A repo in that list has either nothing wrong with it or nobody looking.")
print(" This register cannot tell which, and does not guess.\n")
for name in unheard[:40]:
print(f" {name}")
if len(unheard) > 40:
print(f" … and {len(unheard) - 40} more")
return 0
if __name__ == "__main__":
raise SystemExit(main())