Skip to content

Commit 26b9ca8

Browse files
authored
Merge pull request #3516 from rommapp/copilot/bug-fix-assign-system-folder
Fix config.yml serialization breaking folder-to-platform mappings
2 parents 783c3d8 + 2246ea3 commit 26b9ca8

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

backend/config/config_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ def _update_config_file(self) -> None:
782782
"gamelist": {
783783
"export": self.config.GAMELIST_AUTO_EXPORT_ON_SCAN,
784784
"media": {
785-
"thumbnail": self.config.GAMELIST_MEDIA_THUMBNAIL,
786-
"image": self.config.GAMELIST_MEDIA_IMAGE,
785+
"thumbnail": str(self.config.GAMELIST_MEDIA_THUMBNAIL),
786+
"image": str(self.config.GAMELIST_MEDIA_IMAGE),
787787
},
788788
},
789789
"pegasus": {

backend/tests/config/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from config.config_manager import ConfigManager
4+
from config.config_manager import config_manager as cm
5+
6+
7+
@pytest.fixture(autouse=True)
8+
def restore_config_manager_singleton():
9+
"""``ConfigManager`` is a process-wide singleton (``__new__`` returns the
10+
shared instance). Tests in this module point it at temporary config files
11+
and mutate it (e.g. ``add_platform_binding``), which would otherwise leak
12+
that state into other test modules through the global ``config_manager``.
13+
14+
Re-initialize the singleton from its original config file after each test
15+
so the global instance returns to its default state.
16+
"""
17+
original_config_file = cm.config_file
18+
yield
19+
ConfigManager(original_config_file)

backend/tests/config/test_config_loader.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,24 @@ def test_malformed_yaml_falls_back_to_defaults():
160160
assert loader.config.ROMS_FOLDER_NAME == "roms"
161161
assert loader.config.FIRMWARE_FOLDER_NAME == "bios"
162162
assert loader.config.SCAN_MEDIA == ["box2d", "screenshot", "manual"]
163+
164+
165+
def test_config_updates_serialize_gamelist_media_as_plain_strings(tmp_path):
166+
config_file = tmp_path / "config.yml"
167+
config_file.write_text(
168+
"scan:\n"
169+
" gamelist:\n"
170+
" media:\n"
171+
" thumbnail: box2d\n"
172+
" image: screenshot\n"
173+
)
174+
loader = ConfigManager(str(config_file))
175+
loader.add_platform_binding("atarist", "atari-st")
176+
177+
config_text = config_file.read_text()
178+
assert "!!python/object" not in config_text
179+
assert "thumbnail: box2d" in config_text
180+
assert "image: screenshot" in config_text
181+
182+
reloaded = ConfigManager(str(config_file))
183+
assert reloaded.config.PLATFORMS_BINDING == {"atarist": "atari-st"}

0 commit comments

Comments
 (0)