fix(remote): end a remote session from before its create to after its DELETE

This commit is contained in:
imSp4rky
2026-11-30 13:56:59 -07:00
parent 3634fc5686
commit 34a3820eb8
34 changed files with 1719 additions and 276 deletions
@@ -8,7 +8,7 @@ from enum import Enum
import pytest
from tests.remote.sessions import session_entry, stub_service_build
from tests.remote.sessions import hold_session, session_entry, stub_service_build
from unshackle.core.manifests.snapshot import match_track
from unshackle.core.remote_service import RemoteService
from unshackle.core.titles.episode import Episode
@@ -569,12 +569,8 @@ async def test_session_delete_returns_nested_cache_keys(tmp_path, monkeypatch) -
async def fake_validated(session_id, request):
return session
class FakeStore:
async def delete(self, session_id):
return True
monkeypatch.setattr(handlers, "get_validated_session", fake_validated)
monkeypatch.setattr(session_store, "get_session_store", lambda: FakeStore())
monkeypatch.setattr(session_store, "get_session_store", session_store.SessionStore)
response = await handlers.session_delete_handler("sid", None)
body = json.loads(response.body)
@@ -663,6 +659,7 @@ def test_a_session_create_that_fails_after_the_cache_write_leaves_no_cache_dir(t
from types import SimpleNamespace
from unshackle.core.api import handlers
from unshackle.core.api.session_store import SessionStore
class Stop(Exception):
pass
@@ -685,14 +682,14 @@ def test_a_session_create_that_fails_after_the_cache_write_leaves_no_cache_dir(t
stub_service_build(monkeypatch, lambda: SimpleNamespace(log=logging.getLogger("Svc")))
monkeypatch.setattr("unshackle.core.api.session_store.refuse_while_draining", lambda: None)
class RefusingStore:
class RefusingStore(SessionStore):
async def create(self, *args, **kwargs):
if stop_at == "after_insert":
await super().create(*args, **kwargs)
raise Stop()
def peek(self, session_id):
return object() if stop_at == "after_insert" else None
monkeypatch.setattr("unshackle.core.api.session_store.get_session_store", RefusingStore)
store = RefusingStore()
monkeypatch.setattr("unshackle.core.api.session_store.get_session_store", lambda: store)
data = {"service": "TESTSVC", "title_id": "t", "cache": {"token": blob('"t"')}}
response = asyncio.run(handlers.session_create_handler(data))
@@ -725,6 +722,7 @@ def _remote_service(parent_params: dict, service_params: dict) -> RemoteService:
svc.session = requests.Session()
svc.log = logging.getLogger("test")
svc.client = SimpleNamespace(post=post, server_url="https://server.example")
hold_session(svc, None)
return svc