fix(retroachievements): match SuperGrafx against RetroAchievements

SuperGrafx games never matched against RetroAchievements: the supergrafx
slug had no RA platform ID, so RA hashing was skipped during scans and
matching bailed out early.

RetroAchievements has no separate SuperGrafx console; its games share the
PC Engine/TurboGrafx-16 console, ID 8, same as tg16. Map supergrafx to
that console in both RA tables, mirroring the existing tg16 entries.

Fixes #3651.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Spinnich
2026-07-01 19:52:14 +00:00
parent 2149941ddd
commit ef95f91aa0
4 changed files with 117 additions and 0 deletions

View File

@@ -127,6 +127,9 @@ PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID: dict[UPS, int] = {
UPS.SNES: 3,
UPS.TURBOGRAFX_CD: 76,
UPS.TG16: 8,
# RA has no separate SuperGrafx console; its games share the PC Engine/
# TurboGrafx-16 console, ID 8, same as tg16 (issue #3651).
UPS.SUPERGRAFX: 8,
UPS.UZEBOX: 80,
UPS.VECTREX: 46,
UPS.VIRTUALBOY: 28,

View File

@@ -452,6 +452,9 @@ RA_PLATFORM_LIST: dict[UPS, SlugToRAId] = {
UPS.SFAM: {"id": 3, "name": "Super Famicom"},
UPS.TURBOGRAFX_CD: {"id": 76, "name": "TurboGrafx CD"},
UPS.TG16: {"id": 8, "name": "TurboGrafx-16"},
# RA has no separate SuperGrafx console; its games share the PC Engine/
# TurboGrafx-16 console (ID 8), same as tg16. See GitHub issue #3651.
UPS.SUPERGRAFX: {"id": 8, "name": "SuperGrafx"},
UPS.UZEBOX: {"id": 80, "name": "Uzebox"},
UPS.VECTREX: {"id": 46, "name": "Vectrex"},
UPS.VIRTUALBOY: {"id": 28, "name": "Virtual Boy"},

View File

@@ -680,6 +680,63 @@ class TestRAHasherPspNativeHashing:
mock_subprocess.assert_called_once()
class TestRAHasherSuperGrafxPlatformMapping:
"""RetroAchievements has no dedicated SuperGrafx console; its games live
under the shared PC Engine/TurboGrafx-16 console (ID 8), same as tg16. The
supergrafx slug must be present in the slug->RA-id table and treated as a
buffer-hashable platform, since HuCard images (.sgx/.pce) are hashed
in-buffer rather than as CD/ISO discs (GitHub issue #3651)."""
@pytest.fixture
def service(self):
return RAHasherService()
def test_supergrafx_slug_maps_to_console_8(self):
assert PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID[UPS.SUPERGRAFX] == 8
def test_supergrafx_shares_console_with_tg16(self):
# RA groups the SuperGrafx with the PC Engine/TurboGrafx-16, so it must
# reuse the tg16 console ID (8) rather than being left unmapped.
assert (
PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID[UPS.SUPERGRAFX]
== PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID[UPS.TG16]
)
def test_supergrafx_is_buffer_hashable(self):
# HuCard images are buffer-hashable, so SuperGrafx must not be treated
# as disc-based (which would skip RAHasher for archived ROMs).
assert UPS.SUPERGRAFX not in RA_BUFFER_HASH_UNSUPPORTED
@pytest.mark.asyncio
async def test_calculate_hash_runs_rahasher_for_supergrafx(
self, service: RAHasherService
):
"""A SuperGrafx ROM must actually reach RAHasher (issue #3651)."""
supergrafx_id = PLATFORM_SLUG_TO_RETROACHIEVEMENTS_ID[UPS.SUPERGRAFX]
mock_proc = AsyncMock()
mock_proc.wait.return_value = 0
mock_proc.stdout.read.return_value = b"a1b2c3d4e5f6789012345678901234ab\n"
mock_proc.stderr = None
with patch(
"asyncio.create_subprocess_exec", return_value=mock_proc
) as mock_subprocess:
result = await service.calculate_hash(
{"ra_id": supergrafx_id, "slug": "supergrafx"},
"/roms/supergrafx/game.sgx",
)
assert result == "a1b2c3d4e5f6789012345678901234ab"
mock_subprocess.assert_called_once_with(
"RAHasher",
str(supergrafx_id),
"/roms/supergrafx/game.sgx",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
class TestRAHasherError:
"""Test the RAHasherError exception."""

View File

@@ -0,0 +1,54 @@
"""Tests for the RetroAchievements metadata handler platform mapping."""
import pytest
from handler.metadata.base_handler import UniversalPlatformSlug as UPS
from handler.metadata.ra_handler import (
RA_PLATFORM_LIST,
RAHandler,
)
# RetroAchievements groups the PC Engine, TurboGrafx-16 and SuperGrafx under a
# single console (console ID 8). RomM already maps tg16 to that console; the
# supergrafx slug must resolve to the same one so its ROMs get an RA hash and
# can match. See GitHub issue #3651.
RA_PC_ENGINE_CONSOLE_ID = 8
@pytest.fixture
def handler() -> RAHandler:
return RAHandler()
# ---------------------------------------------------------------------------
# Platform resolution
# ---------------------------------------------------------------------------
def test_get_platform_supergrafx_maps_to_console_8(handler: RAHandler):
"""supergrafx resolves to RA's PC Engine/TurboGrafx-16 console (ID 8), so
its ROMs get an RA hash and can match (issue #3651)."""
platform = handler.get_platform("supergrafx")
assert platform["ra_id"] == RA_PC_ENGINE_CONSOLE_ID
assert platform["slug"] == "supergrafx"
def test_supergrafx_shares_console_with_tg16(handler: RAHandler):
"""RA has no separate SuperGrafx console; supergrafx must reuse the same
console ID as tg16 rather than being left unmapped (issue #3651)."""
assert (
handler.get_platform("supergrafx")["ra_id"]
== handler.get_platform("tg16")["ra_id"]
)
def test_get_platform_unsupported_returns_none(handler: RAHandler):
platform = handler.get_platform("not-a-real-platform")
assert platform["ra_id"] is None
assert platform["slug"] == "not-a-real-platform"
def test_platform_list_uses_ups_keys():
"""Every entry in RA_PLATFORM_LIST should be a UniversalPlatformSlug."""
for key in RA_PLATFORM_LIST.keys():
assert isinstance(key, UPS)