From cbe1848d100cb7c55517e1a12b9397c9b5876b59 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Fri, 14 Aug 2026 14:51:03 -0500 Subject: [PATCH] fix: prefer changelog over Game.ini in census sidecar scan --- scripts/update_swarm/census.py | 26 ++++++++++--------- .../fixtures/library/both-sidecars/Game.ini | 3 +++ .../library/both-sidecars/changelog.txt | 1 + .../fixtures/library/both-sidecars/dummy.bin | 0 tests/update_swarm/test_census.py | 11 ++++++++ 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 tests/update_swarm/fixtures/library/both-sidecars/Game.ini create mode 100644 tests/update_swarm/fixtures/library/both-sidecars/changelog.txt create mode 100644 tests/update_swarm/fixtures/library/both-sidecars/dummy.bin diff --git a/scripts/update_swarm/census.py b/scripts/update_swarm/census.py index aaea6f4..a7b95f1 100644 --- a/scripts/update_swarm/census.py +++ b/scripts/update_swarm/census.py @@ -20,19 +20,21 @@ def _from_text(text: str) -> str | None: def _sidecar_version(file_path: str) -> str | None: parent = os.path.dirname(file_path) - for name in os.listdir(parent) if os.path.isdir(parent) else []: - low = name.lower() - if low in CHANGELOG_NAMES or low == "game.ini": + if not os.path.isdir(parent): + return None + names = os.listdir(parent) + for name in names: + if name.lower() in CHANGELOG_NAMES: with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh: - text = fh.read() - if low == "game.ini": - m = INI_VER.search(text) - if m: - return m.group(1).strip() - else: - found = _from_text(text) - if found: - return found + found = _from_text(fh.read()) + if found: + return found + for name in names: + if name.lower() == "game.ini": + with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh: + m = INI_VER.search(fh.read()) + if m: + return m.group(1).strip() return None def _zip_version(file_path: str) -> str | None: diff --git a/tests/update_swarm/fixtures/library/both-sidecars/Game.ini b/tests/update_swarm/fixtures/library/both-sidecars/Game.ini new file mode 100644 index 0000000..3de6fa0 --- /dev/null +++ b/tests/update_swarm/fixtures/library/both-sidecars/Game.ini @@ -0,0 +1,3 @@ +[Game] +Title=Both Sidecars +Version=9.9.9 diff --git a/tests/update_swarm/fixtures/library/both-sidecars/changelog.txt b/tests/update_swarm/fixtures/library/both-sidecars/changelog.txt new file mode 100644 index 0000000..7cdf4d0 --- /dev/null +++ b/tests/update_swarm/fixtures/library/both-sidecars/changelog.txt @@ -0,0 +1 @@ +Current Version: 3.3.1 diff --git a/tests/update_swarm/fixtures/library/both-sidecars/dummy.bin b/tests/update_swarm/fixtures/library/both-sidecars/dummy.bin new file mode 100644 index 0000000..e69de29 diff --git a/tests/update_swarm/test_census.py b/tests/update_swarm/test_census.py index e87b8b8..6f8f230 100644 --- a/tests/update_swarm/test_census.py +++ b/tests/update_swarm/test_census.py @@ -1,4 +1,5 @@ import hashlib, os, sys, tempfile, unittest, zipfile +from unittest.mock import patch ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) sys.path.insert(0, os.path.join(ROOT, "scripts")) from update_swarm.census import census_job @@ -19,6 +20,16 @@ class TestCensus(unittest.TestCase): self.assertEqual(rec["installed_version"], "1.74.1") self.assertEqual(rec["source"], "file") + @patch( + "update_swarm.census.os.listdir", + return_value=["Game.ini", "changelog.txt", "dummy.bin"], + ) + def test_sidecar_prefers_changelog_over_game_ini(self, _listdir): + rec = census_job(job("B"), os.path.join(FIX, "both-sidecars", "dummy.bin")) + self.assertEqual(rec["installed_version"], "3.3.1") + self.assertEqual(rec["source"], "file") + self.assertEqual(rec["evidence"], "sidecar") + def test_filename_token(self): rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip")) self.assertEqual(rec["installed_version"], "3.3.1")