feat: census installed hack versions from files with note fallback

This commit is contained in:
ginnoir committed 2026-08-14 14:49:02 -05:00
1 parent d91b0bc13d
commit 25eee44483
7 files changed
+145

No files matched your search

@@ -0,0 +1 @@
Current Version: 3.3.1
Whitespace-only changes.
@@ -0,0 +1,3 @@
[Game]
Title=Ini Game
Version=1.74.1
Whitespace-only changes.
+43
View File
@@ -0,0 +1,43 @@
import hashlib, os, sys, tempfile, unittest, zipfile
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
FIX = os.path.join(os.path.dirname(__file__), "fixtures", "library")
def job(stem, note_version=None):
return {"stem": stem, "library_path": None, "note_version": note_version}
class TestCensus(unittest.TestCase):
def test_changelog_current_version_line(self):
rec = census_job(job("C"), os.path.join(FIX, "changelog-game", "dummy.bin"))
self.assertEqual(rec["installed_version"], "3.3.1")
self.assertEqual(rec["source"], "file")
def test_game_ini_version(self):
rec = census_job(job("I"), os.path.join(FIX, "ini-game", "dummy.bin"))
self.assertEqual(rec["installed_version"], "1.74.1")
self.assertEqual(rec["source"], "file")
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")
def test_zip_inner_changelog(self):
with tempfile.TemporaryDirectory() as td:
zpath = os.path.join(td, "game.zip")
with zipfile.ZipFile(zpath, "w") as z:
z.writestr("README.txt", "Current Version: 2.13\n")
rec = census_job(job("Z"), zpath)
self.assertEqual(rec["installed_version"], "2.13")
def test_note_fallback_then_unknown(self):
rec = census_job(job("X", note_version="9.9"), None)
self.assertEqual(rec["source"], "note")
self.assertEqual(rec["installed_version"], "9.9")
rec2 = census_job(job("Y"), None)
self.assertEqual(rec2["source"], "unknown")
self.assertIsNone(rec2["installed_version"])
if __name__ == "__main__":
unittest.main()