feat: keep game data out of the wanted list

Game data is the player's own, and a file the emulator installs for the build that reads it is no gap: neither is listed. A platform entry leaves when every core reading it installs it (validation.deliverable, scoped by the platform's build of each core).
This commit is contained in:
Abdessamad Derraz committed 2026-11-17 03:14:42 +01:00
1 parent 6c03dd07ee
commit ac37802e20
2 files changed
+116 -25

No files matched your search

+44 -12
View File
@@ -22,10 +22,11 @@ from collections.abc import Callable, Iterable
from pathlib import Path from pathlib import Path
import archive_build import archive_build
from common import unique_emulator_profiles from common import runs_standalone, unique_emulator_profiles
from cross_reference import _first_hash from cross_reference import _first_hash
from hashing import cut_md5_owner, parse_hash_list from hashing import cut_md5_owner, parse_hash_list
from validate_pr import LARGE_FILE_ISSUE_URL, Placement, placement from validate_pr import LARGE_FILE_ISSUE_URL, Placement, placement
from validation import deliverable, filter_files_by_mode, installed_with_emulator
ALGORITHMS = ("sha1", "sha256", "md5", "crc32") ALGORITHMS = ("sha1", "sha256", "md5", "crc32")
# GitHub's upload page takes 25 MB per file. A larger file goes in by a # GitHub's upload page takes 25 MB per file. A larger file goes in by a
@@ -156,13 +157,41 @@ def _paired(files: list, details: list[dict]) -> Iterable[tuple[dict, dict]]:
yield detail, same[position] yield detail, same[position]
def _brought_by_readers(detail: dict, config: dict, platform: str, profiles: dict) -> bool:
"""Whether every core that reads a platform entry installs it itself.
The readers are those verify names for the entry's category, the cores
of its system first. A reader brings the file when the entries of its
build that read it are all installed with it (validation.deliverable,
the rule the pack builder applies).
"""
readers = (detail.get("category_evidence") or {}).get("read_by") or []
own = [r for r in readers if r.get("runs_system")] or readers
standalone_cores = set(config.get("standalone_cores") or [])
verdicts = []
for reader in own:
profile = profiles.get(reader.get("emulator", ""))
if not profile:
continue
names = {str(e.get("name")) for e in reader.get("entries") or []}
read = [f for f in profile.get("files") or []
if isinstance(f, dict) and str(f.get("name")) in names]
standalone = runs_standalone(reader["emulator"], profile, standalone_cores)
if filter_files_by_mode(read, standalone):
verdicts.append(not deliverable(read, standalone, platform))
return bool(verdicts) and all(verdicts)
def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> list[dict]: def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> list[dict]:
"""Every declaration of a file the gaps page reports as lacking. """Every declaration of a file the gaps page reports as lacking.
Each is {name, system, required, reader: (kind, key, label), entry, Each is {name, system, required, reader: (kind, key, label), entry,
reason, category, directory}: the reason a file not collected yet reason, category, directory}: the reason a file not collected yet
carries, empty otherwise, and game_data or bios as verify (a carries, empty otherwise, and bios or unread as verify (a platform's
platform's entry) or the profile (an emulator's) gives it. entry) or the profile (an emulator's) gives it. Game data is no
contributor's to send, and a file the emulator installs itself
(`bundled`, scoped by the build that reads it) is no gap: neither is
a declaration here.
""" """
found: list[dict] = [] found: list[dict] = []
for key, coverage in sorted(coverages.items()): for key, coverage in sorted(coverages.items()):
@@ -175,6 +204,9 @@ def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> li
for detail, entry in _paired(files, details): for detail, entry in _paired(files, details):
if detail.get("settled_by") or detail.get("status") not in ("missing", "untested"): if detail.get("settled_by") or detail.get("status") not in ("missing", "untested"):
continue continue
if detail.get("category") == GAME_DATA or _brought_by_readers(
detail, coverage.get("config", {}), key, profiles):
continue
found.append({ found.append({
"name": str(entry["name"]), "system": system, "name": str(entry["name"]), "system": system,
"required": bool(detail.get("required", True)), "required": bool(detail.get("required", True)),
@@ -195,13 +227,15 @@ def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> li
for row, unsourceable in rows: for row, unsourceable in rows:
for entry in gap_entries(profile, str(row.get("name", "")), for entry in gap_entries(profile, str(row.get("name", "")),
str(row.get("identity") or ""), unsourceable): str(row.get("identity") or ""), unsourceable):
if entry.get("category") == GAME_DATA or installed_with_emulator(entry):
continue
system = entry.get("system") or (systems[0] if len(systems) == 1 else "") system = entry.get("system") or (systems[0] if len(systems) == 1 else "")
found.append({ found.append({
"name": str(entry["name"]), "system": str(system), "name": str(entry["name"]), "system": str(system),
"required": bool(row.get("required", False)), "required": bool(row.get("required", False)),
"reader": ("emulator", key, str(data.get("emulator", key))), "entry": entry, "reader": ("emulator", key, str(data.get("emulator", key))), "entry": entry,
"reason": str(row.get("reason") or "") if unsourceable else "", "reason": str(row.get("reason") or "") if unsourceable else "",
"category": GAME_DATA if entry.get("category") == GAME_DATA else BIOS, "category": BIOS,
"directory": _directory(entry), "directory": _directory(entry),
}) })
return found return found
@@ -227,9 +261,8 @@ BIOS = "bios"
GAME_DATA = "game_data" GAME_DATA = "game_data"
# verify's category for a platform entry no core the platform runs reads. # verify's category for a platform entry no core the platform runs reads.
UNREAD = "unread" UNREAD = "unread"
# Firmware first, then what a platform lists and no core reads, then game # Firmware first, then what a platform lists and no core reads.
# data. The value is also the list's k field, absent for firmware. RANK = {BIOS: 0, UNREAD: 1}
RANK = {BIOS: 0, UNREAD: 1, GAME_DATA: 2}
# A name the code builds from the content (<serial>.txt, *.ini) is a # A name the code builds from the content (<serial>.txt, *.ini) is a
# pattern, not a file anyone can upload. # pattern, not a file anyone can upload.
PATTERN = re.compile(r"[<>*?]") PATTERN = re.compile(r"[<>*?]")
@@ -331,9 +364,8 @@ def upload_href(root: str, folder: str) -> str:
def _order(record: dict) -> tuple: def _order(record: dict) -> tuple:
"""Most useful first: required firmware, optional firmware, then the """Most useful first: firmware, then the files no core reads, required
files no core reads, then game data, required first, and within each first in each, then by how many setups and emulators read the file."""
by how many setups and emulators read the file."""
return (RANK[record["category"]], not record["required"], -len(record["readers"]), return (RANK[record["category"]], not record["required"], -len(record["readers"]),
record["name"].casefold(), sorted(record["readers"])) record["name"].casefold(), sorted(record["readers"]))
@@ -384,7 +416,7 @@ def build_wanted(
record = records.setdefault(key, { record = records.setdefault(key, {
"name": declaration["name"], "hashes": {a: list(v) for a, v in hashes.items()}, "name": declaration["name"], "hashes": {a: list(v) for a, v in hashes.items()},
"sizes": sizes, "systems": set(), "required": False, "readers": set(), "sizes": sizes, "systems": set(), "required": False, "readers": set(),
"category": GAME_DATA, "directory": declaration["directory"], "category": UNREAD, "directory": declaration["directory"],
"crc": set(), "links": {}, "crc": set(), "links": {},
}) })
if RANK[declaration["category"]] < RANK[record["category"]]: if RANK[declaration["category"]] < RANK[record["category"]]:
@@ -520,7 +552,7 @@ def page(total: int, known: int) -> str:
"", "",
"## The wanted list", "## The wanted list",
"", "",
(f"{total:,} files, firmware first and game data last. A name opens its details. " (f"{total:,} files, required firmware first. A name opens its details. "
f"{known:,} have a fingerprint (a hash), so a dropped copy is recognised."), f"{known:,} have a fingerprint (a hash), so a dropped copy is recognised."),
"", "",
"The others are known by name only: a dropped file of that name gets a button too.", "The others are known by name only: a dropped file of that name gets a button too.",
+72 -13
View File
@@ -176,9 +176,9 @@ class TheListHoldsWhatTheGapsReportLacks(_World):
def test_names(self): def test_names(self):
names = sorted(e["n"] for e in self.data["entries"]) names = sorted(e["n"] for e in self.data["entries"])
# a.bin is held, m.bin is held inside set.zip, pkg.bin comes with # a.bin is held, m.bin is held inside set.zip, pkg.bin comes with
# its emulator, own.cfg is the user's own: none is wanted. r.bin is # its emulator, own.cfg is the user's own, g.bin is game data: none
# one entry per revision. # is wanted. r.bin is one entry per revision.
self.assertEqual(names, ["b.bin", "c.bin", "cut.bin", "g.bin", "later.bin", "nohash.bin", self.assertEqual(names, ["b.bin", "c.bin", "cut.bin", "later.bin", "nohash.bin",
"r.bin", "r.bin", "v.bin", "z.zip"]) "r.bin", "r.bin", "v.bin", "z.zip"])
def test_an_entry_with_no_hash_is_kept_and_marked(self): def test_an_entry_with_no_hash_is_kept_and_marked(self):
@@ -190,9 +190,9 @@ class TheListHoldsWhatTheGapsReportLacks(_World):
self.assertNotIn("h", self.entry(name)) self.assertNotIn("h", self.entry(name))
self.assertIn("h", self.entry("b.bin")) self.assertIn("h", self.entry("b.bin"))
# The world's categories: g.bin is game data, cut.bin a file a # cut.bin is a file a platform lists and no core reads, the others
# platform lists and no core reads, the others firmware. # firmware.
KIND = {"g.bin": 2, "cut.bin": 1} KIND = {"cut.bin": 1}
def test_required_entries_come_first(self): def test_required_entries_come_first(self):
firmware = [e for e in self.data["entries"] if e["n"] not in self.KIND] firmware = [e for e in self.data["entries"] if e["n"] not in self.KIND]
@@ -203,10 +203,52 @@ class TheListHoldsWhatTheGapsReportLacks(_World):
def test_firmware_comes_before_game_data(self): def test_firmware_comes_before_game_data(self):
kinds = [self.KIND.get(e["n"], 0) for e in self.data["entries"]] kinds = [self.KIND.get(e["n"], 0) for e in self.data["entries"]]
self.assertEqual(kinds, sorted(kinds)) self.assertEqual(kinds, sorted(kinds))
# g.bin is required, and still after every optional firmware file. self.assertEqual(self.data["entries"][-1]["n"], "cut.bin")
self.assertEqual(self.data["entries"][-1]["n"], "g.bin")
self.assertEqual(self.entry("g.bin").get("r"), 1)
def test_game_data_is_not_wanted(self):
"""Game data is the player's own: a retail pak0.pk3 that ioquake3
reads, and a platform entry verify files as game data, stay out."""
profile = yaml.safe_load((REPO_ROOT / "emulators" / "ioquake3.yml").read_text(encoding="utf-8"))
report = {"ioquake3": {"emulator": "ioquake3", "systems": profile.get("systems") or [],
"gap_details": [{"name": "pak0.pk3", "source": "missing",
"identity": ""}],
"unsourceable": [{"name": "pak0.pk3", "required": True,
"reason": "retail data"}]}}
self.assertEqual(sitewanted.wanted_declarations({"ioquake3": profile}, {}, report), [])
coverages = {"plat": {**self.coverages["plat"], "details": [
{**d, "category": "game_data"} if d["name"] == "v.bin" else d
for d in self.coverages["plat"]["details"]]}}
names = [d["name"] for d in sitewanted.wanted_declarations({}, coverages, {})]
self.assertNotIn("v.bin", names)
def test_a_file_the_emulator_installs_is_not_wanted(self):
"""Amiberry's standalone release installs whdboot/boot-data.zip, its
libretro core does not: only the core's entry can be a gap."""
profile = yaml.safe_load((REPO_ROOT / "emulators" / "amiberry.yml").read_text(encoding="utf-8"))
both = [f for f in profile["files"] if isinstance(f, dict) and f.get("name") == "boot-data.zip"]
self.assertEqual(sorted(str(f.get("mode")) for f in both), ["libretro", "standalone"])
report = {"amiberry": {"emulator": "Amiberry", "systems": profile.get("systems") or [],
"gap_details": [{"name": "boot-data.zip", "source": "missing",
"identity": ""}]}}
found = sitewanted.wanted_declarations({"amiberry": profile}, {}, report)
self.assertEqual([d["entry"].get("mode") for d in found], ["libretro"])
def test_a_platform_file_its_core_installs_is_not_wanted(self):
"""v.bin is read by engine, whose build installs it: no gap. When
only the standalone build installs it, the libretro core still
needs it."""
def declarations(entry: dict) -> list[str]:
profiles = {"engine": {"emulator": "Engine", "type": "libretro", "files": [entry]}}
coverages = {"plat": {**self.coverages["plat"], "details": [
{**d, "category_evidence": {"read_by": [
{"emulator": "engine", "runs_system": True, "entries": [{"name": "v.bin"}]}]}}
if d["name"] == "v.bin" else d
for d in self.coverages["plat"]["details"]]}}
return [d["name"] for d in sitewanted.wanted_declarations(profiles, coverages, {})]
self.assertNotIn("v.bin", declarations({"name": "v.bin", "bundled": True}))
self.assertIn("v.bin", declarations({"name": "v.bin", "bundled": True, "mode": "standalone"}))
self.assertIn("v.bin", declarations({"name": "v.bin"}))
def test_a_file_nobody_can_share_is_left_out(self): def test_a_file_nobody_can_share_is_left_out(self):
"""The reason a profile gives decides, read from the profiles """The reason a profile gives decides, read from the profiles
themselves: emucorev's config.txt and puae's WHDLoad.key leave, themselves: emucorev's config.txt and puae's WHDLoad.key leave,
@@ -234,14 +276,12 @@ class TheListHoldsWhatTheGapsReportLacks(_World):
{"name": "b", "required": False, {"name": "b", "required": False,
"readers": {("emulator", "e", "E"), ("platform", "p", "P")}}, "readers": {("emulator", "e", "E"), ("platform", "p", "P")}},
{"name": "c", "required": True, "readers": {("emulator", "e", "E")}}, {"name": "c", "required": True, "readers": {("emulator", "e", "E")}},
{"name": "d", "required": True, "readers": {("emulator", "e", "E")},
"category": sitewanted.GAME_DATA},
{"name": "u", "required": True, "readers": {("platform", "p", "P")}, {"name": "u", "required": True, "readers": {("platform", "p", "P")},
"category": sitewanted.UNREAD}] "category": sitewanted.UNREAD}]
for record in records: for record in records:
record.setdefault("category", sitewanted.BIOS) record.setdefault("category", sitewanted.BIOS)
self.assertEqual([r["name"] for r in sorted(records, key=sitewanted._order)], self.assertEqual([r["name"] for r in sorted(records, key=sitewanted._order)],
["c", "b", "a", "u", "d"]) ["c", "b", "a", "u"])
def test_a_name_with_no_hash_joins_the_hashed_entry_of_its_name(self): def test_a_name_with_no_hash_joins_the_hashed_entry_of_its_name(self):
reader = ("emulator", "other", "Other") reader = ("emulator", "other", "Other")
@@ -249,7 +289,7 @@ class TheListHoldsWhatTheGapsReportLacks(_World):
("b.bin", (("sha1", ("x",)),), ()): { ("b.bin", (("sha1", ("x",)),), ()): {
"name": "b.bin", "hashes": {"sha1": ["x"]}, "systems": {"x"}, "required": False, "name": "b.bin", "hashes": {"sha1": ["x"]}, "systems": {"x"}, "required": False,
"readers": {("emulator", "engine", "Engine")}, "description": "", "readers": {("emulator", "engine", "Engine")}, "description": "",
"category": sitewanted.GAME_DATA, "crc": set(), "links": {(False, "engine"): "e"}}, "category": sitewanted.UNREAD, "crc": set(), "links": {(False, "engine"): "e"}},
("b.bin", "x", ""): { ("b.bin", "x", ""): {
"name": "b.bin", "hashes": {}, "systems": {"x"}, "required": True, "name": "b.bin", "hashes": {}, "systems": {"x"}, "required": True,
"readers": {reader}, "crc": {"1234abcd"}, "links": {(False, "other"): "o"}, "readers": {reader}, "crc": {"1234abcd"}, "links": {(False, "other"): "o"},
@@ -612,6 +652,25 @@ class ThePublishedList(unittest.TestCase):
def test_weight(self): def test_weight(self):
self.assertLess(PUBLISHED.stat().st_size, 200_000) self.assertLess(PUBLISHED.stat().st_size, 200_000)
def test_no_game_data_and_nothing_the_emulator_installs(self):
"""Each emulator a row names declares that file as firmware it does
not install itself: pak0.pk3, game data for every profile, is gone."""
from common import load_emulator_profiles
from validation import installed_with_emulator
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
self.assertNotIn("pak0.pk3", [e["n"] for e in self.data["entries"]])
for entry in self.data["entries"]:
for index in entry["w"]:
kind, key, _label = self.data["readers"][index]
if kind != "e":
continue
declared = [f for f in profiles[key].get("files") or []
if isinstance(f, dict) and f.get("name") == entry["n"]]
with self.subTest(entry=entry["n"], emulator=key):
self.assertTrue([f for f in declared if f.get("category") != "game_data"
and not installed_with_emulator(f)])
def test_every_link_lands_on_its_details(self): def test_every_link_lands_on_its_details(self):
"""Each name's link is a built page, and a card anchor is on it.""" """Each name's link is a built page, and a card anchor is on it."""
dist = WEBSITE / "dist" dist = WEBSITE / "dist"