agent_deply/tests/test_graph.py
dark 14e297a488 feat: 落地 PAM 智能部署 Agent 骨架
- 新增 pam_deploy_graph 包,包含 Agent runtime、ActionRouter、脚本/MCP/fake runner
- 支持 hybrid_node_mcp 策略:PAM_HOME 走脚本 action,PAM_NODE 走 MCP
- 支持 script_only 离线策略,全部 action 走现有脚本 action
- 新增 LLM structured output 骨架和规则 fallback,支持意图识别、参数抽取、计划生成
- 新增 LangGraph StateGraph 工厂和 MCP client adapter
- 新增 CLI:preview、analyze、run-global、run-deploy
- 增加 fake 完整部署流程、单 IP 失败待回滚确认状态和报告输出
- 增加单元测试覆盖路由、parser、runner、Skill 加载、LLM 输出、MCP adapter 和 LangGraph 图
- 更新 README,记录当前代码骨架、进度、使用方式和下一步计划
2026-05-29 15:53:47 +08:00

38 lines
1.2 KiB
Python

import importlib.util
import pytest
from pam_deploy_graph.graph import build_graph_or_none, build_langgraph
from pam_deploy_graph.params_loader import load_params_file
def test_build_graph_or_none_without_langgraph_is_safe():
graph = build_graph_or_none()
if importlib.util.find_spec("langgraph"):
assert graph is not None
else:
assert graph is None
def test_build_langgraph_error_without_dependency_is_clear():
if importlib.util.find_spec("langgraph"):
pytest.skip("langgraph installed")
with pytest.raises(RuntimeError, match="langgraph is not installed"):
build_langgraph()
def test_langgraph_invokes_global_flow_when_installed(tmp_path):
if not importlib.util.find_spec("langgraph"):
pytest.skip("langgraph not installed")
graph = build_langgraph(flow="global")
result = graph.invoke(
{
"params": load_params_file("doc_scripts/config.txt.example"),
"execution_strategy": "fake",
"config_path": str(tmp_path / "config.txt"),
}
)
state = result["agent_state"]
assert state.completed_global_steps[-1] == "poll-download-progress"
assert state.action_backends["get-online-ips"] == "fake"