From 7bd2579022c527ba316a8f7a9fc1ab54a71eec27 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 08:41:32 +0200 Subject: [PATCH] fix: stop calling a held file its own duplicate --- scripts/validate_pr.py | 16 +++++++++++++--- tests/test_validate_pr.py | 11 +++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/scripts/validate_pr.py b/scripts/validate_pr.py index f2b915d8..b801d533 100644 --- a/scripts/validate_pr.py +++ b/scripts/validate_pr.py @@ -210,9 +210,19 @@ def validate_file( if db: if result.sha1 in db.get("files", {}): existing = db["files"][result.sha1] - result.add_warning( - f"Duplicate: identical file already exists at `{existing['path']}`" - ) + held_at = { + os.path.normpath(p) + for p in [existing.get("path"), *(existing.get("paths") or [])] if p + } + if os.path.normpath(filepath) in held_at: + # The file the database was built from, not a copy of it: a + # PR that regenerated database.json was told each new file + # duplicated itself. + result.add_check(True, "Already in the database at this path") + else: + result.add_warning( + f"Duplicate: identical file already exists at `{existing['path']}`" + ) else: result.add_check(True, "Not a duplicate in database") diff --git a/tests/test_validate_pr.py b/tests/test_validate_pr.py index 43127578..65f4d3f2 100644 --- a/tests/test_validate_pr.py +++ b/tests/test_validate_pr.py @@ -184,6 +184,17 @@ class HashRecognition(_Fixture): self.assertTrue(validate_pr.validate_file(rel, db, EMPTY_HASHES).passed) + def test_the_file_the_database_holds_is_not_its_own_duplicate(self): + """The documented example on a tracked file warned "Duplicate: + identical file already exists at" the very path being validated.""" + rel = self._bios_file("bios/Sony/PS/held.bin") + probe = validate_pr.validate_file(rel, None, EMPTY_HASHES) + db = {"files": {probe.sha1: {"path": rel}}} + markdown = validate_pr.validate_file(rel, db, EMPTY_HASHES).to_markdown() + self.assertNotIn("Duplicate", markdown) + self.assertIn("Already in the database at this path", markdown) + + class Placement(_Fixture): def test_manufacturer_and_console_directories_are_accepted(self): rel = self._bios_file("bios/Sega/Saturn/sega_101.bin")