mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
Merge pull request #3693 from rommapp/posthog-code/fix-platform-variant-rename
fix(platforms): stop platform variants from renaming the parent platform
This commit is contained in:
25
backend/tests/utils/test_platforms.py
Normal file
25
backend/tests/utils/test_platforms.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from handler.database import db_platform_handler
|
||||
from models.platform import Platform
|
||||
from utils.platforms import get_supported_platforms
|
||||
|
||||
|
||||
def test_supported_platform_not_shadowed_by_variant():
|
||||
"""A variant/alias folder bound to a parent slug must not shadow the parent.
|
||||
|
||||
Regression for the bug where adding an "fbneo" folder as a variant of
|
||||
"arcade" renamed the Arcade platform to "FBneo" in the platform picker.
|
||||
"""
|
||||
# Canonical Arcade platform (folder name matches the slug).
|
||||
db_platform_handler.add_platform(
|
||||
Platform(name="Arcade", slug="arcade", fs_slug="arcade")
|
||||
)
|
||||
# Variant folder resolved to the same slug during scan.
|
||||
db_platform_handler.add_platform(
|
||||
Platform(name="FBneo", slug="arcade", fs_slug="fbneo")
|
||||
)
|
||||
|
||||
supported = get_supported_platforms()
|
||||
arcade = next(p for p in supported if p.slug == "arcade")
|
||||
|
||||
assert arcade.name == "Arcade"
|
||||
assert arcade.fs_slug == "arcade"
|
||||
@@ -26,7 +26,16 @@ def get_supported_platforms() -> list[PlatformSchema]:
|
||||
Flashpoint, and HowLongToBeat.
|
||||
"""
|
||||
db_platforms = db_platform_handler.get_platforms()
|
||||
db_platforms_map = {p.slug: p for p in db_platforms}
|
||||
|
||||
# Multiple folders can resolve to the same slug (a folder alias or a
|
||||
# platform variant bound to a parent platform). When that happens, prefer
|
||||
# the canonical platform (the one whose fs_slug matches its slug) so a
|
||||
# variant folder doesn't shadow the parent and rename it in the picker.
|
||||
db_platforms_map: dict[str, Platform] = {}
|
||||
for p in db_platforms:
|
||||
existing = db_platforms_map.get(p.slug)
|
||||
if existing is None or p.fs_slug == p.slug:
|
||||
db_platforms_map[p.slug] = p
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
supported_platforms = []
|
||||
|
||||
Reference in New Issue
Block a user