diff --git a/scripts/sitewanted.py b/scripts/sitewanted.py index 84bb987dc..4118ecef7 100644 --- a/scripts/sitewanted.py +++ b/scripts/sitewanted.py @@ -22,10 +22,11 @@ from collections.abc import Callable, Iterable from pathlib import Path import archive_build -from common import unique_emulator_profiles +from common import runs_standalone, unique_emulator_profiles from cross_reference import _first_hash from hashing import cut_md5_owner, parse_hash_list 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") # 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] +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]: """Every declaration of a file the gaps page reports as lacking. Each is {name, system, required, reader: (kind, key, label), entry, reason, category, directory}: the reason a file not collected yet - carries, empty otherwise, and game_data or bios as verify (a - platform's entry) or the profile (an emulator's) gives it. + carries, empty otherwise, and bios or unread as verify (a platform's + 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] = [] 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): if detail.get("settled_by") or detail.get("status") not in ("missing", "untested"): continue + if detail.get("category") == GAME_DATA or _brought_by_readers( + detail, coverage.get("config", {}), key, profiles): + continue found.append({ "name": str(entry["name"]), "system": system, "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 entry in gap_entries(profile, str(row.get("name", "")), 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 "") found.append({ "name": str(entry["name"]), "system": str(system), "required": bool(row.get("required", False)), "reader": ("emulator", key, str(data.get("emulator", key))), "entry": entry, "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), }) return found @@ -227,9 +261,8 @@ BIOS = "bios" GAME_DATA = "game_data" # verify's category for a platform entry no core the platform runs reads. UNREAD = "unread" -# Firmware first, then what a platform lists and no core reads, then game -# data. The value is also the list's k field, absent for firmware. -RANK = {BIOS: 0, UNREAD: 1, GAME_DATA: 2} +# Firmware first, then what a platform lists and no core reads. +RANK = {BIOS: 0, UNREAD: 1} # A name the code builds from the content (.txt, *.ini) is a # pattern, not a file anyone can upload. PATTERN = re.compile(r"[<>*?]") @@ -331,9 +364,8 @@ def upload_href(root: str, folder: str) -> str: def _order(record: dict) -> tuple: - """Most useful first: required firmware, optional firmware, then the - files no core reads, then game data, required first, and within each - by how many setups and emulators read the file.""" + """Most useful first: firmware, then the files no core reads, required + first in each, then by how many setups and emulators read the file.""" return (RANK[record["category"]], not record["required"], -len(record["readers"]), record["name"].casefold(), sorted(record["readers"])) @@ -384,7 +416,7 @@ def build_wanted( record = records.setdefault(key, { "name": declaration["name"], "hashes": {a: list(v) for a, v in hashes.items()}, "sizes": sizes, "systems": set(), "required": False, "readers": set(), - "category": GAME_DATA, "directory": declaration["directory"], + "category": UNREAD, "directory": declaration["directory"], "crc": set(), "links": {}, }) if RANK[declaration["category"]] < RANK[record["category"]]: @@ -520,7 +552,7 @@ def page(total: int, known: int) -> str: "", "## 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."), "", "The others are known by name only: a dropped file of that name gets a button too.", diff --git a/tests/test_site_wanted.py b/tests/test_site_wanted.py index 7d7834fee..824d4a960 100644 --- a/tests/test_site_wanted.py +++ b/tests/test_site_wanted.py @@ -176,9 +176,9 @@ class TheListHoldsWhatTheGapsReportLacks(_World): def test_names(self): 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 - # its emulator, own.cfg is the user's own: none is wanted. r.bin is - # one entry per revision. - self.assertEqual(names, ["b.bin", "c.bin", "cut.bin", "g.bin", "later.bin", "nohash.bin", + # its emulator, own.cfg is the user's own, g.bin is game data: none + # is wanted. r.bin is one entry per revision. + self.assertEqual(names, ["b.bin", "c.bin", "cut.bin", "later.bin", "nohash.bin", "r.bin", "r.bin", "v.bin", "z.zip"]) 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.assertIn("h", self.entry("b.bin")) - # The world's categories: g.bin is game data, cut.bin a file a - # platform lists and no core reads, the others firmware. - KIND = {"g.bin": 2, "cut.bin": 1} + # cut.bin is a file a platform lists and no core reads, the others + # firmware. + KIND = {"cut.bin": 1} def test_required_entries_come_first(self): 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): kinds = [self.KIND.get(e["n"], 0) for e in self.data["entries"]] self.assertEqual(kinds, sorted(kinds)) - # g.bin is required, and still after every optional firmware file. - self.assertEqual(self.data["entries"][-1]["n"], "g.bin") - self.assertEqual(self.entry("g.bin").get("r"), 1) + self.assertEqual(self.data["entries"][-1]["n"], "cut.bin") + 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): """The reason a profile gives decides, read from the profiles themselves: emucorev's config.txt and puae's WHDLoad.key leave, @@ -234,14 +276,12 @@ class TheListHoldsWhatTheGapsReportLacks(_World): {"name": "b", "required": False, "readers": {("emulator", "e", "E"), ("platform", "p", "P")}}, {"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")}, "category": sitewanted.UNREAD}] for record in records: record.setdefault("category", sitewanted.BIOS) 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): reader = ("emulator", "other", "Other") @@ -249,7 +289,7 @@ class TheListHoldsWhatTheGapsReportLacks(_World): ("b.bin", (("sha1", ("x",)),), ()): { "name": "b.bin", "hashes": {"sha1": ["x"]}, "systems": {"x"}, "required": False, "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", ""): { "name": "b.bin", "hashes": {}, "systems": {"x"}, "required": True, "readers": {reader}, "crc": {"1234abcd"}, "links": {(False, "other"): "o"}, @@ -612,6 +652,25 @@ class ThePublishedList(unittest.TestCase): def test_weight(self): 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): """Each name's link is a built page, and a card anchor is on it.""" dist = WEBSITE / "dist"