- 新增 OpenAI-compatible LLM client,支持 base_url、api_key、model 配置 - 固化意图识别、参数抽取、部署计划生成的结构化 JSON 提示词 - 增加 MCP client 配置读取和真实 session 接入说明 - 实现 checkpoint 自动保存、resume 断点续跑和已完成步骤跳过 - 实现人工确认流程,支持失败 IP 回滚 approve/reject - 新增 chat 常驻式 CLI 对话框,支持自然语言分析、参数设置、执行确认、状态查看、回滚确认和续跑 - 同步 README,补充 LLM、MCP、checkpoint、confirm/resume、chat 使用方式 - 增加相关单元测试,覆盖 LLM client、MCP 配置、确认/续跑和交互式 CLI
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
from pathlib import Path
|
|
|
|
from pam_deploy_graph.agent import PamDeployAgent
|
|
from pam_deploy_graph.fake_runner import FakeActionRunner
|
|
from pam_deploy_graph.interactive import InteractiveCliSession
|
|
|
|
|
|
PARAMS = {
|
|
"HOME_BASE_URL": "https://pam.home.example.com",
|
|
"CLIENT_ID": "client",
|
|
"CLIENT_SECRET": "secret",
|
|
"AIRPORT_CODE": "HET",
|
|
"APP_NAME": "PAM",
|
|
"MODULE_NAME": "Node",
|
|
"VERSION_NUMBER": "2.0.5",
|
|
"ZIP_FILE_PATH": "C:/pkg.zip",
|
|
}
|
|
|
|
|
|
def run_session(session: InteractiveCliSession, inputs: list[str]) -> list[str]:
|
|
output: list[str] = []
|
|
iterator = iter(inputs)
|
|
session.input = lambda _prompt: next(iterator)
|
|
session.output = output.append
|
|
session.run()
|
|
return output
|
|
|
|
|
|
def test_chat_analyzes_natural_language_and_updates_context(tmp_path: Path):
|
|
session = InteractiveCliSession(
|
|
agent=PamDeployAgent(),
|
|
params=PARAMS,
|
|
strategy="fake",
|
|
checkpoint_path=str(tmp_path / "checkpoint.json"),
|
|
)
|
|
|
|
output = run_session(session, ["analyze please use MCP deploy 192.168.1.10", "exit"])
|
|
|
|
assert session.strategy == "hybrid_node_mcp"
|
|
assert session.target_ips == ["192.168.1.10"]
|
|
assert any("执行请输 run" in item for item in output)
|
|
|
|
|
|
def test_chat_run_executes_fake_deploy_and_writes_checkpoint(tmp_path: Path):
|
|
checkpoint = tmp_path / "checkpoint.json"
|
|
session = InteractiveCliSession(
|
|
agent=PamDeployAgent(fake_runner=FakeActionRunner()),
|
|
params=PARAMS,
|
|
strategy="fake",
|
|
checkpoint_path=str(checkpoint),
|
|
)
|
|
|
|
run_session(session, ["run", "yes", "exit"])
|
|
|
|
assert checkpoint.exists()
|
|
assert session.state is not None
|
|
assert session.state.pending_confirmation == ""
|
|
assert all(item["status"] == "SUCCESS" for item in session.state.ip_states.values())
|
|
|
|
|
|
def test_chat_approve_then_resume_continues_after_failed_ip(tmp_path: Path):
|
|
fake = FakeActionRunner(
|
|
{
|
|
"verify-ip:192.168.1.10": {
|
|
"ACTION": "verify-ip",
|
|
"IP": "192.168.1.10",
|
|
"SUCCESS": "false",
|
|
"MESSAGE": "health check failed",
|
|
}
|
|
}
|
|
)
|
|
session = InteractiveCliSession(
|
|
agent=PamDeployAgent(fake_runner=fake),
|
|
params=PARAMS,
|
|
strategy="fake",
|
|
checkpoint_path=str(tmp_path / "checkpoint.json"),
|
|
)
|
|
|
|
run_session(session, ["run", "yes", "approve", "resume", "exit"])
|
|
|
|
assert session.state is not None
|
|
assert session.state.pending_confirmation == ""
|
|
assert session.state.ip_states["192.168.1.10"]["rollback_status"] == "ROLLBACK_DONE"
|
|
assert session.state.ip_states["192.168.1.11"]["status"] == "SUCCESS"
|