feat: 重构为 agent / channels / flows / db 分层架构
- agent: 新增 base.py 执行基类、execution.py 执行器、web.py 网络工具, middlewares/steering.py 中间件;移除旧的 agent.py - channels: 新增 ChannelManager、registry、models 与 IM 渠道(企业微信), 扩展 base.py - flows: 新增 agent_task / bus / cron / scheduler / service / stream / rpc / processor / tasks / model_settings / builtin;移除旧的 task.py - db: 新增 sqlite schema 与 repo 层 - docs: 新增架构说明、Channel × EventBus 设计、任务编写教程 - 依赖新增 aiosqlite / httpx / langgraph / primp / pydantic / ripgrep / wecom-aibot-sdk;新增 bot 命令入口 - 测试:232 passed
This commit is contained in:
1 parent
94421e5c2b
commit
fbb01c4c83
65 files changed
+15322
-173
No files matched your search
@@ -0,0 +1,71 @@
|
||||
"""本地执行能力测试:run_python 与无沙箱 shell 后端。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from bot042.agent.base import _build_backend
|
||||
from bot042.agent.execution import run_python
|
||||
from bot042.agent.tools import get_tools
|
||||
from bot042.config import Settings
|
||||
|
||||
|
||||
def test_run_python_prints_stdout() -> None:
|
||||
out = asyncio.run(run_python.ainvoke({"code": "print(1 + 1)"}))
|
||||
|
||||
assert "[退出码 0]" in out
|
||||
assert "2" in out
|
||||
|
||||
|
||||
def test_run_python_multiline_and_unicode() -> None:
|
||||
code = "def f(n):\n return n * 2\n\nprint('结果', f(3))"
|
||||
|
||||
out = asyncio.run(run_python.ainvoke({"code": code}))
|
||||
|
||||
assert "[退出码 0]" in out
|
||||
assert "结果 6" in out
|
||||
|
||||
|
||||
def test_run_python_reports_stderr_and_exit_code() -> None:
|
||||
code = "import sys\nprint('bad', file=sys.stderr)\nsys.exit(3)"
|
||||
|
||||
out = asyncio.run(run_python.ainvoke({"code": code}))
|
||||
|
||||
assert "[退出码 3]" in out
|
||||
assert "[stderr]" in out
|
||||
assert "bad" in out
|
||||
|
||||
|
||||
def test_run_python_times_out() -> None:
|
||||
out = asyncio.run(run_python.ainvoke({"code": "import time\ntime.sleep(10)", "timeout": 1}))
|
||||
|
||||
assert "执行超时" in out
|
||||
|
||||
|
||||
def test_run_python_rejects_empty_code() -> None:
|
||||
out = asyncio.run(run_python.ainvoke({"code": " "}))
|
||||
|
||||
assert "[执行失败]" in out
|
||||
|
||||
|
||||
def test_get_tools_includes_run_python() -> None:
|
||||
names = {tool.name for tool in get_tools()}
|
||||
|
||||
assert "run_python" in names
|
||||
|
||||
|
||||
def test_backend_is_local_shell_with_home_root(tmp_path: Path) -> None:
|
||||
backend = _build_backend(Settings(home=tmp_path))
|
||||
|
||||
assert backend.cwd == tmp_path.resolve()
|
||||
assert tmp_path.is_dir()
|
||||
|
||||
|
||||
def test_backend_executes_shell_command(tmp_path: Path) -> None:
|
||||
backend = _build_backend(Settings(home=tmp_path))
|
||||
|
||||
result = backend.execute("echo hello")
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "hello" in result.output
|
||||
Reference in new issue
Block a user