Files
romm/backend/tests/handler/scan_stubs.py
Georges-Antoine Assi a7ecfd96a9 feat!: make filesystem.structure the single library layout
`filesystem.structure` now spells out the whole layout rather than only the part
below a platform folder. A template is relative to the library root, `{platform}`
marks the platform folder, and `{game}` marks where a game begins.

Merge `{gameFile}` and `{gameDir}` into one `{game}` terminal. The information a
terminal carried was the depth, not the kind: at a declared level a file is a
game of its own and a folder is one multi-file game, which a stat answers. That
drops the two-template idiom for a level holding both, and `_discover_default_roms`
with it, since the default scan is now just `roms/{platform}/{game}`.

Retire the auto-detected `{platform}/roms` layout, along with
`filesystem.roms_folder` and `filesystem.firmware_folder`, which named one path
segment each that a template now contains. Both are refused at startup with the
template that reproduces the layout, so an instance that relied on either says so
instead of scanning an empty library and marking every rom missing. Firmware gets
its own `structure.firmware` key rather than following the rom layout implicitly.

`get_roms_fs_structure` keeps meaning the folder a platform's games start in, so
the `.physical` sentinel paths already in the database still resolve. Per-platform
overrides have to agree with `default` on where the platform folder sits;
relocating one platform needs platform discovery and the watcher to union several
roots, which is left out.

The setup wizard reports `library_ready` plus the configured template instead of
a `struct_a`/`struct_b` discriminator, so the banner shows the layout in force
rather than guessing it client-side.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 08:39:21 -04:00

62 lines
1.9 KiB
Python

"""Scaffolding shared by the tests that drive `scan_rom` end to end."""
from typing import Any
from handler.database import db_platform_handler, db_rom_handler
from handler.scan_handler import ScanType, scan_rom
from models.platform import Platform
from models.rom import Rom
from utils.context import initialize_context
def add_n64_platform(**overrides: Any) -> Platform:
"""Persist the N64 platform the scan tests match against."""
return db_platform_handler.add_platform(
Platform(id=1, slug="n64", fs_slug="n64", name="Nintendo 64", **overrides)
)
def add_rom(platform: Platform, fs_name: str, title: str, **overrides: Any) -> Rom:
"""Persist a single-file ROM whose filename tags are already split out."""
stem, _, extension = fs_name.rpartition(".")
attrs: dict[str, Any] = {
"platform_id": platform.id,
"fs_name": fs_name,
"fs_name_no_tags": title,
"fs_name_no_ext": stem,
"fs_extension": extension,
"fs_path": platform.fs_slug,
"name": title,
"fs_size_bytes": 1024,
"tags": [],
}
return db_rom_handler.add_rom(Rom(**{**attrs, **overrides}))
async def run_scan(
platform: Platform,
rom: Rom,
*,
scan_type: ScanType,
metadata_sources: list[str],
) -> Rom:
"""Scan `rom` with no files on disk, so only the name-based lookups run."""
async with initialize_context():
return await scan_rom(
platform=platform,
scan_type=scan_type,
rom=rom,
fs_rom={
"fs_name": rom.fs_name,
"fs_path": rom.fs_path,
"flat": True,
"files": [],
"crc_hash": "",
"md5_hash": "",
"sha1_hash": "",
"ra_hash": "",
},
metadata_sources=metadata_sources,
newly_added=False,
)