feat: record the commit a branch scrape read

Six platforms are read from a branch: System.dat, batocera-systems.json, checkBIOS.sh, the MiSTer BiosDB, the RetroPie scriptmodules and the RetroDECK component manifests. Their YAML named the branch, so the native export patched whatever the branch had become since the scrape. Each scraper now resolves the branch head once, reads every file at that commit and writes it into source. The export follows a recorded tarball and a recorded tree as it already followed a raw file URL.
This commit is contained in:
Abdessamad Derraz committed 2026-10-19 22:50:45 +02:00
1 parent eafb73bf55
commit 16f6ef8cbf
17 files changed
+203 -38

No files matched your search

+1 -1
View File
@@ -5497,7 +5497,7 @@ struct BurnDriver BurnDrvneogeo = {
from scraper.misterfpga_scraper import Scraper
scraper = Scraper()
scraper = Scraper(url="https://example.test/bios_db.json.zip")
scraper._raw_data = json.dumps(self.MISTER_DB)
return scraper
+16
View File
@@ -34,6 +34,8 @@ class _Response(io.BytesIO):
def _opener(failure):
def urlopen(req, timeout=0):
url = req.full_url
if "/commits/" in url:
return _Response(json.dumps({"sha": "a" * 40}).encode())
if "api.github.com" in url:
return _Response(json.dumps(TREE).encode())
if "pcsx2" in url and failure is not None:
@@ -60,6 +62,20 @@ class ManifestErrors(unittest.TestCase):
error = urllib.error.HTTPError("u", 404, "not found", {}, None)
self.assertEqual([name for name, _ in self.fetch(error)], ["ppsspp"])
def test_the_tree_and_files_are_read_at_one_commit(self):
seen = []
opener = _opener(None)
def recording(req, timeout=0):
seen.append(req.full_url)
return opener(req, timeout)
with mock.patch("urllib.request.urlopen", recording):
Scraper()._fetch_remote_manifests()
reads = [url for url in seen if "/commits/" not in url]
self.assertTrue(reads)
self.assertTrue(all("a" * 40 in url for url in reads), reads)
def test_a_truncated_tree_stops_the_scrape(self):
TREE["truncated"] = True
self.addCleanup(TREE.pop, "truncated")
+56 -1
View File
@@ -11,6 +11,8 @@ exercised is a promise to contributors backed by nothing.
from __future__ import annotations
import importlib
import io
import json
import subprocess
import sys
import tempfile
@@ -246,7 +248,9 @@ class RetroPiePackageList(unittest.TestCase):
def _scraper(self, modules: dict[str, str]):
from scraper.retropie_scraper import Scraper
scraper = Scraper()
# An explicit archive URL: the tests read a local archive, never the
# branch head.
scraper = Scraper(url="https://codeload.github.com/RetroPie/RetroPie-Setup/tar.gz/" + "0" * 40)
scraper.module_ids(self._archive(modules))
return scraper
@@ -502,6 +506,11 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
"scraper.romm_scraper",
"scraper.batocera_scraper",
"scraper.recalbox_scraper",
"scraper.libretro_scraper",
"scraper.retrobat_scraper",
"scraper.emudeck_scraper",
"scraper.misterfpga_scraper",
"scraper.retropie_scraper",
):
module = importlib.import_module(name)
with self.subTest(scraper=name), mock.patch(
@@ -509,6 +518,52 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
), self.assertRaises(RuntimeError):
module.Scraper()
def test_a_branch_read_records_its_commit(self):
"""System.dat, batocera-systems.json, checkBIOS.sh, the BiosDB and the
RetroPie scriptmodules are read from a branch. The YAML named the
branch, so the exporter patched whatever it had become since."""
sha = "0123456789abcdef0123456789abcdef01234567"
class Answer(io.BytesIO):
def __enter__(self):
return self
def __exit__(self, *_exc):
return False
def answer(request, timeout=None):
return Answer(json.dumps({"sha": sha}).encode())
for name in (
"scraper.libretro_scraper",
"scraper.retrobat_scraper",
"scraper.emudeck_scraper",
"scraper.misterfpga_scraper",
"scraper.retropie_scraper",
):
module = importlib.import_module(name)
with self.subTest(scraper=name), mock.patch("urllib.request.urlopen", answer):
self.assertRegex(module.Scraper().url, f"/{sha}(/|$)")
def test_the_export_reads_the_recorded_tarball(self):
from export_native import _tarball_at
branch = "https://codeload.github.com/RetroPie/RetroPie-Setup/tar.gz/refs/heads/master"
pinned = "https://codeload.github.com/RetroPie/RetroPie-Setup/tar.gz/" + "a" * 40
self.assertEqual(_tarball_at(branch, pinned), pinned)
other = "https://codeload.github.com/Other/Repo/tar.gz/" + "b" * 40
self.assertEqual(_tarball_at(branch, other), "")
def test_the_export_reads_every_component_at_the_recorded_tree(self):
from export_native import pinned_base
sha = "c" * 40
base = pinned_base(
{"pcsx2/component_manifest.json": "unused"},
{"source": f"https://github.com/RetroDECK/components/tree/{sha}"},
)
self.assertEqual(base, f"https://raw.githubusercontent.com/RetroDECK/components/{sha}/")
def test_a_release_lookup_raises(self):
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
RuntimeError