fix: address whole-branch review findings for update-swarm

- versions: require entire normalized string to be numeric so dates
  and hotfix suffixes compare as incomparable instead of eq/gt
- hosts: exact host or dot-suffix match rejects lookalikes like
  notmediafire.com and evilmega.nz; GitHub stays exact-set
- census: lazy extractor loop so a later OSError no longer discards an
  earlier sidecar changelog hit
- jobs: watchlist parses only table rows whose vault-note cell is a
  bare wikilink (skips parenthetical related/complete notes); wanted
  also matches bold names in Wanted.md tables with Pokemon prefix
  stripped and casefolded
- cli: validate-scouts and judge raise SystemExit when jobs.json has
  jobs but scouts/ has zero valid files
- fetch: download forwards timeout=60 to urlopen and writes to a
  .part file then os.replace, removing the partial on any failure
This commit is contained in:
ginnoir committed 2026-08-14 15:11:16 -05:00
1 parent 37ebc97b51
commit cb294f72a0
16 files changed
+234 -48

No files matched your search

@@ -1,3 +1,5 @@
| Hack | Vault note |
|---|---|
| **DemoOnly** | [[DemoOnly]] |
| Hack | Vault note | Why parked | Where to watch |
|---|---|---|---|
| **DemoOnly** | [[DemoOnly]] | Essentials demo v0.6.2 | Eevee Expo |
| **Odyssey II / Heroes of Lemuria** | [[Odyssey]] (related) | Demo / early build | Discord |
| **Light Platinum DS** | [[Light Platinum]] (GBA complete; DS is separate) | DS remake — media/teasers only | Twitter |
@@ -0,0 +1,8 @@
---
title: "Pokémon Light Platinum"
platform: GBA
version: "1.0"
status: Complete
---
# Pokémon Light Platinum
@@ -0,0 +1,8 @@
---
title: "Pokémon Odyssey"
platform: GBA
version: "1.0"
status: Complete
---
# Pokémon Odyssey
@@ -1 +1,15 @@
# Wanted — Manual Acquisition List
See [[FakeHack]] still gated.
## Acquired
| Hack | Path |
|---|---|
| **FakeHack** | `gba/Hacks/Pokemon - FakeHack (Hack).gba` |
## Still wanted
| Hack | Notes |
|---|---|
| **DemoOnly** | demo-only entry, not in library yet |
+19
View File
@@ -50,5 +50,24 @@ class TestCensus(unittest.TestCase):
self.assertEqual(rec2["source"], "unknown")
self.assertIsNone(rec2["installed_version"])
@patch(
"update_swarm.census.os.listdir",
return_value=["changelog.txt", "dummy.bin"],
)
def test_rom_version_oserror_keeps_sidecar(self, _listdir):
# A later OSError must not discard an earlier sidecar hit.
with tempfile.TemporaryDirectory() as td:
cpath = os.path.join(td, "changelog.txt")
with open(cpath, "w", encoding="utf-8") as fh:
fh.write("Current Version: 3.3.1\n")
rom_path = os.path.join(td, "dummy.bin")
with open(rom_path, "wb") as fh:
fh.write(b"\x00")
with patch("update_swarm.census._rom_version", side_effect=OSError("boom")):
rec = census_job(job("S"), rom_path)
self.assertEqual(rec["installed_version"], "3.3.1")
self.assertEqual(rec["source"], "file")
self.assertEqual(rec["evidence"], "sidecar")
if __name__ == "__main__":
unittest.main()
+36 -1
View File
@@ -1,8 +1,9 @@
import json, os, sys, tempfile, unittest
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sys.path.insert(0, os.path.join(ROOT, "scripts"))
from update_swarm.cli import deploy_argv, validate_scout
from update_swarm.cli import deploy_argv, validate_scout, main
from update_swarm.reports import write_reports
from update_swarm.schema import write_json
class TestCli(unittest.TestCase):
def test_validate_scout_missing_keys(self):
@@ -41,5 +42,39 @@ class TestCli(unittest.TestCase):
self.assertIn("latest_english_version", text)
self.assertIn("Do not invent versions", text)
def _valid_scout(self, stem):
return {
"stem": stem, "latest_english_version": "1.0", "url": "https://example.com/z.zip",
"host": "other", "gate": "gated", "language_matrix": {"en": "1.0"},
"source_used": "website", "hackdex": "skipped", "upstream_status": "Complete", "notes": "",
}
def test_validate_scouts_fails_when_jobs_but_no_scouts(self):
with tempfile.TemporaryDirectory() as td:
run = os.path.join(td, "2026-08-14")
os.makedirs(os.path.join(run, "scouts"))
write_json(os.path.join(run, "jobs.json"),
{"run_date": "2026-08-14", "jobs": [{"stem": "X"}]})
with self.assertRaises(SystemExit):
main(["--run", run, "validate-scouts"])
def test_validate_scouts_ok_when_scouts_present(self):
with tempfile.TemporaryDirectory() as td:
run = os.path.join(td, "2026-08-14")
scouts = os.path.join(run, "scouts")
os.makedirs(scouts)
write_json(os.path.join(run, "jobs.json"),
{"run_date": "2026-08-14", "jobs": [{"stem": "X"}]})
write_json(os.path.join(scouts, "X.json"), self._valid_scout("X"))
self.assertEqual(main(["--run", run, "validate-scouts"]), 0)
def test_validate_scouts_ok_when_no_jobs(self):
with tempfile.TemporaryDirectory() as td:
run = os.path.join(td, "2026-08-14")
os.makedirs(os.path.join(run, "scouts"))
write_json(os.path.join(run, "jobs.json"),
{"run_date": "2026-08-14", "jobs": []})
self.assertEqual(main(["--run", run, "validate-scouts"]), 0)
if __name__ == "__main__":
unittest.main()
+17 -1
View File
@@ -27,10 +27,26 @@ class TestFetch(unittest.TestCase):
return b"rombytes"
with tempfile.TemporaryDirectory() as td:
dest = os.path.join(td, "g.gba")
with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()):
with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()) as mock_urlopen:
rec = download("https://github.com/a/b/releases/download/v1/g.gba", dest)
self.assertTrue(os.path.isfile(dest))
self.assertEqual(rec["size"], 8)
# timeout kwarg must be forwarded to urlopen
self.assertEqual(mock_urlopen.call_args.kwargs.get("timeout"), 60)
def test_download_failure_leaves_no_dest(self):
class Resp:
def __enter__(self): return self
def __exit__(self, *a): pass
def read(self, n=-1):
raise OSError("network died")
with tempfile.TemporaryDirectory() as td:
dest = os.path.join(td, "g.gba")
with patch("update_swarm.fetch.urllib.request.urlopen", return_value=Resp()):
with self.assertRaises(OSError):
download("https://github.com/a/b/releases/download/v1/g.gba", dest)
self.assertFalse(os.path.exists(dest))
self.assertFalse(os.path.exists(dest + ".part"))
def test_mega_not_implemented(self):
with tempfile.TemporaryDirectory() as td:
+11
View File
@@ -20,5 +20,16 @@ class TestClassify(unittest.TestCase):
self.assertEqual(classify_url("https://www.pokecommunity.com/threads/x.1/"), ("pokecommunity", "gated"))
self.assertEqual(classify_url("https://mystery.example/file.zip"), ("other", "gated"))
def test_lookalike_hosts_are_gated(self):
self.assertEqual(classify_url("https://notmediafire.com/x"), ("other", "gated"))
self.assertEqual(classify_url("https://evilmega.nz/file/a#k"), ("other", "gated"))
self.assertEqual(classify_url("https://notarchive.org/x"), ("other", "gated"))
self.assertEqual(classify_url("https://notitch.io/x"), ("other", "gated"))
def test_real_hosts_still_classified(self):
self.assertEqual(classify_url("https://www.mediafire.com/file/abc/x.zip/file"), ("mediafire", "ungated"))
self.assertEqual(classify_url("https://mega.nz/file/a#k"), ("mega", "ungated"))
self.assertEqual(classify_url("https://sub.archive.org/download/x"), ("archive", "ungated"))
if __name__ == "__main__":
unittest.main()
+13 -1
View File
@@ -13,9 +13,21 @@ class TestJobs(unittest.TestCase):
self.assertFalse(jobs["FakeHack"]["watchlist"])
self.assertEqual(jobs["FakeHack"]["note_version"], "1.0.0")
self.assertTrue(jobs["DemoOnly"]["watchlist"])
self.assertFalse(jobs["DemoOnly"]["wanted"])
self.assertTrue(jobs["DemoOnly"]["wanted"])
self.assertIsNone(jobs["DemoOnly"]["library_path"])
def test_watchlist_skips_parenthetical_notes(self):
jobs = {j["stem"]: j for j in build_jobs(FIXTURE)}
# `[[Odyssey]] (related)` and `[[Light Platinum]] (GBA complete; DS is separate)`
# appear in Demo Watchlist table rows but are parenthetical notes, not watchlist stems.
self.assertFalse(jobs["Odyssey"]["watchlist"])
self.assertFalse(jobs["Light Platinum"]["watchlist"])
def test_wanted_matches_bold_names(self):
jobs = {j["stem"]: j for j in build_jobs(FIXTURE)}
# `**DemoOnly**` in Wanted.md (no wikilink) should still flag wanted.
self.assertTrue(jobs["DemoOnly"]["wanted"])
def test_init_run_creates_dirs(self):
with tempfile.TemporaryDirectory() as td:
run = os.path.join(td, "2026-08-14")
+7
View File
@@ -20,6 +20,13 @@ class TestCompare(unittest.TestCase):
self.assertEqual(compare_versions("Final", "1.2"), "incomparable")
self.assertEqual(compare_versions("2026-03-30", "Nightly"), "incomparable")
def test_dates_are_incomparable(self):
self.assertEqual(compare_versions("2026-03-30", "2026-04-01"), "incomparable")
self.assertEqual(compare_versions("2026-03-30", "1.2"), "incomparable")
def test_hotfix_suffix_is_incomparable(self):
self.assertEqual(compare_versions("1.0.2 Hotfix", "1.0.2"), "incomparable")
def test_equal_non_numeric_after_normalize(self):
self.assertEqual(compare_versions("Final", "final"), "eq")