chore: merge pack and resolver fixes

This commit is contained in:
Abdessamad Derraz committed 2026-11-07 00:06:15 +01:00
commit 70f530516d
66 files changed
+1294 -786

No files matched your search

+34 -9
View File
@@ -1377,23 +1377,29 @@ class OneBaselineVerdict(unittest.TestCase):
)
def test_the_builder_accepts_what_verify_accepts(self):
"""verify took a 29-character md5 by prefix and a ZIP by its
composite, but the builder compared exact md5s and refused both when
another declared hash disagreed."""
"""verify took a ZIP by its composite, but the builder compared exact
md5s and refused it when another declared hash disagreed. A value cut
short accepts nothing: Batocera compares the whole md5 string
(batocera-systems:1088), and verify accepted any prefix, down to one
digit."""
import hashlib
from scripts.common import md5_composite
from scripts.validation import baseline_verdict
from scripts.validation import baseline_verdict, digest_verdict
with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory:
loose = Path(directory) / "abc.bin"
loose.write_bytes(b"abc")
truncated = {"name": "abc.bin", "md5": hashlib.md5(b"abc").hexdigest()[:29],
"crc32": "deadbeef"}
self.assertEqual(
baseline_verdict(truncated, str(loose), "hash_mismatch", "md5"),
("frontend_digest_exact", None),
md5 = hashlib.md5(b"abc").hexdigest()
truncated = {"name": "abc.bin", "md5": md5[:29], "crc32": "deadbeef"}
self.assertIsNotNone(
baseline_verdict(truncated, str(loose), "hash_mismatch", "md5")[1]
)
for length in (1, 29, 31):
self.assertFalse(
digest_verdict({"md5": md5[:length]}, 3, lambda: {"md5": md5}, "md5")
)
self.assertTrue(digest_verdict({"md5": md5}, 3, lambda: {"md5": md5}, "md5"))
archive = self._archive(Path(directory), "rom.bin")
composite = {"name": "dragon32.zip", "md5": md5_composite(archive),
"crc32": "deadbeef"}
@@ -2138,6 +2144,25 @@ class CheckoutCompletenessRegressions(unittest.TestCase):
finally:
os.chdir(cwd)
def test_restore_without_its_registry_fails(self):
"""A mistyped --gitignore read as an empty registry: nothing to
restore, nothing unsatisfied, exit 0 with every asset absent."""
import subprocess
from scripts.restore_large_files import gitignored_paths
with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory:
missing = str(Path(directory) / "absent")
with self.assertRaises(FileNotFoundError):
gitignored_paths(missing)
proc = subprocess.run(
[sys.executable, str(ROOT / "scripts" / "restore_large_files.py"),
"--gitignore", missing, "--cache", directory],
capture_output=True, text=True, timeout=120,
)
self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr)
self.assertIn("lists the release assets", proc.stderr)
def test_restore_refuses_a_copy_replaced_after_the_index(self):
"""The cache is hashed first and copied later: another run that
replaced the cached name in between put its bytes at a path the
+2 -1
View File
@@ -660,10 +660,11 @@ class ShortMd5Handling(unittest.TestCase):
scraper = inspect.getsource(batocera_scraper)
self.assertIn("_resolve_truncated_md5(value, md5_index) for value in values", scraper)
resolver = inspect.getsource(common.resolve_local_file)
self.assertIn("if len(md5_candidate) < 32:", resolver)
self.assertIn("cut_md5_owner(cut, by_md5)", resolver)
self.assertIn("_md5_name_ok(path)", resolver)
section = _section(_page("verification-modes.md"), "MD5 shorter than 32 characters (Batocera)")
self.assertIn("_resolve_truncated_md5", section)
self.assertIn("cut_md5_owner", section)
class RegistryKeysDocumented(unittest.TestCase):
+48
View File
@@ -6376,6 +6376,54 @@ struct BurnDriver BurnDrvneogeo = {
[f for f in os.listdir(out) if f.endswith(".zip")] if os.path.isdir(out) else []
)
def test_an_emulator_needing_no_file_succeeds_like_verify(self):
"""Handy requires no file. --required-only removed the empty ZIP,
printed its path and exited 1, while verify reported 0/0 OK."""
import subprocess
repo = os.path.join(os.path.dirname(__file__), "..")
out = os.path.join(self.root, "no_file_needed")
proc = subprocess.run(
[sys.executable, "scripts/generate_pack.py", "--emulator", "handy",
"--required-only", "--offline", "--output-dir", out],
capture_output=True, text=True, cwd=repo, timeout=300,
)
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
self.assertIn("no file needed, no pack written", proc.stdout)
self.assertNotIn(".zip", proc.stdout)
verify = subprocess.run(
[sys.executable, "scripts/verify.py", "--emulator", "handy", "--required-only"],
capture_output=True, text=True, cwd=repo, timeout=300,
)
self.assertEqual(verify.returncode, proc.returncode)
def test_a_platform_without_cores_refuses_profile_narrowings(self):
"""MiSTer and BizHawk declare cores: []. --region, --one-per-slot
and --no-game-data read the profiles, so their packs withdrew
nothing under a name and README that said otherwise."""
import subprocess
repo = os.path.join(os.path.dirname(__file__), "..")
out = os.path.join(self.root, "blind")
runs = [
["scripts/generate_pack.py", "--platform", "misterfpga", "--region", "us"],
["scripts/generate_pack.py", "--platform", "misterfpga", "--one-per-slot"],
["scripts/generate_pack.py", "--platform", "misterfpga", "--no-game-data"],
["scripts/generate_pack.py", "--platform", "bizhawk", "--manifest",
"--region", "us"],
["scripts/verify.py", "--platform", "bizhawk", "--region", "us"],
]
for argv in runs:
extra = ["--offline", "--output-dir", out] if "generate_pack" in argv[0] else []
with self.subTest(argv=argv):
proc = subprocess.run(
[sys.executable, *argv, *extra],
capture_output=True, text=True, cwd=repo, timeout=300,
)
self.assertEqual(proc.returncode, 1, proc.stdout + proc.stderr)
self.assertIn("runs no core a profile describes", proc.stderr)
self.assertFalse(os.listdir(out) if os.path.isdir(out) else [])
def test_a_full_pack_is_not_announced_as_narrowed(self):
from generate_pack import _build_readme, _narrowings
+6 -5
View File
@@ -61,10 +61,11 @@ class EachProfileEntryIsHashedOnce(unittest.TestCase):
cats = EntryCategories(_config(["core"], []), profiles)
real = candidates._entry_hashes
with mock.patch.object(candidates, "_entry_hashes", side_effect=real) as counted:
for md5 in ("a" * 32, "a" * 29):
self.assertEqual(cats.category({"name": "a.bin", "md5": md5}, "a.bin", "s"), BIOS)
for _ in range(2):
self.assertEqual(cats.category({"name": "a.bin", "md5": "a" * 32}, "a.bin", "s"), BIOS)
self.assertEqual(counted.call_count, 1)
self.assertTrue(candidates._accepts({"a" * 32}, {"md5": {"a" * 29}}))
# A cut md5 verifies nothing: Batocera compares the whole string.
self.assertFalse(candidates._accepts({"a" * 32}, {"md5": {"a" * 29}}))
self.assertFalse(candidates._accepts({"a" * 32}, {"md5": {"b" * 32}}))
class Category(unittest.TestCase):
@@ -242,8 +243,8 @@ class AProfileIsIndexedOncePerKind(unittest.TestCase):
def test_the_index_answers_as_the_scan_did(self):
cases = [
({"name": "one.bin", "md5": "2" * 32}, BIOS, [{"name": "one.bin", "source_ref": "a.c:3"}]),
# A cut md5 (Batocera's 29 characters) matches by prefix.
({"name": "x", "md5": "1" * 29}, BIOS, [{"name": "one.bin", "source_ref": "a.c:2"}]),
# A cut md5 proves nothing: hashes compare whole.
({"name": "x", "md5": "1" * 29}, BIOS, []),
({"name": "one.bin"}, BIOS, [
{"name": "one.bin", "source_ref": "a.c:2", "by": "name"},
{"name": "one.bin", "source_ref": "a.c:3", "by": "name"},
+30
View File
@@ -228,6 +228,36 @@ class LargeFileCacheTest(unittest.TestCase):
self.assertEqual(cached.read_bytes(), rebuilt)
self.assertEqual(len(gets), 1)
def test_an_orphan_link_is_never_returned(self):
"""A revision link whose cache name was removed has one link left.
Downloaded again with the same bytes, the old link was returned and
the prune of that same download removed it."""
self._serve(PAYLOAD_A, [])
sha1 = hashlib.sha1(PAYLOAD_A).hexdigest()
first = common.fetch_large_file("asset.bin", dest_dir=self.dir, expected_sha1=sha1)
self.assertTrue(first and os.path.isfile(first))
os.unlink(Path(self.dir) / "asset.bin")
with mock.patch.object(largefiles, "ORPHAN_GRACE", -1):
second = common.fetch_large_file(
"asset.bin", dest_dir=self.dir, expected_sha1=sha1
)
self.assertTrue(second and os.path.isfile(second))
self.assertTrue(os.path.samefile(second, Path(self.dir) / "asset.bin"))
def test_a_cache_hit_relinks_an_orphan(self):
"""The cache name was replaced by a copy with the same bytes: the hit
handed out the old link, which a prune elsewhere would remove."""
self._serve(PAYLOAD_A, [])
sha1 = hashlib.sha1(PAYLOAD_A).hexdigest()
common.fetch_large_file("asset.bin", dest_dir=self.dir, expected_sha1=sha1)
cached = Path(self.dir) / "asset.bin"
os.unlink(cached)
cached.write_bytes(PAYLOAD_A)
hit = common.fetch_large_file(
"asset.bin", dest_dir=self.dir, expected_sha1=sha1, offline=True
)
self.assertTrue(os.path.samefile(hit, cached))
def test_a_revision_the_release_still_serves_is_kept(self):
cached = Path(self.dir) / "asset.bin"
cached.write_bytes(PAYLOAD_A)
+44 -1
View File
@@ -6,11 +6,14 @@ names live in the platform's ``launchers:`` layer. Copied into a profile as
aliases, they claimed that xemu opens them, and xemu-libretro offers
Complex_4627_v1.03.bin, not Complex_4627v1.03.bin (ui/xemu-libretro.c:115-118).
Two checks read the committed data:
Three checks read the committed data:
- an alias equal to a name a launcher of the same emulator chooses is kept
only when the entry's own note or description names it in a sentence that
speaks of no platform, next to a ``source_ref`` into the emulator's code;
- an entry whose note names its own file only in sentences about a platform
is a launcher's choice: Mini vMac opens no MinivMacBootv2.dsk, the .cmd
Recalbox writes names it;
- no entry cites a platform's launcher script as its source.
"""
@@ -44,6 +47,13 @@ LAUNCHER_REF = re.compile(
r"\bemuDeck\w*\.sh\b|\bscriptmodules/|\(launcher\)",
)
# Entries whose name is the one a platform's launcher picks, kept because
# the code takes any name and the entry needs one.
NAMED_FOR_A_LAUNCHER = {
("pcsx_rearmed_standalone", "SCPH1001.BIN"):
"the code lists any 512 KiB file (frontend/menu.c:2619-2628)",
}
# Profiles whose entries still rest on a launcher, with the fact that blocks
# reading the emulator itself.
LAUNCHER_SOURCED = {
@@ -121,6 +131,39 @@ class ProfileAliasesAreCodeNames(unittest.TestCase):
"code, stated in the entry's note with its source_ref, or removed",
)
def test_an_entry_named_only_by_a_launcher_is_not_the_emulators(self) -> None:
launchers = _launcher_names()
offenders = []
for key, profile in _profiles().items():
emulator_names = {key} | {str(c) for c in profile.get("cores") or []}
for entry in profile.get("files") or []:
name = str(entry.get("name") or "").rsplit("/", 1)[-1]
if (key, name) in NAMED_FOR_A_LAUNCHER or not any(
emulator in emulator_names
for _platform, emulator in launchers.get(name.casefold(), ())
):
continue
prose = _text(entry.get("note")) + " " + _text(entry.get("description"))
if name in prose and not _named_without_platform(name, prose):
offenders.append(f"{key}: {name}")
self.assertEqual(
offenders, [],
"an entry whose own note names it only as a platform's choice "
"belongs to that platform's launchers: layer",
)
def test_rosalies_mupen_gui_names_stay_out_of_mupen64plus(self) -> None:
"""RetroBat's mupen64 generator configures Rosalie's Mupen GUI and
writes IPL_USA.n64 and IPL_DEV.n64 into its config
(Mupen64.Generator.cs:232-238). Mupen64Plus fixes no IPL name."""
profiles = _profiles()
for key in ("mupen64plus", "mupen64plus-ae", "m64plus-fz"):
aliases = {
str(a) for entry in profiles[key].get("files") or []
for a in entry.get("aliases") or []
}
self.assertFalse(aliases & {"IPL_USA.n64", "IPL_DEV.n64"}, key)
def test_check_catches_a_launcher_name(self) -> None:
self.assertFalse(_named_without_platform(
"cerbios.bin", "Batocera writes bios/cerbios.bin into flashrom_path.",
+127
View File
@@ -0,0 +1,127 @@
"""A name means the dump its declarations prove, not whatever is filed under it.
The collection files the DSi Panda (Japan) (Intense) devkit boot ROMs as
dsi_bios7.bin and dsi_bios9.bin. Their eMMC key-Y at 0x8308 is zeroed, so a
retail NAND cannot be opened with them. Every hash declared under those names
(Batocera's md5, melonDS's crc32) designates a retail dump in the same
directory, yet RetroBat and dsperate, which declare no hash, were served the
devkit ROMs by the name step.
"""
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 sys
import tempfile
import unittest
import zlib
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import generate_db # noqa: E402
from common import resolve_local_file # noqa: E402
DEVKIT = b"D" * 64
RETAIL = b"R" * 64
OTHER = b"O" * 64
def record(path: str, data: bytes) -> dict:
return {
"path": path,
"name": path.rsplit("/", 1)[-1],
"size": len(data),
"md5": hashlib.md5(data).hexdigest(),
"crc32": f"{zlib.crc32(data):08x}",
"sha256": hashlib.sha256(data).hexdigest(),
}
class ProvenNameIndex(unittest.TestCase):
def setUp(self):
self.files = {
hashlib.sha1(DEVKIT).hexdigest(): record("bios/N/DSi/dsi_bios7.bin", DEVKIT),
hashlib.sha1(RETAIL).hexdigest(): record("bios/N/DSi/biosdsi7.bin", RETAIL),
hashlib.sha1(OTHER).hexdigest(): record("bios/X/Y/other.bin", OTHER),
}
self.indexes = generate_db.build_indexes(self.files, {})
def index(self, declarations: list[dict]) -> dict:
return generate_db.proven_name_index(self.files, self.indexes, declarations)
def test_name_points_at_the_proven_dump_beside_it(self):
declared = [{"name": "dsi_bios7.bin", "md5": hashlib.md5(RETAIL).hexdigest()}]
self.assertEqual(
self.index(declared),
{"dsi_bios7.bin": [hashlib.sha1(RETAIL).hexdigest()]},
)
def test_a_proven_holder_keeps_its_name(self):
declared = [
{"name": "dsi_bios7.bin", "md5": hashlib.md5(RETAIL).hexdigest()},
{"name": "dsi_bios7.bin", "crc32": f"{zlib.crc32(DEVKIT):08x}"},
]
self.assertEqual(self.index(declared), {})
def test_a_dump_filed_elsewhere_proves_nothing(self):
declared = [{"name": "dsi_bios7.bin", "md5": hashlib.md5(OTHER).hexdigest()}]
self.assertEqual(self.index(declared), {})
def test_a_member_hash_proves_nothing(self):
declared = [{
"name": "dsi_bios7.bin",
"md5": hashlib.md5(RETAIL).hexdigest(),
"zipped_file": "x.bin",
}]
self.assertEqual(self.index(declared), {})
class HashlessEntryTakesTheProvenDump(unittest.TestCase):
def test_resolver_reads_the_index(self):
(REPO_ROOT / "tmp").mkdir(exist_ok=True)
root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
self.addCleanup(shutil.rmtree, root, True)
previous = os.getcwd()
os.chdir(root)
self.addCleanup(os.chdir, previous)
Path("bios/N/DSi").mkdir(parents=True)
Path("bios/N/DSi/dsi_bios7.bin").write_bytes(DEVKIT)
Path("bios/N/DSi/biosdsi7.bin").write_bytes(RETAIL)
files = {
hashlib.sha1(DEVKIT).hexdigest(): record("bios/N/DSi/dsi_bios7.bin", DEVKIT),
hashlib.sha1(RETAIL).hexdigest(): record("bios/N/DSi/biosdsi7.bin", RETAIL),
}
indexes = generate_db.build_indexes(files, {})
db = {"files": files, "indexes": indexes}
entry = {"name": "dsi_bios7.bin", "size": 64}
self.assertEqual(
resolve_local_file(entry, db)[0], "bios/N/DSi/dsi_bios7.bin"
)
indexes["by_proven_name"] = generate_db.proven_name_index(
files, indexes,
[{"name": "dsi_bios7.bin", "md5": hashlib.md5(RETAIL).hexdigest()}],
)
self.assertEqual(
resolve_local_file(entry, db), ("bios/N/DSi/biosdsi7.bin", "name_exact")
)
class TheCollectionServesRetailRoms(unittest.TestCase):
def test_dsi_boot_roms(self):
db = json.loads((REPO_ROOT / "database.json").read_text())
index = db["indexes"].get("by_proven_name", {})
for name in ("dsi_bios7.bin", "dsi_bios9.bin"):
held = [db["files"][sha1]["path"] for sha1 in index.get(name, [])]
self.assertTrue(held, name)
self.assertFalse(any(path.endswith(f"/{name}") for path in held), held)
if __name__ == "__main__":
unittest.main()
+32
View File
@@ -100,5 +100,37 @@ class TheGroupTakesThePlatformSpelling(unittest.TestCase):
)
class ALosingClaimIsKeyedLikeTheWinner(unittest.TestCase):
"""RetroDECK writes its BIOS under bios/. The extra that won a path was
keyed bios/scph1002b.bin, the losing claims bare scph1002b.bin, so verify
--region never matched them against the drops and listed Rustation's
copies as packed while the builder had withdrawn them."""
def test_a_losing_claim_carries_the_declared_root(self):
import os
from common import declared_root, load_database, load_emulator_profiles
from common import load_platform_config
from packextras import platform_region_groups
previous = os.getcwd()
os.chdir(REPO_ROOT)
self.addCleanup(os.chdir, previous)
config = load_platform_config("retrodeck", "platforms")
root = declared_root(config)
self.assertTrue(root)
_groups, claims = platform_region_groups(
config, config["systems"], "emulators", load_database("database.json"),
config.get("base_destination", ""), load_emulator_profiles("emulators"),
)
rustation = {
name: dest for (emulator, name, _path), dest in claims.items()
if emulator == "Rustation" and name.startswith("scph")
}
self.assertTrue(rustation)
for name, dest in rustation.items():
self.assertEqual(dest, f"{root}/{name}")
if __name__ == "__main__":
unittest.main()
+60 -3
View File
@@ -43,9 +43,66 @@ class ARefusedDumpHoldsNothing(unittest.TestCase):
"by_path_suffix": {}},
}
entry = {"name": "us.bin", "md5": "0" * 32}
self.assertFalse(_ships({"verification_mode": "md5"}, entry, db))
self.assertTrue(_ships({"verification_mode": "existence"}, entry, db))
self.assertTrue(_ships({"verification_mode": "md5"}, {"name": "us.bin"}, db))
def ships(config: dict, fe: dict) -> bool:
return _ships(config, fe, db, None, None, None)
self.assertFalse(ships({"verification_mode": "md5"}, entry))
self.assertTrue(ships({"verification_mode": "existence"}, entry))
self.assertTrue(ships({"verification_mode": "md5"}, {"name": "us.bin"}))
class ADataDirectoryCopyIsHeld(unittest.TestCase):
"""The region pass resolves with the builder's inputs.
Without the data directories, AmberELEC's config.ini (served from the
bluemsx tree) and dolphin-mmjr2's nwc24msg.cfg (served from the Dolphin
Sys tree) read as missing while both packs held them.
"""
@classmethod
def setUpClass(cls):
if not (REPO_ROOT / "data" / "bluemsx").is_dir() or not (
REPO_ROOT / "data" / "dolphin-sys"
).is_dir():
raise unittest.SkipTest("data/ not refreshed")
previous = os.getcwd()
os.chdir(REPO_ROOT)
try:
from common import load_data_dir_registry, load_database
from common import load_emulator_profiles, load_platform_config
cls.db = load_database("database.json")
cls.registry = load_data_dir_registry("platforms")
cls.profiles = load_emulator_profiles("emulators")
cls.amberelec = load_platform_config("amberelec", "platforms")
finally:
os.chdir(previous)
def setUp(self):
previous = os.getcwd()
os.chdir(REPO_ROOT)
self.addCleanup(os.chdir, previous)
def test_platform_declaration_from_a_data_tree(self):
entry = next(
fe for fe in self.amberelec["systems"]["coleco-colecovision"]["files"]
if fe["destination"].endswith("Dina/config.ini")
)
self.assertTrue(
_ships(self.amberelec, entry, self.db, {}, self.registry, None)
)
def test_emulator_entry_from_a_data_tree(self):
from packextras import _emulator_ships
from validation import _build_validation_index
profile = self.profiles["dolphin-mmjr2"]
entry = next(
fe for fe in profile["files"] if fe.get("name") == "nwc24msg.cfg"
)
index = _build_validation_index({"dolphin-mmjr2": profile})
self.assertTrue(_emulator_ships(
entry, "dolphin-mmjr2", profile, self.db, index, {}, self.registry,
))
if __name__ == "__main__":
+14 -1
View File
@@ -443,7 +443,8 @@ class PackNamesItsVersion(unittest.TestCase):
if not release_record.pack_for("batocera", record):
self.skipTest("release.json has no Batocera pack")
block = generate_site._pack_buttons("batocera")
version = generate_site._pack_version(release_record.pack_name_for("batocera", record))
name = release_record.pack_name_for("batocera", record)
version = generate_site._pack_version(name, ["batocera"])
self.assertIn(f"Made for Batocera {version}. "
+ generate_site.other_version("batocera"), block)
@@ -454,6 +455,18 @@ class PackNamesItsVersion(unittest.TestCase):
line = generate_site.version_line("retrobat", record, named=len(released) > 1)
self.assertEqual(line, generate_site.other_version("retrobat"))
def test_a_version_with_an_underscore_is_read_whole(self):
"""AmberELEC's prerelease-20261019_1835 read as 1835, and the page
said the pack was built for another version."""
from generate_pack import _platform_pack_stem
version = load_platform_config("amberelec", "platforms")["version"]
name = _platform_pack_stem(["amberelec"], "amberelec", "platforms") + "_BIOS_Pack.zip"
self.assertEqual(generate_site._pack_version(name, ["amberelec"]), version)
record = {"tag": "v2026.10.10", "packs": {name: {
"assets": [name], "platforms": ["amberelec"]}}}
self.assertEqual(len(generate_site.release_line("amberelec", record)), 1)
def test_another_version_is_sent_to_the_check_commands(self):
"""A ZIP reader read "Run `--check` after copying." with no command."""
line = generate_site.other_version("emudeck")
+2 -1
View File
@@ -547,7 +547,8 @@ class AFolderCheckAgreesWithTheVerifier(unittest.TestCase):
for entry in contract["systems"]["s"]["files"]
]
self.assertEqual(found, expected)
self.assertEqual([v for _d, v in found], ["ok", "wrong", "ok", "wrong", "ok", "missing"])
# plain.bin declares a cut md5: Batocera compares the whole string.
self.assertEqual([v for _d, v in found], ["ok", "wrong", "wrong", "wrong", "ok", "missing"])
def test_batocera_from_the_csv_matches_the_verifier(self):
"""A check driven by platform-files.csv, with zipped_file, gives the
+36
View File
@@ -994,6 +994,42 @@ class TwoPathsHoldingOneContentAgree(unittest.TestCase):
self.assertFalse(slots._satisfies(different, platform, db))
class ACopierHeaderIsNotAnotherImage(unittest.TestCase):
"""Geargrafx drops a 512-byte header before the crc32 (src/media.cpp:
754-773). EmuELEC's headered syscard3.pce was reported contested, though
the core reads it as the 6d9a73ef image its profile lists."""
def test_headered_file_satisfies_the_profile(self):
import zlib # noqa: PLC0415
image = b"S" * 1024
with tempfile.TemporaryDirectory() as tmp:
headered = Path(tmp, "headered.pce")
headered.write_bytes(b"\0" * 512 + image)
plain = Path(tmp, "plain.pce")
plain.write_bytes(image)
crc = f"{zlib.crc32(image):08x}"
db = {"files": {
"a" * 40: {"path": str(headered), "size": 1536,
"crc32": f"{zlib.crc32(headered.read_bytes()):08x}"},
"b" * 40: {"path": str(plain), "size": 1024, "crc32": crc},
}}
platform = Claim("platform", "syscard3.pce", "syscard3.pce",
local_path=str(headered), status="md5_exact")
profile = Claim(
"profile", "syscard3.pce", "syscard3.pce", emulator="geargrafx",
local_path=str(plain), status="crc32_exact",
entry={"name": "syscard3.pce", "crc32": [crc], "size": [1024, 1536]},
)
self.assertTrue(slots._satisfies(profile, platform, db))
one_size = Claim(
"profile", "syscard3.pce", "syscard3.pce", emulator="geargrafx",
local_path=str(plain), status="crc32_exact",
entry={"name": "syscard3.pce", "crc32": [crc], "size": 1024},
)
self.assertFalse(slots._satisfies(one_size, platform, db))
class TheSlotsSummaryClosesTheRun(unittest.TestCase):
"""The totals came before the collision section and ignored it, and the
help said the default run fails on conflicts the pack should settle,