Files
ginnoir cb294f72a0 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
2026-08-14 15:11:16 -05:00

81 lines
3.8 KiB
Python

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, 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):
errs = validate_scout({"stem": "Z"})
self.assertIn("latest_english_version", " ".join(errs))
def test_validate_scout_ok(self):
obj = {
"stem": "Z", "latest_english_version": "2.13", "url": "https://example.com/z.zip",
"host": "other", "gate": "gated", "language_matrix": {"en": "2.13", "es": "2.18"},
"source_used": "website", "hackdex": "skipped", "upstream_status": "Complete", "notes": "",
}
self.assertEqual(validate_scout(obj), [])
def test_reports(self):
with tempfile.TemporaryDirectory() as td:
verdicts = [
{"stem": "A", "bucket": "gated_queue", "latest_english_version": "2.0", "fetch_url": None, "gate": "itch", "reason": "newer-gated"},
{"stem": "B", "bucket": "watchlist_report", "latest_english_version": "0.7", "reason": "watchlist-demo"},
]
write_reports(td, verdicts)
gated = open(os.path.join(td, "gated.md"), encoding="utf-8").read()
wl = open(os.path.join(td, "watchlist-report.md"), encoding="utf-8").read()
self.assertIn("A", gated)
self.assertIn("B", wl)
def test_deploy_argv(self):
cmds = deploy_argv("/pokemon", "/site")
self.assertEqual(cmds[0], ["python", "scripts/build-vault-mocs.py"])
self.assertEqual(cmds[1], ["python", "scripts/build-wiki-data.py"])
self.assertEqual(cmds[2][-1], "scripts/deploy-site.ps1")
def test_prompt_file_exists(self):
path = os.path.join(ROOT, "scripts", "update_swarm", "scout_prompt.md")
text = open(path, encoding="utf-8").read()
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()