mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 13:28:51 -06:00
chore: merge origin main into the lint work
This commit is contained in:
commit
3e732fd57e
104 files changed
+9122
-3414
No files matched your search
@@ -43,6 +43,7 @@ _ONLINE = mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""})
|
||||
# a bare name no registered path carries is never asked of the release.
|
||||
TEST_REGISTERED = [
|
||||
"bios/Test/asset.bin",
|
||||
"bios/Test/spaced asset.bin",
|
||||
"bios/Test/big.bin",
|
||||
"bios/Sony/PlayStation 3/PS3UPDAT.PUP",
|
||||
]
|
||||
@@ -142,6 +143,34 @@ class LargeFileCacheTest(unittest.TestCase):
|
||||
self.assertIsNone(common.fetch_large_file("asset.bin", dest_dir=self.dir))
|
||||
self.assertEqual(os.listdir(self.dir), [])
|
||||
|
||||
def test_a_spaced_name_served_dotted_reports_nothing(self):
|
||||
"""GitHub publishes "spaced asset.bin" as "spaced.asset.bin": the
|
||||
404 on the spaced name came first and was printed as a failure."""
|
||||
asked: list[str] = []
|
||||
|
||||
def urlopen(req, timeout=None):
|
||||
asked.append(req.full_url)
|
||||
if "spaced%20asset" in req.full_url:
|
||||
raise urllib.error.HTTPError(req.full_url, 404, "Not Found", {}, None)
|
||||
return _SlowResponse(PAYLOAD_A)
|
||||
|
||||
largefiles.urllib.request.urlopen = urlopen
|
||||
with mock.patch("sys.stderr", new_callable=io.StringIO) as err:
|
||||
result = common.fetch_large_file("spaced asset.bin", dest_dir=self.dir)
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(len(asked), 2)
|
||||
self.assertEqual(err.getvalue(), "")
|
||||
|
||||
def test_no_candidate_answering_reports_each(self):
|
||||
def fail(req, timeout=None):
|
||||
raise urllib.error.HTTPError(req.full_url, 404, "Not Found", {}, None)
|
||||
|
||||
largefiles.urllib.request.urlopen = fail
|
||||
with mock.patch("sys.stderr", new_callable=io.StringIO) as err:
|
||||
self.assertIsNone(common.fetch_large_file("spaced asset.bin", dest_dir=self.dir))
|
||||
self.assertIn("spaced asset.bin", err.getvalue())
|
||||
self.assertIn("spaced.asset.bin", err.getvalue())
|
||||
|
||||
def test_hash_mismatch_leaves_no_scratch_file(self):
|
||||
largefiles.urllib.request.urlopen = lambda req, timeout=None: _SlowResponse(
|
||||
PAYLOAD_A
|
||||
|
||||
@@ -43,6 +43,7 @@ WEBSITE = REPO_ROOT / "website"
|
||||
DIST = WEBSITE / "dist"
|
||||
COMPONENTS = WEBSITE / "src" / "components"
|
||||
SITE_TS = WEBSITE / "src" / "scripts" / "site.ts"
|
||||
HASHES_TS = WEBSITE / "src" / "scripts" / "hashes.ts"
|
||||
CONFIG = WEBSITE / "astro.config.mjs"
|
||||
PLUGIN = WEBSITE / "src" / "plugins" / "rehype-stack-tables.mjs"
|
||||
|
||||
@@ -188,6 +189,38 @@ class SectionTabsInTheHeader(unittest.TestCase):
|
||||
self.assertRegex(nav.group(1), r'aria-current="true"[^>]*>\s*Start here')
|
||||
|
||||
|
||||
class TheWantedPageIsInTheBar(unittest.TestCase):
|
||||
"""The wanted page is the site's call to contribute: in the bar on every
|
||||
page, beside the search and menu buttons on a phone, where the section
|
||||
tabs fold into the menu."""
|
||||
|
||||
LINK = re.compile(r'<a class="rb-wanted-link[^"]*" href="/retrobios/wanted/"([^>]*)>Wanted files</a>')
|
||||
|
||||
def test_the_bar_holds_it_outside_the_tabs(self):
|
||||
header = _read(COMPONENTS / "Header.astro")
|
||||
bar = header[header.index('<div class="rb-header-bar">'):header.index("</div>")]
|
||||
self.assertIn('class="rb-wanted-link print:hidden"', bar)
|
||||
self.assertIn("aria-current={onWanted ? 'page' : undefined}", bar)
|
||||
# Theme colours only, the same in both themes' variables.
|
||||
style = header[header.index(".rb-wanted-link {"):header.index("@media")]
|
||||
self.assertNotRegex(style, r"#[0-9a-fA-F]{3,6}\b")
|
||||
# At 360 px the name was cut to "Retr": the logo stays, the name is
|
||||
# kept for screen readers only.
|
||||
narrow = header[header.index("@media (max-width: 26.99rem)"):]
|
||||
self.assertIn(".site-title span {", narrow[:200])
|
||||
self.assertIn("clip-path: inset(50%);", narrow[:400])
|
||||
|
||||
def test_built_on_every_page_current_on_its_own(self):
|
||||
for page in ("which-pack", "files", "systems"):
|
||||
with self.subTest(page=page):
|
||||
found = self.LINK.search(_built(page))
|
||||
self.assertIsNotNone(found)
|
||||
self.assertNotIn("aria-current", found.group(1))
|
||||
own = self.LINK.search(_built("wanted"))
|
||||
self.assertIsNotNone(own)
|
||||
self.assertIn('aria-current="page"', own.group(1))
|
||||
|
||||
|
||||
def _title_block(html: str) -> str:
|
||||
"""What PageTitle draws: from the main column to the h1."""
|
||||
end = html.index('id="_top"')
|
||||
@@ -497,26 +530,76 @@ class HashAFileHere(unittest.TestCase):
|
||||
source = _read(SITE_TS)
|
||||
self.assertIn("input.type = 'file';", source)
|
||||
self.assertIn("It is hashed on this device. Nothing is uploaded.", source)
|
||||
self.assertIn("crypto.subtle.digest(name, buffer)", source)
|
||||
self.assertIn("['SHA-1', 'SHA-256']", source)
|
||||
self.assertIn("import { type FileHashes, hashFile } from './hashes.ts';", source)
|
||||
self.assertIn("lookUp(status, result, [found.sha1, found.md5, found.crc32, found.sha256])", source)
|
||||
hashing = _read(HASHES_TS)
|
||||
self.assertIn("crypto.subtle.digest(name, buffer)", hashing)
|
||||
self.assertIn("['SHA-1', 'SHA-256']", hashing)
|
||||
|
||||
def test_md5_and_crc32_match_python(self):
|
||||
source = _read(SITE_TS)
|
||||
block = source[source.index("// Hashing a file on this device"):source.index("type FileHashes")]
|
||||
sizes = [0, 1, 55, 56, 63, 64, 65, 119, 120, 128, 1000, 70_001]
|
||||
out = _node_module(block + (
|
||||
f"console.log(JSON.stringify({json.dumps(sizes)}.map((n) => {{"
|
||||
"const bytes = new Uint8Array(n);"
|
||||
"for (let i = 0; i < n; i += 1) bytes[i] = (i * 31 + 7) & 0xff;"
|
||||
"return [md5(bytes), crc32(bytes)]; })));"
|
||||
|
||||
class FileHashesMatchPython(unittest.TestCase):
|
||||
"""MD5 and CRC32 are written here, Web Crypto having neither: each is
|
||||
checked against hashlib and zlib, whole and fed in uneven slices, and
|
||||
hashFile's four values against a file read in 4 MiB slices."""
|
||||
|
||||
SIZES = [0, 1, 55, 56, 63, 64, 65, 119, 120, 128, 1000, 70_001]
|
||||
|
||||
@staticmethod
|
||||
def _bytes(size: int) -> bytes:
|
||||
return bytes((i * 31 + 7) & 0xFF for i in range(size))
|
||||
|
||||
def _run(self, body: str) -> list:
|
||||
return json.loads(_node_module(
|
||||
f"import {{ Crc32, Md5, crc32, hashFile, md5 }} from {json.dumps(HASHES_TS.as_uri())};"
|
||||
"const fill = (n) => { const b = new Uint8Array(n);"
|
||||
" for (let i = 0; i < n; i += 1) b[i] = (i * 31 + 7) & 0xff; return b; };" + body
|
||||
))
|
||||
for size, (md5, crc) in zip(sizes, json.loads(out)):
|
||||
data = bytes((i * 31 + 7) & 0xFF for i in range(size))
|
||||
|
||||
def test_md5_and_crc32_whole(self):
|
||||
out = self._run(
|
||||
f"console.log(JSON.stringify({json.dumps(self.SIZES)}.map((n) => "
|
||||
"{ const bytes = fill(n); return [md5(bytes), crc32(bytes)]; })));"
|
||||
)
|
||||
for size, (md5, crc) in zip(self.SIZES, out):
|
||||
data = self._bytes(size)
|
||||
with self.subTest(size=size):
|
||||
self.assertEqual(md5, hashlib.md5(data).hexdigest())
|
||||
self.assertEqual(crc, f"{zlib.crc32(data):08x}")
|
||||
|
||||
def test_md5_and_crc32_in_slices(self):
|
||||
"""A slice ending inside a 64-byte block carries it to the next."""
|
||||
size, steps = 200_003, [1, 63, 64, 65, 3, 1000, 7, 100_000]
|
||||
out = self._run(
|
||||
f"const bytes = fill({size}); const steps = {json.dumps(steps)};"
|
||||
"const m = new Md5(); const c = new Crc32();"
|
||||
"for (let at = 0, k = 0; at < bytes.length; k += 1) {"
|
||||
" const piece = bytes.subarray(at, at + steps[k % steps.length]);"
|
||||
" m.update(piece); c.update(piece); at += piece.length; }"
|
||||
"console.log(JSON.stringify([m.digest(), c.digest()]));"
|
||||
)
|
||||
data = self._bytes(size)
|
||||
self.assertEqual(out, [hashlib.md5(data).hexdigest(), f"{zlib.crc32(data):08x}"])
|
||||
|
||||
def test_hash_file_reads_slices_and_reports_progress(self):
|
||||
size = 9 * 1024 * 1024 + 17
|
||||
out = self._run(
|
||||
f"const shares = []; const found = await hashFile(new Blob([fill({size})]),"
|
||||
" (share) => shares.push(share));"
|
||||
"console.log(JSON.stringify([found, shares.length, shares.at(-1),"
|
||||
" shares.every((v, i) => i === 0 || v >= shares[i - 1])]));"
|
||||
)
|
||||
data = self._bytes(size)
|
||||
found, steps, last, rising = out
|
||||
self.assertEqual(found, {
|
||||
"sha1": hashlib.sha1(data).hexdigest(),
|
||||
"md5": hashlib.md5(data).hexdigest(),
|
||||
"crc32": f"{zlib.crc32(data):08x}",
|
||||
"sha256": hashlib.sha256(data).hexdigest(),
|
||||
})
|
||||
self.assertGreaterEqual(steps, 3)
|
||||
self.assertEqual(last, 1)
|
||||
self.assertTrue(rising)
|
||||
|
||||
|
||||
class SearchFoldsPagesUnderAHash(unittest.TestCase):
|
||||
"""Under "Look up this hash" came 14 unrelated pages: Magnavox for
|
||||
|
||||
@@ -41,6 +41,8 @@ START_PAGES = {
|
||||
START_LEVEL_PAGES = {
|
||||
"wiki/measurements.md": 300,
|
||||
"wiki/archive-recipes.md": 160,
|
||||
# The drop box, then the steps from a file in hand to its merge.
|
||||
"wanted.md": 260,
|
||||
}
|
||||
# Level 1: the guide part of each setup page, above its Reference heading.
|
||||
SETUP_CEILING = 220
|
||||
@@ -229,7 +231,8 @@ def parse(markdown: str) -> Page:
|
||||
flush()
|
||||
tab = 0
|
||||
continue
|
||||
if "rb-button" in stripped or "rb-tile" in stripped or stripped.startswith("<FilePicker"):
|
||||
if "rb-button" in stripped or "rb-tile" in stripped or stripped.startswith(
|
||||
("<FilePicker", "<WantedFiles")):
|
||||
act()
|
||||
continue
|
||||
if re.match(r"</?(?!abbr\b|a\b|code\b|strong\b|em\b)[A-Za-z]", stripped):
|
||||
|
||||
@@ -292,8 +292,10 @@ BEFORE_WEIGHT = {
|
||||
# Vita PUPs, dsi_nand.bin): 1,396,955 bytes on the site deployed from
|
||||
# 7d6efc352, 1,396,475 without the assets. Generated at 8d87f28cd and at
|
||||
# 750a6eb8e from the same inputs, the Markdown of all 13 pages is the
|
||||
# same size.
|
||||
"batocera": (13, 18_854, 1_396_955),
|
||||
# same size. The "Wanted files" link in the header of every page adds
|
||||
# about 80 bytes a page: 1,398,008 bytes on the site deployed from
|
||||
# aada55e65.
|
||||
"batocera": (13, 18_854, 1_398_008),
|
||||
# AmberELEC's MSX files cite the fMSX ROM loader since 2026-11-11 (fMSX
|
||||
# named 82 times instead of 28, the same 295 files): the section moved
|
||||
# to a part page of its own, 2 pages, 7,160 elements and 545,681 bytes
|
||||
@@ -301,18 +303,24 @@ BEFORE_WEIGHT = {
|
||||
# that read the set (546,385 bytes on the built site of 2026-11-11).
|
||||
# The openMSX system ROMs collected on 2026-11-12 split the MSX system
|
||||
# page in two, and nine of its files now link to microsoft-msx-2:
|
||||
# 546,403 bytes on the built site of 82d134cd8.
|
||||
"amberelec": (2, 7_928, 546_403),
|
||||
# 546,403 bytes on the built site of 82d134cd8. The "Wanted files" link
|
||||
# in the header of every page: 546,565 bytes on the site deployed from
|
||||
# aada55e65.
|
||||
"amberelec": (2, 7_928, 546_565),
|
||||
# RomM's PS2 page names scph10000.bin, the label LRPS2 reads through
|
||||
# RetroDECK's pcsx2_bios option, beside SCPH-10000.bin since 2026-11-13:
|
||||
# 572,528 bytes on the built site of that day.
|
||||
"romm": (2, 9_561, 572_528),
|
||||
# 572,528 bytes on the built site of that day. The "Wanted files" link
|
||||
# in the header of every page: 572,690 bytes on the site deployed from
|
||||
# aada55e65.
|
||||
"romm": (2, 9_561, 572_690),
|
||||
# RetroArch's MSX files cite the fMSX ROM loader and its ScummVM files
|
||||
# the readers of each data file since 2026-11-11 (46,737 and 9,275 bytes
|
||||
# more): 1,433,702 bytes on the built site of 964875572. Its PS2 page
|
||||
# names scph10000.bin with the LRPS2 refs that read it since 2026-11-13:
|
||||
# 1,434,426 bytes on the built site of that day.
|
||||
"retroarch": (14, 21_503, 1_434_426),
|
||||
# 1,434,426 bytes on the built site of that day. The "Wanted files" link
|
||||
# in the header of every page: 1,435,479 bytes on the site deployed from
|
||||
# aada55e65.
|
||||
"retroarch": (14, 21_503, 1_435_479),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
|
||||
import generate_site # noqa: E402
|
||||
import sitewanted # noqa: E402
|
||||
import siterender # noqa: E402
|
||||
from common import ( # noqa: E402
|
||||
list_registered_platforms,
|
||||
@@ -1256,10 +1257,18 @@ class FilesToSourceOnAPhone(unittest.TestCase):
|
||||
for row in rows:
|
||||
self.assertIn(f"[Have it? Upload]({generate_site.UPLOAD_URL}", row)
|
||||
|
||||
def test_the_upload_lands_in_the_console_folder(self):
|
||||
with mock.patch("siterender._own_section", return_value=("Sony", "PlayStation")):
|
||||
self.assertEqual(generate_site._upload_folder({"systems": ["sony-playstation"]}),
|
||||
"Sony/PlayStation")
|
||||
def test_the_upload_lands_in_the_folder_the_review_asks_for(self):
|
||||
"""The link read the profile's first system: Raze's Duke Nukem 3D
|
||||
files were sent to bios/Monolith/Blood/. It reads validate_pr's
|
||||
placement now (tests/test_site_wanted.py)."""
|
||||
held = "a" * 40
|
||||
db = {"files": {held: {"path": "bios/Sony/PlayStation/scph1001.bin"}},
|
||||
"indexes": {"by_md5": {}, "by_sha256": {}, "by_name": {}}}
|
||||
profile_hashes = {"folders": {"b" * 40: {"bios/Sony/PlayStation/"}}, "named": {}}
|
||||
placer = sitewanted.Placer(db, {}, profile_hashes)
|
||||
self.assertEqual(placer.folder({"name": "scph5501.bin", "sha1": "b" * 40}),
|
||||
"bios/Sony/PlayStation/")
|
||||
self.assertEqual(placer.folder({"name": "x.bin"}), "")
|
||||
|
||||
|
||||
GENERATED = REPO_ROOT / "website" / "src" / "generated"
|
||||
|
||||
@@ -0,0 +1,704 @@
|
||||
"""The wanted page's list: what the collection lacks, by hash, and where
|
||||
each file goes.
|
||||
|
||||
A visitor drops a file on wanted/ and the page says whether the collection
|
||||
wants it, then lists every wanted file with its own upload button. The list
|
||||
is built from the gaps page's own report, so a file the collection holds
|
||||
must never be on it, and its folder must be the one the review of the pull
|
||||
request asks for (validate_pr.placement): a page that sent a file elsewhere
|
||||
would have its upload flagged by the same project.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import re
|
||||
import zlib
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
|
||||
import generate_site # noqa: E402
|
||||
import sitewanted # noqa: E402
|
||||
import validate_pr # noqa: E402
|
||||
import yaml # noqa: E402
|
||||
from common import load_database # noqa: E402
|
||||
from tests.test_site_pronouns import pronouns # noqa: E402
|
||||
|
||||
WEBSITE = REPO_ROOT / "website"
|
||||
WANTED_TS = WEBSITE / "src" / "scripts" / "wanted.ts"
|
||||
COMPONENTS = WEBSITE / "src" / "components"
|
||||
PUBLISHED = WEBSITE / "public" / sitewanted.DATA_FILE
|
||||
|
||||
HELD = b"held rom"
|
||||
WANTED = b"wanted rom"
|
||||
VARIANT = b"another revision"
|
||||
MEMBER = b"rom inside an archive"
|
||||
CRC_ONLY = b"crc only rom"
|
||||
CUT = b"cut md5 rom"
|
||||
RECALBOX = [b"revision one", b"revision two"]
|
||||
GAME = b"game data file"
|
||||
HOMONYM = b"another machine's nohash.bin"
|
||||
|
||||
|
||||
def sha1(data: bytes) -> str:
|
||||
return hashlib.sha1(data).hexdigest()
|
||||
|
||||
|
||||
def md5(data: bytes) -> str:
|
||||
return hashlib.md5(data).hexdigest()
|
||||
|
||||
|
||||
def crc(data: bytes) -> str:
|
||||
return f"{zlib.crc32(data):08x}"
|
||||
|
||||
|
||||
class _World(unittest.TestCase):
|
||||
"""One held file of system x in bios/Maker/Console/, a profile and a
|
||||
platform that ask for files around it."""
|
||||
|
||||
def setUp(self) -> None:
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
self.tmp = Path(self._tmp.name)
|
||||
self._cwd = os.getcwd()
|
||||
os.chdir(self.tmp)
|
||||
self.addCleanup(os.chdir, self._cwd)
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
self.db = {
|
||||
"files": {sha1(HELD): {"path": "bios/Maker/Console/a.bin", "name": "a.bin",
|
||||
"size": len(HELD), "sha1": sha1(HELD), "md5": md5(HELD),
|
||||
"crc32": crc(HELD)},
|
||||
sha1(b"named"): {"path": "bios/Maker/Console/v.bin", "name": "v.bin",
|
||||
"size": 5, "sha1": sha1(b"named"), "md5": md5(b"named"),
|
||||
"crc32": crc(b"named")},
|
||||
# A file of the same name held for another machine.
|
||||
sha1(HOMONYM): {"path": "bios/Other/Elsewhere/nohash.bin",
|
||||
"name": "nohash.bin", "size": len(HOMONYM),
|
||||
"sha1": sha1(HOMONYM), "md5": md5(HOMONYM),
|
||||
"crc32": crc(HOMONYM)}},
|
||||
"indexes": {"by_md5": {md5(HELD): sha1(HELD), md5(b"named"): sha1(b"named")},
|
||||
"by_sha256": {}, "by_name": {"v.bin": [sha1(b"named")],
|
||||
"a.bin": [sha1(HELD)],
|
||||
"nohash.bin": [sha1(HOMONYM)]}},
|
||||
}
|
||||
(self.tmp / "bios" / "Maker" / "Console").mkdir(parents=True)
|
||||
(self.tmp / "bios" / "Maker" / "Console" / "a.bin").write_bytes(HELD)
|
||||
(self.tmp / "bios" / "Maker" / "Console" / "v.bin").write_bytes(b"named")
|
||||
emulators = self.tmp / "emulators"
|
||||
emulators.mkdir()
|
||||
(emulators / "engine.yml").write_text(
|
||||
"emulator: Engine\ntype: standalone\nsystems: [x]\nfiles:\n"
|
||||
f" - name: a.bin\n system: x\n sha1: \"{sha1(HELD)}\"\n"
|
||||
f" - name: b.bin\n system: x\n sha1: \"{sha1(WANTED)}\"\n required: true\n"
|
||||
f" - name: m.bin\n system: x\n sha1: \"{sha1(MEMBER)}\"\n"
|
||||
f" - name: c.bin\n system: x\n crc32: \"{crc(CRC_ONLY)}\"\n size: {len(CRC_ONLY)}\n"
|
||||
" - name: nohash.bin\n system: x\n description: A boot ROM. Read at start.\n"
|
||||
" - name: later.bin\n system: x\n unsourceable: not dumped yet\n"
|
||||
f" md5: \"{md5(b'later')}\"\n"
|
||||
f" - name: g.bin\n system: x\n category: game_data\n required: true\n"
|
||||
f" sha1: \"{sha1(GAME)}\"\n"
|
||||
" - name: own.cfg\n system: x\n unsourceable: settings the user writes\n"
|
||||
)
|
||||
self.profiles = {"engine": {
|
||||
"emulator": "Engine", "type": "standalone", "systems": ["x"],
|
||||
"files": [
|
||||
{"name": "a.bin", "system": "x", "sha1": sha1(HELD)},
|
||||
{"name": "b.bin", "system": "x", "sha1": sha1(WANTED), "required": True},
|
||||
{"name": "m.bin", "system": "x", "sha1": sha1(MEMBER)},
|
||||
{"name": "c.bin", "system": "x", "crc32": crc(CRC_ONLY), "size": len(CRC_ONLY)},
|
||||
{"name": "nohash.bin", "system": "x", "description": "A boot ROM. Read at start."},
|
||||
{"name": "later.bin", "system": "x", "unsourceable": "not dumped yet",
|
||||
"md5": md5(b"later")},
|
||||
{"name": "g.bin", "system": "x", "category": "game_data", "required": True,
|
||||
"sha1": sha1(GAME)},
|
||||
{"name": "own.cfg", "system": "x", "unsourceable": "settings the user writes"},
|
||||
],
|
||||
}}
|
||||
self.gap_report = {"engine": {
|
||||
"emulator": "Engine", "systems": ["x"],
|
||||
"gap_details": [
|
||||
{"name": name, "source": "missing", "identity": "",
|
||||
"required": name in ("b.bin", "g.bin")}
|
||||
for name in ("a.bin", "b.bin", "m.bin", "c.bin", "nohash.bin", "g.bin")
|
||||
] + [{"name": "pkg.bin", "source": "missing", "bundled": True, "identity": ""}],
|
||||
"unsourceable": [{"name": "later.bin", "required": False, "reason": "not dumped yet"},
|
||||
{"name": "own.cfg", "required": True,
|
||||
"reason": "settings the user writes"}],
|
||||
}}
|
||||
platform = {
|
||||
"x": {"files": [
|
||||
{"name": "v.bin", "md5": md5(VARIANT)},
|
||||
{"name": "cut.bin", "md5": md5(CUT)[:29]},
|
||||
{"name": "z.zip", "md5": md5(b"inner rom"), "zipped_file": "inner.rom"},
|
||||
{"name": "r.bin", "md5": ",".join(md5(r) for r in RECALBOX)},
|
||||
]},
|
||||
}
|
||||
self.coverages = {"plat": {
|
||||
"platform": "Plat", "config": {"systems": platform},
|
||||
"details": [
|
||||
{"name": "v.bin", "status": "untested", "system": "x", "required": True},
|
||||
{"name": "cut.bin", "status": "missing", "system": "x", "required": False,
|
||||
"category": "unread"},
|
||||
{"name": "z.zip", "status": "missing", "system": "x", "required": True},
|
||||
{"name": "r.bin", "status": "missing", "system": "x", "required": True},
|
||||
{"name": "a.bin", "status": "ok", "system": "x"},
|
||||
],
|
||||
}}
|
||||
self.ledger = [{"path": "bios/Maker/Console/set.zip", "members": [
|
||||
{"name": "m.bin", "size": len(MEMBER), "crc32": crc(MEMBER), "sha1": sha1(MEMBER)},
|
||||
]}]
|
||||
self.platform_hashes = {"sha1": set(), "md5": set(), "names": set(), "folders": {},
|
||||
"named": {}}
|
||||
self.profile_hashes = validate_pr.load_profile_hashes(str(emulators), self.db)
|
||||
self.placer = sitewanted.Placer(self.db, self.platform_hashes, self.profile_hashes)
|
||||
self.data = sitewanted.build_wanted(
|
||||
self.profiles, self.coverages, self.gap_report, self.db, self.placer,
|
||||
lambda system: f"System {system.upper()}", self.ledger,
|
||||
)
|
||||
|
||||
def entry(self, name: str) -> dict:
|
||||
found = [e for e in self.data["entries"] if e["n"] == name]
|
||||
self.assertEqual(len(found), 1, name)
|
||||
return found[0]
|
||||
|
||||
|
||||
class TheListHoldsWhatTheGapsReportLacks(_World):
|
||||
def test_names(self):
|
||||
names = sorted(e["n"] for e in self.data["entries"])
|
||||
# a.bin is held, m.bin is held inside set.zip, pkg.bin comes with
|
||||
# its emulator, own.cfg is the user's own, g.bin is game data: none
|
||||
# is wanted. r.bin is one entry per revision.
|
||||
self.assertEqual(names, ["b.bin", "c.bin", "cut.bin", "later.bin", "nohash.bin",
|
||||
"r.bin", "r.bin", "v.bin", "z.zip"])
|
||||
|
||||
def test_an_entry_with_no_hash_is_kept_and_marked(self):
|
||||
"""nohash.bin declares no hash and z.zip only the md5 of a ROM
|
||||
inside it: a dropped file cannot be compared with either, but a
|
||||
person who has it can still upload it from the list."""
|
||||
for name in ("nohash.bin", "z.zip"):
|
||||
with self.subTest(name=name):
|
||||
self.assertNotIn("h", self.entry(name))
|
||||
self.assertIn("h", self.entry("b.bin"))
|
||||
|
||||
# cut.bin is a file a platform lists and no core reads, the others
|
||||
# firmware.
|
||||
KIND = {"cut.bin": 1}
|
||||
|
||||
def test_required_entries_come_first(self):
|
||||
firmware = [e for e in self.data["entries"] if e["n"] not in self.KIND]
|
||||
needs = [bool(e.get("r")) for e in firmware]
|
||||
self.assertEqual(needs, sorted(needs, reverse=True))
|
||||
self.assertTrue(any(needs) and not all(needs))
|
||||
|
||||
def test_firmware_comes_before_game_data(self):
|
||||
kinds = [self.KIND.get(e["n"], 0) for e in self.data["entries"]]
|
||||
self.assertEqual(kinds, sorted(kinds))
|
||||
self.assertEqual(self.data["entries"][-1]["n"], "cut.bin")
|
||||
|
||||
def test_game_data_is_not_wanted(self):
|
||||
"""Game data is the player's own: a retail pak0.pk3 that ioquake3
|
||||
reads, and a platform entry verify files as game data, stay out."""
|
||||
profile = yaml.safe_load((REPO_ROOT / "emulators" / "ioquake3.yml").read_text(encoding="utf-8"))
|
||||
report = {"ioquake3": {"emulator": "ioquake3", "systems": profile.get("systems") or [],
|
||||
"gap_details": [{"name": "pak0.pk3", "source": "missing",
|
||||
"identity": ""}],
|
||||
"unsourceable": [{"name": "pak0.pk3", "required": True,
|
||||
"reason": "retail data"}]}}
|
||||
self.assertEqual(sitewanted.wanted_declarations({"ioquake3": profile}, {}, report), [])
|
||||
coverages = {"plat": {**self.coverages["plat"], "details": [
|
||||
{**d, "category": "game_data"} if d["name"] == "v.bin" else d
|
||||
for d in self.coverages["plat"]["details"]]}}
|
||||
names = [d["name"] for d in sitewanted.wanted_declarations({}, coverages, {})]
|
||||
self.assertNotIn("v.bin", names)
|
||||
|
||||
def test_a_file_the_emulator_installs_is_not_wanted(self):
|
||||
"""Amiberry's standalone release installs whdboot/boot-data.zip, its
|
||||
libretro core does not: only the core's entry can be a gap."""
|
||||
profile = yaml.safe_load((REPO_ROOT / "emulators" / "amiberry.yml").read_text(encoding="utf-8"))
|
||||
both = [f for f in profile["files"] if isinstance(f, dict) and f.get("name") == "boot-data.zip"]
|
||||
self.assertEqual(sorted(str(f.get("mode")) for f in both), ["libretro", "standalone"])
|
||||
report = {"amiberry": {"emulator": "Amiberry", "systems": profile.get("systems") or [],
|
||||
"gap_details": [{"name": "boot-data.zip", "source": "missing",
|
||||
"identity": ""}]}}
|
||||
found = sitewanted.wanted_declarations({"amiberry": profile}, {}, report)
|
||||
self.assertEqual([d["entry"].get("mode") for d in found], ["libretro"])
|
||||
|
||||
def test_a_platform_file_its_core_installs_is_not_wanted(self):
|
||||
"""v.bin is read by engine, whose build installs it: no gap. When
|
||||
only the standalone build installs it, the libretro core still
|
||||
needs it."""
|
||||
def declarations(entry: dict) -> list[str]:
|
||||
profiles = {"engine": {"emulator": "Engine", "type": "libretro", "files": [entry]}}
|
||||
coverages = {"plat": {**self.coverages["plat"], "details": [
|
||||
{**d, "category_evidence": {"read_by": [
|
||||
{"emulator": "engine", "runs_system": True, "entries": [{"name": "v.bin"}]}]}}
|
||||
if d["name"] == "v.bin" else d
|
||||
for d in self.coverages["plat"]["details"]]}}
|
||||
return [d["name"] for d in sitewanted.wanted_declarations(profiles, coverages, {})]
|
||||
|
||||
self.assertNotIn("v.bin", declarations({"name": "v.bin", "bundled": True}))
|
||||
self.assertIn("v.bin", declarations({"name": "v.bin", "bundled": True, "mode": "standalone"}))
|
||||
self.assertIn("v.bin", declarations({"name": "v.bin"}))
|
||||
def test_a_file_nobody_can_share_is_left_out(self):
|
||||
"""The reason a profile gives decides, read from the profiles
|
||||
themselves: emucorev's config.txt and puae's WHDLoad.key leave,
|
||||
a ROM no one has dumped yet stays."""
|
||||
reasons = {}
|
||||
for key, name in (("emucorev", "config.txt"), ("puae", "WHDLoad.key")):
|
||||
profile = yaml.safe_load((REPO_ROOT / "emulators" / f"{key}.yml").read_text(encoding="utf-8"))
|
||||
found = [f for f in profile["files"] if isinstance(f, dict) and f.get("name") == name
|
||||
and f.get("unsourceable")]
|
||||
self.assertTrue(found, (key, name))
|
||||
reasons[name] = str(found[0]["unsourceable"])
|
||||
for name, reason in reasons.items():
|
||||
with self.subTest(name=name):
|
||||
self.assertFalse(sitewanted.shareable(reason), reason)
|
||||
for reason in ("no public dump located (2026-10-04), and a same-named ROM of another set "
|
||||
"must not stand in",
|
||||
"retail data the collection does not hold, and a same-named file of another "
|
||||
"game must not stand in",
|
||||
"ships inside the Ghostship release, and the collection does not hold it"):
|
||||
with self.subTest(reason=reason):
|
||||
self.assertTrue(sitewanted.shareable(reason))
|
||||
|
||||
def test_more_readers_come_first(self):
|
||||
records = [{"name": "a", "required": False, "readers": {("emulator", "e", "E")}},
|
||||
{"name": "b", "required": False,
|
||||
"readers": {("emulator", "e", "E"), ("platform", "p", "P")}},
|
||||
{"name": "c", "required": True, "readers": {("emulator", "e", "E")}},
|
||||
{"name": "u", "required": True, "readers": {("platform", "p", "P")},
|
||||
"category": sitewanted.UNREAD}]
|
||||
for record in records:
|
||||
record.setdefault("category", sitewanted.BIOS)
|
||||
self.assertEqual([r["name"] for r in sorted(records, key=sitewanted._order)],
|
||||
["c", "b", "a", "u"])
|
||||
|
||||
def test_a_name_with_no_hash_joins_the_hashed_entry_of_its_name(self):
|
||||
reader = ("emulator", "other", "Other")
|
||||
records = {
|
||||
("b.bin", (("sha1", ("x",)),), ()): {
|
||||
"name": "b.bin", "hashes": {"sha1": ["x"]}, "systems": {"x"}, "required": False,
|
||||
"readers": {("emulator", "engine", "Engine")}, "description": "",
|
||||
"category": sitewanted.UNREAD, "crc": set(), "links": {(False, "engine"): "e"}},
|
||||
("b.bin", "x", ""): {
|
||||
"name": "b.bin", "hashes": {}, "systems": {"x"}, "required": True,
|
||||
"readers": {reader}, "crc": {"1234abcd"}, "links": {(False, "other"): "o"},
|
||||
"category": sitewanted.BIOS},
|
||||
}
|
||||
sitewanted._merge_named(records)
|
||||
self.assertEqual(len(records), 1)
|
||||
merged = next(iter(records.values()))
|
||||
self.assertIn(reader, merged["readers"])
|
||||
self.assertTrue(merged["required"])
|
||||
self.assertEqual(merged["category"], sitewanted.BIOS)
|
||||
|
||||
def test_a_pattern_is_not_a_file(self):
|
||||
profiles = {"engine": {**self.profiles["engine"], "files": [
|
||||
*self.profiles["engine"]["files"], {"name": "<serial>.txt", "system": "x"}]}}
|
||||
report = {"engine": {**self.gap_report["engine"], "gap_details": [
|
||||
*self.gap_report["engine"]["gap_details"],
|
||||
{"name": "<serial>.txt", "source": "missing", "identity": ""}]}}
|
||||
data = sitewanted.build_wanted(profiles, self.coverages, report, self.db, self.placer,
|
||||
str, self.ledger)
|
||||
self.assertNotIn("<serial>.txt", [e["n"] for e in data["entries"]])
|
||||
|
||||
def test_every_name_links_its_details(self):
|
||||
"""An emulator's entry links its card, a file only a setup lists
|
||||
links that setup's page."""
|
||||
seen = []
|
||||
|
||||
def link(kind: str, key: str, entry: dict) -> str:
|
||||
seen.append((kind, key, entry["name"]))
|
||||
return f"{kind}/{key}/#{entry['name']}"
|
||||
|
||||
data = sitewanted.build_wanted(self.profiles, self.coverages, self.gap_report, self.db,
|
||||
self.placer, str, self.ledger, link)
|
||||
links = {e["n"]: e["a"] for e in data["entries"]}
|
||||
self.assertEqual(links["b.bin"], "emulator/engine/#b.bin")
|
||||
self.assertEqual(links["v.bin"], "platform/plat/#v.bin")
|
||||
self.assertTrue(all(e["a"] for e in data["entries"]))
|
||||
self.assertEqual(sitewanted.reader_page("platform", "plat", {}), "platforms/plat/")
|
||||
|
||||
def test_a_crc32_beside_a_stronger_hash_is_shown_not_matched(self):
|
||||
profiles = {"engine": {**self.profiles["engine"], "files": [
|
||||
{**f, "crc32": crc(WANTED)} if f["name"] == "b.bin" else f
|
||||
for f in self.profiles["engine"]["files"]]}}
|
||||
data = sitewanted.build_wanted(profiles, self.coverages, self.gap_report, self.db,
|
||||
self.placer, str, self.ledger)
|
||||
entry = next(e for e in data["entries"] if e["n"] == "b.bin")
|
||||
self.assertEqual(entry["h"], {"sha1": [sha1(WANTED)]})
|
||||
self.assertEqual(entry["c"], [crc(WANTED)])
|
||||
|
||||
def test_the_list_carries_only_what_the_table_and_the_drop_box_read(self):
|
||||
allowed = {"n", "h", "c", "w", "s", "r", "z", "a", "f", "t", "v"}
|
||||
for entry in self.data["entries"]:
|
||||
with self.subTest(entry=entry["n"]):
|
||||
self.assertLessEqual(set(entry), allowed)
|
||||
|
||||
def test_an_entry_carries_its_readers_system_and_need(self):
|
||||
entry = self.entry("b.bin")
|
||||
self.assertEqual(entry["h"], {"sha1": [sha1(WANTED)]})
|
||||
self.assertEqual([self.data["systems"][i] for i in entry["s"]], ["System X"])
|
||||
self.assertEqual(entry["r"], 1)
|
||||
self.assertEqual([self.data["readers"][i] for i in entry["w"]], [["e", "engine", "Engine"]])
|
||||
self.assertEqual([self.data["readers"][i] for i in self.entry("v.bin")["w"]],
|
||||
[["p", "plat", "Plat"]])
|
||||
|
||||
def test_hashes_as_the_resolver_reads_them(self):
|
||||
self.assertEqual(self.entry("c.bin")["h"], {"crc32": [crc(CRC_ONLY)]})
|
||||
self.assertEqual(self.entry("c.bin")["z"], [len(CRC_ONLY)])
|
||||
self.assertEqual(self.entry("cut.bin")["h"], {"md5": [md5(CUT)[:29]]})
|
||||
revisions = sorted(e["h"]["md5"][0] for e in self.data["entries"] if e["n"] == "r.bin")
|
||||
self.assertEqual(revisions, sorted(md5(r) for r in RECALBOX))
|
||||
|
||||
def test_a_cut_md5_another_wanted_md5_starts_is_that_md5(self):
|
||||
records = [{"hashes": {"md5": [md5(CUT)[:29]]}}, {"hashes": {"md5": [md5(CUT)]}}]
|
||||
sitewanted._settle_cut(records)
|
||||
self.assertEqual(records[0]["hashes"], {"md5": [md5(CUT)]})
|
||||
both = [{"hashes": {"md5": ["ab" * 14 + "a"]}},
|
||||
{"hashes": {"md5": ["ab" * 14 + "a" + "000"]}},
|
||||
{"hashes": {"md5": ["ab" * 14 + "a" + "111"]}}]
|
||||
sitewanted._settle_cut(both)
|
||||
self.assertEqual(both[0]["hashes"], {})
|
||||
|
||||
def test_a_cut_md5_a_held_md5_starts_is_held(self):
|
||||
held = sitewanted.Held(self.db)
|
||||
self.assertTrue(held.holds({"md5": [md5(HELD)[:29]]}, []))
|
||||
self.assertFalse(held.holds({"md5": [md5(CUT)[:29]]}, []))
|
||||
|
||||
def test_a_crc32_counts_at_its_declared_size(self):
|
||||
held = sitewanted.Held(self.db)
|
||||
self.assertTrue(held.holds({"crc32": [crc(HELD)]}, [len(HELD)]))
|
||||
self.assertTrue(held.holds({"crc32": [crc(HELD)]}, []))
|
||||
self.assertFalse(held.holds({"crc32": [crc(HELD)]}, [len(HELD) + 1]))
|
||||
|
||||
|
||||
class EveryFolderIsTheReviewsFolder(_World):
|
||||
"""The folder and name of each entry, against what validate_pr says for
|
||||
the same bytes dropped outside bios/: the destination --place copies to."""
|
||||
|
||||
def test_the_review_places_each_file_where_the_page_sends_it(self):
|
||||
platform_hashes = {**self.platform_hashes, "md5": {md5(VARIANT)}, "names": {"v.bin"}}
|
||||
for data, name in ((WANTED, "b.bin"), (VARIANT, "v.bin")):
|
||||
with self.subTest(name=name):
|
||||
path = self.tmp / "card" / name
|
||||
path.parent.mkdir(exist_ok=True)
|
||||
path.write_bytes(data)
|
||||
result = validate_pr.validate_file(
|
||||
f"card/{name}", self.db, platform_hashes, self.profile_hashes)
|
||||
entry = self.entry(name)
|
||||
folder = self.data["folders"][entry["f"]]
|
||||
expected = (f"{folder}.variants/{entry['t']}.{sha1(data)[:8]}" if entry.get("v")
|
||||
else folder + entry["t"])
|
||||
self.assertEqual(result.destination, expected)
|
||||
self.assertEqual(self.data["folders"][self.entry("b.bin")["f"]], "bios/Maker/Console/")
|
||||
self.assertEqual(self.entry("v.bin").get("v"), 1)
|
||||
|
||||
def test_each_entry_is_placed_by_validate_pr(self):
|
||||
for entry in self.data["entries"]:
|
||||
values = [v for algo in ("sha1", "md5", "sha256") for v in entry.get("h", {}).get(algo, [])
|
||||
if len(v) == sitewanted.FULL_LENGTH[algo]]
|
||||
spot = validate_pr.placement(values, entry["n"], self.db, self.platform_hashes,
|
||||
self.profile_hashes, declared="h" in entry,
|
||||
exists=self.placer.paths.__contains__,
|
||||
systems=["x"])
|
||||
with self.subTest(entry=entry["n"]):
|
||||
self.assertEqual(self.data["folders"][entry["f"]] if "f" in entry else "",
|
||||
spot.folder)
|
||||
self.assertEqual(entry.get("t", ""), spot.name)
|
||||
self.assertEqual(bool(entry.get("v")), spot.variant)
|
||||
|
||||
def test_a_name_held_for_another_machine_is_no_folder(self):
|
||||
"""nohash.bin is held only in bios/Other/Elsewhere/, a folder no
|
||||
file of system x is in: the folder comes from system x."""
|
||||
self.assertEqual(self.data["folders"][self.entry("nohash.bin")["f"]], "bios/Maker/Console/")
|
||||
spot = validate_pr.placement([], "nohash.bin", self.db, self.platform_hashes,
|
||||
self.profile_hashes, declared=False, systems=["x"])
|
||||
self.assertEqual(spot.folder, "bios/Maker/Console/")
|
||||
# The review, given the name alone, reads the systems that declare it.
|
||||
self.assertEqual(validate_pr.placement([], "nohash.bin", self.db, self.platform_hashes,
|
||||
self.profile_hashes, declared=False).folder,
|
||||
"bios/Maker/Console/")
|
||||
|
||||
def test_the_review_accepts_the_folder_the_page_gives(self):
|
||||
folder = self.data["folders"][self.entry("nohash.bin")["f"]]
|
||||
path = self.tmp / folder / "nohash.bin"
|
||||
path.write_bytes(b"a copy of the wanted file")
|
||||
result = validate_pr.validate_file(f"{folder}nohash.bin", self.db, self.platform_hashes,
|
||||
self.profile_hashes)
|
||||
self.assertFalse([m for kind, m in result.checks if kind == "WARN" and m.startswith("Placed under")])
|
||||
self.assertIn(("PASS", "Correct placement: bios/Maker/Console/"), result.checks)
|
||||
|
||||
def test_a_declared_directory_names_its_folder(self):
|
||||
spot = validate_pr.placement([], "v.bin", self.db, self.platform_hashes, self.profile_hashes,
|
||||
declared=False, directory="system/Maker/Console/")
|
||||
self.assertEqual(spot.folder, "bios/Maker/Console/")
|
||||
|
||||
def test_the_gaps_page_upload_link_reads_the_same_rule(self):
|
||||
source = (REPO_ROOT / "scripts" / "generate_site.py").read_text(encoding="utf-8")
|
||||
self.assertIn("folder = placer.folder(declared[0]) if placer and declared else \"\"", source)
|
||||
self.assertNotIn("def _upload_folder", source)
|
||||
self.assertEqual(self.placer.folder(self.profiles["engine"]["files"][1]),
|
||||
"bios/Maker/Console/")
|
||||
self.assertEqual(sitewanted.upload_href(sitewanted.UPLOAD_ROOT, "bios/Maker/Sub Dir/"),
|
||||
"https://github.com/Abdess/retrobios/upload/main/bios/Maker/Sub%20Dir")
|
||||
self.assertEqual(sitewanted.upload_href(sitewanted.UPLOAD_ROOT, ""),
|
||||
generate_site.UPLOAD_URL)
|
||||
|
||||
|
||||
def _node(script: str) -> str:
|
||||
node = shutil.which("node")
|
||||
if not node:
|
||||
raise unittest.SkipTest("node is missing")
|
||||
return subprocess.run([node, "--input-type=module-typescript", "-e", script],
|
||||
capture_output=True, text=True, check=True, cwd=WEBSITE).stdout
|
||||
|
||||
|
||||
class ThePageReadsTheListAsTheResolverDoes(_World):
|
||||
"""wanted.ts against the list built above: a dropped file matches by
|
||||
every hash its entry declares, and its upload goes where the review
|
||||
places it."""
|
||||
|
||||
def _page(self, data: bytes, own_name: str) -> dict:
|
||||
hashes = {"sha1": sha1(data), "md5": md5(data), "crc32": crc(data),
|
||||
"sha256": hashlib.sha256(data).hexdigest()}
|
||||
return json.loads(_node(
|
||||
f"import {{ matches, target, uploadUrl, issueUrl }} from {json.dumps(WANTED_TS.as_uri())};"
|
||||
f"const data = {json.dumps(self.data)}; const file = {json.dumps(hashes)};"
|
||||
f"const found = matches(data, file, {len(data)});"
|
||||
f"const place = found.length ? target(data, found[0], file, {json.dumps(own_name)}) : null;"
|
||||
"console.log(JSON.stringify({names: found.map((e) => e.n), place,"
|
||||
" upload: place && uploadUrl(data, place.folder),"
|
||||
f" issue: found.length && issueUrl(data, found[0].n, file, {len(data)})}}));"
|
||||
))
|
||||
|
||||
def test_matches(self):
|
||||
self.assertEqual(self._page(WANTED, "x.bin")["names"], ["b.bin"])
|
||||
self.assertEqual(self._page(CRC_ONLY, "x.bin")["names"], ["c.bin"])
|
||||
self.assertEqual(self._page(CUT, "x.bin")["names"], ["cut.bin"])
|
||||
self.assertEqual(self._page(RECALBOX[1], "x.bin")["names"], ["r.bin"])
|
||||
self.assertEqual(self._page(HELD, "a.bin")["names"], [])
|
||||
self.assertEqual(self._page(b"unknown", "u.bin")["names"], [])
|
||||
|
||||
def test_a_crc32_at_another_size_is_not_the_file(self):
|
||||
entry = {"n": "c.bin", "h": {"crc32": [crc(CRC_ONLY)]}, "w": [], "z": [len(CRC_ONLY) + 1]}
|
||||
out = _node(
|
||||
f"import {{ satisfies }} from {json.dumps(WANTED_TS.as_uri())};"
|
||||
f"console.log(JSON.stringify(satisfies({json.dumps(entry)}, "
|
||||
f"{{sha1: '', md5: '', sha256: '', crc32: {json.dumps(crc(CRC_ONLY))}}}, {len(CRC_ONLY)})));"
|
||||
)
|
||||
self.assertFalse(json.loads(out))
|
||||
|
||||
def test_the_upload_goes_where_the_review_places_it(self):
|
||||
page = self._page(WANTED, "dump.rom")
|
||||
self.assertEqual(page["place"], {"folder": "bios/Maker/Console/", "name": "b.bin"})
|
||||
self.assertEqual(page["upload"],
|
||||
"https://github.com/Abdess/retrobios/upload/main/bios/Maker/Console")
|
||||
variant = self._page(VARIANT, "v.bin")["place"]
|
||||
self.assertEqual(variant, {"folder": "bios/Maker/Console/.variants/",
|
||||
"name": f"v.bin.{sha1(VARIANT)[:8]}"})
|
||||
|
||||
def test_a_dropped_file_meets_a_name_only_entry_by_its_name(self):
|
||||
out = json.loads(_node(
|
||||
f"import {{ byName, matches }} from {json.dumps(WANTED_TS.as_uri())};"
|
||||
f"const data = {json.dumps(self.data)};"
|
||||
"const file = {sha1: 'x', md5: 'x', crc32: 'x', sha256: 'x'};"
|
||||
"console.log(JSON.stringify([byName(data, 'NOHASH.BIN').map((e) => e.n),"
|
||||
" byName(data, 'b.bin').map((e) => e.n), matches(data, file, 1).map((e) => e.n)]));"
|
||||
))
|
||||
self.assertEqual(out, [["nohash.bin"], [], []])
|
||||
|
||||
def test_the_issue_form_is_filled_as_the_review_fills_it(self):
|
||||
result = validate_pr.ValidationResult("b.bin")
|
||||
result.sha1, result.md5, result.size = sha1(WANTED), md5(WANTED), len(WANTED)
|
||||
self.assertEqual(self._page(WANTED, "b.bin")["issue"], validate_pr.large_file_issue_url(result))
|
||||
|
||||
|
||||
class TheTwoPagesLinkEachOther(unittest.TestCase):
|
||||
"""files/ checks any file, wanted/ the ones the collection lacks: each
|
||||
sends a reader to the other in one line."""
|
||||
|
||||
def test_links(self):
|
||||
self.assertIn("[See if it is wanted](../wanted.md)", generate_site.generate_files_page())
|
||||
self.assertIn("[Find or check a file](files/index.md)", sitewanted.page(2, 1))
|
||||
|
||||
|
||||
class ThePageSpeaksWithoutPronouns(unittest.TestCase):
|
||||
"""The generated page is held by test_site_pronouns. The words the
|
||||
components write at run time are held here."""
|
||||
|
||||
STRING = re.compile(r"'((?:[^'\\\n]|\\.)*)'|`([^`]*)`")
|
||||
MARKUP_TEXT = re.compile(r">([^<>{}]+)<")
|
||||
|
||||
def test_page(self):
|
||||
self.assertEqual(pronouns(sitewanted.page(1_165, 199)), [])
|
||||
|
||||
def test_components(self):
|
||||
for name in ("WantedFiles.astro", "WantedList.astro"):
|
||||
source = (COMPONENTS / name).read_text(encoding="utf-8")
|
||||
script = source[source.index("<script>"):source.index("</script>")]
|
||||
texts = [a or b for a, b in self.STRING.findall(script)]
|
||||
texts += self.MARKUP_TEXT.findall(source[:source.index("<script>")])
|
||||
with self.subTest(component=name):
|
||||
self.assertTrue(texts)
|
||||
self.assertEqual([t for t in texts if pronouns(t)], [])
|
||||
|
||||
def test_a_simple_table(self):
|
||||
"""File name, size and the three hashes, a name linked to its
|
||||
details: nothing else on a row."""
|
||||
source = (COMPONENTS / "WantedList.astro").read_text(encoding="utf-8")
|
||||
head = re.search(r"<thead>(.*?)</thead>", source, re.S)[1]
|
||||
self.assertEqual(re.findall(r"<th[^>]*>([^<]*)</th>", head),
|
||||
["File name", "Size", "CRC32", "MD5", "SHA1"])
|
||||
script = source[source.index("<script>"):source.index("</script>")]
|
||||
self.assertIn("name.href = `${base}${entry.a}`;", script)
|
||||
for gone in ("entry.d", "entry.u", "entry.l", "entry.r", "entry.w", "Upload", "rb-badge",
|
||||
"Copy"):
|
||||
self.assertNotIn(gone, script)
|
||||
|
||||
def test_the_page_lists_the_steps(self):
|
||||
text = sitewanted.page(1_165, 199)
|
||||
for step in ("<WantedFiles />", "<WantedList />", "https://github.com/signup",
|
||||
"pull request", "issue form", "Drop them all", "1,165 files"):
|
||||
self.assertIn(step, text)
|
||||
self.assertLess(text.index("<WantedFiles />"), text.index("<WantedList />"))
|
||||
|
||||
|
||||
class AFolderComesFromTheSystem(unittest.TestCase):
|
||||
"""AmberELEC declares config.ini once per blueMSX machine, with no
|
||||
hash. The only config.ini files the collection holds are msx.emu's,
|
||||
one of them under its ColecoVision machine: a match by name alone sent
|
||||
the MSX ones there."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
if not (REPO_ROOT / "database.json").is_file():
|
||||
raise unittest.SkipTest("no database")
|
||||
cls.db = load_database(str(REPO_ROOT / "database.json"))
|
||||
cls.platform_hashes = validate_pr.load_platform_hashes(str(REPO_ROOT / "platforms"), cls.db)
|
||||
cls.profile_hashes = validate_pr.load_profile_hashes(str(REPO_ROOT / "emulators"), cls.db)
|
||||
|
||||
def place(self, systems: list[str], directory: str) -> validate_pr.Placement:
|
||||
return validate_pr.placement([], "config.ini", self.db, self.platform_hashes,
|
||||
self.profile_hashes, declared=False,
|
||||
systems=systems, directory=directory)
|
||||
|
||||
def test_an_msx_machine_config_stays_with_msx(self):
|
||||
spot = self.place(["microsoft-msx"], "bios/Machines/MSX2 - Arabic/")
|
||||
self.assertNotIn("ColecoVision", spot.folder)
|
||||
self.assertTrue(spot.folder.startswith("bios/Microsoft/MSX/"), spot)
|
||||
|
||||
def test_the_name_alone_names_no_machine(self):
|
||||
"""The review of an upload outside bios/ knows the name only: eight
|
||||
systems declare config.ini, so no copy of one of them answers."""
|
||||
spot = self.place([], "")
|
||||
self.assertEqual(spot.home, "")
|
||||
self.assertIn("bios/Microsoft/MSX/", spot.folders)
|
||||
|
||||
def test_a_colecovision_config_keeps_its_machine(self):
|
||||
spot = self.place(["coleco-colecovision"], "bios/Machines/COL - ColecoVision/")
|
||||
self.assertTrue(spot.folder.endswith("/Machines/COL - ColecoVision/"), spot)
|
||||
|
||||
|
||||
class ThePublishedList(unittest.TestCase):
|
||||
"""The list generate_site.py wrote, against the collection: nothing it
|
||||
holds, every folder by validate_pr, and light enough for a phone."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
if not PUBLISHED.is_file():
|
||||
raise unittest.SkipTest("no generated site data")
|
||||
cls.data = json.loads(PUBLISHED.read_text(encoding="utf-8"))
|
||||
cls.db = load_database(str(REPO_ROOT / "database.json"))
|
||||
|
||||
def test_nothing_held_is_wanted(self):
|
||||
held = sitewanted.Held(self.db, sitewanted.load_ledger(REPO_ROOT / "recipes" / "archives.json"))
|
||||
for entry in self.data["entries"]:
|
||||
if "h" not in entry:
|
||||
continue
|
||||
with self.subTest(entry=entry["n"]):
|
||||
self.assertFalse(held.holds(entry["h"], entry.get("z", [])))
|
||||
|
||||
def test_name_only_entries_are_kept(self):
|
||||
self.assertTrue(any("h" not in e for e in self.data["entries"]))
|
||||
|
||||
def test_every_folder_is_the_reviews(self):
|
||||
placer = sitewanted.Placer(
|
||||
self.db, validate_pr.load_platform_hashes(str(REPO_ROOT / "platforms"), self.db),
|
||||
validate_pr.load_profile_hashes(str(REPO_ROOT / "emulators"), self.db))
|
||||
# An entry placed by its hashes. The others take their folder from
|
||||
# their system and directory, which the list does not carry: the
|
||||
# synthetic world above holds them to the rule.
|
||||
for entry in self.data["entries"]:
|
||||
values = [v for algo in ("sha1", "md5", "sha256") for v in entry.get("h", {}).get(algo, [])
|
||||
if len(v) == sitewanted.FULL_LENGTH[algo]]
|
||||
if not validate_pr.expected_folders(values, placer.platform_hashes, placer.profile_hashes):
|
||||
continue
|
||||
spot = placer.place(entry.get("h", {}), entry["n"])
|
||||
with self.subTest(entry=entry["n"]):
|
||||
self.assertEqual(self.data["folders"][entry["f"]] if "f" in entry else "", spot.folder)
|
||||
self.assertEqual(entry.get("t", ""), spot.name)
|
||||
|
||||
def test_weight(self):
|
||||
self.assertLess(PUBLISHED.stat().st_size, 200_000)
|
||||
|
||||
def test_no_game_data_and_nothing_the_emulator_installs(self):
|
||||
"""Each emulator a row names declares that file as firmware it does
|
||||
not install itself: pak0.pk3, game data for every profile, is gone."""
|
||||
from common import load_emulator_profiles
|
||||
from validation import installed_with_emulator
|
||||
|
||||
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
self.assertNotIn("pak0.pk3", [e["n"] for e in self.data["entries"]])
|
||||
for entry in self.data["entries"]:
|
||||
for index in entry["w"]:
|
||||
kind, key, _label = self.data["readers"][index]
|
||||
if kind != "e":
|
||||
continue
|
||||
declared = [f for f in profiles[key].get("files") or []
|
||||
if isinstance(f, dict) and f.get("name") == entry["n"]]
|
||||
with self.subTest(entry=entry["n"], emulator=key):
|
||||
self.assertTrue([f for f in declared if f.get("category") != "game_data"
|
||||
and not installed_with_emulator(f)])
|
||||
|
||||
def test_every_link_lands_on_its_details(self):
|
||||
"""Each name's link is a built page, and a card anchor is on it."""
|
||||
dist = WEBSITE / "dist"
|
||||
if not dist.is_dir():
|
||||
self.skipTest("no built site")
|
||||
pages: dict[str, str] = {}
|
||||
for entry in self.data["entries"]:
|
||||
path, _, anchor = entry["a"].partition("#")
|
||||
html = pages.get(path)
|
||||
if html is None:
|
||||
built = dist / path / "index.html"
|
||||
html = pages[path] = built.read_text(encoding="utf-8") if built.is_file() else ""
|
||||
with self.subTest(entry=entry["n"], link=entry["a"]):
|
||||
self.assertTrue(html)
|
||||
if anchor:
|
||||
self.assertIn(f'id="{anchor}"', html)
|
||||
|
||||
def test_the_built_page_asks_for_this_list(self):
|
||||
"""The list's address carries its version: a browser that cached an
|
||||
older list (another shape) fetches this one."""
|
||||
built = WEBSITE / "dist" / "wanted" / "index.html"
|
||||
if not built.is_file():
|
||||
self.skipTest("no built site")
|
||||
html = built.read_text(encoding="utf-8")
|
||||
version = hashlib.sha1(PUBLISHED.read_bytes()).hexdigest()[:12]
|
||||
self.assertEqual(html.count(f'data-version="{version}"'), 2)
|
||||
self.assertNotIn("data/wanted.json", html)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -186,6 +186,33 @@ class AFileOnlyACoreReadsIsKnown(_Fixture):
|
||||
self.assertTrue(any("Placed under bios/Other/Place/" in m for _s, m in placed.checks))
|
||||
|
||||
|
||||
class ADeclaredFileBesideItsHeldNameIsAVariant(_Fixture):
|
||||
"""A file a profile declares, of a system the collection files nowhere
|
||||
yet, whose name the collection holds: the review named the folder and
|
||||
left the copy to land on the held file of that name."""
|
||||
|
||||
def test_place_copies_it_beside_the_held_name(self):
|
||||
import hashlib # noqa: PLC0415
|
||||
|
||||
data = b"declared revision"
|
||||
emulators = self.tmp / "emulators"
|
||||
emulators.mkdir()
|
||||
(emulators / "engine.yml").write_text(
|
||||
"emulator: Engine\ntype: standalone\nsystems: [x, y]\nfiles:\n"
|
||||
f" - name: \"v.bin\"\n sha1: \"{hashlib.sha1(data).hexdigest()}\"\n"
|
||||
)
|
||||
db = {"files": {"a" * 40: {"path": "bios/Maker/Console/v.bin"}},
|
||||
"indexes": {"by_md5": {}, "by_sha256": {}, "by_name": {"v.bin": ["a" * 40]}}}
|
||||
known = validate_pr.load_profile_hashes(str(emulators), db)
|
||||
result = validate_pr.validate_file(
|
||||
self._bios_file("card/v.bin", data), db, EMPTY_HASHES, known)
|
||||
slot = f"bios/Maker/Console/.variants/v.bin.{result.sha1[:8]}"
|
||||
self.assertEqual(result.destination, slot)
|
||||
self.assertIn(("WARN", "File is not under bios/ yet. The collection keeps this name in "
|
||||
f"`bios/Maker/Console/`. --place copies it to `{slot}`"),
|
||||
result.checks)
|
||||
|
||||
|
||||
class ASizeEveryDeclarationRulesOutIsNotAVariant(_Fixture):
|
||||
"""1024 random bytes named scph5501.bin, a name every declaration sizes
|
||||
at 524288, were told "File size OK" and offered a .variants slot at the
|
||||
@@ -450,7 +477,8 @@ class PlatformHashLoading(_Fixture):
|
||||
known = validate_pr.load_platform_hashes(str(self.tmp / "absent"))
|
||||
self.assertEqual(known, {"sha1": set(), "md5": set(), "sha256": set(), "crc32": set(),
|
||||
"names": set(), "folders": {}, "sizes": {}, "entries": {},
|
||||
"named": {}})
|
||||
"named": {}, "name_systems": {}, "system_dirs": {},
|
||||
"system_folders": {}})
|
||||
|
||||
def test_declared_hashes_and_names_are_collected(self):
|
||||
platforms = self.tmp / "platforms"
|
||||
|
||||
Reference in new issue
Block a user