mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 17:08:35 +08:00
fix(config): bind runtime service to legacy settings
This commit is contained in:
@@ -195,6 +195,11 @@ async def _initialize_configuration_services(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _build_runtime_settings_service() -> RuntimeSettingsService:
|
||||||
|
"""将可变部署配置实现注入管理服务,避免把兼容代理再次包装。"""
|
||||||
|
return RuntimeSettingsService(legacy_settings)
|
||||||
|
|
||||||
|
|
||||||
async def _async_get_subscribe(subscribe_id: int):
|
async def _async_get_subscribe(subscribe_id: int):
|
||||||
"""通过数据库操作器异步读取订阅,供服务端共享用例使用。"""
|
"""通过数据库操作器异步读取订阅,供服务端共享用例使用。"""
|
||||||
return await SubscribeOper().async_get(subscribe_id)
|
return await SubscribeOper().async_get(subscribe_id)
|
||||||
@@ -630,7 +635,7 @@ async def init_modules() -> HostRuntime:
|
|||||||
scheduler=lambda: build_scheduler_runtime_config(settings),
|
scheduler=lambda: build_scheduler_runtime_config(settings),
|
||||||
chain=lambda: build_chain_runtime_config(settings),
|
chain=lambda: build_chain_runtime_config(settings),
|
||||||
)
|
)
|
||||||
runtime_settings = RuntimeSettingsService(settings)
|
runtime_settings = _build_runtime_settings_service()
|
||||||
host_runtime = HostRuntime(
|
host_runtime = HostRuntime(
|
||||||
agent_chat=AgentChatRuntime(
|
agent_chat=AgentChatRuntime(
|
||||||
async_session=get_async_db,
|
async_session=get_async_db,
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import pytest
|
|||||||
|
|
||||||
from app.startup import modules_initializer
|
from app.startup import modules_initializer
|
||||||
from app.startup.lifecycle import initialize_modules_component
|
from app.startup.lifecycle import initialize_modules_component
|
||||||
|
from app.application.configuration import configure_runtime_settings
|
||||||
|
from app.runtime.settings import RuntimeSettingsCompat
|
||||||
|
|
||||||
|
|
||||||
class _InlineWorker:
|
class _InlineWorker:
|
||||||
@@ -16,6 +18,48 @@ class _InlineWorker:
|
|||||||
return operation()
|
return operation()
|
||||||
|
|
||||||
|
|
||||||
|
class _MutableSettings:
|
||||||
|
"""提供运行时配置代理回归测试所需的最小可变设置实现。"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""初始化一项可读写的部署设置。"""
|
||||||
|
self.VALUE = "before"
|
||||||
|
|
||||||
|
def model_dump(self, *, include=None, exclude=None):
|
||||||
|
"""导出测试设置快照。"""
|
||||||
|
values = {"VALUE": self.VALUE}
|
||||||
|
if include is not None:
|
||||||
|
values = {key: value for key, value in values.items() if key in include}
|
||||||
|
if exclude is not None:
|
||||||
|
values = {key: value for key, value in values.items() if key not in exclude}
|
||||||
|
return values
|
||||||
|
|
||||||
|
def update_settings(self, env):
|
||||||
|
"""批量更新测试设置。"""
|
||||||
|
for key, value in env.items():
|
||||||
|
setattr(self, key, value)
|
||||||
|
return {key: (True, "") for key in env}
|
||||||
|
|
||||||
|
def update_setting(self, key, value):
|
||||||
|
"""更新单项测试设置。"""
|
||||||
|
setattr(self, key, value)
|
||||||
|
return True, ""
|
||||||
|
|
||||||
|
|
||||||
|
def test_runtime_settings_compat_uses_legacy_settings_from_startup_root(monkeypatch) -> None:
|
||||||
|
"""组合根装配的兼容代理应读写原始部署配置而不是自身。"""
|
||||||
|
legacy_settings = _MutableSettings()
|
||||||
|
monkeypatch.setattr(modules_initializer, "legacy_settings", legacy_settings)
|
||||||
|
|
||||||
|
service = modules_initializer._build_runtime_settings_service()
|
||||||
|
configure_runtime_settings(service)
|
||||||
|
compat = RuntimeSettingsCompat()
|
||||||
|
|
||||||
|
assert compat.model_dump(include={"VALUE"}) == {"VALUE": "before"}
|
||||||
|
assert compat.update_setting("VALUE", "after") == (True, "")
|
||||||
|
assert compat.model_dump(include={"VALUE"}) == {"VALUE": "after"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_configuration_services_publish_after_both_snapshots_load(
|
async def test_configuration_services_publish_after_both_snapshots_load(
|
||||||
monkeypatch,
|
monkeypatch,
|
||||||
|
|||||||
Reference in New Issue
Block a user