fix: check every romfolders source_ref

model.romfolders.source_refs walks every ref a setup carries, offers[]
and searched_by[] included, which the three hand lists in
validate_schemas and the tests skipped: 4176 refs were never matched
against the declared sources. validate_schemas parses them with
split_refs and reports a malformed part.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:04:31 +01:00
1 parent ed19ae4198
commit 3467b80b38
4 files changed
+29 -26

No files matched your search

+15
View File
@@ -13,6 +13,7 @@ change to either reaches every setup without a rescrape.
from __future__ import annotations
import re
from collections.abc import Iterator
from dataclasses import dataclass, field
from pathlib import Path
@@ -41,6 +42,20 @@ def split_refs(source_ref: str) -> list[tuple[str, str, str | None]]:
return parts
def source_refs(doc: dict) -> Iterator[str]:
"""Every source_ref a setup document carries, offers and searched_by included."""
yield doc["roms_root"]["source_ref"]
if doc.get("case_ref"):
yield doc["case_ref"]
for key in ("skip", "hidden", "media"):
yield from (rule["source_ref"] for rule in doc.get(key) or ())
for row in doc["folders"]:
yield row["source_ref"]
yield from (b["source_ref"] for b in (row.get("board_defaults") or {}).values())
for key in ("offers", "searched_by"):
yield from (item["source_ref"] for item in row.get(key) or () if item.get("source_ref"))
def setup_paths(directory: Path = ROMFOLDERS_DIR) -> list[Path]:
"""The setup files of a directory, without the sources file."""
return sorted(p for p in Path(directory).glob("*.yml") if not p.name.startswith("_"))
+10 -9
View File
@@ -879,6 +879,8 @@ def _romfolder_errors() -> list[str]:
"""Every scraped setup against its schema, and every source_ref against
the sources the file declares: a ref naming no declared repository can
never be read back at a pin."""
from model.romfolders import source_refs, split_refs
directory = REPO_ROOT / PLATFORMS_DIR / "romfolders"
if not directory.is_dir():
return []
@@ -893,16 +895,15 @@ def _romfolder_errors() -> list[str]:
if errors:
continue
declared = set(data["sources"])
refs = [data["roms_root"]["source_ref"]]
refs += [data["case_ref"]] if data.get("case_ref") else []
refs += [r["source_ref"] for key in ("skip", "hidden", "media") for r in data.get(key, [])]
for row in data["folders"]:
refs.append(row["source_ref"])
refs += [b["source_ref"] for b in (row.get("board_defaults") or {}).values()]
for ref in refs:
for part in ref.split("; "):
key = part.split(" ", 1)[0]
for ref in source_refs(data):
try:
parts = split_refs(ref)
except ValueError as exc:
out.append(f"{label}: {exc}")
continue
for key, path, lines in parts:
if key not in declared:
part = f"{key} {path}" + (f":{lines}" if lines else "")
out.append(f"{label}: source_ref {part!r} names undeclared source {key!r}")
return out
+2 -9
View File
@@ -13,7 +13,7 @@ import json
import unittest
from pathlib import Path
from model.romfolders import split_refs
from model.romfolders import source_refs, split_refs
from model.safeparse import yaml_load
from scraper.romfolders import SourceError, load_sources, scrape_setup
from scraper.romfolders.__main__ import dump_setup
@@ -257,14 +257,7 @@ class CommittedSetupTests(unittest.TestCase):
def test_every_ref_names_a_declared_source(self) -> None:
for setup, doc in self.documents().items():
declared = set(doc["sources"])
refs = [doc["roms_root"]["source_ref"]]
refs += [doc["case_ref"]] if doc.get("case_ref") else []
for block in ("skip", "hidden", "media"):
refs += [r["source_ref"] for r in doc.get(block, [])]
refs += [row["source_ref"] for row in doc["folders"]]
refs += [b["source_ref"] for row in doc["folders"]
for b in (row.get("board_defaults") or {}).values()]
for source_ref in refs:
for source_ref in source_refs(doc):
for key, _, _ in split_refs(source_ref):
self.assertIn(key, declared, f"{setup}: {source_ref}")
+2 -8
View File
@@ -15,7 +15,7 @@ import json
import unittest
from pathlib import Path
from model.romfolders import setup_paths, split_refs
from model.romfolders import setup_paths, source_refs, split_refs
from scraper.romfolders import (
Fetcher,
SourceError,
@@ -369,13 +369,7 @@ class CommittedSetups(unittest.TestCase):
doc = yaml_load(self.written(setup).read_text(encoding="utf-8"))
if setup not in self.paths:
continue
refs = [doc["roms_root"]["source_ref"]]
for key in ("skip", "hidden", "media"):
refs += [rule["source_ref"] for rule in doc.get(key, [])]
for row in doc["folders"]:
refs.append(row["source_ref"])
refs += [b["source_ref"] for b in (row.get("board_defaults") or {}).values()]
for ref in refs:
for ref in source_refs(doc):
for key, _path, _lines in split_refs(ref):
with self.subTest(setup=setup, ref=ref):
self.assertIn(key, doc["sources"])