diff --git a/scripts/scraper/mame_hash_scraper.py b/scripts/scraper/mame_hash_scraper.py index 3274007f..0590a374 100644 --- a/scripts/scraper/mame_hash_scraper.py +++ b/scripts/scraper/mame_hash_scraper.py @@ -157,11 +157,22 @@ def _parse_version_tag(tag: str) -> str: def _get_commit() -> str: + """The commit the clone holds, or an error: never an empty pin. + + Returned empty, it was cached for a day and the merge advanced + core_version and the refs to the new release while upstream_commit + stayed on the old one, a profile describing two revisions at once. + """ try: result = _run_git(["rev-parse", "HEAD"], cwd=_CLONE_DIR) - return result.stdout.strip() - except subprocess.CalledProcessError: - return "" + except subprocess.CalledProcessError as exc: + raise RuntimeError( + f"cannot read the commit of the MAME clone in {_CLONE_DIR}: {exc}" + ) from exc + commit = result.stdout.strip() + if not commit: + raise RuntimeError(f"the MAME clone in {_CLONE_DIR} names no commit") + return commit def _cleanup() -> None: diff --git a/tests/test_hash_merge.py b/tests/test_hash_merge.py index 9336bbb6..c75ccf35 100644 --- a/tests/test_hash_merge.py +++ b/tests/test_hash_merge.py @@ -685,5 +685,26 @@ class TestDerivativeVersion(unittest.TestCase): self.assertEqual(entry["source_ref"], "src/mame/philips/cdi.cpp:484") +class AnUnreadableCloneStopsTheScrape(unittest.TestCase): + """_get_commit swallowed a failed rev-parse and returned "": cached for a + day, the merge then advanced core_version and the refs while + upstream_commit stayed on the previous release.""" + + def test_no_empty_commit_reaches_the_cache(self): + import subprocess + from unittest import mock + + from scripts.scraper import mame_hash_scraper as scraper + + failing = subprocess.CalledProcessError(128, ["git", "rev-parse", "HEAD"]) + with mock.patch.object(scraper, "_run_git", side_effect=failing): + with self.assertRaises(RuntimeError): + scraper._get_commit() + empty = subprocess.CompletedProcess(["git"], 0, stdout="\n", stderr="") + with mock.patch.object(scraper, "_run_git", return_value=empty): + with self.assertRaises(RuntimeError): + scraper._get_commit() + + if __name__ == "__main__": unittest.main()