From 380b3df8230132d9e65939c9b2f8a3c26977adad Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:39:57 +0100 Subject: [PATCH] fix: gaps badge reads verify's severity counts The badge refiltered coverage details for missing required firmware and ignored hle_fallback: a required file the core replaces by HLE is INFO in verify and passes --strict, yet showed as a red required gap. The count now comes from severity_counts through packs.verdicts.blocking_missing. --- scripts/packs/verdicts.py | 12 ++++++++++++ scripts/sitegen/gaps.py | 15 +-------------- scripts/sitegen/readme.py | 6 +++++- tests/test_contributing_text.py | 3 ++- tests/test_site_reference.py | 20 +++++++++++++------- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/scripts/packs/verdicts.py b/scripts/packs/verdicts.py index 5cf47cd7b..d0066da82 100644 --- a/scripts/packs/verdicts.py +++ b/scripts/packs/verdicts.py @@ -269,6 +269,18 @@ def compute_severity( return Severity.OK +def blocking_missing(severity_counts: dict[str, int], mode: str) -> int: + """Destinations whose missing file stops the console, from verify's counts. + + compute_severity gives a required firmware gap with no HLE fallback + CRITICAL where the frontend reads the bytes and WARNING where it only + checks the file is there, and nothing else reaches that severity in an + existence frontend. + """ + severity = Severity.CRITICAL if reads_file_contents(mode) else Severity.WARNING + return severity_counts.get(severity, 0) + + def storage_verdict(file_entry: dict, emulator_pack: bool) -> dict | None: """The result a storage tier fixes before any lookup, as the builder sees it. diff --git a/scripts/sitegen/gaps.py b/scripts/sitegen/gaps.py index c97c5046b..f2e9ced3d 100644 --- a/scripts/sitegen/gaps.py +++ b/scripts/sitegen/gaps.py @@ -321,19 +321,6 @@ def _platform_lists_sentence( ) -def _missing_required_firmware(cov: dict) -> int: - """Entries of a platform's list that are missing, required and firmware. - - Only those stop a console from starting. Game data and files no core - opens are counted apart, and red on every short row carried no signal. - """ - return len({ - (d.get("system", ""), d.get("name", "")) for d in cov.get("details") or [] - if d.get("status") == "missing" and d.get("required", True) - and d.get("category", "bios") == "bios" and not d.get("settled_by") - }) - - def _ratio_cell(done: int, total: int, alarm: int = 0) -> str: """A held-over-needed cell: the numbers, a bar, and a badge only when required firmware is missing.""" @@ -453,7 +440,7 @@ def _pack_content_rows(coverages: dict) -> list[str]: ) rows.append( f"| [{display}](platforms/{pname}.md) " - f"| {_ratio_cell(cov['present'], cov['total'], _missing_required_firmware(cov))} " + f"| {_ratio_cell(cov['present'], cov['total'], cov['required_missing'])} " f"| {_ratio_cell(cov['core_present'], core_total)} " f"| {check_label(cov['mode'], cov['config'].get('hash_rule'))} |" ) diff --git a/scripts/sitegen/readme.py b/scripts/sitegen/readme.py index dd1ed541e..df70a8c75 100644 --- a/scripts/sitegen/readme.py +++ b/scripts/sitegen/readme.py @@ -29,6 +29,7 @@ from model.profiles import load_emulator_profiles, unique_emulator_profiles from model.registry import VERSIONS_FILE, list_registered_platforms, load_platform_registry from model.systems import system_index from packs.coverage import verify_platform +from packs.verdicts import blocking_missing from resolve.cores import resolve_platform_cores from resolve.review import LARGE_FILE_ISSUE_URL from sitegen.config import REPO_SLUG, REPO_URL, SITE_URL, UPLOAD_ROOT @@ -103,6 +104,9 @@ def compute_coverage( "pack_files": present + core_present, "total_missing": missing + core_missing, "mode": config.get("verification_mode", "existence"), + # The gaps page badge: verify's count, never refiltered from details. + "required_missing": blocking_missing( + result["severity_counts"], result["verification_mode"]), "details": result["details"], "config": config, "ground_truth": result.get( @@ -116,7 +120,7 @@ def compute_coverage( # stores it here and the second reads it back, instead of verifying every # platform twice (about a minute of the site build). COVERAGE_CACHE_DIR = REPO_ROOT / "tmp" / "coverage-cache" -_COVERAGE_CACHE_FORMAT = "3" +_COVERAGE_CACHE_FORMAT = "4" def _coverage_inputs(db_path: Path, platforms_dir: str, emulators_dir: str) -> str: diff --git a/tests/test_contributing_text.py b/tests/test_contributing_text.py index 37a776b3c..7a8539f78 100644 --- a/tests/test_contributing_text.py +++ b/tests/test_contributing_text.py @@ -44,7 +44,8 @@ class CoverageReadsTheGivenProfiles(unittest.TestCase): def fake_verify(_config, _db, emulators_dir, **_kwargs): seen.append(emulators_dir) - return {"status_counts": {}, "total_files": 0, "undeclared_files": [], "details": []} + return {"status_counts": {}, "severity_counts": {}, "verification_mode": "existence", + "total_files": 0, "undeclared_files": [], "details": []} with mock.patch.object(readme, "verify_platform", fake_verify), \ mock.patch.object(readme, "load_emulator_profiles", return_value={}): diff --git a/tests/test_site_reference.py b/tests/test_site_reference.py index 0312d0754..d5a7327fd 100644 --- a/tests/test_site_reference.py +++ b/tests/test_site_reference.py @@ -82,6 +82,7 @@ import core from sitegen import sources from model import releaserecord from core import upstream +from packs.verdicts import Severity, blocking_missing, compute_severity REPO_ROOT = Path(__file__).resolve().parents[1] @@ -329,13 +330,18 @@ class GapsPageNumbers(unittest.TestCase): self.assertNotIn("rb-badge", gaps._ratio_cell(99, 100)) self.assertIn('class="rb-bar"', gaps._ratio_cell(99, 100)) self.assertIn("rb-badge-danger", gaps._ratio_cell(99, 100, 1)) - cov = {"details": [ - {"name": "a", "system": "s", "status": "missing", "required": True, "category": "bios"}, - {"name": "b", "system": "s", "status": "missing", "required": True, - "category": "game_data"}, - {"name": "c", "system": "s", "status": "missing", "required": False}, - ]} - self.assertEqual(gaps._missing_required_firmware(cov), 1) + self.assertNotIn("_missing_required_firmware", script_source("generate_site.py")) + + def test_blocking_missing_reads_verify_severity(self): + """The badge is verify's count: a required gap with an HLE fallback + is INFO there and stopped no console, yet the page counted it.""" + def gap(mode: str, hle: bool) -> int: + severity = compute_severity("missing", True, mode, hle) + return blocking_missing({severity: 1}, mode) + for mode in ("existence", "md5", "sha1"): + self.assertEqual(gap(mode, False), 1, mode) + self.assertEqual(gap(mode, True), 0, mode) + self.assertEqual(blocking_missing({Severity.WARNING: 2}, "md5"), 0) def test_headings_and_header(self): source = script_source("generate_site.py")