chore: merge launcher names

This commit is contained in:
Abdessamad Derraz committed 2026-11-09 18:29:52 +01:00
commit 2fe15e99f9
24 files changed
+1400 -62

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
"""A platform declaration that a content-found core entry accepts by hash.
atari800 identifies its ROMs by CRC32 in the folder it scans. RetroDECK
lists Atari BASIC Rev A as ROM_BASIC_A, a name atari800 never opens, and
the profile answered it with a false alias. Settled by content instead, the
declared file meets the entry and the label is not shipped a second time.
"""
from __future__ import annotations
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
import os
import sys
import unittest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts"))
from common import platform_declared_contents # noqa: E402
from validation import declaration_settles # noqa: E402
SHA1 = "70cdf57469a208528f78a14275837352e90e20f1"
DB = {
"files": {SHA1: {"path": "bios/Atari/ROM_BASIC_A", "name": "ROM_BASIC_A", "sha1": SHA1,
"md5": "a4dc52536d526ecc51ea857b9fa2b90f", "crc32": "4bec4de2",
"size": 8192}},
"indexes": {"by_md5": {"a4dc52536d526ecc51ea857b9fa2b90f": SHA1}},
}
CONFIG = {
"base_destination": "",
"systems": {"atari800": {"files": [
{"name": "ROM_BASIC_A", "destination": "bios/ROM_BASIC_A",
"md5": "a4dc52536d526ecc51ea857b9fa2b90f"},
]}},
}
ENTRY = {"name": "atari-basic-rev-a.rom", "found_by": "content", "crc32": "4bec4de2"}
class ContentDeclarationTest(unittest.TestCase):
def setUp(self) -> None:
self.contents = platform_declared_contents(CONFIG, DB)
def test_the_declared_file_is_indexed_by_each_hash(self) -> None:
self.assertEqual(self.contents["crc32:4bec4de2"], {""})
self.assertEqual(self.contents[f"sha1:{SHA1}"], {""})
def test_a_content_found_entry_is_met_by_its_hash(self) -> None:
self.assertTrue(declaration_settles(
ENTRY, ENTRY["name"], {}, ENTRY["name"], declared_contents=self.contents,
))
def test_an_entry_opened_by_name_is_not(self) -> None:
entry = {key: value for key, value in ENTRY.items() if key != "found_by"}
self.assertFalse(declaration_settles(
entry, entry["name"], {}, entry["name"], declared_contents=self.contents,
))
def test_another_folder_is_not_the_one_scanned(self) -> None:
self.assertFalse(declaration_settles(
ENTRY, ENTRY["name"], {}, "atari800/" + ENTRY["name"],
declared_contents=self.contents,
))
if __name__ == "__main__":
unittest.main()
+51 -4
View File
@@ -66,8 +66,15 @@ LAUNCHERS = [
_record("diremu", "passes_path", []),
{"emulator": "pkg", "build": "standalone", "kind": "package", "names": [],
"source_ref": "pkg.sh:1"},
_record("missemu", "names_searched", ["held.bin", "absent.bin"]),
_record("missemu", "names_searched", ["absent.bin"]),
_record("otheremu", "copies", ["absent.bin"]),
_record("altemu", "names_searched", ["alt.bin", "held.bin", "late.bin"]),
_record("pkgemu", "copies", ["shipped.bin"], search_dir="$md_inst"),
{"emulator": "pkgemu", "build": "standalone", "kind": "copies",
"names": ["written.ini"], "source_ref": "pkg.sh:2"},
_record("setemu", "fixed_name", ["setname.bin"], passes_to="command line -romslot"),
_record("aliasemu", "fixed_name", ["alias.bin.rom"]),
_record("setemu", "copies", ["user.sf2"]),
_record("caseemu", "fixed_name", ["mixed.rom"]),
_record("foldemu", "fixed_name", ["MIXED.rom"], case_insensitive=True),
_record("labelemu", "core_option", ["labelled.rom (CDZ)"]),
@@ -128,6 +135,12 @@ class LauncherGapTest(unittest.TestCase):
"emulator": "AliasEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "aliases": ["alias.bin"], "required": True}],
},
"setemu": {
"emulator": "SetEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "config_key": "romslot", "required": True},
{"name": "user.sf2", "required": False,
"unsourceable": "user supplied, no canonical file"}],
},
"missemu": {
"emulator": "MissEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "absent.bin", "required": True, "md5": "0" * 32}],
@@ -167,6 +180,39 @@ class LauncherGapTest(unittest.TestCase):
reported = {r["emulators"][0] for r in self._rows().values()}
self.assertFalse(reported & {"tplemu", "diremu", "pkg"})
def test_a_search_with_one_held_name_reads_nothing_missing(self) -> None:
"""The launcher keeps the first name it finds, so the held one fills it."""
names = {name for _, name in self._rows()}
self.assertFalse(names & {"alt.bin", "late.bin"})
def test_a_copy_from_the_platform_package_is_not_owed(self) -> None:
"""RetroPie copies lr-vecx's system.bin from $md_inst and writes mame.ini."""
names = {name for _, name in self._rows()}
self.assertFalse(names & {"shipped.bin", "written.ini"})
def test_a_name_with_an_appended_extension_is_held(self) -> None:
"""ROCKNIX's kick34005.A500.rom is Amiberry's kick34005.A500."""
self.assertNotIn("alias.bin.rom", {name for _, name in self._rows()})
def test_a_name_its_reader_declares_unsourceable_is_counted_apart(self) -> None:
"""RetroBat copies any SoundFont saved as Roland_SC-88.sf2: not a
file to find, yet never dropped silently."""
row = self._rows()[("gaptest", "user.sf2")]
self.assertEqual(row["unsourceable"], "user supplied, no canonical file")
out = io.StringIO()
with contextlib.redirect_stdout(out):
print_launcher_reads(list(self._rows().values()))
text = out.getvalue()
self.assertIn("Launcher reads, not held: 3 names", text)
self.assertIn("Launcher reads, unsourceable: 1 names across 1 platform", text)
self.assertIn("gaptest: user.sf2 [setemu, gen/setemu.py:1]: user supplied, no canonical file",
text)
held_part = text.split("Launcher reads, unsourceable")[0]
self.assertNotIn("user.sf2", held_part)
def test_a_name_handed_to_a_held_entry_setting_is_held(self) -> None:
self.assertNotIn("setname.bin", {name for _, name in self._rows()})
def test_a_label_after_the_name_is_dropped(self) -> None:
self.assertEqual(launcher_file_names(LAUNCHERS[-1]), ["labelled.rom"])
self.assertIn(("gaptest", "labelled.rom"), self._rows())
@@ -223,9 +269,9 @@ class LauncherGapTest(unittest.TestCase):
self.assertEqual(result.returncode, 0, result.stderr)
report = json.loads(result.stdout)
names = {r["name"] for r in report[LAUNCHER_READS_KEY]}
self.assertEqual(names, {"absent.bin", "mixed.rom", "labelled.rom"})
self.assertEqual(names, {"absent.bin", "mixed.rom", "labelled.rom", "user.sf2"})
# The emulator rows keep their own shape and counts.
self.assertEqual(set(report) - {LAUNCHER_READS_KEY}, {"aliasemu", "missemu"})
self.assertEqual(set(report) - {LAUNCHER_READS_KEY}, {"aliasemu", "missemu", "setemu"})
def test_verify_counts_and_exit_code_are_unchanged(self) -> None:
"""A launcher name is reported, not judged: nothing else moves."""
@@ -239,7 +285,8 @@ class LauncherGapTest(unittest.TestCase):
)
rows = with_rows.pop("launcher_reads_not_held")
without.pop("launcher_reads_not_held")
self.assertEqual({r["name"] for r in rows}, {"absent.bin", "mixed.rom", "labelled.rom"})
self.assertEqual({r["name"] for r in rows},
{"absent.bin", "mixed.rom", "labelled.rom", "user.sf2"})
self.assertEqual(with_rows, without)
def exit_code(result: dict) -> int:
+103 -1
View File
@@ -24,7 +24,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts"))
import yaml # noqa: E402
from common import _emulator_profiles_cache, load_emulator_profiles, load_platform_config # noqa: E402
from launchers import LauncherLayer, launcher_places # noqa: E402
from launchers import LauncherLayer, launcher_places, suffixed_stem # noqa: E402
from verify import find_undeclared_files, verify_platform # noqa: E402
CONTENT = {
@@ -252,6 +252,108 @@ class LauncherLayerTest(unittest.TestCase):
self.assertNotIn("core.bin", {u["name"] for u in self._report()})
self.assertNotIn("core.bin", self._pack_names())
def test_a_file_handed_to_an_entry_setting_takes_the_entry_content(self) -> None:
"""RetroPie runs sdl2trs with -romfile4p $biosdir/level4p.rom and
EmuDeck writes a No-Intro name into ares's NeoGeoPocket firmware
setting: neither name is the core's, and the held file of the entry
that setting reads went in under no name at all."""
profile = {
"emulator": "FixEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "required": True, "config_key": "romslot"},
{"name": "other.bin", "required": True, "config_key": "otherslot"}],
}
with open(os.path.join(self.emulators_dir, "fixemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"][2]["names"] = ["launcher.rom"]
self.config["launchers"][2]["passes_to"] = "command line -romslot"
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["launcher.rom"]["launcher_of"], "core.bin")
self.assertEqual(added["launcher.rom"]["md5"], _md5(CONTENT["core.bin"]))
self.assertIn("launcher.rom", self._pack_names())
def test_a_fixed_name_with_an_appended_extension_takes_the_entry(self) -> None:
"""ROCKNIX passes kick34005.A500.rom to Amiberry, which names
Kickstart 1.3 kick34005.A500: the pack shipped nothing under it."""
profile = {
"emulator": "FixEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "aliases": ["kick.A500"], "required": True}],
}
with open(os.path.join(self.emulators_dir, "fixemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"][2]["names"] = ["kick.A500.rom"]
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["kick.A500.rom"]["md5"], _md5(CONTENT["core.bin"]))
self.assertIsNone(suffixed_stem("scph1001.bin"))
def test_an_entry_the_platform_declares_still_fills_the_launcher_name(self) -> None:
"""AmberELEC declares kick34005.A500, so the report never offers
Amiberry's entry, and its config still passes kick34005.A500.rom."""
profile = {
"emulator": "FixEmu", "type": "standalone", "systems": ["test-sys"],
"files": [{"name": "core.bin", "aliases": ["kick.A500"], "required": True}],
}
with open(os.path.join(self.emulators_dir, "fixemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"][2]["names"] = ["kick.A500.rom"]
self.config["systems"]["test-sys"]["files"].append(
{"name": "core.bin", "destination": "core.bin", "required": True}
)
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["kick.A500.rom"]["md5"], _md5(CONTENT["core.bin"]))
def test_each_name_of_a_config_takes_its_own_key(self) -> None:
"""AmberELEC's atari800.cfg names eight ROMs under eight keys, and
one record describes them in order: 5200a.rom is ROM_5200_A's file,
not every key's."""
config = {"base_destination": "bios", "launchers": [{
"emulator": "e", "build": "libretro", "kind": "fixed_name",
"names": ["a.rom", "b.rom"], "search_dir": "/storage/roms/bios",
"passes_to": "e.cfg ROM_A, ROM_B", "source_ref": "e.cfg:1",
}]}
places = {p.paths[0]: p.passes_to for p in launcher_places(config)}
self.assertEqual(places, {"a.rom": "e.cfg ROM_A", "b.rom": "e.cfg ROM_B"})
def test_a_core_option_names_the_dump_of_a_model(self) -> None:
"""RetroDECK sets LRPS2's pcsx2_bios to scph10000.bin. LRPS2's entry
is a placeholder for every BIOS its scan finds, and the catalogues
name two revisions of the SCPH-10000: the earlier goes in."""
older, newer = b"S" * 64, b"T" * 64
for data, catalogue in ((newer, "ps2-0101j-20000217.bin"),
(older, "ps2-0100j-20000117.bin")):
sha1 = hashlib.sha1(data).hexdigest()
path = os.path.join(self.bios_dir, catalogue)
with open(path, "wb") as fh:
fh.write(data)
self.db["files"][sha1] = {
"path": path, "name": catalogue, "md5": _md5(data), "sha1": sha1,
"size": len(data), "crc32": "",
"provenance": {"redump": {"name": catalogue,
"description": "SCPH-10000 (Version 5.0)"}},
}
profile = {
"emulator": "OptEmu", "type": "libretro", "systems": ["test-sys"],
"files": [{"name": "<bios>.bin", "path": "ps2/bios/<bios>.bin", "required": True,
"min_size": 32, "max_size": 64, "validation": ["size"],
"config_key": "emu_bios"}],
}
with open(os.path.join(self.emulators_dir, "optemu.yml"), "w") as fh:
yaml.dump(profile, fh)
self.config["launchers"].append({
"emulator": "retroarch", "build": "libretro", "kind": "core_option",
"names": ["scph10000.bin"], "passes_to": "core option emu_bios",
"source_ref": "core-options.cfg:515",
})
_emulator_profiles_cache.clear()
self.profiles = load_emulator_profiles(self.emulators_dir)
added = {u["path"]: u for u in self._report() if u.get("launcher")}
self.assertEqual(added["ps2/bios/scph10000.bin"]["md5"], _md5(older))
def test_the_default_name_a_launcher_replaces_is_not_packed(self) -> None:
"""EmuDeck passes Complex_4627v1.03.bin to xemu, which then never
opens Complex_4627.bin: the pack carried both, one read by nobody."""