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