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
+45
-10
@@ -2,11 +2,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from bot042.agent import get_tools as agent_get_tools
|
||||
from bot042.agent import reset_robot
|
||||
from bot042.agent.tools import get_tools, move, perceive, robot, speak
|
||||
from bot042.agent.middlewares import get_tools, move, perceive, robot, speak
|
||||
from bot042.channels import CliChannel
|
||||
from bot042.config import Settings
|
||||
|
||||
@@ -27,32 +29,65 @@ def test_tools_registered() -> None:
|
||||
|
||||
def test_move_updates_state() -> None:
|
||||
reset_robot()
|
||||
result = move.invoke({"direction": "北", "distance": 2})
|
||||
result = asyncio.run(move.ainvoke({"direction": "北", "distance": 2}))
|
||||
assert robot.y == pytest.approx(2.0)
|
||||
assert robot.facing == "north"
|
||||
assert "[移动]" in result
|
||||
|
||||
bad = move.invoke({"direction": "up", "distance": 1})
|
||||
bad = asyncio.run(move.ainvoke({"direction": "up", "distance": 1}))
|
||||
assert "[移动失败]" in bad
|
||||
|
||||
|
||||
def test_perceive_and_speak() -> None:
|
||||
reset_robot()
|
||||
assert "[感知]" in perceive.invoke({})
|
||||
assert "[播报]" in speak.invoke({"text": "hello"})
|
||||
assert "[感知]" in asyncio.run(perceive.ainvoke({}))
|
||||
assert "[播报]" in asyncio.run(speak.ainvoke({"text": "hello"}))
|
||||
assert robot.log == ["speak: hello"]
|
||||
|
||||
|
||||
def test_cli_channel(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
def test_cli_channel(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
channel = CliChannel()
|
||||
monkeypatch.setattr("builtins.input", lambda _prompt="": "hello")
|
||||
assert channel.receive() == "hello"
|
||||
|
||||
channel.send("hi")
|
||||
msg = channel.parse_inbound("hello")
|
||||
assert msg.text == "hello"
|
||||
assert msg.channel_subject is not None
|
||||
assert msg.channel_subject.subject_id == "local"
|
||||
|
||||
async def _send() -> None:
|
||||
await channel.reply_text(msg.channel_subject, "hi")
|
||||
|
||||
asyncio.run(_send())
|
||||
assert capsys.readouterr().out.strip() == "hi"
|
||||
|
||||
|
||||
def test_cli_channel_input_pump(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
channel = CliChannel()
|
||||
enqueued: list[str] = []
|
||||
channel.attach(lambda payload: enqueued.append(payload))
|
||||
|
||||
inputs = iter(["ping", "exit"])
|
||||
monkeypatch.setattr("builtins.input", lambda _prompt="": next(inputs))
|
||||
|
||||
async def _run() -> None:
|
||||
await channel.start()
|
||||
await channel.wait_closed()
|
||||
await channel.stop()
|
||||
|
||||
asyncio.run(_run())
|
||||
assert enqueued == ["ping"]
|
||||
|
||||
|
||||
def test_cli_channel_eof_closes(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
channel = CliChannel()
|
||||
|
||||
def raise_eof(_prompt: str = "") -> str:
|
||||
raise EOFError
|
||||
|
||||
monkeypatch.setattr("builtins.input", raise_eof)
|
||||
assert channel.receive() is None
|
||||
|
||||
async def _run() -> None:
|
||||
await channel.start()
|
||||
await channel.wait_closed()
|
||||
await channel.stop()
|
||||
|
||||
asyncio.run(_run())
|
||||
Reference in new issue
Block a user