mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
refactor: unify host agent runtime access
This commit is contained in:
+6
-6
@@ -14,7 +14,7 @@
|
||||
"workflow_to_db": []
|
||||
},
|
||||
"edge_count": 6546,
|
||||
"edge_sha256": "c840c6290e55ff267e35481176484590c5635d2d22904f57dd32d5adf396d0d1",
|
||||
"edge_sha256": "64bd673bda7224d371b91e229d23eeea6ac14655301357a209dff510e30e151b",
|
||||
"edges": [
|
||||
"app -> app.runtime",
|
||||
"app -> app.runtime.compat",
|
||||
@@ -1663,6 +1663,7 @@
|
||||
"app.api.endpoints.agent -> app.api.principal",
|
||||
"app.api.endpoints.agent -> app.api.response",
|
||||
"app.api.endpoints.agent -> app.application",
|
||||
"app.api.endpoints.agent -> app.application.agent",
|
||||
"app.api.endpoints.agent -> app.application.commands",
|
||||
"app.api.endpoints.agent -> app.application.configuration",
|
||||
"app.api.endpoints.agent -> app.application.messaging",
|
||||
@@ -1702,8 +1703,6 @@
|
||||
"app.api.endpoints.anthropic -> app.adapters.web",
|
||||
"app.api.endpoints.anthropic -> app.adapters.web.security",
|
||||
"app.api.endpoints.anthropic -> app.adapters.web.security.access",
|
||||
"app.api.endpoints.anthropic -> app.agent",
|
||||
"app.api.endpoints.anthropic -> app.agent.runtime_loader",
|
||||
"app.api.endpoints.anthropic -> app.api",
|
||||
"app.api.endpoints.anthropic -> app.api.context",
|
||||
"app.api.endpoints.anthropic -> app.api.endpoints",
|
||||
@@ -1712,6 +1711,7 @@
|
||||
"app.api.endpoints.anthropic -> app.api.presentation",
|
||||
"app.api.endpoints.anthropic -> app.api.presentation.sse",
|
||||
"app.api.endpoints.anthropic -> app.application",
|
||||
"app.api.endpoints.anthropic -> app.application.agent",
|
||||
"app.api.endpoints.anthropic -> app.application.configuration",
|
||||
"app.api.endpoints.anthropic -> app.runtime",
|
||||
"app.api.endpoints.anthropic -> app.runtime.tasks",
|
||||
@@ -1847,7 +1847,6 @@
|
||||
"app.api.endpoints.history -> app.agent.contracts",
|
||||
"app.api.endpoints.history -> app.agent.prompt",
|
||||
"app.api.endpoints.history -> app.agent.prompt.transfer_redo",
|
||||
"app.api.endpoints.history -> app.agent.runtime_loader",
|
||||
"app.api.endpoints.history -> app.api",
|
||||
"app.api.endpoints.history -> app.api.context",
|
||||
"app.api.endpoints.history -> app.api.dependencies",
|
||||
@@ -1855,6 +1854,7 @@
|
||||
"app.api.endpoints.history -> app.api.dependencies.history",
|
||||
"app.api.endpoints.history -> app.api.response",
|
||||
"app.api.endpoints.history -> app.application",
|
||||
"app.api.endpoints.history -> app.application.agent",
|
||||
"app.api.endpoints.history -> app.application.configuration",
|
||||
"app.api.endpoints.history -> app.application.history",
|
||||
"app.api.endpoints.history -> app.runtime",
|
||||
@@ -2064,6 +2064,7 @@
|
||||
"app.api.endpoints.openai -> app.api.presentation",
|
||||
"app.api.endpoints.openai -> app.api.presentation.sse",
|
||||
"app.api.endpoints.openai -> app.application",
|
||||
"app.api.endpoints.openai -> app.application.agent",
|
||||
"app.api.endpoints.openai -> app.application.configuration",
|
||||
"app.api.endpoints.openai -> app.runtime",
|
||||
"app.api.endpoints.openai -> app.runtime.tasks",
|
||||
@@ -5798,9 +5799,8 @@
|
||||
"app.scheduler -> app.adapters",
|
||||
"app.scheduler -> app.adapters.external",
|
||||
"app.scheduler -> app.adapters.external.server",
|
||||
"app.scheduler -> app.agent",
|
||||
"app.scheduler -> app.agent.runtime_loader",
|
||||
"app.scheduler -> app.application",
|
||||
"app.scheduler -> app.application.agent",
|
||||
"app.scheduler -> app.application.configuration",
|
||||
"app.scheduler -> app.application.database",
|
||||
"app.scheduler -> app.application.image",
|
||||
|
||||
@@ -404,7 +404,7 @@ async def test_interrupted_date_task_manual_run_disables_and_removes_job(
|
||||
)
|
||||
manager.execute_scheduled_task = AgentManager.execute_scheduled_task.__get__(manager)
|
||||
monkeypatch.setattr(
|
||||
"app.agent.runtime_loader.get_running_agent_manager",
|
||||
"app.application.agent.get_running_agent_manager",
|
||||
lambda: manager,
|
||||
)
|
||||
|
||||
@@ -432,7 +432,7 @@ async def test_scheduler_propagates_scheduled_trigger_source(monkeypatch) -> Non
|
||||
scheduler = _build_agent_task_scheduler()
|
||||
execute = AsyncMock(return_value=(True, "执行完成"))
|
||||
monkeypatch.setattr(
|
||||
"app.agent.runtime_loader.get_running_agent_manager",
|
||||
"app.application.agent.get_running_agent_manager",
|
||||
lambda: SimpleNamespace(execute_scheduled_task=execute),
|
||||
)
|
||||
|
||||
@@ -677,7 +677,7 @@ async def test_scheduler_config_reload_preserves_active_agent_task(
|
||||
)
|
||||
manager.execute_scheduled_task = AgentManager.execute_scheduled_task.__get__(manager)
|
||||
monkeypatch.setattr(
|
||||
"app.agent.runtime_loader.get_running_agent_manager",
|
||||
"app.application.agent.get_running_agent_manager",
|
||||
lambda: manager,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
|
||||
@@ -175,7 +175,7 @@ async def test_scheduler_agent_task_cleanup_uses_async_query(monkeypatch) -> Non
|
||||
sync_get = Mock(side_effect=AssertionError("不应调用同步 AgentTaskOper.get"))
|
||||
scheduler = SimpleNamespace(remove_agent_task_job=Mock())
|
||||
monkeypatch.setattr(
|
||||
"app.agent.runtime_loader.get_running_agent_manager",
|
||||
"app.application.agent.get_running_agent_manager",
|
||||
lambda: SimpleNamespace(execute_scheduled_task=execute),
|
||||
)
|
||||
monkeypatch.setattr(AgentTaskOper, "async_get", async_get)
|
||||
|
||||
@@ -1156,6 +1156,27 @@ def test_agent_application_facade_does_not_import_agent_implementation():
|
||||
} == set()
|
||||
|
||||
|
||||
def test_host_consumers_get_agent_manager_through_application_facade():
|
||||
"""宿主消费者不得绕过 Application 门面直接定位 Agent manager。"""
|
||||
forbidden = {"get_agent_manager", "get_running_agent_manager"}
|
||||
violations: dict[str, set[str]] = {}
|
||||
for module_name, path in _discover_modules().items():
|
||||
if module_name.startswith(("app.agent", "app.startup")):
|
||||
continue
|
||||
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
||||
imported = {
|
||||
alias.name
|
||||
for node in ast.walk(tree)
|
||||
if isinstance(node, ast.ImportFrom)
|
||||
and node.module == "app.agent.runtime_loader"
|
||||
for alias in node.names
|
||||
if alias.name in forbidden
|
||||
}
|
||||
if imported:
|
||||
violations[module_name] = imported
|
||||
assert violations == {}
|
||||
|
||||
|
||||
def test_agent_tools_do_not_import_entrypoint_internals():
|
||||
"""Agent 工具不得穿透导入 HTTP 端点、调度器与命令注册表内部实现。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user