From 1bbb1d4749fb7d42c9599d3474595f422cc23e6d Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 20 Oct 2026 06:17:40 +0200 Subject: [PATCH] fix: emulator JSON-LD names every repository read The structured data of an emulator page published one repository and one commit. A profile whose builds live in two repositories, or a port with an upstream_commit, now lists each repository with its own pin. --- scripts/generate_site.py | 39 ++++++++++++++++++++------------- tests/test_audit_regressions.py | 16 ++++++++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/scripts/generate_site.py b/scripts/generate_site.py index 14ef408b..4a996920 100644 --- a/scripts/generate_site.py +++ b/scripts/generate_site.py @@ -1498,21 +1498,30 @@ def emulator_structured_data(profile: dict) -> dict: the core loads, their hashes, the source read or when. """ data: dict = {} - source = profile.get("source") - if isinstance(source, dict): - source = next(iter(source.values()), "") - commit = profile.get("source_commit") - if isinstance(commit, dict): - commit = next(iter(commit.values()), "") - if source: - about = { - "@type": "SoftwareSourceCode", - "name": str(profile.get("emulator", "")), - "codeRepository": str(source), - } - if commit: - about["version"] = str(commit) - data["about"] = about + # Every repository the profile reads, each with its own pin: xemu's + # libretro build lives in another repository at another commit, and a + # port's upstream_commit was never published. + about = [] + seen: set[str] = set() + for field in ("source", "upstream"): + urls = profile.get(field) + pins = profile.get(f"{field}_commit") + for mode, url in (urls.items() if isinstance(urls, dict) else [("", urls)]): + if not url or not str(url).startswith("http") or str(url) in seen: + continue + seen.add(str(url)) + pin = pins.get(mode) if isinstance(pins, dict) else pins + entry = { + "@type": "SoftwareSourceCode", + "name": str(profile.get("emulator", "")), + "codeRepository": str(url), + "description": " ".join(filter(None, [mode, field])), + } + if pin: + entry["version"] = str(pin) + about.append(entry) + if about: + data["about"] = about[0] if len(about) == 1 else about if profile.get("profiled_date"): data["dateModified"] = str(profile["profiled_date"]) parts = [] diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 9cf2f40b..03fcdf53 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -4125,6 +4125,22 @@ class EmulatorPagesStateTheirDataForMachines(unittest.TestCase): self.assertEqual(data["hasPart"][0]["identifier"], ["sha1:" + "a" * 40, "md5:490f666e"]) self.assertNotIn("identifier", data["hasPart"][1]) + def test_every_repository_with_its_own_pin(self): + """xemu's libretro build lives in another repository at another + commit, and a port's upstream_commit was never published.""" + from scripts.generate_site import emulator_structured_data + + data = emulator_structured_data({ + "emulator": "xemu", + "source": {"standalone": "https://github.com/xemu-project/xemu", + "libretro": "https://github.com/LibretroAdmin/xemu-libretro"}, + "source_commit": {"standalone": "f9b14039", "libretro": "d9804db7"}, + "upstream": "https://github.com/mborgerson/xemu", "upstream_commit": "aa11", + }) + self.assertEqual( + [(a["codeRepository"].rsplit("/", 1)[1], a.get("version")) for a in data["about"]], + [("xemu", "f9b14039"), ("xemu-libretro", "d9804db7"), ("xemu", "aa11")]) + class AManifestHashesAFileOnce(unittest.TestCase):