chore: 初始化 bot042 项目(uv + deepagents)
This commit is contained in:
commit
94421e5c2b
20 files changed
+2213
No files matched your search
@@ -0,0 +1,58 @@
|
||||
"""冒烟测试:配置、工具与通道(不需要网络和 API key)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
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.channels import CliChannel
|
||||
from bot042.config import Settings
|
||||
|
||||
|
||||
def test_settings_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("BOT042_MODEL", "openai:test-model")
|
||||
monkeypatch.setenv("BOT042_MAX_STEPS", "12")
|
||||
s = Settings.from_env()
|
||||
assert s.model == "openai:test-model"
|
||||
assert s.max_steps == 12
|
||||
|
||||
|
||||
def test_tools_registered() -> None:
|
||||
names = {t.name for t in get_tools()}
|
||||
assert {"perceive", "move", "speak"} <= names
|
||||
assert agent_get_tools() == get_tools()
|
||||
|
||||
|
||||
def test_move_updates_state() -> None:
|
||||
reset_robot()
|
||||
result = move.invoke({"direction": "北", "distance": 2})
|
||||
assert robot.y == pytest.approx(2.0)
|
||||
assert robot.facing == "north"
|
||||
assert "[移动]" in result
|
||||
|
||||
bad = move.invoke({"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 robot.log == ["speak: hello"]
|
||||
|
||||
|
||||
def test_cli_channel(monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
channel = CliChannel()
|
||||
monkeypatch.setattr("builtins.input", lambda _prompt="": "hello")
|
||||
assert channel.receive() == "hello"
|
||||
|
||||
channel.send("hi")
|
||||
assert capsys.readouterr().out.strip() == "hi"
|
||||
|
||||
def raise_eof(_prompt: str = "") -> str:
|
||||
raise EOFError
|
||||
|
||||
monkeypatch.setattr("builtins.input", raise_eof)
|
||||
assert channel.receive() is None
|
||||
Reference in new issue
Block a user