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

+36 -7
View File
@@ -6,17 +6,45 @@ import enrich_vault as E
from update_swarm.schema import write_json
WIKILINK = re.compile(r"\[\[([^\]|#]+)")
BOLD = re.compile(r"\*\*([^*]+)\*\*")
WL_CELL = re.compile(r"^\s*\[\[([^\]|#]+)\]\]\s*$")
POKE_PREFIX = re.compile(r"^pokémon\s+", re.I)
def _links(path: str) -> set[str]:
def _norm_stem(s: str) -> str:
return POKE_PREFIX.sub("", s.strip()).casefold()
def _watchlist_stems(path: str) -> set[str]:
if not os.path.isfile(path):
return set()
text = open(path, encoding="utf-8").read()
return {m.strip() for m in WIKILINK.findall(text)}
stems: set[str] = set()
with open(path, encoding="utf-8") as fh:
for line in fh:
if not line.lstrip().startswith("|"):
continue
for cell in line.split("|"):
m = WL_CELL.match(cell)
if m:
stems.add(m.group(1).strip())
return stems
def _wanted_stems(path: str) -> set[str]:
if not os.path.isfile(path):
return set()
with open(path, encoding="utf-8") as fh:
text = fh.read()
stems = {m.strip() for m in WIKILINK.findall(text)}
for line in text.splitlines():
if not line.lstrip().startswith("|"):
continue
for cell in line.split("|"):
for m in BOLD.finditer(cell):
stems.add(m.group(1).strip())
return stems
def build_jobs(vault_romhacks_dir: str) -> list[dict]:
hacks = os.path.join(vault_romhacks_dir, "Hacks")
watch = _links(os.path.join(vault_romhacks_dir, "Demo Watchlist.md"))
wanted = _links(os.path.join(vault_romhacks_dir, "Wanted.md"))
watch = {_norm_stem(s) for s in _watchlist_stems(os.path.join(vault_romhacks_dir, "Demo Watchlist.md"))}
wanted = {_norm_stem(s) for s in _wanted_stems(os.path.join(vault_romhacks_dir, "Wanted.md"))}
jobs = []
for path in sorted(glob.glob(os.path.join(hacks, "*.md"))):
stem = os.path.splitext(os.path.basename(path))[0]
@@ -24,6 +52,7 @@ def build_jobs(vault_romhacks_dir: str) -> list[dict]:
fm = E.parse_fm(fm_text)
def blank(v):
return None if v in (None, "", "—") else v
nstem = _norm_stem(stem)
jobs.append({
"stem": stem,
"title": fm.get("title") or stem,
@@ -33,8 +62,8 @@ def build_jobs(vault_romhacks_dir: str) -> list[dict]:
"source": blank(fm.get("source")),
"note_version": blank(fm.get("version")),
"note_status": blank(fm.get("status")),
"watchlist": stem in watch,
"wanted": stem in wanted,
"watchlist": nstem in watch,
"wanted": nstem in wanted,
})
return jobs