fix(core): load every service config through one launch-context function

This commit is contained in:
imSp4rky
2026-11-25 16:14:21 -07:00
parent fcda47d995
commit 7838226590
20 changed files with 139 additions and 82 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ def session_params(monkeypatch: pytest.MonkeyPatch, data: dict) -> dict:
seen["params"] = parent_ctx.params
return object()
monkeypatch.setattr(handlers, "load_service_yaml", lambda service: {})
monkeypatch.setattr(handlers, "load_service_config", lambda service: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
monkeypatch.setattr(handlers.Services, "load", lambda service: None)
monkeypatch.setattr(handlers, "instantiate_service", fake_instantiate)
+2 -2
View File
@@ -170,7 +170,7 @@ def test_a_relaying_client_gets_a_stand_in_with_its_device_facts(monkeypatch: py
class Declares:
CLIENT_CONFIG = ("esn",)
monkeypatch.setattr(handlers, "load_service_yaml", lambda tag: {"esn": "SERVER"})
monkeypatch.setattr(handlers, "load_service_config", lambda tag: {"esn": "SERVER"})
monkeypatch.setattr(
handlers,
"served_context",
@@ -331,7 +331,7 @@ def test_a_lent_device_gives_the_service_the_server_config_back(monkeypatch: pyt
CLIENT_CONFIG = ("esn", "esn_map")
monkeypatch.setattr(
handlers, "load_service_yaml", lambda tag: {"esn": "SERVER", "esn_map": {7000: "s"}, "other": 1}
handlers, "load_service_config", lambda tag: {"esn": "SERVER", "esn_map": {7000: "s"}, "other": 1}
)
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: server_device)
monkeypatch.setattr(handlers, "served_context", lambda obj, *a: built.update(cdm=obj.cdm, config=obj.config))
@@ -181,7 +181,7 @@ def test_setup_list_service_threads_request(monkeypatch):
def authenticate(self, cookies, credential):
seen["authenticated"] = True
monkeypatch.setattr(handlers, "load_service_yaml", lambda service: {})
monkeypatch.setattr(handlers, "load_service_config", lambda service: {})
monkeypatch.setattr(handlers, "resolve_handler_proxy", fake_resolve)
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
monkeypatch.setattr(handlers.Services, "load", lambda service: None)
@@ -199,7 +199,7 @@ def test_search_reports_failed_proxy_check_as_invalid_proxy(monkeypatch):
def failed_check(*args):
raise ConnectionError("Proxy check failed: no IP lookup got through the proxy.")
monkeypatch.setattr(handlers, "load_service_yaml", lambda service: {})
monkeypatch.setattr(handlers, "load_service_config", lambda service: {})
monkeypatch.setattr(handlers, "resolve_handler_proxy", lambda *args: ("http://127.0.0.1:9", []))
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
monkeypatch.setattr(handlers.Services, "load", lambda service: None)
+2 -2
View File
@@ -44,7 +44,7 @@ def test_a_session_keeps_the_user_config_it_was_created_with(server, monkeypatch
def test_the_key_block_beats_the_server_config_and_profile_sections(server, monkeypatch):
base = {"device_id": "server", "device_key": "server", "p1": {"device_id": "p1", "other": 1}, "urls": {"a": "b"}}
monkeypatch.setattr(handlers, "load_service_yaml", lambda service: json.loads(json.dumps(base)))
monkeypatch.setattr(handlers, "load_service_config", lambda service: json.loads(json.dumps(base)))
user = {"service_config": {"example": {"device_id": "key", "device_key": "key"}}}
merged = handlers.key_service_yaml("EXAMPLE", user)
@@ -172,7 +172,7 @@ def test_a_reload_checks_key_devices_against_the_new_config(server, monkeypatch)
def test_a_block_value_reaches_only_plain_values_of_other_sections(server, monkeypatch):
base = {"p1": {"device_id": "p1", "headers": {"a": "b"}}, "device_key": "server"}
monkeypatch.setattr(handlers, "load_service_yaml", lambda service: json.loads(json.dumps(base)))
monkeypatch.setattr(handlers, "load_service_config", lambda service: json.loads(json.dumps(base)))
block = {"device_id": "key", "headers": {"c": "d"}, "device_key": {"nested": 1}}
merged = handlers.key_service_yaml("EXAMPLE", {"service_config": {"EXAMPLE": block}})
+1 -1
View File
@@ -59,7 +59,7 @@ def seen(tmp_path, monkeypatch):
monkeypatch.setattr(config.directories, "cache", tmp_path)
monkeypatch.setattr(stats, "mode", "remote_only")
monkeypatch.setattr(handlers, "validate_service", lambda tag, request=None: tag)
monkeypatch.setattr(handlers, "load_service_yaml", lambda service: {})
monkeypatch.setattr(handlers, "load_service_config", lambda service: {})
monkeypatch.setattr(handlers, "resolve_handler_proxy", lambda *args: (None, []))
monkeypatch.setattr(handlers, "resolve_server_account", lambda *args: None)
monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None)
+5 -5
View File
@@ -71,7 +71,7 @@ def test_single_account_always_same(accounts):
def test_client_managed_gets_nothing(monkeypatch, accounts):
monkeypatch.setattr(handlers, "load_service_yaml", lambda s: {})
monkeypatch.setattr(handlers, "load_service_config", lambda s: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
monkeypatch.setattr(handlers.Services, "load", staticmethod(lambda s: object()))
monkeypatch.setattr(handlers, "instantiate_service", lambda *a: "svc")
@@ -101,7 +101,7 @@ def test_rotation_per_region_pool(accounts):
def test_server_account_ignores_client_credentials(monkeypatch, accounts):
monkeypatch.setattr(handlers, "load_service_yaml", lambda s: {})
monkeypatch.setattr(handlers, "load_service_config", lambda s: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
monkeypatch.setattr(handlers.Services, "load", staticmethod(lambda s: object()))
monkeypatch.setattr(handlers, "instantiate_service", lambda *a: "svc")
@@ -125,7 +125,7 @@ def test_server_cdm_ignores_client_cdm_type(monkeypatch):
"""A server_cdm tier licenses with the server's own device, so the client's CDM type must
not swap it for a stub of the other DRM system."""
seen = []
monkeypatch.setattr(handlers, "load_service_yaml", lambda s: {})
monkeypatch.setattr(handlers, "load_service_config", lambda s: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda s, p, t=None, app_config=None: seen.append(t))
monkeypatch.setattr(handlers.Services, "load", staticmethod(lambda s: object()))
monkeypatch.setattr(handlers, "instantiate_service", lambda *a: "svc")
@@ -155,7 +155,7 @@ def _lang_option_module():
def _create_with_real_ctx(monkeypatch, data):
monkeypatch.setattr(handlers, "load_service_yaml", lambda s: {})
monkeypatch.setattr(handlers, "load_service_config", lambda s: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
monkeypatch.setattr(handlers.Services, "load", staticmethod(lambda s: _lang_option_module()))
svc, _, _ = handlers.create_service_instance("OTHER", "t", data, None, [], None)
@@ -230,7 +230,7 @@ def test_malformed_dl_params_are_ignored(monkeypatch, dl_params):
def test_profile_reaches_the_parent_ctx_params(monkeypatch):
monkeypatch.setattr(handlers, "load_service_yaml", lambda s: {})
monkeypatch.setattr(handlers, "load_service_config", lambda s: {})
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
monkeypatch.setattr(handlers.Services, "load", staticmethod(lambda s: _lang_option_module()))
svc, _, _ = handlers.create_service_instance("OTHER", "t", {}, None, [], "work")
@@ -478,7 +478,7 @@ def test_a_client_device_session_builds_the_service_on_a_stub_of_that_device(mon
def no_server_device(*a, **k):
raise AssertionError("a client-device session must not load the server's device")
monkeypatch.setattr(handlers, "load_service_yaml", lambda tag: {})
monkeypatch.setattr(handlers, "load_service_config", lambda tag: {})
monkeypatch.setattr(handlers, "load_full_cdm", no_server_device)
monkeypatch.setattr(handlers, "served_context", lambda obj, *a: built.update(cdm=obj.cdm))
monkeypatch.setattr(handlers.Services, "load", lambda tag: object)
@@ -237,7 +237,7 @@ def test_the_server_device_follows_the_client_only_when_both_systems_are_mapped(
):
asked: list = []
monkeypatch.setattr(handlers.config, "cdm", mapping, raising=False)
monkeypatch.setattr(handlers, "load_service_yaml", lambda tag: {})
monkeypatch.setattr(handlers, "load_service_config", lambda tag: {})
monkeypatch.setattr(
handlers, "load_full_cdm", lambda service, profile, cdm_type, app_config=None: asked.append(cdm_type)
)