From 2ccd7bb88fed7e6b68bd2340dcc56397944cdba5 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:28:12 +0100 Subject: [PATCH] fix: gaps and wanted read one sendable rule --- .github/workflows/deploy-site.yml | 1 + scripts/resolve/sendable.py | 53 +++++++++++++++++++++++++++++ scripts/sitegen/gaps.py | 40 +++++++++++++++++----- scripts/sitegen/wanted.py | 56 ++++--------------------------- tests/test_audit_regressions.py | 7 ++-- tests/test_site_wanted.py | 27 +++++++++++++-- 6 files changed, 120 insertions(+), 64 deletions(-) create mode 100644 scripts/resolve/sendable.py diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 16680d509..10adefdf3 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -116,6 +116,7 @@ on: - "scripts/resolve/reconcile.py" - "scripts/resolve/regions.py" - "scripts/resolve/review.py" + - "scripts/resolve/sendable.py" - "scripts/resolve/slot.py" - "scripts/resolve/standalone.py" - "scripts/resolve/truth.py" diff --git a/scripts/resolve/sendable.py b/scripts/resolve/sendable.py new file mode 100644 index 000000000..41e48e67b --- /dev/null +++ b/scripts/resolve/sendable.py @@ -0,0 +1,53 @@ +"""Whether a contributor can send a file the collection lacks.""" + +from __future__ import annotations + +import re + +from resolve.gamedata import is_game_data +from resolve.validation import installed_everywhere + +# A name the code builds from the content (.txt, *.ini) is a +# pattern, not a file anyone can upload. +PATTERN = re.compile(r"[<>*?]") +# A file not collected yet stays wanted, however hard it is to find ("no +# public dump located", "retail data the collection does not hold"). It +# leaves the list only when its reason (the profile's `unsourceable:`) +# says no copy can be shared, read by the rules below. +NOT_SHAREABLE = re.compile("|".join([ + # Any file of the name serves: there is no one file to collect. + r"\bno canonical\b", + # The user writes, picks, records or places it (WHDLoad's key aside, + # emucorev's config.txt: "plugin list the user writes"). + r"\bthe user\b|\buser[- ](?:supplied|authored|created|settings|overlay|placeholder)\b" + r"|\bother users\b", + # The emulator or the guest writes it: a save, a state, a generated key. + r"\bwritten by (?:the (?:emulator|guest|firmware editor)|bam)\b|\bgenerated by the emulator\b" + r"|\bwith the debug key\b|\bmachine state\b|\bcreat\w* (?:this directory )?empty\b", + # It belongs to one person, one account or one copy (puae's WHDLoad.key). + r"\bper[- ]user\b|\btied to the (?:account|tag)\b|\bnever distributed generically\b" + r"|\bissued for one copy\b", + # Nothing was ever released under the name. + r"\bno (?:distributed form|released artefact|hardware dump equivalent)\b" + r"|\bno file of this name is distributed\b", +]), re.I) + + +def shareable(reason: str) -> bool: + """False when a reason says no copy of the file can be shared.""" + return not NOT_SHAREABLE.search(reason) + + +def can_send(name: str, reason: str = "") -> bool: + """Whether a declared name and the reason it is not collected leave a + file someone can upload: not a pattern, not a file no copy of which can + be shared.""" + return not PATTERN.search(name) and shareable(reason) + + +def sendable(entry: dict, reason: str = "") -> bool: + """Whether a profile entry the collection lacks is a file to ask for: + can_send() holds, it is not game data (no contributor's to send), and + the emulator does not install it on every setup.""" + return (can_send(str(entry.get("name", "")), reason) + and not is_game_data(entry) and not installed_everywhere(entry)) diff --git a/scripts/sitegen/gaps.py b/scripts/sitegen/gaps.py index 3caeb838e..3fec54285 100644 --- a/scripts/sitegen/gaps.py +++ b/scripts/sitegen/gaps.py @@ -15,6 +15,7 @@ from model.profiles import is_emulator from packs.crossref import gap_source_counts from resolve.cores import resolve_platform_cores from resolve.nativemode import check_label +from resolve.sendable import sendable from sitegen import markup, wanted as sitewanted from sitegen.cards import PROVENANCE_LABELS, fetch_url from sitegen.config import date_line @@ -96,13 +97,29 @@ def _hash_cell(hashes: dict[str, list[str]]) -> str: ) +def catalog_listings(report: dict | None, labels: dict[str, str]) -> dict[tuple[str, str], list[tuple[str, str]]]: + """(profile, file name casefolded) -> (catalog or romset, the name it + lists the file under), from a provenance report built with the + profiles' needs: the "Listed in" column of the gaps page.""" + out: dict[tuple[str, str], list[tuple[str, str]]] = {} + for source, data in sorted((report or {}).items()): + label = labels.get(source, source) + for entry in data.get("missing", []): + where = [(label, str(entry.get("name", "")))] + where += [(str(hit["source"]), str(hit["archive"])) for hit in entry.get("romsets", [])] + for need in entry.get("needed_by", []): + held = out.setdefault((need["emulator"], str(need["name"]).casefold()), []) + held += [w for w in where if w not in held] + return out + + def _catalogued_needs(report: dict | None) -> dict[tuple[str, str], list[str]]: """(profile, file name casefolded) -> where a dump catalog or an imported romset lists that file, from a provenance report built with the profiles' needs.""" return { need: [f"{escape_tags(where)} `{escape_tags(name)}`" for where, name in listed] - for need, listed in sitewanted.catalog_listings(report, PROVENANCE_LABELS).items() + for need, listed in catalog_listings(report, PROVENANCE_LABELS).items() } @@ -783,6 +800,9 @@ def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict | "emu_key": emu_name, "reason": u["reason"], "source_ref": u.get("source_ref", ""), + # The wanted page's own rule, on the entries behind the row. + "wanted": any(sendable(entry, str(u["reason"])) for entry in sitewanted.gap_entries( + profiles.get(emu_name) or {}, str(u["name"]), "", True)), } for emu_name, data in sorted(report_all.items()) for u in data.get("unsourceable", []) @@ -797,8 +817,11 @@ def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict | "## Not collected yet", "", f"{len(all_unsourceable)} files the collection does not hold. A file " - "with the same name is never served in their place. Each is still " - "wanted, and the last column names a catalog or romset that lists it.", + "with the same name is never served in their place. The [wanted " + f"page](wanted.md) asks for the {sum(u['wanted'] for u in all_unsourceable)} " + "marked wanted. No one can send the others: a name the code builds, a " + "file no copy of which can be shared, game data, or a file the emulator " + "installs itself. \"Listed in\" names a catalog or romset that lists a file.", "", ] rows = [] @@ -807,15 +830,16 @@ def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict | rows.append( f"| `{u['name']}` | {u['emulator']} | {_reason_cell(u['reason'])} " f"| {source_ref_markdown(profiles[u['emu_key']], u['source_ref'])} " - f"| {', '.join(where) or '-'} |" + f"| {', '.join(where) or '-'} | {'yes' if u['wanted'] else 'no'} |" ) lines.extend(_moved_table( NOT_COLLECTED_STEM, "Files not collected yet", f"{count_text(len(rows), 'file')} the collection does not hold, each with the " - "emulator that loads it, why it is not collected and the catalog or romset " - "that lists it. Part of [What the packs do not hold](gaps.md#not-collected-yet).", - ["| File | Emulator | Reason | Source ref | Listed in |", - "|------|----------|--------|-----------|-----------|"], + "emulator that loads it, why it is not collected, the catalog or romset " + "that lists it and whether the [wanted page](wanted.md) asks for it. Part of " + "[What the packs do not hold](gaps.md#not-collected-yet).", + ["| File | Emulator | Reason | Source ref | Listed in | Wanted |", + "|------|----------|--------|-----------|-----------|--------|"], rows, "file", moved)) return lines diff --git a/scripts/sitegen/wanted.py b/scripts/sitegen/wanted.py index c447d8582..e632e20af 100644 --- a/scripts/sitegen/wanted.py +++ b/scripts/sitegen/wanted.py @@ -16,7 +16,6 @@ the review of the pull request asks for that same folder. from __future__ import annotations -import re import urllib.parse from collections.abc import Callable, Iterable from pathlib import Path @@ -28,7 +27,8 @@ from model.profiles import unique_emulator_profiles from packs.crossref import first_hash from core.hashing import cut_md5_owner, declared_hash_lists, parse_hash_list from resolve.review import LARGE_FILE_ISSUE_URL, Placement, placement -from resolve.validation import deliverable, filter_files_by_mode, installed_everywhere +from resolve.sendable import can_send, sendable +from resolve.validation import deliverable, filter_files_by_mode from sitegen.config import UPLOAD_ROOT ALGORITHMS = ("sha1", "sha256", "md5", "crc32") @@ -229,73 +229,29 @@ def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> li if gap.get("source") == "missing" and not gap.get("bundled")] rows += [(row, True) for row in data.get("unsourceable") or []] for row, unsourceable in rows: + reason = str(row.get("reason") or "") if unsourceable else "" for entry in gap_entries(profile, str(row.get("name", "")), str(row.get("identity") or ""), unsourceable): - if entry.get("category") == GAME_DATA or installed_everywhere(entry): + if not sendable(entry, reason): 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 "", + "reason": reason, "category": BIOS, "directory": _directory(entry), }) return found -def catalog_listings(report: dict | None, labels: dict[str, str]) -> dict[tuple[str, str], list[tuple[str, str]]]: - """(profile, file name casefolded) -> (catalog or romset, the name it - lists the file under), from a provenance report built with the - profiles' needs: the "Listed in" column of the gaps page.""" - out: dict[tuple[str, str], list[tuple[str, str]]] = {} - for source, data in sorted((report or {}).items()): - label = labels.get(source, source) - for entry in data.get("missing", []): - where = [(label, str(entry.get("name", "")))] - where += [(str(hit["source"]), str(hit["archive"])) for hit in entry.get("romsets", [])] - for need in entry.get("needed_by", []): - held = out.setdefault((need["emulator"], str(need["name"]).casefold()), []) - held += [w for w in where if w not in held] - return out - - 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. 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"[<>*?]") -# A file not collected yet stays wanted, however hard it is to find ("no -# public dump located", "retail data the collection does not hold"). It -# leaves the list only when its reason (the profile's `unsourceable:`) -# says no copy can be shared, read by the rules below. -NOT_SHAREABLE = re.compile("|".join([ - # Any file of the name serves: there is no one file to collect. - r"\bno canonical\b", - # The user writes, picks, records or places it (WHDLoad's key aside, - # emucorev's config.txt: "plugin list the user writes"). - r"\bthe user\b|\buser[- ](?:supplied|authored|created|settings|overlay|placeholder)\b" - r"|\bother users\b", - # The emulator or the guest writes it: a save, a state, a generated key. - r"\bwritten by (?:the (?:emulator|guest|firmware editor)|bam)\b|\bgenerated by the emulator\b" - r"|\bwith the debug key\b|\bmachine state\b|\bcreat\w* (?:this directory )?empty\b", - # It belongs to one person, one account or one copy (puae's WHDLoad.key). - r"\bper[- ]user\b|\btied to the (?:account|tag)\b|\bnever distributed generically\b" - r"|\bissued for one copy\b", - # Nothing was ever released under the name. - r"\bno (?:distributed form|released artefact|hardware dump equivalent)\b" - r"|\bno file of this name is distributed\b", -]), re.I) - - -def shareable(reason: str) -> bool: - """False when a reason says no copy of the file can be shared.""" - return not NOT_SHAREABLE.search(reason) def _settle_cut(records: list[dict]) -> None: @@ -444,7 +400,7 @@ def _collect_records(declarations: Iterable[dict], held: Held, share are left out.""" records: dict[tuple, dict] = {} for declaration in declarations: - if PATTERN.search(declaration["name"]) or not shareable(declaration["reason"]): + if not can_send(declaration["name"], declaration["reason"]): continue entry = declaration["entry"] sizes = _sizes(entry) diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 27342e4b5..a5fb965fc 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -5804,11 +5804,12 @@ class UnsourceableCardSaysWhy(unittest.TestCase): "needed_by": [{"emulator": "xm7", "name": "KANJI2.ROM", "required": True}], }]}} page = generate_gap_analysis( - {"xm7": {"emulator": "XM7", "files": []}}, {}, {"files": {}, "indexes": {}}, - gap_report=report, catalogued=catalogued) + {"xm7": {"emulator": "XM7", "files": [{"name": "KANJI2.ROM", + "unsourceable": "no dump distributed"}]}}, + {}, {"files": {}, "indexes": {}}, gap_report=report, catalogued=catalogued) self.assertIn("## Not collected yet", page) self.assertIn('', page) - self.assertIn("| No-Intro `KANJI2.rom`, mame `fm7740sx.zip` |", page) + self.assertIn("| No-Intro `KANJI2.rom`, mame `fm7740sx.zip` | yes |", page) self.assertNotIn("Acknowledged", page) self.assertNotIn("verified from source code", page) diff --git a/tests/test_site_wanted.py b/tests/test_site_wanted.py index 265ab305f..dc2b8fd36 100644 --- a/tests/test_site_wanted.py +++ b/tests/test_site_wanted.py @@ -28,7 +28,7 @@ from pathlib import Path from sitegen import gaps from sitegen import lookup from sitegen import wanted as sitewanted -from resolve import review +from resolve import review, sendable import yaml from model.database import load_database from tests.test_site_pronouns import pronouns @@ -221,6 +221,27 @@ class TheListHoldsWhatTheGapsReportLacks(_World): names = [d["name"] for d in sitewanted.wanted_declarations({}, coverages, {})] self.assertNotIn("v.bin", names) + def test_the_gaps_page_marks_what_the_wanted_page_asks_for(self): + """The gaps page said every file not collected yet was still wanted, + while the wanted page leaves out a pattern and a file no copy of + which can be shared: 125 rows a contributor could not find there.""" + rows = [{"name": "kanji.rom", "reason": "no public dump located", "source_ref": ""}, + {"name": "default.lua", "reason": "script the user writes", "source_ref": ""}, + {"name": ".txt", "reason": "no public dump located", "source_ref": ""}] + profile = {"emulator": "E", "files": [{"name": row["name"], "unsourceable": row["reason"]} + for row in rows]} + report = {"e": {"emulator": "E", "gaps": 0, "gap_missing": 0, "gap_bios": 0, + "unsourceable": rows, "gap_details": []}} + page = gaps.generate_gap_analysis({"e": profile}, {}, {"files": {}, "indexes": {}}, + gap_report=report) + self.assertIn("asks for the 1 marked wanted", page) + self.assertIn("| `kanji.rom` | E |", page) + marks = {line.split("`")[1]: line.rsplit("|", 2)[1].strip() + for line in page.splitlines() if line.startswith("| `")} + self.assertEqual(marks, {"kanji.rom": "yes", "default.lua": "no", ".txt": "no"}) + listed = [d["name"] for d in sitewanted.wanted_declarations({"e": profile}, {}, report)] + self.assertEqual(listed, [name for name, mark in marks.items() if mark == "yes"]) + 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.""" @@ -262,14 +283,14 @@ class TheListHoldsWhatTheGapsReportLacks(_World): reasons[name] = str(found[0]["unsourceable"]) for name, reason in reasons.items(): with self.subTest(name=name): - self.assertFalse(sitewanted.shareable(reason), reason) + self.assertFalse(sendable.shareable(reason), reason) for reason in ("no public dump located (2026-10-04), and a same-named ROM of another set " "must not stand in", "retail data the collection does not hold, and a same-named file of another " "game must not stand in", "ships inside the Ghostship release, and the collection does not hold it"): with self.subTest(reason=reason): - self.assertTrue(sitewanted.shareable(reason)) + self.assertTrue(sendable.shareable(reason)) def test_more_readers_come_first(self): records = [{"name": "a", "required": False, "readers": {("emulator", "e", "E")}},