Files
pgames-manager/backend/tests/test_game_profiles.py
T
mrleo1nidandClaude Sonnet 5.5 12ec82c7e6 refactor: move game-specific import logic into profiles; unblock Tomie import
- Add app/games: GameProfile base, registry, ReaderHooks and renpy/naninovel/
  tomie profiles. pipeline, preflight, detect and mods dispatch via the registry
- Move tomie_* converter modules to app/games/tomie and split out reader hooks,
  import, mod validation and known defects
- Tolerate the 31 authoring defects of the pinned Tomie build as report
  warnings (exact list, per-script counts); any new defect still blocks import
- Frontend: runtime registry (runtimes.ts) with lazy Tomie launcher
- Add profile/registry tests and docs/GAME_PROFILES.md; update IMPORT.md

Full media export of the original Tomie build is not yet verified.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 11:35:23 +03:00

55 lines
2.3 KiB
Python

from pathlib import Path
import pytest
from app.converter.compatibility import Issue
from app.games import registry
from app.games.base import GameProfile
from app.games.tomie.defects import KNOWN_DEFECTS, split_known
def test_builtin_profiles_are_registered():
ids = {profile.id for profile in registry.all_profiles()}
assert {"renpy", "naninovel", "tomie/expansion-1.3801"} <= ids
assert registry.for_runtime("tomie/1").id == "tomie/expansion-1.3801"
assert registry.for_runtime(None) is None
assert registry.for_runtime("unknown/9") is None
def test_specific_profile_wins_over_engine_profile(tmp_path, monkeypatch):
assert registry.select("naninovel", tmp_path).id == "naninovel" # hash does not match
monkeypatch.setattr("app.games.tomie.identify", lambda root: "tomie/expansion-1.3801")
assert registry.select("naninovel", tmp_path).id == "tomie/expansion-1.3801"
assert registry.select("renpy", tmp_path).id == "renpy"
assert registry.select("godot", tmp_path) is None
def test_new_profile_can_be_registered_once(monkeypatch):
monkeypatch.setattr(registry, "_PROFILES", list(registry.all_profiles()))
class Custom(GameProfile):
id = "custom/game-1"
engine = "naninovel"
specific = True
def claims(self, root: Path) -> bool:
return root.name == "Custom"
registry.register(Custom())
assert registry.select("naninovel", Path("x/Custom")).id == "custom/game-1"
assert registry.select("naninovel", Path("x/Other")).id == "naninovel"
with pytest.raises(ValueError, match="уже зарегистрирован"):
registry.register(Custom())
def test_known_defects_are_waived_only_up_to_the_recorded_count():
(code, message, script), allowed = next(iter(KNOWN_DEFECTS.items()))
known_issue = Issue(code, message, f"{script}:10")
blocking, known = split_known([known_issue] * (allowed + 1))
assert len(known) == allowed and len(blocking) == 1
new = Issue("missing_target", "Не найден переход Nowhere.Start", "Common:1")
blocking, known = split_known([new, known_issue])
assert blocking == [new] and known == [known_issue]
same_message_other_script = Issue(code, message, "SomewhereElse:1")
assert split_known([same_message_other_script])[0] == [same_message_other_script]