mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-13 04:25:07 +00:00
refactor(api): remove dead code paths in serve/remote layer
Delete code paths that never executed in the serve/API/remote stack: - BridgeCancelledError: raised but never caught; replace raises with RuntimeError and drop the class. - InputBridge.error setter and _error field: written at the handler layer, never read (session.auth_error is the surfaced channel). - cancel_event param and _check_cancel inner fn on _perform_download: the only caller always passed None (the live job.cancel_event is untouched). - result_with_progress monkeypatch: its status pings were redundant with the file-polled progress_sink, which is now the sole path. - session param on _resolve_manifest_data: unused in the body. Reconcile SessionStore's hardcoded 600s auth-state TTL into a shared AUTH_INPUT_TIMEOUT constant referenced by both the InputBridge input timeout and the store, removing the magic number without changing the longer grace window. Update input_bridge/session_store tests for the new channels and add an assertion that auth-state entries expire at the single rule.
This commit is contained in:
@@ -7,7 +7,7 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.api.input_bridge import AuthStatus, BridgeCancelledError, InputBridge
|
||||
from unshackle.core.api.input_bridge import AuthStatus, InputBridge
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
@@ -16,7 +16,6 @@ def test_initial_status_is_authenticating() -> None:
|
||||
bridge = InputBridge()
|
||||
assert bridge.status is AuthStatus.AUTHENTICATING
|
||||
assert bridge.get_pending_prompt() is None
|
||||
assert bridge.error is None
|
||||
|
||||
|
||||
def test_submit_response_returns_false_when_no_prompt_pending() -> None:
|
||||
@@ -49,16 +48,15 @@ def test_request_input_blocks_until_submit() -> None:
|
||||
|
||||
def test_request_input_times_out() -> None:
|
||||
bridge = InputBridge()
|
||||
with pytest.raises(TimeoutError):
|
||||
with pytest.raises(TimeoutError, match="No client response"):
|
||||
bridge.request_input("hello", timeout=0.6)
|
||||
assert bridge.status is AuthStatus.FAILED
|
||||
assert "timed out" in (bridge.error or "")
|
||||
|
||||
|
||||
def test_cancel_before_request_raises_immediately() -> None:
|
||||
bridge = InputBridge()
|
||||
bridge.cancel()
|
||||
with pytest.raises(BridgeCancelledError):
|
||||
with pytest.raises(RuntimeError, match="cancelled"):
|
||||
bridge.request_input("hello", timeout=5)
|
||||
assert bridge.status is AuthStatus.FAILED
|
||||
|
||||
@@ -70,7 +68,7 @@ def test_cancel_unblocks_pending_request() -> None:
|
||||
def worker() -> None:
|
||||
try:
|
||||
bridge.request_input("OTP?", timeout=5)
|
||||
except BridgeCancelledError as e:
|
||||
except RuntimeError as e:
|
||||
exc.append(e)
|
||||
|
||||
t = threading.Thread(target=worker)
|
||||
@@ -82,7 +80,7 @@ def test_cancel_unblocks_pending_request() -> None:
|
||||
|
||||
bridge.cancel()
|
||||
t.join(timeout=2)
|
||||
assert exc and isinstance(exc[0], BridgeCancelledError)
|
||||
assert exc and isinstance(exc[0], RuntimeError)
|
||||
assert bridge.status is AuthStatus.FAILED
|
||||
|
||||
|
||||
@@ -92,9 +90,7 @@ def test_get_pending_prompt_returns_none_outside_pending_state() -> None:
|
||||
assert bridge.get_pending_prompt() is None
|
||||
|
||||
|
||||
def test_status_and_error_setters() -> None:
|
||||
def test_status_setter() -> None:
|
||||
bridge = InputBridge()
|
||||
bridge.status = AuthStatus.AUTHENTICATED
|
||||
bridge.error = "boom"
|
||||
assert bridge.status is AuthStatus.AUTHENTICATED
|
||||
assert bridge.error == "boom"
|
||||
|
||||
@@ -85,6 +85,21 @@ async def test_cleanup_expired_keeps_pending_input_under_grace(store: SessionSto
|
||||
assert store.session_count == 1
|
||||
|
||||
|
||||
async def test_cleanup_expired_drops_pending_input_past_grace(store: SessionStore) -> None:
|
||||
"""The auth-state grace is the single AUTH_INPUT_TIMEOUT rule, not a separate magic number."""
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from unshackle.core.api.input_bridge import AUTH_INPUT_TIMEOUT
|
||||
|
||||
entry = await store.create("ATV", _FakeService())
|
||||
entry.input_bridge = InputBridge()
|
||||
entry.auth_status = AuthStatus.PENDING_INPUT
|
||||
entry.last_accessed = datetime.now(timezone.utc) - timedelta(seconds=AUTH_INPUT_TIMEOUT + 1)
|
||||
removed = await store.cleanup_expired()
|
||||
assert removed == 1
|
||||
assert store.session_count == 0
|
||||
|
||||
|
||||
async def test_cancel_all_bridges(store: SessionStore) -> None:
|
||||
a = await store.create("ATV", _FakeService())
|
||||
b = await store.create("NF", _FakeService())
|
||||
|
||||
Reference in New Issue
Block a user