refactor: name the stale rows the planner reads

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:33 +01:00
1 parent 4835c59508
commit 66c83b06b0
6 files changed
+95 -29

No files matched your search

+13 -10
View File
@@ -13,7 +13,10 @@ from core import upstream
from core.paths import REPO_ROOT
from scripts.scraper import game_dat_importer
from scripts.scraper.redump_dat_scraper import fetch_snapshot
from freshness.findings import OK, SKIPPED, STALE, UNKNOWN, Finding
from freshness.findings import (
FBNEO_RECIPES, MAME_RECIPES, NO_INTRO_GAMES, OK, REDUMP_GAMES, SKIPPED, STALE, UNKNOWN,
Finding,
)
NO_INTRO_MIRROR = game_dat_importer.NOINTRO_MIRROR
@@ -90,7 +93,7 @@ def _check_nointro_games(cache_dir: str, offline: bool) -> Finding:
"""games/catalogs/no-intro/ against the pack it was read from. The pack
holds every DAT: rebuilt after the catalogs were read, it may carry
games the games-on-card mode does not recognise."""
subject = "no-intro games"
subject = NO_INTRO_GAMES
fetched = min((str(doc.get("fetched", "")) for doc in _game_catalogs("no-intro")), default="")
if offline:
return Finding("catalogs", subject, SKIPPED, local=fetched, detail="offline")
@@ -118,7 +121,7 @@ def redump_datfile_version(code: str) -> str:
def _check_redump_games(offline: bool) -> Finding:
"""games/catalogs/redump/ against the datfiles redump.info serves now.
A disc dumped since is not recognised by the games-on-card mode."""
subject = "redump games"
subject = REDUMP_GAMES
local = {doc.get("system"): str(doc.get("version", "")) for doc in _game_catalogs("redump")}
newest = max(local.values(), default="")
if offline:
@@ -218,13 +221,13 @@ def _check_mame(cache_dir: str, offline: bool) -> Finding:
versions = mame_versions(local)
newest = versions[-1] if versions else "none"
if offline:
return Finding("catalogs", "mame recipes", SKIPPED, local=newest, detail="offline")
return Finding("catalogs", MAME_RECIPES, SKIPPED, local=newest, detail="offline")
release = upstream.latest_release(upstream.parse_repo(MAME_REPO), cache_dir, offline)
if release is None:
return Finding("catalogs", "mame recipes", UNKNOWN, local=newest, detail="no release seen")
return Finding("catalogs", MAME_RECIPES, UNKNOWN, local=newest, detail="no release seen")
return Finding(
"catalogs",
"mame recipes",
MAME_RECIPES,
OK if release.tag in versions else STALE,
local=newest,
remote=f"{release.tag} ({release.date})",
@@ -257,7 +260,7 @@ def _check_fbneo(cache_dir: str, offline: bool) -> Finding:
local = _snapshot(REPO_ROOT / "recipes" / "fbneo.json")
imported = str(local.get("imported_at", ""))
if offline:
return Finding("catalogs", "fbneo recipes", SKIPPED, local=imported, detail="offline")
return Finding("catalogs", FBNEO_RECIPES, SKIPPED, local=imported, detail="offline")
repo = upstream.parse_repo(FBNEO_REPO)
listing = upstream.cached_api(
f"{repo.api_base}/repos/{repo.slug}/contents/dats",
@@ -266,12 +269,12 @@ def _check_fbneo(cache_dir: str, offline: bool) -> Finding:
upstream.MOVING_TTL,
)
if not isinstance(listing, list):
return Finding("catalogs", "fbneo recipes", UNKNOWN, local=imported, detail="dats/ listing unavailable")
return Finding("catalogs", FBNEO_RECIPES, UNKNOWN, local=imported, detail="dats/ listing unavailable")
drifted, tracked = fbneo_blob_drift(local, listing)
if not tracked:
return Finding(
"catalogs",
"fbneo recipes",
FBNEO_RECIPES,
STALE,
local=imported,
detail="snapshot records no upstream blobs: re-import with --fetch",
@@ -279,7 +282,7 @@ def _check_fbneo(cache_dir: str, offline: bool) -> Finding:
shown = ", ".join(n.removeprefix("FinalBurn Neo (ClrMame Pro XML, ").removesuffix(" only).dat") for n in drifted[:4])
return Finding(
"catalogs",
"fbneo recipes",
FBNEO_RECIPES,
STALE if drifted else OK,
local=imported,
remote=f"{len(listing)} DATs listed",
+2 -2
View File
@@ -8,7 +8,7 @@ import re
from core import upstream
from core.paths import REPO_ROOT
from installer_build import pins as installer_build_pins
from freshness.findings import OK, SKIPPED, STALE, UNKNOWN, Finding
from freshness.findings import INSTALLER_PIN, OK, SKIPPED, STALE, UNKNOWN, Finding
PYPI_URL = "https://pypi.org/pypi/{name}/json"
@@ -189,7 +189,7 @@ def _check_installer_pins() -> Finding:
stale = installer_build_pins.stale_pins(REPO_ROOT)
return Finding(
"ci",
"install.py pin",
INSTALLER_PIN,
STALE if stale else OK,
local=installer_build_pins.installer_sha256(REPO_ROOT)[:12],
detail=(
+19
View File
@@ -14,6 +14,25 @@ OK, STALE, UNKNOWN, ERROR, SKIPPED = "OK", "STALE", "UNKNOWN", "ERROR", "SKIPPED
# Every status a finding may carry, in the order the summary counts them.
STATUSES = (STALE, UNKNOWN, ERROR, SKIPPED, OK)
# Subjects the refresh planner (freshness.stalecommands) picks a command by:
# the checks name their rows with these, so a rename reaches both sides.
NO_INTRO_GAMES = "no-intro games"
REDUMP_GAMES = "redump games"
MAME_RECIPES = "mame recipes"
FBNEO_RECIPES = "fbneo recipes"
INSTALLER_PIN = "install.py pin"
_UNPROFILED_CORES = " cores"
def unprofiled_cores_subject(platform: str) -> str:
"""The targets row listing the core names of a platform no profile claims."""
return f"{platform}{_UNPROFILED_CORES}"
def is_unprofiled_cores(subject: str) -> bool:
"""Whether a targets row is the backlog of unprofiled names, not a target file."""
return subject.endswith(_UNPROFILED_CORES)
@dataclass(frozen=True)
class Finding:
+14 -15
View File
@@ -8,6 +8,9 @@ from functools import lru_cache
from core.paths import DATA_DIRS_FILE, REPO_ROOT
from model.registry import data_dir_registry_at
from freshness.findings import (
FBNEO_RECIPES, INSTALLER_PIN, MAME_RECIPES, NO_INTRO_GAMES, REDUMP_GAMES, is_unprofiled_cores,
)
from freshness.scrapers import rescrape_command
DATA_DIRS_REGISTRY = REPO_ROOT / DATA_DIRS_FILE
@@ -50,7 +53,7 @@ def _platform_command(subject: str, registry: dict[str, dict]) -> list[str] | No
def _target_command(subject: str, registry: dict[str, dict]) -> list[str] | None:
# "<platform> cores" rows list buildbot names without a profile. No
# scraper fixes that, a human writes `cores:` or _overrides.yml.
if subject.endswith(" cores"):
if is_unprofiled_cores(subject):
return None
return rescrape_command("targets", subject, f"platforms/targets/{subject}.yml")
@@ -69,33 +72,29 @@ def _data_command(subject: str, registry: dict[str, dict]) -> list[str] | None:
]
# The romset recipes and the game DATs each importer fetches, by row.
_RECIPE_SOURCES = {MAME_RECIPES: "mame", FBNEO_RECIPES: "fbneo"}
_GAME_SOURCES = {NO_INTRO_GAMES: "no-intro", REDUMP_GAMES: "redump"}
def _catalog_command(subject: str, registry: dict[str, dict]) -> list[str] | None:
if subject == "mame recipes":
if subject in _RECIPE_SOURCES:
return [
sys.executable,
"-m",
"scripts.scraper.romset_dat_importer",
"--source",
"mame",
_RECIPE_SOURCES[subject],
"--fetch",
]
if subject == "fbneo recipes":
return [
sys.executable,
"-m",
"scripts.scraper.romset_dat_importer",
"--source",
"fbneo",
"--fetch",
]
if subject in ("no-intro games", "redump games"):
if subject in _GAME_SOURCES:
# The game DATs download without a browser, unlike the BIOS ones.
return [
sys.executable,
"-m",
"scripts.scraper.game_dat_importer",
"--source",
subject.split()[0],
_GAME_SOURCES[subject],
"--fetch",
"--refresh",
"--floor",
@@ -121,7 +120,7 @@ def command_for(
# truth comes first and the original follows (Job.then).
return truth_refresh(subject)
if area == "ci" and subject == "install.py pin":
if area == "ci" and subject == INSTALLER_PIN:
# The pin is the hash of the committed install.py, nothing to judge.
return [sys.executable, "scripts/pin_installer.py"]
+4 -2
View File
@@ -11,7 +11,9 @@ from pathlib import Path
from model.profiles import upstream_profile_index
from model.sources import source_yaml_file
from model.targets import apply_target_overrides, platform_overrides, read_target_overrides
from freshness.findings import ERROR, OK, SHOWN_NAMES, SKIPPED, STALE, UNKNOWN, Finding
from freshness.findings import (
ERROR, OK, SHOWN_NAMES, SKIPPED, STALE, UNKNOWN, Finding, unprofiled_cores_subject,
)
from freshness.platformdiff import diff_targets
from freshness.rescrape import scrape_into_copy
from freshness.scrapers import target_scrapers
@@ -161,7 +163,7 @@ def _unresolved_findings(platform: str, missing: dict[str, list[str]]) -> list[F
return [
Finding(
"targets",
f"{platform} cores",
unprofiled_cores_subject(platform),
STALE,
local=f"{len(names)} without a profile",
detail=f"cores: alias or _overrides remove_cores needed for {shown}",
+43
View File
@@ -188,6 +188,49 @@ class Planning(unittest.TestCase):
self.assertEqual(surfaced, [])
class ProducedRows(unittest.TestCase):
"""The rows the checks write are the ones the planner knows: a renamed
row would otherwise leave its refresher unplanned with the suite green."""
def _stale(self, row) -> dict:
from dataclasses import asdict, replace
return asdict(replace(row, status="STALE"))
def test_catalog_rows_reach_their_importers(self):
from freshness import catalogs
with tempfile.TemporaryDirectory() as cache:
rows = [
catalogs._check_mame(cache, True),
catalogs._check_fbneo(cache, True),
catalogs._check_nointro_games(cache, True),
catalogs._check_redump_games(True),
]
jobs, surfaced, _ = plan_jobs([self._stale(r) for r in rows], REGISTRY, {})
sources = {job.subject: job.command[job.command.index("--source") + 1] for job in jobs}
self.assertEqual(sources, {
"mame recipes": "mame", "fbneo recipes": "fbneo",
"no-intro games": "no-intro", "redump games": "redump",
})
self.assertEqual(surfaced, [])
def test_the_installer_pin_row_reaches_its_script(self):
from freshness import ci
jobs, surfaced, _ = plan_jobs([self._stale(ci._check_installer_pins())], REGISTRY, {})
self.assertEqual([job.command[1:] for job in jobs], [["scripts/pin_installer.py"]])
self.assertEqual(surfaced, [])
def test_the_unprofiled_cores_row_is_surfaced(self):
from freshness import targets
rows = targets._unresolved_findings("batocera", {"newcore": []})
jobs, surfaced, _ = plan_jobs([self._stale(r) for r in rows], REGISTRY, {})
self.assertEqual(jobs, [])
self.assertEqual([f["subject"] for f in surfaced], ["batocera cores"])
class Running(unittest.TestCase):
def test_a_child_starts_after_its_parent_ends(self):
with tempfile.TemporaryDirectory() as directory: