mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
fix(streaming): code-review pass on the RetroArch core override
This commit is contained in:
@@ -75,9 +75,8 @@ _EMULATOR_DISPLAY_NAMES: dict[str, str] = {
|
||||
"xenia": "Xenia",
|
||||
}
|
||||
|
||||
# Display name of the libretro core the broker's RetroArch launcher picks for
|
||||
# each platform (its retroarch_platforms.json). Display only: RomM never
|
||||
# selects cores. A platform missing here is labelled by its slug instead.
|
||||
# Display name of the core the broker's RetroArch launcher boots for each
|
||||
# platform when config.yml sets none (its retroarch_platforms.json).
|
||||
_RETROARCH_CORE_NAMES: dict[str, str] = {
|
||||
"3do": "Opera",
|
||||
"3ds": "Azahar",
|
||||
@@ -422,9 +421,11 @@ def _resolve_one(
|
||||
platform,
|
||||
core,
|
||||
)
|
||||
if label == emulator_display_label(emulator, platform, core):
|
||||
label = None
|
||||
core = None
|
||||
opt_in = entry.get("experimental_cores")
|
||||
if opt_in is not None and not isinstance(opt_in, bool):
|
||||
if core is not None and opt_in is not None and not isinstance(opt_in, bool):
|
||||
log.warning(
|
||||
"container for platform '%s' sets experimental_cores to %r, only an "
|
||||
"unquoted true opts in",
|
||||
@@ -447,9 +448,8 @@ def _resolve_one(
|
||||
capabilities=capabilities,
|
||||
state_transfer=state_transfer_limits(emulator),
|
||||
core=core,
|
||||
# Only a real boolean opts in: this runs cores known to be broken, and
|
||||
# a quoted "false" is truthy to bool(). Without a core it is never
|
||||
# sent, so it must not tell pool members apart either.
|
||||
# Only a real boolean opts in (a quoted "false" is truthy to bool()),
|
||||
# and only beside a core, the one place it is ever sent.
|
||||
experimental_cores=opt_in is True and core is not None,
|
||||
)
|
||||
|
||||
@@ -705,9 +705,9 @@ def _warn_about_later_pools(
|
||||
later = [c.key for pool in pools[1:] for c in pool]
|
||||
if later:
|
||||
log.warning(
|
||||
"containers for platform '%s' disagree on emulator, memory card "
|
||||
"sync, save picker or protocol, so game claims only use the first "
|
||||
"pool; never claimed for a game: %s",
|
||||
"containers for platform '%s' disagree on emulator, core, memory "
|
||||
"card sync, save picker or protocol, so game claims only use the "
|
||||
"first pool; never claimed for a game: %s",
|
||||
pools[0][0].platform,
|
||||
", ".join(later),
|
||||
)
|
||||
|
||||
@@ -147,6 +147,10 @@ async def run_launch(
|
||||
if container.core and isinstance(launch_result, dict)
|
||||
else None
|
||||
)
|
||||
if not isinstance(core_tier, str):
|
||||
# The payload model takes a str only; a malformed tier must not
|
||||
# strand an already running session without its launch-ready.
|
||||
core_tier = None
|
||||
await stamp_launched(session_key, session, host=host)
|
||||
await lifecycle.publish_session_activity(session_key, session)
|
||||
|
||||
|
||||
@@ -496,11 +496,8 @@ async def hydrate_states_to_broker(
|
||||
deferred load fires. A container that resumes from its save archive takes no
|
||||
state file at all, and the archive already carries the newest exit state.
|
||||
|
||||
A container on a configured core other than the broker's default gets
|
||||
nothing: stored states don't record which core wrote them, so each one is
|
||||
presumed to be the default's, and pushing it lands where the other core's
|
||||
quick-load reads it. `core_tier` is what the activate reply said; None
|
||||
means it said nothing, which is treated as not the default.
|
||||
A configured core gets nothing unless the activate reply's `core_tier`
|
||||
says it is the default, since stored states are presumed to be the default's.
|
||||
"""
|
||||
if resume_pushed or container.resumes_from_archive:
|
||||
return 0
|
||||
|
||||
@@ -183,12 +183,14 @@ def activate(
|
||||
"emulator": emulator,
|
||||
"multiplayer": multiplayer,
|
||||
}
|
||||
# A romless launch (the desktop) boots no core, whatever the platform sets.
|
||||
core = container.core if rom is not None else None
|
||||
if rom is not None:
|
||||
body["rom"] = rom
|
||||
if container.core:
|
||||
if core:
|
||||
# Only a configured core goes out, so an unconfigured platform's
|
||||
# body is what a broker without core support has always read.
|
||||
body["rom"] = {**rom, "core": container.core}
|
||||
body["rom"] = {**rom, "core": core}
|
||||
if container.experimental_cores:
|
||||
body["rom"]["experimental_cores"] = True
|
||||
if gui_language:
|
||||
@@ -225,22 +227,20 @@ def activate(
|
||||
|
||||
resp = resp if isinstance(resp, dict) else {}
|
||||
log.info("broker activated session, %s", resp)
|
||||
if container.core and resp.get("core") != container.core:
|
||||
# A broker older than core support drops the field and boots its
|
||||
# default core. Saving on the way out would file that core's files
|
||||
# under this platform's archive, so the exit asks for no dump. It is
|
||||
# best-effort and an old broker may not honour save=0.
|
||||
if core and resp.get("core") != core:
|
||||
# An older broker drops the field and boots its default; a dump at exit
|
||||
# would file that core's saves under this platform, so ask for none.
|
||||
log.warning(
|
||||
"broker booted core %s, not the configured %s, ending the session",
|
||||
resp.get("core"),
|
||||
container.core,
|
||||
core,
|
||||
)
|
||||
exit_session(container, 0, save=False)
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail=(
|
||||
"This broker doesn't support `core:`. Upgrade the container, "
|
||||
f"or remove `core: {container.core}` from the "
|
||||
f"or remove `core: {core}` from the "
|
||||
f"{container.platform} platform in config.yml."
|
||||
),
|
||||
)
|
||||
|
||||
@@ -524,7 +524,7 @@ def test_a_bad_core_on_a_flat_entry_skips_it(caplog):
|
||||
|
||||
|
||||
def test_a_container_level_core_is_ignored_beside_platforms(caplog):
|
||||
"""Review Focus 5: one core serves one platform, so inheriting it would
|
||||
"""One core serves one platform, so inheriting it would
|
||||
boot every platform in the map on it."""
|
||||
container = _warnings_of(caplog, lambda: _snes("retroarch", core="bsnes"))
|
||||
assert container.core is None
|
||||
@@ -532,7 +532,7 @@ def test_a_container_level_core_is_ignored_beside_platforms(caplog):
|
||||
|
||||
|
||||
def test_a_quoted_false_does_not_opt_in():
|
||||
"""Review Focus 4: bool("false") is True, and this opt-in runs cores
|
||||
"""A quoted "false" is truthy to bool(), and this opt-in runs cores
|
||||
known to be broken."""
|
||||
container = _snes(
|
||||
{"emulator": "retroarch", "core": "bsnes", "experimental_cores": "false"}
|
||||
@@ -568,6 +568,28 @@ def test_a_core_on_a_legacy_container_is_dropped_with_a_warning(caplog):
|
||||
assert "core" in caplog.text
|
||||
|
||||
|
||||
def test_a_mapped_core_on_a_legacy_container_is_not_in_its_label(caplog):
|
||||
entry = {
|
||||
"host": "http://192.168.1.10:3000",
|
||||
"broker_host": "http://192.168.1.10:8000",
|
||||
"platforms": {"snes": "retroarch:bsnes"},
|
||||
}
|
||||
resolved = _warnings_of(caplog, lambda: _expand(entry))
|
||||
assert (resolved[0].core, resolved[0].label) == (None, "RA Snes9x")
|
||||
|
||||
|
||||
def test_an_explicit_label_survives_a_dropped_core(caplog):
|
||||
entry = {
|
||||
"host": "http://192.168.1.10:3000",
|
||||
"broker_host": "http://192.168.1.10:8000",
|
||||
"platforms": {
|
||||
"snes": {"emulator": "retroarch", "core": "bsnes", "label": "Mine"}
|
||||
},
|
||||
}
|
||||
resolved = _warnings_of(caplog, lambda: _expand(entry))
|
||||
assert resolved[0].label == "Mine"
|
||||
|
||||
|
||||
def test_the_platform_opt_in_wins_over_the_container():
|
||||
inherited = _snes("retroarch:bsnes", experimental_cores=True)
|
||||
overridden = _snes(
|
||||
@@ -579,7 +601,7 @@ def test_the_platform_opt_in_wins_over_the_container():
|
||||
|
||||
|
||||
def test_containers_on_different_cores_are_not_one_pool():
|
||||
"""Review Focus 2: a claim landing on either would boot a different core
|
||||
"""A claim landing on either would boot a different core
|
||||
and file its states where the other never looks."""
|
||||
assert not _snes("retroarch:bsnes").interchangeable_with(_snes("retroarch"))
|
||||
assert _snes("retroarch:bsnes").interchangeable_with(_snes("retroarch:bsnes"))
|
||||
@@ -8623,7 +8645,7 @@ def test_import_spec_query_is_unchanged_without_a_core():
|
||||
|
||||
|
||||
def test_import_spec_asks_again_when_the_core_changes():
|
||||
"""Review Focus 1: a 404/422 is cached for the worker's life, so a key
|
||||
"""A 404/422 is cached for the worker's life, so a key
|
||||
without the core would keep the old core's answer after a config edit."""
|
||||
with patch(
|
||||
"handler.streaming.broker.request", side_effect=_http_error(404)
|
||||
@@ -9599,7 +9621,7 @@ def test_no_core_leaves_the_activate_body_unchanged(client, access_token, rom: R
|
||||
def test_an_older_broker_that_drops_the_core_is_exited_asking_for_no_save(
|
||||
client, access_token, rom: Rom
|
||||
):
|
||||
"""Review Focus 3: pydantic drops the unknown field and the broker boots
|
||||
"""Pydantic drops the unknown field and the broker boots
|
||||
its default, which would file this session's saves under the wrong core."""
|
||||
_, sent, exit_session = _ra_claim(
|
||||
client, access_token, rom, "retroarch:bsnes", {"url": "/room/x"}
|
||||
@@ -9651,6 +9673,41 @@ def test_launch_ready_has_no_tier_without_a_core(client, access_token, rom: Rom)
|
||||
assert (ready["core"], ready["core_tier"]) == (None, None)
|
||||
|
||||
|
||||
def test_a_malformed_core_tier_still_reaches_launch_ready(
|
||||
client, access_token, rom: Rom
|
||||
):
|
||||
"""The session is already running, so a bad tier must not cost the player
|
||||
the room URL."""
|
||||
reply = {**_BSNES_REPLY, "core_tier": 3}
|
||||
_, sent, _ = _ra_claim(client, access_token, rom, "retroarch:bsnes", reply)
|
||||
ready = _launch_ready(sent)
|
||||
assert (ready["core"], ready["core_tier"]) == ("bsnes", None)
|
||||
|
||||
|
||||
def test_a_desktop_on_a_container_with_a_core_boots_no_core(client, access_token):
|
||||
"""The desktop runs on the container's first platform record, whose core
|
||||
it never boots, so the broker's missing echo is not a skew."""
|
||||
container = _webstation(platforms={"snes": "retroarch:bsnes"})
|
||||
with _streaming(container):
|
||||
with (
|
||||
patch(
|
||||
"handler.streaming.broker.request", return_value={"url": "/room/x"}
|
||||
) as request,
|
||||
patch("handler.streaming.webstation.exit_session") as exit_session,
|
||||
):
|
||||
response = client.post(
|
||||
"/api/streaming/desktop",
|
||||
json={"container": _key_of(container)},
|
||||
headers=_auth(access_token),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
exit_session.assert_not_called()
|
||||
activate = next(
|
||||
c for c in request.call_args_list if c.args[1].endswith("/activate")
|
||||
)
|
||||
assert "rom" not in activate.kwargs["body"]
|
||||
|
||||
|
||||
# ── multiplayer flag ─────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user