mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
feat(saves): convert DS, Sega cartridge and Game Boy Advance saves through sigil (#5643)
* feat(saves): convert Nintendo DS saves through sigil Sigil now converts a DS save between melonDS's raw file and DeSmuME's .dsv, so a download with core= gets the file that emulator reads instead of the stored one as is. DS moves from the native list to the platforms sigil restores; like Saturn and Sega CD it carries no title id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): accept a single-file neutral unit as sigil names it, for DS and Game Boy Sigil names a cart's single-file unit after the content, `{stem}.srm`, and sets the unit format; the neutral check only took `save.raw` for DS and `save.sram` for Game Boy, so a client pushing sigil's own unit got a 422. A SINGLE unit's one file may now carry sigil's name on those platforms; multi-file units and every other platform keep their names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name DS among the cartridges that take no companions Sigil refuses companions on every cartridge platform, DS included now that it converts DS saves, so the refusal says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(saves): convert Mega Drive, 32X, Master System and Game Gear saves through sigil genesis_plus_gx and picodrive keep these carts' save RAM at the same offsets but fill and size it differently. With sigil converting between them, the four platforms move from NATIVE_SAVE_PLATFORM_SLUGS to SIGIL_RESTORE_PLATFORM_SLUGS (sigil slugs genesis, 32x, sms, gamegear), so a download with core= gets the file that core keeps. The companion refusal message names the new cartridges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): accept the Sega cartridges' single-file neutral unit as sigil names it Sigil names a Mega Drive, 32X, Master System or Game Gear unit after the content, `{stem}.srm`. A SINGLE unit's one file may now carry that name, as DS and Game Boy's may; RomM's `save.sram` still passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(saves): convert Game Boy Advance saves between emulators with sigil GBA moves from the native-save platforms to the ones sigil reads at scan time and restores for a core. The stored file doesn't load everywhere: VBA Next keeps an EEPROM save at 128 KiB into a 136 KiB file, gpSP pads every save to 128 KiB, and standalone mGBA appends the cart clock. The scan stores the cart's save chip and clock in sigil_features, which sigil uses to size a padded save. The tests that used GBA as their native example now use SNES. Needs a sigil pin with GBA collect and restore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): accept a single-file GBA neutral unit as sigil names it Sigil names a GBA cart's unit as it does a Game Boy's: the save alone as `{stem}.srm`, or a clock cart's zip of `save.sram` and `clock.rtc`. GBA now takes Game Boy's form, so the single file may carry sigil's name. The clock-only form had no other platform left and goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): pin sigil at the DS merge, and take only a plain file name as its single unit Both SIGIL_VERSION pins move to baa96b8 (rommapp/argosy-sigil#22), the first sigil commit with DS. _SIGIL_SINGLE is [^/]+\.srm, so a single unit named with a folder in it is refused; test_neutral.py checks it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at the GBA merge rommapp/argosy-sigil#24 is merged as 4980f69. Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from baa96b8 to that commit on sigil's main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at the Mega Drive merge rommapp/argosy-sigil#23 is merged as be0809d. Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from baa96b8 to that commit on sigil's main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at 650b265 Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from be0809d to 650b265, sigil's main. It holds rommapp/argosy-sigil#23 (be0809d) and is the commit rommapp/romm#5758 pins, so the two pull requests set the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at 650b265 Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from baa96b8 to 650b265, sigil's main. It holds rommapp/argosy-sigil#22 (baa96b8) and is the commit rommapp/romm#5758 pins, so the two pull requests set the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at 650b265 Both SIGIL_VERSION pins (Dockerfile, docker/Dockerfile) move from 4980f69 to 650b265, sigil's main. It holds rommapp/argosy-sigil#24 (4980f69) and is the commit rommapp/romm#5758 pins, so the two pull requests set the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name no systems in the companion refusal The message listed the cartridges that take no companions, so each platform added to sigil's restores edited it, and the open save PRs (#5643 to #5647) each edited it differently. It now says what holds for every platform: companions go only on memory cards and volumes. All five carry the same line, so they merge in any order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name no systems in the companion refusal The message listed the cartridges that take no companions, so each platform added to sigil's restores edited it, and the open save PRs (#5643 to #5647) each edited it differently. It now says what holds for every platform: companions go only on memory cards and volumes. All five carry the same line, so they merge in any order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(saves): name no systems in the companion refusal The message listed the cartridges that take no companions, so each platform added to sigil's restores edited it, and the open save PRs (#5643 to #5647) each edited it differently. It now says what holds for every platform: companions go only on memory cards and volumes. All five carry the same line, so they merge in any order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(saves): restore Sega cart saves through RomM's platform map and binding From review: the Mega Drive, 32X, Master System and Game Gear tests mock the binding, so a slug sigil doesn't take would still pass. A ROM on each RomM platform now goes through stored_game and the real binding, and the restored file is checked in the form sigil's genesis.md gives the core: genesis_plus_gx without trailing 0xFF, picodrive's 32 KiB for Master System and Game Gear. rom_game is the same helper in #5643 to #5647. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(saves): restore a DS save through RomM's platform map and the binding From review: the DS tests mock the binding, so a slug sigil doesn't take for DS would still pass. A ROM on RomM's nds platform now goes through stored_game and the real binding, and the restored file is checked in the form sigil's nds.md gives each core: DeSmuME's .dsv ends in its 122-byte footer, melonDS's .sav is the save. rom_game is the same helper in #5643 to #5647. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(saves): restore a GBA save through RomM's platform map and the binding From review: the GBA tests mock the binding, so a slug sigil doesn't take for GBA would still pass. A ROM on RomM's gba platform now goes through stored_game and the real binding, and the restored file is checked at the size sigil's gba.md gives each core: gpSP 128 KiB padded with 0xFF, VBA Next 136 KiB, mGBA the chip. rom_game is the same helper in #5643 to #5647. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at ef9b51e Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758 pins now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at ef9b51e Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758 pins now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(deps): pin sigil at ef9b51e Both SIGIL_VERSION pins move from 650b265 to ef9b51e, sigil's main since rommapp/argosy-sigil#30 merged, the commit rommapp/romm#5758 pins now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: MMagTech <mmagtech@Mac.home> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
This commit is contained in:
@@ -36,13 +36,14 @@ SIGIL_EXTRACT_PLATFORM_SLUGS: Final[dict[str, str]] = {
|
||||
UPS.N64: "n64",
|
||||
UPS.GB: "gb",
|
||||
UPS.GBC: "gbc",
|
||||
UPS.GBA: "gba",
|
||||
}
|
||||
|
||||
# Sigil reads these titles but can't collect or restore their saves.
|
||||
_EXTRACT_ONLY_PLATFORM_SLUGS: Final = frozenset({UPS.XBOX, UPS.XBOX360})
|
||||
|
||||
# The platforms sigil collects and restores saves for. Saturn and Sega CD saves
|
||||
# carry no title id, so sigil restores them without one.
|
||||
# The platforms sigil collects and restores saves for. Saturn, Sega CD, DS and
|
||||
# the Sega cartridge saves carry no title id, so sigil restores them without one.
|
||||
SIGIL_RESTORE_PLATFORM_SLUGS: Final[dict[str, str]] = {
|
||||
**{
|
||||
slug: sigil_slug
|
||||
@@ -51,6 +52,11 @@ SIGIL_RESTORE_PLATFORM_SLUGS: Final[dict[str, str]] = {
|
||||
},
|
||||
UPS.SATURN: "saturn",
|
||||
UPS.SEGACD: "segacd",
|
||||
UPS.NDS: "nds",
|
||||
UPS.GENESIS: "genesis",
|
||||
UPS.SEGA32: "32x",
|
||||
UPS.SMS: "sms",
|
||||
UPS.GAMEGEAR: "gamegear",
|
||||
}
|
||||
|
||||
# Cartridge platforms with no sigil converter, whose stored save is already the
|
||||
@@ -61,12 +67,6 @@ NATIVE_SAVE_PLATFORM_SLUGS: Final = frozenset(
|
||||
UPS.FAMICOM,
|
||||
UPS.SNES,
|
||||
UPS.SFAM,
|
||||
UPS.GENESIS,
|
||||
UPS.SMS,
|
||||
UPS.GAMEGEAR,
|
||||
UPS.SEGA32,
|
||||
UPS.GBA,
|
||||
UPS.NDS,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -146,8 +146,8 @@ def _refusal(exc: Exception, companions: Sequence[RestoreCompanion]) -> SigilRef
|
||||
message = str(exc)
|
||||
if code is RefusalCode.INVALID_ARG and companions:
|
||||
message = (
|
||||
"companions only go on cards and volumes: layouts with profiles and "
|
||||
"cartridges (N64, GB, GBC) take none"
|
||||
"companions only go on memory cards and volumes, and this emulator "
|
||||
"keeps its saves on neither"
|
||||
)
|
||||
profiles = tuple(
|
||||
RestoreProfile(id=p.id, name=p.name) for p in getattr(exc, "profiles", ())
|
||||
|
||||
@@ -18,19 +18,33 @@ class _Form:
|
||||
allowed: re.Pattern[str]
|
||||
# At least one present member must match this; `allowed` when unset.
|
||||
required: re.Pattern[str] | None = None
|
||||
# Another name a SINGLE unit's one file may carry: sigil names a cart's
|
||||
# single-file unit after the content, `{stem}.srm`.
|
||||
single: re.Pattern[str] | None = None
|
||||
|
||||
@property
|
||||
def primary(self) -> re.Pattern[str]:
|
||||
return self.required or self.allowed
|
||||
|
||||
def single_name(self, name: str, shape: SaveShape) -> bool:
|
||||
return bool(
|
||||
shape == SaveShape.SINGLE and self.single and self.single.fullmatch(name)
|
||||
)
|
||||
|
||||
|
||||
def _names(*names: str) -> re.Pattern[str]:
|
||||
return re.compile("|".join(re.escape(name) for name in names))
|
||||
|
||||
|
||||
_SIGIL_SINGLE = re.compile(r"[^/]+\.srm")
|
||||
|
||||
_BATTERY = _Form(_names("save.sram"))
|
||||
_CLOCKED = _Form(_names("save.sram", "clock.rtc"), _names("save.sram"))
|
||||
_SEGA_CART = _Form(_names("save.sram"), single=_SIGIL_SINGLE)
|
||||
_GAME_BOY = _Form(
|
||||
_names("save.sram", "clock.rtc"), _names("save.sram"), single=_SIGIL_SINGLE
|
||||
)
|
||||
_RAW = _Form(_names("save.raw"))
|
||||
_DS = _Form(_names("save.raw"), single=_SIGIL_SINGLE)
|
||||
_BACKUP_RAM = _Form(_names("backup.ram", "cart.ram"))
|
||||
|
||||
NEUTRAL_FORMS: Final[dict[str, _Form]] = {
|
||||
@@ -38,15 +52,15 @@ NEUTRAL_FORMS: Final[dict[str, _Form]] = {
|
||||
UPS.FAMICOM: _BATTERY,
|
||||
UPS.SNES: _BATTERY,
|
||||
UPS.SFAM: _BATTERY,
|
||||
UPS.GENESIS: _BATTERY,
|
||||
UPS.SMS: _BATTERY,
|
||||
UPS.GAMEGEAR: _BATTERY,
|
||||
UPS.SEGA32: _BATTERY,
|
||||
UPS.GB: _CLOCKED,
|
||||
UPS.GBC: _CLOCKED,
|
||||
UPS.GBA: _CLOCKED,
|
||||
UPS.GENESIS: _SEGA_CART,
|
||||
UPS.SMS: _SEGA_CART,
|
||||
UPS.GAMEGEAR: _SEGA_CART,
|
||||
UPS.SEGA32: _SEGA_CART,
|
||||
UPS.GB: _GAME_BOY,
|
||||
UPS.GBC: _GAME_BOY,
|
||||
UPS.GBA: _GAME_BOY,
|
||||
UPS.N64: _Form(_names("eeprom", "pak1", "pak2", "pak3", "pak4", "sram", "flash")),
|
||||
UPS.NDS: _RAW,
|
||||
UPS.NDS: _DS,
|
||||
UPS.JAGUAR: _RAW,
|
||||
UPS.LYNX: _RAW,
|
||||
UPS.NEO_GEO_POCKET: _RAW,
|
||||
@@ -82,12 +96,19 @@ def check_neutral_unit(
|
||||
form = NEUTRAL_FORMS.get(platform_slug)
|
||||
if form is None:
|
||||
return
|
||||
strays = sorted(name for name in members if not form.allowed.fullmatch(name))
|
||||
strays = sorted(
|
||||
name
|
||||
for name in members
|
||||
if not form.allowed.fullmatch(name) and not form.single_name(name, shape)
|
||||
)
|
||||
if strays:
|
||||
raise NeutralUnitRejected(
|
||||
f"{', '.join(strays)} isn't a neutral member name for {platform_slug}"
|
||||
)
|
||||
if not any(form.primary.fullmatch(name) for name in members):
|
||||
if not any(
|
||||
form.primary.fullmatch(name) or form.single_name(name, shape)
|
||||
for name in members
|
||||
):
|
||||
raise NeutralUnitRejected(f"the unit holds no save for {platform_slug}")
|
||||
if shape == SaveShape.SINGLE and len(members) != 1:
|
||||
raise NeutralUnitRejected("a SINGLE unit holds exactly one member")
|
||||
|
||||
@@ -147,6 +147,20 @@ class TestSigilService:
|
||||
assert (result.title_id, result.features) == ("", 1)
|
||||
assert extract.call_args.kwargs["platform"] == sigil_slug
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reads_a_gba_carts_save_chip_and_clock(
|
||||
self, service: SigilService, monkeypatch
|
||||
):
|
||||
# sigil's FEATURE_RTC | FEATURE_GBA_FLASH1M, as it reads Pokemon Emerald
|
||||
extract = Mock(return_value=make_result(title_id="", save_id="", features=17))
|
||||
monkeypatch.setattr(sigil_adapter, "sigil", make_fake_sigil(extract))
|
||||
|
||||
result = await service.extract_title_id(UPS.GBA, "/roms/gba/game.gba")
|
||||
|
||||
assert result is not None
|
||||
assert (result.title_id, result.features) == ("", 17)
|
||||
assert extract.call_args.kwargs["platform"] == "gba"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_successful_extraction_maps_fields(
|
||||
self, service: SigilService, monkeypatch
|
||||
@@ -520,7 +534,17 @@ class TestStoredGame:
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("slug", "sigil_slug"),
|
||||
[(UPS.GBC, "gbc"), (UPS.SATURN, "saturn"), (UPS.SEGACD, "segacd")],
|
||||
[
|
||||
(UPS.GBC, "gbc"),
|
||||
(UPS.GBA, "gba"),
|
||||
(UPS.SATURN, "saturn"),
|
||||
(UPS.SEGACD, "segacd"),
|
||||
(UPS.NDS, "nds"),
|
||||
(UPS.GENESIS, "genesis"),
|
||||
(UPS.SEGA32, "32x"),
|
||||
(UPS.SMS, "sms"),
|
||||
(UPS.GAMEGEAR, "gamegear"),
|
||||
],
|
||||
)
|
||||
def test_a_platform_without_title_ids_still_restores(
|
||||
self, fake_sigil, slug: str, sigil_slug: str
|
||||
|
||||
@@ -17,7 +17,7 @@ from tests.sigil_cards import (
|
||||
saturn_volume,
|
||||
)
|
||||
|
||||
from adapters.services.sigil import SigilGame
|
||||
from adapters.services.sigil import SigilGame, SigilService
|
||||
from adapters.services.sigil_restore import (
|
||||
ContainerMismatch,
|
||||
RefusalCode,
|
||||
@@ -29,6 +29,9 @@ from adapters.services.sigil_restore import (
|
||||
restore_layouts,
|
||||
restore_per_game,
|
||||
)
|
||||
from models.platform import Platform
|
||||
from models.rom import Rom
|
||||
from utils.platform_slugs import UniversalPlatformSlug as UPS
|
||||
|
||||
SEGACD_BLOCK = 64
|
||||
SEGACD_VOLUME = 0x2000
|
||||
@@ -212,6 +215,25 @@ def target(core: str, content_path: str, **options: str) -> RestoreTarget:
|
||||
)
|
||||
|
||||
|
||||
def rom_game(
|
||||
binding: ModuleType, slug: str, title_id: str = "", save_id: str = ""
|
||||
) -> SigilGame:
|
||||
"""A ROM on RomM's `slug` read back through its platform map, so a slug sigil
|
||||
doesn't take for that platform fails the test restoring it."""
|
||||
rom = Rom(
|
||||
id=1,
|
||||
fs_name="Game",
|
||||
fs_path=f"{slug}/roms",
|
||||
title_id=title_id or None,
|
||||
save_target=save_id or None,
|
||||
platform=Platform(name=slug, slug=slug, fs_slug=slug),
|
||||
)
|
||||
game = SigilService.stored_game(rom, [])
|
||||
assert game is not None
|
||||
assert isinstance(game.result, binding.SigilResult)
|
||||
return game
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_per_game_ps1_card_is_built_from_nothing(binding, tmp_path: Path):
|
||||
game = cross(binding)
|
||||
@@ -234,6 +256,22 @@ async def test_a_per_game_ps1_card_is_built_from_nothing(binding, tmp_path: Path
|
||||
assert saves == {"BASLUSP01041CROSS": bytes([0x11]) * PS1_BLOCK}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_ds_save_restores_in_each_cores_form(binding):
|
||||
"""DeSmuME keeps the save then a 122-byte footer, melonDS the save alone."""
|
||||
game = rom_game(binding, UPS.NDS)
|
||||
save = bytes(range(256)) * 32
|
||||
|
||||
desmume = await restore_per_game(save, game, target("desmume", "Game.nds"))
|
||||
melonds = await restore_per_game(save, game, target("melonds", "Game.nds"))
|
||||
|
||||
assert list(desmume) == ["Game.dsv"]
|
||||
assert len(desmume["Game.dsv"]) == len(save) + 122
|
||||
assert desmume["Game.dsv"][: len(save)] == save
|
||||
assert desmume["Game.dsv"][-16:] == b"|-DESMUME SAVE-|"
|
||||
assert melonds == {"Game.sav": save}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_shared_card_target_names_the_container(binding, tmp_path: Path):
|
||||
game = cross(binding)
|
||||
@@ -256,6 +294,23 @@ async def test_a_shared_card_target_names_the_container(binding, tmp_path: Path)
|
||||
assert excinfo.value.container_path == "pcsx-card1.mcd"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_gba_save_restores_at_each_cores_size(binding):
|
||||
"""gpSP keeps 128 KiB and VBA Next 136 KiB for every chip; mGBA keeps the chip."""
|
||||
game = rom_game(binding, UPS.GBA)
|
||||
sram = bytes(range(256)) * 128
|
||||
|
||||
gpsp = await restore_per_game(sram, game, target("gpsp", "Game.gba"))
|
||||
vba_next = await restore_per_game(sram, game, target("vba_next", "Game.gba"))
|
||||
mgba = await restore_per_game(sram, game, target("mgba", "Game.gba"))
|
||||
|
||||
assert gpsp == {"Game.srm": sram + b"\xff" * (128 * 1024 - len(sram))}
|
||||
assert list(vba_next) == ["Game.srm"]
|
||||
assert len(vba_next["Game.srm"]) == 136 * 1024
|
||||
assert vba_next["Game.srm"][: len(sram)] == sram
|
||||
assert mgba == {"Game.srm": sram}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_ps1_shared_card_merge_keeps_another_games_save(
|
||||
binding, tmp_path: Path
|
||||
@@ -317,6 +372,32 @@ async def test_a_segacd_volume_merge_replaces_only_the_games_save(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("slug", "core"),
|
||||
[
|
||||
(UPS.GENESIS, "genesis_plus_gx"),
|
||||
(UPS.SEGA32, "genesis_plus_gx"),
|
||||
(UPS.SMS, "picodrive"),
|
||||
(UPS.GAMEGEAR, "picodrive"),
|
||||
],
|
||||
)
|
||||
async def test_a_sega_cart_save_restores_in_the_cores_form(
|
||||
binding, slug: str, core: str
|
||||
):
|
||||
"""genesis_plus_gx saves up to the last byte that isn't 0xFF; picodrive keeps a
|
||||
Master System or Game Gear cart's 32 KiB, padded here with 0xFF."""
|
||||
game = rom_game(binding, slug)
|
||||
ram = bytes(i % 255 for i in range(8 * 1024))
|
||||
|
||||
restored = await restore_per_game(
|
||||
ram + b"\xff" * (8 * 1024), game, target(core, "Game.bin")
|
||||
)
|
||||
|
||||
padding = b"\xff" * (32 * 1024 - len(ram)) if core == "picodrive" else b""
|
||||
assert restored == {"Game.srm": ram + padding}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_segacd_volume_of_another_region_is_refused(binding, tmp_path: Path):
|
||||
game = lunar(binding)
|
||||
@@ -490,9 +571,7 @@ async def test_a_gb_clock_is_written_in_the_cores_format(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_companions_on_a_cartridge_are_refused_naming_both_cases(
|
||||
binding, tmp_path: Path
|
||||
):
|
||||
async def test_companions_on_a_cartridge_are_refused(binding, tmp_path: Path):
|
||||
game = gb_clock_game(binding)
|
||||
unit = collected(
|
||||
binding,
|
||||
@@ -512,8 +591,7 @@ async def test_companions_on_a_cartridge_are_refused_naming_both_cases(
|
||||
)
|
||||
|
||||
assert excinfo.value.code is RefusalCode.INVALID_ARG
|
||||
assert "profiles" in str(excinfo.value)
|
||||
assert "cartridges" in str(excinfo.value)
|
||||
assert "memory cards and volumes" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_a_zip_unit_lists_each_volume(binding, tmp_path: Path):
|
||||
|
||||
@@ -55,11 +55,10 @@ def _stored(save: Save, data: bytes = UNIT) -> Save:
|
||||
return save
|
||||
|
||||
|
||||
def _neutral_gba_unit() -> bytes:
|
||||
def _neutral_snes_unit() -> bytes:
|
||||
buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(buffer, "w") as zf:
|
||||
zf.writestr("save.sram", b"battery")
|
||||
zf.writestr("clock.rtc", b"clock")
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
@@ -285,7 +284,7 @@ class TestGetWithCore:
|
||||
|
||||
assert _awaited_args(restore)[2].content_path == "Chrono Cross (USA).bin"
|
||||
|
||||
@pytest.mark.parametrize("slug", ["nes", "snes", "genesis", "gba", "nds"])
|
||||
@pytest.mark.parametrize("slug", ["nes", "snes"])
|
||||
def test_a_platform_without_a_converter_serves_the_stored_file(
|
||||
self, client, headers, admin_user: User, restore, slug: str
|
||||
):
|
||||
@@ -304,7 +303,7 @@ class TestGetWithCore:
|
||||
):
|
||||
save = _stored(
|
||||
make_save(
|
||||
_rom_on("gba", "Game", admin_user),
|
||||
_rom_on("snes", "Game", admin_user),
|
||||
admin_user,
|
||||
"save.sram",
|
||||
shape=SaveShape.SINGLE,
|
||||
@@ -312,7 +311,7 @@ class TestGetWithCore:
|
||||
)
|
||||
)
|
||||
|
||||
response = _get(client, save, headers, "core=mgba")
|
||||
response = _get(client, save, headers, "core=snes9x")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.content == UNIT
|
||||
@@ -324,19 +323,19 @@ class TestGetWithCore:
|
||||
):
|
||||
save = _stored(
|
||||
make_save(
|
||||
_rom_on("gba", "Game", admin_user),
|
||||
_rom_on("snes", "Game", admin_user),
|
||||
admin_user,
|
||||
"save.zip",
|
||||
shape=shape,
|
||||
format=SaveFormat.NEUTRAL,
|
||||
),
|
||||
_neutral_gba_unit(),
|
||||
_neutral_snes_unit(),
|
||||
)
|
||||
|
||||
response = _get(client, save, headers, "core=mgba")
|
||||
response = _get(client, save, headers, "core=snes9x")
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert "gba" in response.json()["detail"]
|
||||
assert "snes" in response.json()["detail"]
|
||||
restore.assert_not_awaited()
|
||||
|
||||
def test_a_wii_save_converts_for_dolphin(
|
||||
@@ -351,6 +350,58 @@ class TestGetWithCore:
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert _awaited_args(restore)[2].core == "dolphin"
|
||||
|
||||
def test_a_ds_save_converts_for_desmume(
|
||||
self, client, headers, admin_user: User, stored_game, restore
|
||||
):
|
||||
save = _stored(
|
||||
make_save(_rom_on("nds", "Game", admin_user), admin_user, "Game.sav")
|
||||
)
|
||||
|
||||
response = _get(client, save, headers, "core=desmume")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert _awaited_args(restore)[2].core == "desmume"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("slug", "core"),
|
||||
[
|
||||
("genesis", "picodrive"),
|
||||
("sega32", "picodrive"),
|
||||
("sms", "genesis_plus_gx"),
|
||||
("gamegear", "genesis_plus_gx"),
|
||||
],
|
||||
)
|
||||
def test_a_sega_cart_save_converts_for_the_core(
|
||||
self,
|
||||
client,
|
||||
headers,
|
||||
admin_user: User,
|
||||
stored_game,
|
||||
restore,
|
||||
slug: str,
|
||||
core: str,
|
||||
):
|
||||
save = _stored(
|
||||
make_save(_rom_on(slug, "Game", admin_user), admin_user, "Game.srm")
|
||||
)
|
||||
|
||||
response = _get(client, save, headers, f"core={core}")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert _awaited_args(restore)[2].core == core
|
||||
|
||||
def test_a_gba_save_converts_for_gpsp(
|
||||
self, client, headers, admin_user: User, stored_game, restore
|
||||
):
|
||||
save = _stored(
|
||||
make_save(_rom_on("gba", "Game", admin_user), admin_user, "Game.srm")
|
||||
)
|
||||
|
||||
response = _get(client, save, headers, "core=gpsp")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert _awaited_args(restore)[2].core == "gpsp"
|
||||
|
||||
@pytest.mark.parametrize("slug", ["neogeoaes", "turbografx-cd", "unknown"])
|
||||
def test_a_platform_sigil_does_not_sync_is_refused(
|
||||
self, client, headers, admin_user: User, restore, slug: str
|
||||
@@ -772,13 +823,13 @@ class TestPostContainer:
|
||||
):
|
||||
save = _stored(
|
||||
make_save(
|
||||
_rom_on("gba", "Game", admin_user),
|
||||
_rom_on("snes", "Game", admin_user),
|
||||
admin_user,
|
||||
"save.zip",
|
||||
shape=SaveShape.MULTI,
|
||||
format=SaveFormat.NEUTRAL,
|
||||
),
|
||||
_neutral_gba_unit(),
|
||||
_neutral_snes_unit(),
|
||||
)
|
||||
|
||||
response = _post(client, save, headers)
|
||||
|
||||
@@ -356,6 +356,29 @@ def test_a_neutral_save_with_foreign_member_names_is_unprocessable(
|
||||
assert "Pokemon Red.srm" in response.json()["detail"]["save"]
|
||||
|
||||
|
||||
def test_a_neutral_single_unit_named_as_sigil_names_it_is_written(
|
||||
client: TestClient,
|
||||
headers: dict[str, str],
|
||||
game_file: RomFile,
|
||||
rom: Rom,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
from handler.snapshots import neutral
|
||||
|
||||
monkeypatch.setitem(
|
||||
neutral.NEUTRAL_FORMS, rom.platform_slug, neutral.NEUTRAL_FORMS["gb"]
|
||||
)
|
||||
|
||||
response = post(
|
||||
client,
|
||||
headers,
|
||||
manifest(game_file, label="default", save=save_entry()),
|
||||
{"save": ("Pokemon Red.srm", SRAM)},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED, response.text
|
||||
|
||||
|
||||
def test_an_archive_escaping_its_folder_is_unprocessable(
|
||||
client: TestClient, headers: dict[str, str], game_file: RomFile, rom: Rom
|
||||
):
|
||||
|
||||
@@ -8,13 +8,25 @@ from models.assets import SaveShape
|
||||
"platform,shape,members",
|
||||
[
|
||||
("gb", SaveShape.SINGLE, ["save.sram"]),
|
||||
("gb", SaveShape.SINGLE, ["Pokemon Red.srm"]),
|
||||
("gbc", SaveShape.SINGLE, ["Pokemon Crystal.srm"]),
|
||||
("gbc", SaveShape.MULTI, ["save.sram", "clock.rtc"]),
|
||||
("gba", SaveShape.SINGLE, ["Pokemon Emerald.srm"]),
|
||||
("gba", SaveShape.SINGLE, ["save.sram"]),
|
||||
("gba", SaveShape.MULTI, ["save.sram", "clock.rtc"]),
|
||||
("snes", SaveShape.SINGLE, ["save.sram"]),
|
||||
("n64", SaveShape.MULTI, ["eeprom", "pak1"]),
|
||||
("nds", SaveShape.SINGLE, ["save.raw"]),
|
||||
("nds", SaveShape.SINGLE, ["Mario Kart DS.srm"]),
|
||||
("saturn", SaveShape.MULTI, ["backup.ram", "cart.ram"]),
|
||||
("dc", SaveShape.MULTI, ["vmu_A1.bin", "vmu_B2.bin"]),
|
||||
("psx", SaveShape.SINGLE, ["anything.mcd"]),
|
||||
("genesis", SaveShape.SINGLE, ["Sonic The Hedgehog 3 (USA).srm"]),
|
||||
("genesis", SaveShape.SINGLE, ["save.sram"]),
|
||||
("sega32", SaveShape.SINGLE, ["36 Great Holes (Europe).srm"]),
|
||||
("sms", SaveShape.SINGLE, ["Phantasy Star (USA, Europe).srm"]),
|
||||
("gamegear", SaveShape.SINGLE, ["Defenders of Oasis (USA, Europe).srm"]),
|
||||
("gamegear", SaveShape.MULTI, ["save.sram"]),
|
||||
],
|
||||
)
|
||||
def test_a_platforms_neutral_names_pass(
|
||||
@@ -26,14 +38,26 @@ def test_a_platforms_neutral_names_pass(
|
||||
@pytest.mark.parametrize(
|
||||
"platform,shape,members",
|
||||
[
|
||||
("gb", SaveShape.SINGLE, ["Pokemon Red.srm"]),
|
||||
("gb", SaveShape.MULTI, ["Pokemon Red.srm", "clock.rtc"]),
|
||||
("nds", SaveShape.SINGLE, ["Mario Kart DS.dsv"]),
|
||||
("nds", SaveShape.MULTI, ["Mario Kart DS.srm"]),
|
||||
("nds", SaveShape.SINGLE, ["saves/Mario Kart DS.srm"]),
|
||||
("snes", SaveShape.SINGLE, ["Game.srm"]),
|
||||
("gba", SaveShape.MULTI, ["save.sram", "Pokemon.rtc"]),
|
||||
("gba", SaveShape.MULTI, ["Pokemon Emerald.srm", "clock.rtc"]),
|
||||
("gba", SaveShape.SINGLE, ["Pokemon Emerald.sav"]),
|
||||
("gba", SaveShape.SINGLE, ["clock.rtc"]),
|
||||
("gb", SaveShape.SINGLE, ["clock.rtc"]),
|
||||
("snes", SaveShape.MULTI, ["save.sram", "clock.rtc"]),
|
||||
("gb", SaveShape.SINGLE, ["save.sram", "clock.rtc"]),
|
||||
("dc", SaveShape.MULTI, ["vmu_E1.bin"]),
|
||||
("fds", SaveShape.SINGLE, ["save.sram"]),
|
||||
("arcade", SaveShape.SINGLE, ["nvram"]),
|
||||
("genesis", SaveShape.SINGLE, ["Sonic.sav"]),
|
||||
("genesis", SaveShape.MULTI, ["Sonic.srm"]),
|
||||
("gamegear", SaveShape.MULTI, ["save.sram", "clock.rtc"]),
|
||||
("sms", SaveShape.SINGLE, ["Game.srm", "save.sram"]),
|
||||
("nes", SaveShape.SINGLE, ["Zelda.srm"]),
|
||||
],
|
||||
)
|
||||
def test_other_names_are_refused(platform: str, shape: SaveShape, members: list[str]):
|
||||
|
||||
Reference in New Issue
Block a user