From ccf1a1573adac625d1d326cfb16896acaabd1ca2 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 01:47:48 +0200 Subject: [PATCH] fix: read platform hashes as verify does in PR checks --- scripts/validate_pr.py | 34 ++++++++++++++++++---------- tests/test_validate_pr_hashes.py | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 tests/test_validate_pr_hashes.py diff --git a/scripts/validate_pr.py b/scripts/validate_pr.py index 25a6a8e8..462dbdd6 100644 --- a/scripts/validate_pr.py +++ b/scripts/validate_pr.py @@ -25,7 +25,13 @@ import sys from pathlib import Path sys.path.insert(0, os.path.dirname(__file__)) -from common import compute_hashes, list_registered_platforms, load_database, yaml_load +from common import ( + compute_hashes, + list_registered_platforms, + load_database, + load_platform_config, + parse_md5_list, +) try: import yaml @@ -109,20 +115,24 @@ def load_platform_hashes(platforms_dir: str) -> dict: if not os.path.isdir(platforms_dir) or yaml is None: return known + # Read the way verify reads them: inheritance and shared groups resolved, + # and a Recalbox md5 field split into the revisions it lists. The raw + # file kept "a,b,c" as one value, so a PR adding the seventh accepted + # falcon.img was told its hash differs. for name in list_registered_platforms(platforms_dir, include_archived=True): - f = Path(platforms_dir) / f"{name}.yml" - with open(f) as fh: - try: - config = yaml_load(fh) or {} - except yaml.YAMLError: - continue + try: + config = load_platform_config(name, platforms_dir) + except (OSError, yaml.YAMLError) as exc: + print(f"WARNING: {name}: {exc}", file=sys.stderr) + continue - for sys_id, system in config.get("systems", {}).items(): + for system in config.get("systems", {}).values(): for file_entry in system.get("files", []): - if "sha1" in file_entry: - known["sha1"].add(file_entry["sha1"]) - if "md5" in file_entry: - known["md5"].add(file_entry["md5"]) + sha1 = file_entry.get("sha1") + for value in sha1 if isinstance(sha1, list) else [sha1]: + if value: + known["sha1"].add(str(value).lower()) + known["md5"].update(parse_md5_list(file_entry.get("md5"))) if "name" in file_entry: known["names"].add(file_entry["name"]) diff --git a/tests/test_validate_pr_hashes.py b/tests/test_validate_pr_hashes.py new file mode 100644 index 00000000..28075668 --- /dev/null +++ b/tests/test_validate_pr_hashes.py @@ -0,0 +1,39 @@ +"""validate_pr knows every revision a platform accepts. + +It read the platform YAMLs raw: a Recalbox md5 field "a,b,c" stayed one +value, so a pull request adding the seventh falcon.img Recalbox lists was +answered "hash differs, may be a variant". Inheritance and shared groups +were lost the same way. +""" + +from __future__ import annotations + +import sys +import unittest +from pathlib import Path + +import yaml + +REPO_ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(REPO_ROOT / "scripts")) + + +class EveryAcceptedRevisionIsKnown(unittest.TestCase): + def test_multi_hash_members_are_known(self): + import validate_pr + + known = validate_pr.load_platform_hashes(str(REPO_ROOT / "platforms")) + raw = yaml.safe_load((REPO_ROOT / "platforms" / "recalbox.yml").read_text()) + listed = [ + value.strip().lower() + for system in raw["systems"].values() + for entry in system.get("files", []) + if "," in str(entry.get("md5", "")) + for value in str(entry["md5"]).split(",") + ] + self.assertTrue(listed) + self.assertEqual([v for v in listed if v not in known["md5"]], []) + + +if __name__ == "__main__": + unittest.main()