chore: merge site and docs fixes, third pass

This commit is contained in:
Abdessamad Derraz committed 2026-11-06 06:38:47 +01:00
commit 19898cb6ea
46 files changed
+38582 -163

No files matched your search

+7 -1
View File
@@ -6330,7 +6330,13 @@ class DocsDescribeTheRegistriesTheyName(unittest.TestCase):
from dedup import NODEDUP_DIRS
tools = (ROOT / "wiki" / "tools.md").read_text(encoding="utf-8")
line = next(l for l in tools.splitlines() if "NODEDUP_DIRS" in l)
self.assertEqual(sorted(d for d in NODEDUP_DIRS if d not in line), [])
# Compared as list items: `mame` was missing while the substring
# test found it in `_mame_clones.json` on the same line.
listed = line.split("`NODEDUP_DIRS`", 1)[1].split(":", 1)[1].rstrip(" |")
self.assertEqual(
sorted(item.strip() for item in listed.split(",")),
sorted(NODEDUP_DIRS),
)
readme_gen = (ROOT / "scripts" / "generate_readme.py").read_text(encoding="utf-8")
self.assertIn("NODEDUP_DIRS", readme_gen)
+38
View File
@@ -8,6 +8,7 @@ report is folded, since each of those decides whether a row says STALE.
from __future__ import annotations
import json
import os
import sys
import tempfile
@@ -353,6 +354,43 @@ class PinParsingTests(unittest.TestCase):
self.assertTrue(cf.specifier_allows(">=10.14", "12.0.1"))
class SiteNpmPins(unittest.TestCase):
"""The site's npm dependencies are pinned to exact versions in
website/package.json, and the ci area compared only the PyPI and action
pins: astro 7.4.2 stayed behind 7.4.7 with no STALE row."""
def test_both_dependency_kinds_are_read(self):
pins = cf.parse_npm_pins(
'{"dependencies": {"astro": "7.4.2"}, "devDependencies": {"x": "^1.0.0"}}'
)
self.assertEqual(pins, {"astro": "7.4.2", "x": "^1.0.0"})
def test_a_newer_release_is_stale(self):
with tempfile.TemporaryDirectory() as tmp:
package = Path(tmp) / "package.json"
package.write_text(json.dumps({"dependencies": {
"astro": "7.4.2", "@astrojs/starlight": "0.42.9", "y": "^2.0.0",
}}))
latest = {"astro": "7.4.7", "@astrojs/starlight": "0.42.9"}
def answer(url):
name = url.split("registry.npmjs.org/", 1)[1].rsplit("/latest", 1)[0]
return {"version": latest[name]}
with mock.patch.object(cf, "SITE_PACKAGE", package), \
mock.patch.object(cf.upstream, "_http_json", side_effect=answer):
rows = {f.subject: f for f in cf._npm_findings()}
self.assertEqual(rows["npm:astro"].status, cf.STALE)
self.assertEqual(rows["npm:astro"].remote, "7.4.7")
self.assertEqual(rows["npm:@astrojs/starlight"].status, cf.OK)
self.assertEqual(rows["npm:y"].status, cf.UNKNOWN)
def test_the_ci_area_reads_the_site_pins(self):
with mock.patch.object(cf, "_npm_findings", return_value=[]) as npm, \
mock.patch.object(cf, "parse_pip_pins", return_value={}), \
mock.patch.object(cf, "parse_action_pins", return_value={}):
cf.check_ci("unused", offline=False)
npm.assert_called_once()
class RomFolderPins(unittest.TestCase):
"""The rom folders of a setup were pinned by hand and nothing compared
the pins with the platform file or the project's releases."""
+2 -1
View File
@@ -75,7 +75,8 @@ class BeforeOpeningAPullRequest(unittest.TestCase):
# CI holds added profiles to their upstream, not edited ones: --changed
# failed a contributor on refs they never wrote.
self.assertIn("profile_sync.py --added --base", workflow)
self.assertIn("profile_sync.py --added --base upstream/main --strict", block)
self.assertIn("profile_sync.py --added --strict", block)
self.assertNotIn("upstream/main", section)
self.assertNotIn("--changed --strict", block)
def test_it_names_the_site_build_and_the_packages_ci_runs(self):
+90
View File
@@ -1738,6 +1738,12 @@ class ArchitectureStatesTheArbitration(unittest.TestCase):
section = page[page.index("### When both layers claim one destination"):]
section = section[:section.index("\n## ")]
self.assertIn("`slots.arbitrate()`", section)
# The pack, the manifest and verify decide through slot_choices, and
# a test in test_slots forbids them to call arbitrate: the page names
# the function they read, not only the one the report prints.
self.assertIn("`slots.slot_choices()`", section)
self.assertIn("`slots.pack_overrides()`", section)
self.assertNotIn("both decide through `slots.arbitrate()`", section)
source = inspect.getsource(slots.arbitrate)
# The three outcomes the section describes.
for outcome in ("ADDRESSEE", "SERVES_BOTH", "FRONTEND_CHECKS_CONTENT"):
@@ -1894,5 +1900,89 @@ class SkipFlagsNameTheSteps(unittest.TestCase):
self.assertEqual(set(re.findall(self.STEP, text)), steps)
class TheInstallerSamplesTravelWithTheManifests(unittest.TestCase):
"""A manifest refresh (c624a820f) went out without the run samples of
wiki/installer.md, which count what the manifests hold, and CI turned
red. The rule lived in no page, and the nightly's commit rules had no
place for the samples the gate's pipeline rewrites."""
def test_the_pages_and_the_nightly_carry_them(self):
import autorun # noqa: PLC0415
guide = (WIKI / "testing-guide.md").read_text(encoding="utf-8")
for name in ("wiki/installer.md", "derivable.json", "generate_installer_doc.py"):
self.assertIn(name, guide)
tools = (WIKI / "tools.md").read_text(encoding="utf-8")
manifests = tools.index("--all --manifest --output-dir install/")
self.assertIn("generate_installer_doc.py", tools[manifests:manifests + 300])
nightly = autorun.load_jobs()["nightly"]
patterns = [p for rule in nightly.commits for p in rule.paths]
for path in ("wiki/installer.md", "derivable.json", "install/retroarch.json"):
with self.subTest(path=path):
self.assertTrue(any(autorun.path_matches(p, path) for p in patterns))
class TheRemovalProofsAreTheExportersOwn(unittest.TestCase):
"""tools.md listed the proofs that keep an entry out of
removal_candidates without the platform's launcher records, which
candidates.py checks right after a path."""
WORDS = {"path": "`path:`", "launcher": "`launchers:`", "name": "by name or alias",
"hash": "by any hash", "directory": "`type: directory`",
"data_directory": "a data directory"}
def test_the_page_names_each_proof_in_order(self):
from exporter.candidates import _PROOF_ORDER # noqa: PLC0415
page = (WIKI / "tools.md").read_text(encoding="utf-8")
start = page.index("No entry the platform declares is removed.")
section = page[start:page.index("removal_candidates", start)]
self.assertEqual(set(self.WORDS), set(_PROOF_ORDER))
positions = [section.index(self.WORDS[kind]) for kind in _PROOF_ORDER]
self.assertEqual(positions, sorted(positions))
class APlatformListIsDescribedNotJudged(unittest.TestCase):
"""adding-a-platform opened on files a platform's own list "leaves out",
read first by the maintainer of that platform: "does not name" says the
same without imputing an omission."""
def test_no_page_says_a_list_leaves_files_out(self):
pattern = re.compile(r"\blists? (?:leaves|left|leave) out\b")
for page in sorted(WIKI.glob("*.md")):
with self.subTest(page=page.name):
self.assertIsNone(pattern.search(page.read_text(encoding="utf-8")))
class ArchivedIsWhatTheToolsDo(unittest.TestCase):
"""The README and the setup pages said an archived platform is no longer
scraped on a schedule, and adding-a-platform said `active` feeds a CI
matrix and the scrapers. No workflow calls list_platforms.py and no tool
reads `schedule:`: what `archived` changes is which full runs include it."""
def test_no_text_ties_the_status_to_automation(self):
import generate_pack # noqa: PLC0415
import generate_readme # noqa: PLC0415
import generate_site # noqa: PLC0415
import list_platforms # noqa: PLC0415
texts = {
"adding-a-platform.md": (WIKI / "adding-a-platform.md").read_text(encoding="utf-8"),
"generate_readme": inspect.getsource(generate_readme),
"generate_site": inspect.getsource(generate_site),
"generate_pack": inspect.getsource(generate_pack),
"list_platforms": inspect.getsource(list_platforms),
"_guides.yml": (ROOT / "platforms" / "_guides.yml").read_text(encoding="utf-8"),
}
for name, text in texts.items():
with self.subTest(name):
for claim in ("scraped on a schedule", "read again on a schedule",
"CI matrix", "without the automation"):
self.assertNotIn(claim, text)
self.assertIn("`--include-archived`", texts["adding-a-platform.md"])
for workflow in (ROOT / ".github" / "workflows").glob("*.yml"):
self.assertNotIn("list_platforms", workflow.read_text(encoding="utf-8"))
if __name__ == "__main__":
unittest.main()
+15
View File
@@ -248,6 +248,21 @@ class SlicesLeaveWithTheirRelease(unittest.TestCase):
self.assertNotIn(".zip.001", _which_pack())
class TheReadmeLeadsBeginnersToTheirPages(unittest.TestCase):
"""The README linked the installer reference and the FAQ's no-ZIP anchor
only: a user stopped by an install error or a BIOS-not-found message had
no link to the first install or troubleshooting page."""
def test_quick_install_links_the_start_pages(self):
# The code block holds `#` comment lines, so the section runs to
# the next level-two heading.
section = _read("README.md").split("## Quick install", 1)[1].split("\n## ", 1)[0]
for page in ("first-install", "troubleshooting", "faq"):
with self.subTest(page=page):
self.assertIn(f"wiki/{page}/)", section)
self.assertTrue((REPO_ROOT / "wiki" / f"{page}.md").is_file())
class EndUsersCheckTheirOwnFolder(unittest.TestCase):
"""verify.py reads database.json and bios/. Advice about a user's own
files points at the installer's --check, which hashes their folder."""
+5 -1
View File
@@ -6034,7 +6034,11 @@ class TestBranchCheckIsWired(unittest.TestCase):
import generate_readme # noqa: PLC0415
text = generate_readme.generate_contributing()
self.assertIn("profile_sync.py --added --base upstream/main --strict", text)
self.assertIn("profile_sync.py --added --strict", text)
# The default base is fetched by the tool: a documented upstream
# remote failed every clone that had origin alone.
self.assertNotIn("--base upstream/main", text)
self.assertNotIn("remote add upstream", text)
self.assertNotIn("--emulator NAME --strict", text)
workflow = (root / ".github" / "workflows" / "validate.yml").read_text()
self.assertIn("profile_sync.py --added --base", workflow)
+18
View File
@@ -1452,5 +1452,23 @@ class UsaRegionServesTheAmericas(unittest.TestCase):
self.assertEqual(region.rank(jpn, requested), 1)
class RegionWordsInAPackReadme(unittest.TestCase):
"""The pack README title-cased each slug: asia-ntsc read "Asia Ntsc"."""
def test_the_priority_line_reads_as_written(self):
from packreadme import _build_readme # noqa: PLC0415
readme = _build_readme(
"retroarch", "RetroArch", "system", 1, 1,
regions=region.parse_requested("us,asia-ntsc,jp"),
)
self.assertIn("Region priority: North America, Asia (NTSC), Japan", readme)
def test_every_region_has_a_label(self):
for slug in region.REGIONS:
with self.subTest(slug=slug):
self.assertNotRegex(region.label(slug), r"\bNtsc\b|\bPal\b|\bUk\b")
if __name__ == "__main__":
unittest.main()
+103
View File
@@ -0,0 +1,103 @@
"""A file that leaves the collection keeps its published address.
a2diskiing.zip (bd02f6a0) was rebuilt from its recipe on 2026-10-22 and
filed under Apple II as d9bb1897. Its card's address, files/?sha1=bd02f6a0,
answered that no file the site knows has the hash and asked for a
contribution of a file the collection had held.
"""
from __future__ import annotations
import json
import sys
import tempfile
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import retired_files # noqa: E402
OLD = "bd" * 20
NEW = "d9" * 20
def _db(**files: dict) -> dict:
return {"files": files}
class WhatLeftIsRecorded(unittest.TestCase):
def setUp(self):
self.old = _db(**{
OLD: {"name": "a2diskiing.zip", "path": "bios/Arcade/Arcade/a2diskiing.zip",
"md5": "43" * 16, "crc32": "292ef826", "size": 589},
"11" * 20: {"name": "kept.bin", "path": "bios/A/B/kept.bin"},
})
self.new = _db(**{
NEW: {"name": "a2diskiing.zip", "path": "bios/Apple/Apple II/a2diskiing.zip"},
"11" * 20: {"name": "kept.bin", "path": "bios/A/B/kept.bin"},
})
def test_the_departure_and_the_file_in_its_place(self):
left = retired_files.retired_between(self.old, self.new, "2026-10-22")
self.assertEqual(list(left), [OLD])
self.assertEqual(left[OLD]["left"], "2026-10-22")
self.assertEqual(left[OLD]["successor"], NEW)
self.assertEqual(left[OLD]["md5"], "43" * 16)
def test_the_first_departure_stays_and_a_return_leaves_the_record(self):
first = retired_files.merge({}, retired_files.retired_between(self.old, self.new, "2026-10-22"),
self.new)
again = retired_files.merge(first, {OLD: {"left": "2026-11-01"}}, self.new)
self.assertEqual(again[OLD]["left"], "2026-10-22")
self.assertEqual(retired_files.merge(again, {}, self.old), {})
def test_generate_db_writes_it_beside_the_database(self):
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
database = Path(tmp) / "database.json"
path = retired_files.retired_path(database)
self.assertEqual(path, Path(tmp) / "retired.json")
self.assertEqual(retired_files.update(path, self.old, self.new, "2026-10-22"), 1)
self.assertEqual(retired_files.update(path, self.old, self.new, "2026-10-23"), 0)
record = json.loads(path.read_text())["files"]
self.assertEqual(record[OLD]["left"], "2026-10-22")
source = (REPO_ROOT / "scripts" / "generate_db.py").read_text(encoding="utf-8")
self.assertIn("retired_files.update(", source)
class TheLookupAnswersForIt(unittest.TestCase):
def test_records_lead_to_the_card_in_its_place(self):
import generate_site # noqa: PLC0415
retired = {OLD: {"name": "a2diskiing.zip", "path": "bios/Arcade/Arcade/a2diskiing.zip",
"crc32": "292ef826", "left": "2026-10-22", "successor": "ee" * 20},
"ee" * 20: {"name": "a2diskiing.zip", "path": "bios/Apple/x/a2diskiing.zip",
"left": "2026-10-23", "successor": NEW}}
files = {NEW: {"name": "a2diskiing.zip"}}
locations = [{"sha1": NEW, "url": "/retrobios/systems/apple/#sha1-d9d9d9d9d9d9"}]
records = generate_site.retired_records(retired, files, locations)
found = {(r["sha1"], r["algorithm"]): r for r in records}
# Followed to the file held today, through the copy that left after.
self.assertEqual(found[(OLD, "sha1")]["url"], locations[0]["url"])
self.assertEqual(found[(OLD, "sha1")]["successor"], NEW)
self.assertEqual(found[(OLD, "crc32")]["value"], "292ef826")
self.assertEqual(found[(OLD, "sha1")]["layer"], "retired")
self.assertEqual(found[(OLD, "sha1")]["left"], "2026-10-22")
def test_the_committed_record_holds_the_reported_file(self):
record = retired_files.load(REPO_ROOT / "retired.json")
if not record:
self.skipTest("retired.json is not written")
self.assertIn("bd02f6a0ce8accba7ea5415fd22c2e8f23ec4b10", record)
database = json.loads((REPO_ROOT / "database.json").read_text(encoding="utf-8"))
self.assertFalse(set(record) & set(database["files"]))
def test_the_page_script_answers_with_it(self):
script = (REPO_ROOT / "website" / "src" / "scripts" / "site.ts").read_text(encoding="utf-8")
self.assertIn("item.layer === 'retired'", script)
self.assertIn("left the collection on", script)
if __name__ == "__main__":
unittest.main()
+15 -3
View File
@@ -110,7 +110,7 @@ class ASystemCardShowsTheAnswerFirst(unittest.TestCase):
self.shown = self.text.replace(self.fold, "")
def test_the_open_part(self) -> None:
for fact in ("<code>ppge_atlas.zim</code>", ">650.9 KB<", ">Download</a>",
for fact in ("<code>ppge_atlas.zim</code>", ">666,539 B<", ">Download</a>",
"<dt>On the setup's list</dt>", "<dt>Packed for its emulators by</dt>",
"<dt>Emulators</dt>", f'<dt>SHA1</dt><dd class="rb-hash">{SHA1[:12]}</dd>'):
self.assertIn(fact, self.shown)
@@ -193,11 +193,23 @@ class AnInstallBoxShowsOneCommand(unittest.TestCase):
self.assertEqual(re.findall(r'<TabItem label="([^"]+)"', tabs),
["Windows", "macOS", "Linux", "Steam Deck"])
self.assertEqual(tabs.count("--platform"), 4)
self.assertEqual(tabs.count("--platform emudeck --system sony-psp"), 4)
# RetroArch, which runs on each tab's system, not the first by name.
self.assertEqual(tabs.count("--platform retroarch --system"), 4)
def test_the_default_setup(self) -> None:
"""AmberELEC led 17 system pages, a handheld system under the
Windows tab, for being first in alphabetical order."""
self.assertEqual(gs._default_setup([("amberelec", "psx"), ("retroarch", "Sony - PlayStation")]),
("retroarch", "Sony - PlayStation"))
self.assertEqual(gs._default_setup([("amberelec", "x"), ("batocera", "x")]), ("batocera", "x"))
self.assertEqual(gs._default_setup([("amberelec", "x"), ("knulli", "x")]), ("amberelec", "x"))
select = re.search(r"<select>(.*?)</select>", self.text).group(1)
self.assertEqual(re.findall(r'<option value="([^"]+)" selected', select), ["retroarch"])
def test_the_setup_list_carries_every_command(self) -> None:
select = re.search(r"<select>(.*?)</select>", self.text).group(1)
options = re.findall(r'<option value="([^"]+)" data-sh="([^"]+)" data-ps="([^"]+)">', select)
options = re.findall(r'<option value="([^"]+)"(?: selected)? data-sh="([^"]+)" data-ps="([^"]+)">',
select)
self.assertEqual([value for value, _sh, _ps in options], ["emudeck", "retroarch", "retrobat"])
self.assertIn(("retrobat", "--platform retrobat --system 'Neo Geo'",
"--platform retrobat --system 'Neo Geo'"), options)
+71
View File
@@ -763,5 +763,76 @@ class SmallFixes(unittest.TestCase):
self.assertEqual(said, [])
class AnEmulatorPageNamesItsSetups(unittest.TestCase):
"""emulators/handy named no setup that runs Handy: its lynxboot.img card
names the setups whose own list holds it, not EmuDeck, ROCKNIX and
NextUI, which pack it for the core."""
def test_setups_come_from_the_core_resolution(self):
coverages = {
"b": {"config": {"cores": ["handy"]}},
"a": {"config": {"cores": ["handy", "other"]}},
"c": {"config": {"cores": ["other"]}},
}
profiles = {"handy": {"type": "libretro"}, "other": {"type": "libretro"}}
self.assertEqual(gs.emulator_setups(coverages, profiles)["handy"], ["a", "b"])
def test_the_page_names_them(self):
from tests import sitepages # noqa: PLC0415
sitepages.require()
text = sitepages.page("emulators/handy.md").read_text(encoding="utf-8")
row = next(line for line in text.splitlines() if line.startswith("| Run by |"))
for setup in ("emudeck", "rocknix", "nextui", "retroarch"):
self.assertIn(f"/platforms/{setup}/", row)
# Setup names on every emulator page outranked the setup's own page.
self.assertIn("data-pagefind-ignore", row)
class SizesTheCodeComparesAreExact(unittest.TestCase):
"""raze validates DUKE3D.GRP by size, and its page showed 42.3 MB for
44,356,548 and 44,348,015 bytes alike."""
def test_a_validated_size_carries_its_bytes(self):
profile = {"emulator": "x", "type": "libretro", "systems": ["sony-playstation"], "files": [
{"name": "DUKE3D.GRP", "size": 44348015, "validation": ["size", "crc32"]},
{"name": "other.bin", "size": 44356548},
{"name": "built.bin", "size": 2304, "validation": {"core": ["size"]}},
]}
page = _page("x", profile)
self.assertIn("Size: 42.3 MB (44,348,015 bytes)", page)
self.assertIn("Size: 2.2 KB (2,304 bytes)", page)
self.assertNotIn("44,356,548", page)
class ADataDirectoryNamesAFetchableOrigin(unittest.TestCase):
"""pcee2's page linked github.com/PCSX2/pcsx2/archive/{version}.tar.gz,
a 404, and buildbot zips showed `Revision: master (2047720058)`: a branch
that means nothing for a buildbot URL and the server's ETag."""
def test_the_url_is_substituted_and_a_commit_is_linked(self):
entry = {"source_url": "https://github.com/PCSX2/pcsx2/archive/{version}.tar.gz",
"version": "6db638dc0373769b4c5d5b5dd7ed6da641b9a18e"}
lines = gs.data_directory_origin(entry, {"sha": entry["version"],
"version": entry["version"]})
self.assertEqual(lines[0], "Fetched from <https://github.com/PCSX2/pcsx2/archive/"
"6db638dc0373769b4c5d5b5dd7ed6da641b9a18e.tar.gz>")
self.assertIn("(https://github.com/PCSX2/pcsx2/commit/6db638dc0373769b4c5d5b5dd7ed6da641b9a18e)",
lines[1])
self.assertNotIn("{version}", " ".join(lines))
def test_an_etag_is_no_revision(self):
entry = {"source_url": "https://buildbot.libretro.com/assets/system/Dolphin.zip"}
lines = gs.data_directory_origin(entry, {"sha": '"2047720058"', "version": "master"})
self.assertEqual(lines, ["Fetched from <https://buildbot.libretro.com/assets/system/Dolphin.zip>"])
def test_every_registered_url_resolves(self):
registry = yaml.safe_load((REPO_ROOT / "platforms" / "_data_dirs.yml").read_text())
for ref, entry in (registry.get("data_directories") or registry).items():
if isinstance(entry, dict):
with self.subTest(ref=ref):
self.assertNotIn("{", " ".join(gs.data_directory_origin(entry, {})))
if __name__ == "__main__":
unittest.main()
+13
View File
@@ -937,6 +937,19 @@ class ARouteWithoutANetwork(unittest.TestCase):
self.assertEqual(_tab_labels(card), set())
self.assertIn("**Linux**", card)
def test_a_linux_partition_card_says_why_and_offers_linux_alone(self):
"""Lakka's /storage is the card's ext4 partition (Lakka-LibreELEC
scripts/mkimage): its page offered Windows and macOS tabs for a
folder neither can open."""
for name in ("lakka", "retropie"):
with self.subTest(setup=name):
self.assertEqual(siteguides.GUIDES[name].card_run, ("linux",))
card = _plain_page(f"platforms/{name}.md").split("No network?", 1)[1]
card = card.split("## On the device", 1)[0]
self.assertEqual(_tab_labels(card), set())
self.assertNotIn("E:\\", card)
self.assertIn("Only a Linux computer opens the card.", card)
def test_no_zip_is_promised_for_an_unmarked_setup(self):
for name in SETUPS:
if REGISTRY[name].get("release_pack") is True:
+47
View File
@@ -785,6 +785,53 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
self.assertNotIn("no.json", names)
class AnArchiveMemberIsFoundByItsCrc(unittest.TestCase):
"""A pasted CRC of logica2.u2 (8484f426), which the collection holds
inside a500.zip, answered that no file the site knows has it: the
lookup held the members a profile's `contents:` declares, 7,389 of
33,403."""
def test_each_member_is_a_record_leading_to_its_archive(self):
import zipfile # noqa: PLC0415
import generate_site # noqa: PLC0415
with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp:
root = Path(tmp)
archive = root / "bios" / "Arcade" / "Arcade" / "a500.zip"
archive.parent.mkdir(parents=True)
with zipfile.ZipFile(archive, "w") as handle:
handle.writestr("logica2.u2", b"rom")
handle.writestr("sub/kick.rom", b"kick")
entry = {"name": "a500.zip", "path": "bios/Arcade/Arcade/a500.zip"}
records = generate_site._archive_member_records(entry, "ab" * 20, "/retrobios/x/", root)
plain = generate_site._archive_member_records(
{"name": "a.bin", "path": "bios/a.bin"}, "cd" * 20, "/retrobios/y/", root)
self.assertEqual(plain, [])
import zlib # noqa: PLC0415
self.assertEqual(records, [
{"value": f"{zlib.crc32(b'rom'):08x}", "algorithm": "crc32", "layer": "archive-member",
"name": "logica2.u2", "archive": "a500.zip", "sha1": "ab" * 20, "url": "/retrobios/x/"},
{"value": f"{zlib.crc32(b'kick'):08x}", "algorithm": "crc32", "layer": "archive-member",
"name": "kick.rom", "archive": "a500.zip", "sha1": "ab" * 20, "url": "/retrobios/x/"},
])
def test_the_lookup_and_the_schema_carry_the_layer(self):
import json as _json # noqa: PLC0415
import generate_site # noqa: PLC0415
source = Path(generate_site.__file__).read_text(encoding="utf-8")
self.assertIn("records += _archive_member_records(entry, sha1, item[\"url\"])", source)
schema = _json.loads((Path(__file__).resolve().parents[1] / "schemas"
/ "site-api-envelope.schema.json").read_text())
self.assertIn('"archive-member"', _json.dumps(schema))
script = (Path(__file__).resolve().parents[1] / "website" / "src" / "scripts"
/ "site.ts").read_text(encoding="utf-8")
self.assertIn("byLayer('archive-member')", script)
class AFileHasAnAddressByContent(unittest.TestCase):
"""mt32_control.rom moved from the Commodore page to the Roland page and
every link to its card broke: the anchor was content-based, the page
+11 -3
View File
@@ -206,13 +206,21 @@ class FaqInstallsFromWhatYouHold(unittest.TestCase):
import install # noqa: PLC0415
section = " ".join(self._section("Fill an SD card from a computer?").split())
self.assertIn("The interface finds a muOS, Onion, spruceOS, MinUI, KNULLI or ROCKNIX "
"card by itself.", section)
self.assertIn("The interface finds a muOS, Onion, spruceOS, MinUI, KNULLI, ROCKNIX, Lakka "
"or MiSTer card.", section)
known = {rule.name for rule in install._card_rules()}
known |= {install.display_name(name) for name, _marker, _prefix in install._CARD_RULES}
for name in ("muOS", "Onion", "spruceOS", "MinUI", "KNULLI", "ROCKNIX"):
for name in ("muOS", "Onion", "spruceOS", "MinUI", "KNULLI", "ROCKNIX", "MiSTer FPGA"):
with self.subTest(card=name):
self.assertIn(name, known)
# A card told by a rule of its share (MiSTer since 73b82375d) is named
# here and in the README, or its user passes --dest the card's root.
readme = (REPO_ROOT / "README.md").read_text(encoding="utf-8")
for rule in install._SHARE_RULES:
word = rule.name.split()[0]
with self.subTest(share=rule.name):
self.assertIn(word, section)
self.assertRegex(readme, rf"# SD card mounted on a PC: .*\b{word}\b")
# The label the first screen gives a card found: "Onion SD card".
self.assertEqual(install._card_word(("retroarch", Path("/x/BIOS"), "Onion")), "SD card")
self.assertEqual(install._card_word(("batocera", Path("/x/bios"), "Batocera")),
+18
View File
@@ -649,6 +649,24 @@ class TheContractsValidate(unittest.TestCase):
[e.message for e in envelope.iter_errors(json.loads((API / name).read_text()))], [])
class TheIndexSaysWhatTheCatalogLists(unittest.TestCase):
"""index.json called catalog.json every published file, while the 990
one-item documents of emulators/, platforms/, systems/ and lookup/ are
in none of its 80 items."""
def test_the_description_matches_the_items(self):
index = json.loads(_built(API / "index.json").read_text())
catalog = json.loads(_built(API / "catalog.json").read_text())
described = next(i["description"] for i in index["items"] if i["url"] == "catalog.json")
self.assertNotIn("Every published file", described)
listed = {item["url"].split("/", 1)[0] for item in catalog["items"]}
for folder in ("emulators", "platforms", "systems", "lookup"):
with self.subTest(folder=folder):
self.assertIn(f"{folder}/", described)
self.assertNotIn(folder, listed)
self.assertTrue(any((API / folder).glob("*.json")))
class EveryEnvelopeCarriesTheCommit(unittest.TestCase):
"""8.5: emulators/ and systems/ lacked `commit` (716 documents)."""
+29
View File
@@ -503,5 +503,34 @@ class NoTooltipInsideAName(unittest.TestCase):
self.assertIn('>BIOS</abbr>', marked)
class TheArcadeCacheHoldsItsDatabase(unittest.TestCase):
"""The set of sha1s filed under Arcade/ was cached by id(db): a database
freed and replaced at the same address answered with the first one's set,
and an arcade card of the second landed in another section."""
@staticmethod
def _db(sha1: str) -> dict:
return {"files": {}, "indexes": {"by_path_suffix": {"Arcade/x.zip": [sha1]}}}
def test_a_new_database_at_a_reused_address_is_read_again(self):
saved = siterender._suffix_cache[0]
self.addCleanup(siterender._suffix_cache.__setitem__, 0, saved)
first = self._db("a" * 40)
self.assertTrue(siterender._in_arcade("a" * 40, first))
address = id(first)
del first
# CPython hands a freed dict's address to a later one of its size,
# unless the cache still holds the first database.
for _ in range(1000):
second = self._db("b" * 40)
if id(second) == address:
break
del second
else:
second = self._db("b" * 40)
self.assertTrue(siterender._in_arcade("b" * 40, second))
self.assertFalse(siterender._in_arcade("a" * 40, second))
if __name__ == "__main__":
unittest.main()
+17
View File
@@ -304,5 +304,22 @@ class BuildCount(unittest.TestCase):
self.assertIn("system ids linked", source)
class AnEntryListingSystemsIsFiledUnderEach(unittest.TestCase):
"""MAME declares a device set under `systems:`, the machines of several
systems loading it. The site read only `system:`, so ym2608.zip was filed
under neither Arcade nor NEC PC-88, and kept on pages it does not serve."""
def test_the_site_reads_the_common_rule(self):
import generate_site as gs # noqa: PLC0415
from common import entry_system_ids # noqa: PLC0415
entry = {"name": "ym2608.zip", "systems": ["arcade", "pc80"]}
self.assertEqual(gs._entry_systems("mame", entry), ["arcade", "pc80"])
self.assertEqual(
gs._entry_systems("mame", entry), entry_system_ids(entry, {"systems": []})
)
self.assertEqual(gs._entry_systems("mame", {"name": "a", "system": "pc80"}), ["pc80"])
if __name__ == "__main__":
unittest.main()
+13
View File
@@ -184,6 +184,19 @@ class ThePermalinkIsAnIcon(unittest.TestCase):
self.assertEqual(page.count('href="#rb-link-icon"'), 2)
class TheCardGivesTheSizeInBytes(unittest.TestCase):
"""The badge rounded to 0.1 KB and no line of a system card gave the
bytes an emulator compares."""
def test_the_badge_is_exact(self):
for size, shown in ((524288, "512 KB"), (44348015, "44,348,015 B"),
(2 * 1024 * 1024, "2 MB"), (2304, "2,304 B"), (10, "10 B")):
with self.subTest(size=size):
card = {**_sony_file("scph5501.bin", "4"), "size": size}
title = gs._system_file_card(card, FileConsumers({"files": {}}))[2]
self.assertIn(f'<span class="rb-badge rb-badge-muted">{shown}</span>', title)
class TheCardLinesSayWhatTheyMean(unittest.TestCase):
""""Platforms:" and "Also installed by:" listed different setups, as
lower-case ids, and only a code comment told them apart."""
+22 -25
View File
@@ -75,31 +75,6 @@ def tearDownModule():
shutil.rmtree(_ROOT, ignore_errors=True)
class TestClaimIndex(unittest.TestCase):
"""Keyed by destination and by name, the name carrying the union."""
def _claims(self):
return [
slots.Claim("profile", "GC/USA/IPL.bin", "IPL.bin", emulator="dolphin"),
slots.Claim("profile", "GC/JAP/IPL.bin", "IPL.bin", emulator="dolphin"),
]
def test_destination_key_separates_same_named_entries(self):
index = slots.build_claim_index(self._claims())
self.assertEqual(len(index["gc/usa/ipl.bin"]), 1)
self.assertEqual(len(index["gc/jap/ipl.bin"]), 1)
def test_bare_name_answers_with_the_union(self):
index = slots.build_claim_index(self._claims())
self.assertEqual(len(index["ipl.bin"]), 2)
def test_lookup_ignores_case_and_leading_separator(self):
index = slots.build_claim_index(
[slots.Claim("platform", "/BIOS/Disk.rom", "Disk.rom")]
)
self.assertIn("bios/disk.rom", index)
class TestConflicts(unittest.TestCase):
"""A proven profile claim contradicting what the baseline would ship."""
@@ -411,6 +386,28 @@ class TestArbitration(unittest.TestCase):
# The hashed declaration keeps the file the frontend checks.
self.assertEqual(overrides, {"IPL.bin": "bios/Console/GC/JAP/IPL.bin"})
def test_the_report_and_the_pack_decide_alike(self):
"""The report prints arbitrate(), the pack, the manifest and verify
read slot_choices(): both must name the same file for a slot."""
for mode in ("existence", "md5"):
config = {
"verification_mode": mode,
"cores": ["dolphin"],
"systems": {"console": {"files": [
{"name": "IPL.bin", "destination": "GC/JAP/IPL.bin", "md5": "m" * 32},
]}},
}
profiles = {"dolphin": {"type": "libretro", "systems": ["console"], "files": [
{"name": "IPL.bin", "path": "GC/JAP/IPL.bin"},
]}}
with self.subTest(mode=mode):
[conflict] = slots.find_conflicts(config, profiles, REGIONS_DB)
decision = slots.arbitrate(conflict, mode)
served = slots.pack_overrides(config, profiles, REGIONS_DB).get(
"GC/JAP/IPL.bin", conflict.platform_claim.local_path
)
self.assertEqual(served, decision.winner.local_path)
def test_the_reported_line_gives_the_ground_for_the_decision(self):
kept = slots.format_decision(slots.arbitrate(self._conflict(), "md5"))
self.assertIn("verifies content", kept)
+24
View File
@@ -115,6 +115,30 @@ class OversizedFileAdvice(unittest.TestCase):
self.assertIn("open an issue", message)
self.assertIn(validate_pr.LARGE_FILE_ISSUE_URL, message)
def test_the_issue_form_is_filled_and_nothing_points_to_the_pr(self):
"""The link opened an empty form, and the same report said to put the
file in the pull request and under bios/."""
import urllib.parse # noqa: PLC0415
path = self.tmp / "big.bin"
path.write_bytes(b"x" * 8)
validate_pr.MAX_FILE_SIZE = 4
result = validate_pr.validate_file(
"big.bin", None, {"sha1": set(), "md5": set(), "names": set()},
)
message = next(m for s, m in result.checks if s == "FAIL" and "too large" in m)
url = message.split("(", 2)[2].split(")", 1)[0]
query = urllib.parse.parse_qs(urllib.parse.urlsplit(url).query)
template = (REPO_ROOT / ".github" / "ISSUE_TEMPLATE" / "missing-bios.yml").read_text()
for field, value in (("filename", "big.bin"), ("sha1", result.sha1),
("md5", result.md5), ("size", "8")):
with self.subTest(field=field):
self.assertIn(f"id: {field}\n", template)
self.assertEqual(query[field], [value])
others = " ".join(m for _s, m in result.checks)
self.assertNotIn("pull request which", others)
self.assertNotIn("not under bios/", others)
def test_the_linked_issue_template_exists(self):
template = validate_pr.LARGE_FILE_ISSUE_URL.rsplit("template=", 1)[1]
self.assertTrue(