mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-17 05:40:31 +08:00
fix(testing): wire site protocol and lazy module runtime in prepare_backend
This commit is contained in:
committed by
InfinityPacer
parent
410722b0bf
commit
8580eb2cae
@@ -25,6 +25,7 @@ from app.application.image import (
|
||||
configure_wallpaper_providers,
|
||||
reset_wallpaper_providers,
|
||||
)
|
||||
from app.application.module import ModuleRuntime, configure_module_runtime
|
||||
from app.application.subscription.activity import SubscriptionActivityService
|
||||
from app.application.system import SystemService
|
||||
from app.chain._recognition import (
|
||||
@@ -192,6 +193,13 @@ def configure_chain_runtime_context(
|
||||
)
|
||||
|
||||
|
||||
def configure_module_runtime_provider() -> None:
|
||||
"""
|
||||
在组合层登记惰性宿主模块运行时,不在此阶段实例化具体模块管理器。
|
||||
"""
|
||||
configure_module_runtime(lambda: cast(ModuleRuntime, ModuleManager()))
|
||||
|
||||
|
||||
def reset_chain_services() -> None:
|
||||
"""
|
||||
按发布逆序撤销 Chain 无参上下文和壁纸来源。
|
||||
|
||||
@@ -273,6 +273,14 @@ def prepare_backend() -> None:
|
||||
chain=lambda: build_chain_runtime_config(settings),
|
||||
)
|
||||
)
|
||||
# 插件 SDK 的站点域名与协议入口依赖站点协议端口与惰性模块运行时,统一经启动组合层按需装配。
|
||||
from app.runtime.settings import configure_runtime_setting_provider
|
||||
from app.startup.composition.chain import configure_module_runtime_provider
|
||||
from app.startup.composition.site import configure_site_protocol_composition
|
||||
|
||||
configure_runtime_setting_provider(lambda key: getattr(settings, key))
|
||||
configure_module_runtime_provider()
|
||||
configure_site_protocol_composition()
|
||||
|
||||
|
||||
def prepare_v2_backend(plugins_repo: Path) -> None:
|
||||
|
||||
@@ -837,7 +837,7 @@ flowchart LR
|
||||
| 指标 | 当前值 |
|
||||
|---|---:|
|
||||
| Python 模块 | 1164 |
|
||||
| 内部导入边 | 10,117 |
|
||||
| 内部导入边 | 10,121 |
|
||||
| 非平凡 SCC | 1(29 个模块的 TMDB vendor 精确 containment) |
|
||||
| Application / Chain 具体 Adapter 直连 | 0 / 0 |
|
||||
| Direct egress | 51(精确 policy 准入,Application / Chain 均为 0) |
|
||||
|
||||
@@ -962,8 +962,8 @@
|
||||
"runtime_only": true
|
||||
}
|
||||
},
|
||||
"edge_count": 10117,
|
||||
"edge_sha256": "220d35d404b1eb6a5b2900840a44af7d560a9d48e3250e0dbbee1e8714f79ebd",
|
||||
"edge_count": 10121,
|
||||
"edge_sha256": "f06f17caade13860d2d7e0865955ebcb940d3dcb5922dc784420932b2c4f460d",
|
||||
"edges": [
|
||||
"app -> app.foundation",
|
||||
"app -> app.foundation.environment",
|
||||
@@ -10091,6 +10091,7 @@
|
||||
"app.startup.composition.chain -> app.application.configuration",
|
||||
"app.startup.composition.chain -> app.application.directory",
|
||||
"app.startup.composition.chain -> app.application.image",
|
||||
"app.startup.composition.chain -> app.application.module",
|
||||
"app.startup.composition.chain -> app.application.subscription",
|
||||
"app.startup.composition.chain -> app.application.subscription.activity",
|
||||
"app.startup.composition.chain -> app.application.system",
|
||||
@@ -10877,9 +10878,12 @@
|
||||
"app.testing.bootstrap -> app.db.uow",
|
||||
"app.testing.bootstrap -> app.runtime",
|
||||
"app.testing.bootstrap -> app.runtime.config",
|
||||
"app.testing.bootstrap -> app.runtime.settings",
|
||||
"app.testing.bootstrap -> app.startup",
|
||||
"app.testing.bootstrap -> app.startup.composition",
|
||||
"app.testing.bootstrap -> app.startup.composition.chain",
|
||||
"app.testing.bootstrap -> app.startup.composition.configuration",
|
||||
"app.testing.bootstrap -> app.startup.composition.site",
|
||||
"app.testing.bootstrap -> app.startup.initializers",
|
||||
"app.testing.bootstrap -> app.startup.initializers.cache",
|
||||
"app.testing.bootstrap -> app.startup.initializers.database",
|
||||
|
||||
@@ -105,3 +105,29 @@ def test_mark_plugin_generation_prefers_pathlib_item_path():
|
||||
|
||||
assert v2_item.markers == ["v2"]
|
||||
assert v1_item.markers == ["v1"]
|
||||
|
||||
|
||||
def test_prepare_backend_wires_site_protocol_for_standalone_plugin_runners():
|
||||
"""
|
||||
不依赖后端 tests/conftest.py 的独立插件测试进程在调用 prepare_backend 后可直接解析站点域名协议。
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
project_root = Path(__file__).resolve().parents[1]
|
||||
code = (
|
||||
"from app.testing.bootstrap import prepare_backend; "
|
||||
"prepare_backend(); "
|
||||
"from app.runtime.extensions.module.manager import ModuleManager; "
|
||||
"assert ModuleManager.get_existing_instance() is None; "
|
||||
"from app.sdk.string import StringUtils; "
|
||||
"assert StringUtils.get_url_domain('https://u2.dmhy.org/torrents.php') == 'u2.dmhy.org'; "
|
||||
"assert StringUtils.get_url_domain('https://tracker.example.com/rss') == 'example.com'"
|
||||
)
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", code],
|
||||
cwd=project_root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
|
||||
Reference in New Issue
Block a user