diff --git a/backend/config/config_manager.py b/backend/config/config_manager.py index 5fd879771..afd15f6a9 100644 --- a/backend/config/config_manager.py +++ b/backend/config/config_manager.py @@ -419,13 +419,14 @@ class Config: """The custom library structure(s) for a platform, or ``None``. Opt-in per platform via `filesystem.structure` in config.yml (a map of - ``fs_slug -> template`` or ``fs_slug -> [template, ...]``). When unset, + ``fs_slug -> template`` or ``fs_slug -> [template, ...]``, keyed + case-insensitively like `system.platforms`). When unset, the platform uses RomM's default discovery (top-level files and folders). Returns the parsed structures whose discovery is unioned; templates are validated at load time, so parsing here is expected to succeed. """ - value = getattr(self, "STRUCTURE_TEMPLATES", {}).get(fs_slug) + value = getattr(self, "STRUCTURE_TEMPLATES", {}).get(fs_slug.lower()) if not value: return None return parse_platform_structures(value) @@ -1019,6 +1020,12 @@ class ConfigManager: "Invalid config.yml: filesystem.structure must be a dictionary" ) sys.exit(3) + # Folder names are lowercased so lookups ignore case, matching + # `system.platforms`. + self.config.STRUCTURE_TEMPLATES = { + str(fs_slug).lower(): value + for fs_slug, value in self.config.STRUCTURE_TEMPLATES.items() + } for fs_slug, value in self.config.STRUCTURE_TEMPLATES.items(): is_str = isinstance(value, str) is_str_list = isinstance(value, list) and all( diff --git a/backend/tests/config/test_config_loader.py b/backend/tests/config/test_config_loader.py index 20274716f..42a654bee 100644 --- a/backend/tests/config/test_config_loader.py +++ b/backend/tests/config/test_config_loader.py @@ -204,6 +204,19 @@ def test_parse_library_structure_names_a_near_miss_terminal(): parse_library_structure("{category}/{gameFolder}") +def test_structure_templates_are_keyed_case_insensitively(monkeypatch, tmp_path): + """`system.platforms` lowercases its folder names, so `filesystem.structure` + has to as well or the same key works in one block and not the other.""" + config_file = tmp_path / "config.yml" + config_file.write_text( + "filesystem:\n structure:\n 'Atari - 2600': '{gameFile}'\n" + ) + config = ConfigManager(str(config_file)).get_config() + + assert config.platform_structure("Atari - 2600") is not None + assert config.platform_structure("atari - 2600") is not None + + def test_parse_platform_structures_string_and_list(): # A bare string yields a single structure. single = parse_platform_structures("{gameFile}")