From 19d50e86b910dce63f01a06f6667bf63dcce496f Mon Sep 17 00:00:00 2001 From: Spinnich Date: Fri, 29 May 2026 20:30:59 +0000 Subject: [PATCH] fix(screenscraper): use internal filename as romnom for single-file archives When sending a hash lookup to ScreenScraper, romnom was always set to the archive filename on disk (e.g. Mario.zip). For single-file archives, the hash is computed from the internal file (e.g. mario.n64), so sending the archive name sends slightly incorrect info to ss.fr during a KO scrape. When archive_members has exactly one entry, romnom now uses that member's name. Multi-file archives and non-archive files continue to use the filesystem filename unchanged. Closes #3444 Co-Authored-By: Claude Sonnet 4.6 --- backend/handler/metadata/ss_handler.py | 6 +- .../tests/handler/metadata/test_ss_handler.py | 87 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/backend/handler/metadata/ss_handler.py b/backend/handler/metadata/ss_handler.py index 3b0fcaf78..52cb8a71e 100644 --- a/backend/handler/metadata/ss_handler.py +++ b/backend/handler/metadata/ss_handler.py @@ -713,7 +713,11 @@ class SSHandler(MetadataHandler): sha1=sha1_hash, crc=crc_hash, rom_size_bytes=fs_size_bytes, - rom_name=first_file.file_name, + rom_name=( + first_file.archive_members[0]["name"] + if first_file.archive_members and len(first_file.archive_members) == 1 + else first_file.file_name + ), rom_type=_get_rom_type(first_file), ) if not res: diff --git a/backend/tests/handler/metadata/test_ss_handler.py b/backend/tests/handler/metadata/test_ss_handler.py index 1aa921100..ea9c3960c 100644 --- a/backend/tests/handler/metadata/test_ss_handler.py +++ b/backend/tests/handler/metadata/test_ss_handler.py @@ -716,6 +716,93 @@ class TestLookupRom: assert result["ss_id"] is None assert is_not_game is True + @pytest.mark.asyncio + async def test_romnom_uses_archive_member_name_for_single_file_archive(self): + handler = SSHandler() + mock_file = self._make_mock_file() + mock_file.file_name = "Mario.zip" + mock_file.archive_members = [ + { + "name": "mario.n64", + "size": 1024, + "crc_hash": "", + "md5_hash": "", + "sha1_hash": "", + } + ] + captured = {} + + async def capture(**kwargs): + captured.update(kwargs) + return None + + with patch.object(handler.ss_service, "get_game_info", side_effect=capture): + await handler.lookup_rom(MagicMock(platform_slug="n64"), 14, [mock_file]) + assert captured.get("rom_name") == "mario.n64" + + @pytest.mark.asyncio + async def test_romnom_uses_archive_filename_for_multi_file_archive(self): + handler = SSHandler() + mock_file = self._make_mock_file() + mock_file.file_name = "Mario.zip" + mock_file.archive_members = [ + { + "name": "mario.bin", + "size": 1024, + "crc_hash": "", + "md5_hash": "", + "sha1_hash": "", + }, + { + "name": "mario.cue", + "size": 64, + "crc_hash": "", + "md5_hash": "", + "sha1_hash": "", + }, + ] + captured = {} + + async def capture(**kwargs): + captured.update(kwargs) + return None + + with patch.object(handler.ss_service, "get_game_info", side_effect=capture): + await handler.lookup_rom(MagicMock(platform_slug="psx"), 57, [mock_file]) + assert captured.get("rom_name") == "Mario.zip" + + @pytest.mark.asyncio + async def test_romnom_uses_archive_filename_when_no_archive_members(self): + handler = SSHandler() + mock_file = self._make_mock_file() + mock_file.file_name = "mario.n64" + mock_file.archive_members = None + captured = {} + + async def capture(**kwargs): + captured.update(kwargs) + return None + + with patch.object(handler.ss_service, "get_game_info", side_effect=capture): + await handler.lookup_rom(MagicMock(platform_slug="n64"), 14, [mock_file]) + assert captured.get("rom_name") == "mario.n64" + + @pytest.mark.asyncio + async def test_romnom_uses_archive_filename_when_archive_members_empty(self): + handler = SSHandler() + mock_file = self._make_mock_file() + mock_file.file_name = "Mario.zip" + mock_file.archive_members = [] + captured = {} + + async def capture(**kwargs): + captured.update(kwargs) + return None + + with patch.object(handler.ss_service, "get_game_info", side_effect=capture): + await handler.lookup_rom(MagicMock(platform_slug="n64"), 14, [mock_file]) + assert captured.get("rom_name") == "Mario.zip" + @pytest.mark.asyncio async def test_returns_notgame_flag_on_zzz_prefix(self): notgame_response = {