fix: one attention verdict on the profile report

check_freshness rebuilt the profile_sync verdict from single JSON keys and
dropped version_warning, version_unread and detection_skipped: a core_version
behind its pin and a refused detection both read OK. ProfileReport.attention()
now gives every reason with its level, report_to_dict serializes it, freshness
maps the levels, and --strict names the kinds it fails on.
This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent e146a8f349
commit 5cce11e7d0
5 files changed
+238 -90

No files matched your search

+52 -52
View File
@@ -80,15 +80,56 @@ def check_profiles(run: bool, offline: bool) -> list[Finding]:
return summarize_profile_sync(report)
_LEVELS = {"stale": STALE, "unknown": UNKNOWN}
def _verdict(row: dict) -> tuple[str | None, list[str]]:
"""The status profile_sync's attention reasons give a row, and their details.
The reasons are decided once, on the report: a stale one makes the row
stale, an unreadable one unknown, and a note says something without
asking anything.
"""
reasons = [r for r in row.get("attention") or () if isinstance(r, dict)]
levels = {_LEVELS.get(str(r.get("level"))) for r in reasons}
status = STALE if STALE in levels else UNKNOWN if UNKNOWN in levels else None
asking = [str(r.get("detail") or "") for r in reasons if str(r.get("level")) in _LEVELS]
notes = [str(r.get("detail") or "") for r in reasons if str(r.get("level")) not in _LEVELS]
return status, asking or notes
def _skipped_finding(name: str, row: dict) -> Finding:
"""A profile profile_sync could not compare: its release page, or the skip.
A skip profile_sync counts as a defect (no repository answers, no
resolvable pin) is unknown. One that is the profile's nature (an upstream
declared gone, a host no forge API serves, no source_ref) is never
checkable and does not hold the exit code.
"""
status, details = _verdict(row)
reason = str(row["skipped"])
declared = str(row.get("declared_version") or "")
if row.get("page_version"):
return Finding("profiles", name, status or OK, local=declared,
remote=str(row["page_version"]), detail=", ".join(details))
if row.get("page_version_unread"):
return Finding("profiles", name, status or UNKNOWN, local=declared,
detail=", ".join(details))
if status is None:
return Finding("profiles", name, SKIPPED, detail=reason)
if reason not in details:
details.insert(0, reason)
return Finding("profiles", name, status, detail=", ".join(details))
def summarize_profile_sync(report: object) -> list[Finding]:
"""One row per profile with something to look at, from profile_sync's JSON.
The JSON carries the ref verdicts and the pin against the tip. A profile
whose refs need review is stale, one the forge could not serve is unknown,
and one whose upstream moved while every ref still anchors is reported as
such without being counted as stale. A cited file that gained a file name
since the pin, or a hash the profile does not declare, is stale too: the
upstream may load a file the profile does not document.
Each row carries the report's attention reasons: refs to review, a
version behind its code, a file name or hash the cited code gained since
the pin, a check the forge refused. A stale reason makes the profile
stale, an unreadable one unknown, and one whose upstream moved while
nothing asks for attention is counted as such without being stale.
"""
if not isinstance(report, list):
return [Finding("profiles", "profile_sync", ERROR, detail="report is not a list")]
@@ -98,61 +139,20 @@ def summarize_profile_sync(report: object) -> list[Finding]:
if not isinstance(row, dict):
continue
name = str(row.get("name") or "?")
if row.get("skipped") and row.get("page_version"):
# Off any forge, the release page is the feed: a version there
# beyond the declared one is a release the profile does not cover.
declared, announced = str(row.get("declared_version") or ""), str(row["page_version"])
if announced == declared:
status, detail = OK, ""
elif announced == str(row.get("no_genuine_copy") or ""):
# Searched for and found only rebuilt: the profile covers the
# newest build that can be read, until the page moves on.
status, detail = OK, "no genuine copy of the announced release"
else:
status, detail = STALE, "a newer release is announced"
findings.append(Finding("profiles", name, status, local=declared,
remote=announced, detail=detail))
continue
if row.get("skipped") and row.get("page_version_unread"):
# The release page is the only feed this profile has: unread, a
# new release cannot be told from none, so the row is unknown.
findings.append(Finding("profiles", name, UNKNOWN,
local=str(row.get("declared_version") or ""),
detail=f"version page unread: {row['page_version_unread']}"))
continue
if row.get("skipped"):
# A skip profile_sync counts as a defect (no repository answers,
# no resolvable pin) is unknown. One that is the profile's nature
# (an upstream declared gone, a host no forge API serves, no
# source_ref) is never checkable and does not hold the exit code.
from profiling.reports import ProfileReport
reason = str(row["skipped"])
status = UNKNOWN if reason.startswith(ProfileReport.UNCHECKABLE) else SKIPPED
findings.append(Finding("profiles", name, status, detail=reason))
findings.append(_skipped_finding(name, row))
continue
review = row.get("needs_review") or 0
pin, head = str(row.get("pin") or ""), str(row.get("head") or "")
added = sorted({
str(item.get("name"))
for item in row.get("new_files") or ()
if isinstance(item, dict) and item.get("since_pin")
})
hashes = len(row.get("new_hashes") or ())
reasons = [f"{review} refs to review"] if review else []
if added:
reasons.append(f"new file names since the pin: {', '.join(added)}")
if hashes:
reasons.append(f"{hashes} undeclared hashes added since the pin")
if reasons:
status, details = _verdict(row)
if status is not None:
findings.append(
Finding(
"profiles",
name,
STALE,
status,
local=pin[:8],
remote=head[:8],
detail=", ".join(reasons),
detail=", ".join(details),
)
)
elif pin and head and pin != head:
+2 -3
View File
@@ -22,6 +22,7 @@ from profiling import quota, selection
from profiling.bump import DEFAULT_CACHE
from profiling.flagchecks import refuse_flag_combinations
from profiling.realignpass import run_realign
from profiling.reports import STRICT_KINDS
from profiling.run import emit_reports, read_selected
from profiling.sourcepaths import refresh_source_paths
from profiling.versioncheck import run_versions
@@ -217,9 +218,7 @@ def main() -> None:
refresh_source_paths(args, written)
if not complete:
raise SystemExit(130)
if failed or (args.strict and any(
report.needs_review() or report.uncheckable() for report in reports
)):
if failed or (args.strict and any(report.fails(STRICT_KINDS) for report in reports)):
raise SystemExit(1)
+89
View File
@@ -38,6 +38,26 @@ class CitedSource:
return self.pin != self.head and not self.own_revision
# The reasons profile_sync --strict fails on: a ref or pin to look at again,
# and a profile that cannot be checked as written.
STRICT_KINDS = frozenset({"review", "uncheckable"})
# Levels of an attention reason: the profile is behind its upstream, it
# could not be read in full, or a remark that asks nothing.
STALE_LEVEL = "stale"
UNKNOWN_LEVEL = "unknown"
NOTE_LEVEL = "note"
@dataclass(frozen=True)
class Attention:
"""One reason to look at a profile again, with its level."""
kind: str
level: str
detail: str
@dataclass
class ProfileReport:
name: str
@@ -140,6 +160,74 @@ class ProfileReport:
+ sum(1 for ref in self.build_refs if ref["status"] != "BUILD_OK")
)
def attention(self) -> list[Attention]:
"""Every reason the pass gives to look at this profile again.
The one verdict its consumers read: check_freshness maps the levels
to its statuses, and --strict picks the kinds that fail a run. A
profile skipped for want of a source_ref still has its revisions
read, so an orphaned pin or a version warning stands beside the skip.
"""
reasons = self._skip_attention() if self.skipped else []
review = self.needs_review()
if review:
reasons.append(Attention("review", STALE_LEVEL, f"{review} refs to review"))
added = sorted({
str(item.get("name")) for item in self.new_files or () if item.get("since_pin")
})
if added:
reasons.append(Attention(
"new_files", STALE_LEVEL, f"new file names since the pin: {', '.join(added)}"
))
if self.new_hashes:
reasons.append(Attention(
"new_hashes", STALE_LEVEL,
f"{len(self.new_hashes)} undeclared hashes added since the pin",
))
if self.version_warning:
reasons.append(Attention("version", STALE_LEVEL, self.version_warning))
if self.version_unread:
reasons.append(Attention("version_unread", UNKNOWN_LEVEL, self.version_unread))
if self.detection_skipped:
reasons.append(Attention(
"detection_skipped", UNKNOWN_LEVEL,
f"new file and hash detection unread: {self.detection_skipped}",
))
return reasons
def _skip_attention(self) -> list[Attention]:
"""A skipped profile: a skip that is a defect, then its release page."""
reasons = []
if self.uncheckable():
reasons.append(Attention("uncheckable", UNKNOWN_LEVEL, self.skipped or ""))
if self.page_version:
# Off any forge, the release page is the feed: a version there
# beyond the declared one is a release the profile does not cover.
if self.page_version == (self.declared_version or ""):
return reasons
if self.page_version == self.no_genuine_copy:
# Searched for and found only rebuilt: the profile covers the
# newest build that can be read, until the page moves on.
reasons.append(Attention(
"no_genuine_copy", NOTE_LEVEL, "no genuine copy of the announced release"
))
return reasons
reasons.append(
Attention("page_version", STALE_LEVEL, "a newer release is announced")
)
elif self.page_version_unread:
# The page is the only feed: unread, a new release cannot be told
# from none.
reasons.append(Attention(
"page_version_unread", UNKNOWN_LEVEL,
f"version page unread: {self.page_version_unread}",
))
return reasons
def fails(self, kinds: frozenset[str]) -> bool:
"""Whether a reason of one of ``kinds`` stands on this profile."""
return any(reason.kind in kinds for reason in self.attention())
def triage_state(report: ProfileReport) -> str:
"""One triage line: what to review, the pin to set again named first.
@@ -322,6 +410,7 @@ def report_to_dict(report: ProfileReport) -> dict:
payload = asdict(report)
del payload["cited_sources"]
payload["needs_review"] = report.needs_review()
payload["attention"] = [asdict(reason) for reason in report.attention()]
return payload
+75 -35
View File
@@ -67,6 +67,7 @@ from freshness.targets import (
from model.registry import load_platform_registry
from model.safeparse import yaml_load
from model.targets import platform_overrides
from profiling.reports import ProfileReport, report_to_dict
from scripts.scraper import game_dat_importer
from tests.sources import SCRIPTS
@@ -591,15 +592,20 @@ class CatalogParsingTests(unittest.TestCase):
self.assertEqual(mame_versions(recipes), ["mame0250", "mame0289"])
def _rows(*reports: ProfileReport) -> list[dict]:
"""The JSON rows profile_sync --json writes for these reports."""
return [report_to_dict(report) for report in reports]
class ProfileSummaryTests(unittest.TestCase):
def test_summary_separates_review_moved_and_unreachable(self):
report = [
{"name": "a", "pin": "1" * 40, "head": "1" * 40, "needs_review": 0},
{"name": "b", "pin": "1" * 40, "head": "2" * 40, "needs_review": 0},
{"name": "c", "pin": "1" * 40, "head": "2" * 40, "needs_review": 3},
{"name": "d", "skipped": "no declared repository answers"},
{"name": "e", "skipped": "upstream gone (declared): archived 2019"},
]
report = _rows(
ProfileReport("a", pin="1" * 40, head="1" * 40),
ProfileReport("b", pin="1" * 40, head="2" * 40),
ProfileReport("c", pin="1" * 40, head="2" * 40, counts={"CHANGED": 3}),
ProfileReport("d", skipped="no declared repository answers"),
ProfileReport("e", skipped="upstream gone (declared): archived 2019"),
)
findings = summarize_profile_sync(report)
by_subject = {f.subject: f for f in findings}
self.assertEqual(by_subject["profile_sync"].status, STALE)
@@ -614,19 +620,17 @@ class ProfileSummaryTests(unittest.TestCase):
def test_new_upstream_names_and_hashes_are_stale(self):
"""A file name the cited code gained since the pin, or a hash nobody
declares, was printed only by the text pass that --profiles never ran."""
report = [
{"name": "a", "pin": "1" * 40, "head": "2" * 40, "needs_review": 0,
"new_files": [
{"path": "x.c", "line": 4, "name": "old.rom", "since_pin": False},
{"path": "x.c", "line": 9, "name": "new.rom", "since_pin": True},
], "new_hashes": []},
{"name": "b", "pin": "1" * 40, "head": "2" * 40, "needs_review": 0,
"new_files": [], "new_hashes": [{"path": "x.c", "kind": "md5", "value": "0" * 32}]},
{"name": "c", "pin": "1" * 40, "head": "2" * 40, "needs_review": 0,
"new_files": [
{"path": "x.c", "line": 4, "name": "old.rom", "since_pin": False},
], "new_hashes": []},
]
report = _rows(
ProfileReport("a", pin="1" * 40, head="2" * 40, new_files=[
{"path": "x.c", "line": 4, "name": "old.rom", "since_pin": False},
{"path": "x.c", "line": 9, "name": "new.rom", "since_pin": True},
], new_hashes=[]),
ProfileReport("b", pin="1" * 40, head="2" * 40, new_files=[],
new_hashes=[{"path": "x.c", "kind": "md5", "value": "0" * 32}]),
ProfileReport("c", pin="1" * 40, head="2" * 40, new_files=[
{"path": "x.c", "line": 4, "name": "old.rom", "since_pin": False},
], new_hashes=[]),
)
by_subject = {f.subject: f for f in summarize_profile_sync(report)}
self.assertEqual(by_subject["a"].status, STALE)
self.assertIn("new.rom", by_subject["a"].detail)
@@ -634,6 +638,42 @@ class ProfileSummaryTests(unittest.TestCase):
self.assertEqual(by_subject["b"].status, STALE)
self.assertNotIn("c", by_subject)
def test_a_version_behind_its_code_is_stale(self):
"""version_warning was on the report and --profiles passed
--check-version, yet a core_version older than its pin read OK."""
warning = ("core_version 1.0 is older than the code: "
"the pin aaaaaaa already contains release 1.1")
rows = _rows(ProfileReport("x", pin="a" * 40, head="a" * 40,
version_warning=warning))
overall, row = summarize_profile_sync(rows)
self.assertEqual(overall.status, STALE)
self.assertEqual((row.status, row.detail), (STALE, warning))
def test_a_refused_detection_or_version_check_is_unknown(self):
"""A detection the forge refused read as "nothing gained": OK."""
rows = _rows(
ProfileReport("x", pin="a" * 40, head="a" * 40, new_files=None,
new_hashes=None, detection_skipped="403 forbidden"),
ProfileReport("y", pin="a" * 40, head="a" * 40,
version_unread="version check skipped: 403 forbidden"),
)
overall, x, y = summarize_profile_sync(rows)
self.assertEqual(overall.status, OK)
self.assertEqual(x.status, UNKNOWN)
self.assertIn("403 forbidden", x.detail)
self.assertEqual((y.status, y.detail),
(UNKNOWN, "version check skipped: 403 forbidden"))
def test_a_profile_without_refs_still_reports_its_pin(self):
"""A profile skipped for want of a source_ref has its revisions
read: an orphaned pin there is as stale as anywhere."""
rows = _rows(ProfileReport("x", pin="a" * 40, head="b" * 40,
skipped="no source_ref",
orphaned=["o/r: pin aaaaaaaa is no ancestor of bbbbbbbb"]))
_, row = summarize_profile_sync(rows)
self.assertEqual(row.status, STALE)
self.assertEqual(row.detail, "no source_ref, 1 refs to review")
def test_profile_sync_accepts_the_command_it_is_given(self):
"""--json with the detection flags was refused, so --profiles read an
empty stdout and reported "unreadable report" on every run."""
@@ -896,12 +936,12 @@ class RowsSayAllTheyStandFor(unittest.TestCase):
class AReleasePageMakesAProfileStale(unittest.TestCase):
def test_a_newer_announced_version_is_stale(self):
rows = [
{"name": "altirra", "skipped": "unsupported host: x",
"declared_version": "4.40", "page_version": "4.50"},
{"name": "mednafen", "skipped": "unsupported host: y",
"declared_version": "1.32.1", "page_version": "1.32.1"},
]
rows = _rows(
ProfileReport("altirra", skipped="unsupported host: x",
declared_version="4.40", page_version="4.50"),
ProfileReport("mednafen", skipped="unsupported host: y",
declared_version="1.32.1", page_version="1.32.1"),
)
found = {f.subject: f.status for f in summarize_profile_sync(rows)}
self.assertEqual(found["altirra"], STALE)
self.assertEqual(found["mednafen"], OK)
@@ -910,9 +950,9 @@ class AReleasePageMakesAProfileStale(unittest.TestCase):
"""An unreadable page read like a profile with no version_source:
SKIPPED by nature, and a moved or dead feed went unseen."""
rows = [{"name": "altirra", "skipped": "unsupported host: virtualdub.org",
"declared_version": "4.40", "page_version": None,
"page_version_unread": "page absent"}]
rows = _rows(ProfileReport("altirra", skipped="unsupported host: virtualdub.org",
declared_version="4.40", page_version=None,
page_version_unread="page absent"))
(overall, row) = summarize_profile_sync(rows)
self.assertEqual(row.status, UNKNOWN)
self.assertEqual(row.detail, "version page unread: page absent")
@@ -921,12 +961,12 @@ class AReleasePageMakesAProfileStale(unittest.TestCase):
"""FPse 13.0 exists only as rebuilt copies: the profile stays on 12.1
and flagging it on every run said nothing new. 13.1 would."""
rows = [
{"name": "fpse", "skipped": "unsupported host: x", "declared_version": "12.1",
"page_version": "13.0", "no_genuine_copy": "13.0"},
{"name": "later", "skipped": "unsupported host: x", "declared_version": "12.1",
"page_version": "13.1", "no_genuine_copy": "13.0"},
]
rows = _rows(
ProfileReport("fpse", skipped="unsupported host: x", declared_version="12.1",
page_version="13.0", no_genuine_copy="13.0"),
ProfileReport("later", skipped="unsupported host: x", declared_version="12.1",
page_version="13.1", no_genuine_copy="13.0"),
)
found = {f.subject: f for f in summarize_profile_sync(rows)}
self.assertEqual(found["fpse"].status, OK)
self.assertIn("no genuine copy", found["fpse"].detail)
+20
View File
@@ -2295,6 +2295,26 @@ class TestReportToDict(unittest.TestCase):
payload = report_to_dict(_sample_report())
self.assertEqual(payload["entries"][0]["parts"][0]["status"], "SHIFTED")
def test_carries_one_attention_verdict(self):
"""check_freshness rebuilt the verdict from single keys and dropped
version_warning and detection_skipped: the report gives it once."""
report = _sample_report()
report.version_warning = "core_version 1.0 names tag commit aaaaaaa"
report.detection_skipped = "HTTP 403"
kinds = [(r["kind"], r["level"]) for r in report_to_dict(report)["attention"]]
self.assertEqual(kinds, [
("review", "stale"), ("version", "stale"), ("detection_skipped", "unknown"),
])
def test_strict_kinds_keep_review_and_uncheckable(self):
from profiling.reports import STRICT_KINDS, ProfileReport
self.assertTrue(_sample_report().fails(STRICT_KINDS))
dead = ProfileReport("x", skipped="no declared repository answers")
self.assertTrue(dead.fails(STRICT_KINDS))
warned = ProfileReport("y", pin="a", head="a", version_warning="behind")
self.assertFalse(warned.fails(STRICT_KINDS))
def test_markdown_lists_every_profile(self):
text = format_markdown([_sample_report()])
self.assertIn("demo", text)