fix: quote rom and core names in yaml

YAML 1.1 reads an unquoted 01 as the integer 1 and 81 as 81, so the
manager set stopped naming the file its driver opens and the API
published "cores": [2048] as a number where consumers match strings.

Ground truth from MAME 0.289 at the revision the profile cites:
src/mame/vtech/crvision.cpp:957 loads "01" and "23".

The root cause was the scraper: _hash_merge wrote these names through an
f-string, so quoting the profiles alone would be undone on the next
refresh. _yaml_scalar now quotes every name, archive and description it
writes.
This commit is contained in:
Abdessamad Derraz committed 2026-08-10 13:35:42 +02:00
1 parent 5d417c8229
commit 597a8ff919
7 files changed
+66 -11

No files matched your search

+46
View File
@@ -196,6 +196,52 @@ class TestMameMerge(unittest.TestCase):
self.assertTrue(pgm["required"])
self.assertEqual(pgm["category"], "bios_zip")
def test_numeric_looking_rom_name_survives_the_write(self) -> None:
"""MAME ships ROMs named 01 and 23. Bare YAML turns them into numbers.
The manager set loads "01"; written unquoted it re-parses as the
integer 1 and the profile stops naming the file the driver opens.
"""
from scripts.scraper._hash_merge import (
_append_new_entries,
_format_contents,
)
contents = [
{"name": "01", "description": "ROM bank 0-1", "size": 8192,
"crc32": "702f4cf5"},
{"name": "23", "description": "ROM bank 2-3", "size": 8192,
"crc32": "46489d88"},
]
document = yaml.safe_load(
"files:\n - name: manager.zip\n" + _format_contents(contents)
)
names = [rom["name"] for rom in document["files"][0]["contents"]]
self.assertEqual(names, ["01", "23"])
for name in names:
self.assertIsInstance(name, str)
original = "emulator: MAME\nfiles:\n - name: neogeo.zip\n"
appended = _append_new_entries(
original,
[{
"name": "manager.zip",
"required": False,
"category": "bios_zip",
"source_ref": "src/mame/vtech/crvision.cpp:955-959",
"contents": contents,
}],
original,
)
entry = next(
f
for f in yaml.safe_load(appended)["files"]
if f["name"] == "manager.zip"
)
self.assertEqual(
[rom["name"] for rom in entry["contents"]], ["01", "23"]
)
def test_merge_preserves_non_bios_files(self) -> None:
profile = _make_mame_profile()
profile["files"].append({"name": "hiscore.dat", "required": False})