From 892cff38bc26b7bc7c76e0ac7a4fe6dac199e65b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:43:58 +0200 Subject: [PATCH] fix: diff every declaration of a repeated destination --- scripts/check_freshness.py | 24 ++++++++++++++++++------ tests/test_check_freshness.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/scripts/check_freshness.py b/scripts/check_freshness.py index 6985dae9..5e35d0d0 100644 --- a/scripts/check_freshness.py +++ b/scripts/check_freshness.py @@ -157,6 +157,22 @@ def _core_names(config: dict) -> set[str]: return names +def _keyed_files(files: list[dict]) -> dict[str, dict]: + """Each declaration under its own key. + + A platform declares one destination several times (an archive once per + inner ROM, MD5 alternatives): keyed by destination alone, the dict kept + the last and a change to the others read as identical. + """ + keyed: dict[str, dict] = {} + seen: dict[str, int] = {} + for f in files: + key = _file_key(f) + seen[key] = seen.get(key, 0) + 1 + keyed[key if seen[key] == 1 else f"{key}#{seen[key]}"] = f + return keyed + + def diff_platform(old: dict, new: dict) -> PlatformDiff: """Compare two platform files the way a reviewer reads the diff. @@ -172,12 +188,8 @@ def diff_platform(old: dict, new: dict) -> PlatformDiff: diff.systems_added = sorted(set(new_systems) - set(old_systems)) diff.systems_removed = sorted(set(old_systems) - set(new_systems)) for system in sorted(set(old_systems) & set(new_systems)): - old_files = { - _file_key(f): f for f in (old_systems[system] or {}).get("files") or [] - } - new_files = { - _file_key(f): f for f in (new_systems[system] or {}).get("files") or [] - } + old_files = _keyed_files((old_systems[system] or {}).get("files") or []) + new_files = _keyed_files((new_systems[system] or {}).get("files") or []) diff.files_added.extend( f"{system}/{k}" for k in sorted(set(new_files) - set(old_files)) ) diff --git a/tests/test_check_freshness.py b/tests/test_check_freshness.py index 21d38f38..809f8b56 100644 --- a/tests/test_check_freshness.py +++ b/tests/test_check_freshness.py @@ -304,5 +304,19 @@ class RepositoryWiringTests(unittest.TestCase): self.assertIn("[data]", text) +class RepeatedDestinations(unittest.TestCase): + def test_a_change_to_an_earlier_declaration_is_seen(self): + from check_freshness import diff_platform # noqa: PLC0415 + + def platform(first_md5: str) -> dict: + return {"systems": {"pce": {"files": [ + {"name": "syscard3.pce", "destination": "syscard3.pce", "md5": first_md5}, + {"name": "syscard3.pce", "destination": "syscard3.pce", "md5": "b" * 32}, + ]}}} + + diff = diff_platform(platform("a" * 32), platform("c" * 32)) + self.assertEqual(diff.files_changed, ["pce/syscard3.pce"]) + + if __name__ == "__main__": unittest.main()