Fix tests for fake LLM response

This commit is contained in:
Shawn Bot
2026-04-02 10:54:15 +00:00
parent 76f9c1ca75
commit 75ca806146

View File

@@ -1,13 +1,14 @@
from agt.agent import Agent, Tool, echo_tool
from agt.agent import Agent, FakeLLMClient, Tool, echo_tool
def test_agent_returns_default_message() -> None:
agent = Agent()
def test_agent_returns_fake_llm_message() -> None:
agent = Agent(llm=FakeLLMClient())
agent.register_tool(Tool("echo", "Echo input text", echo_tool))
result = agent.run("hello")
assert "教学用 Agent 骨架" in result
assert "[fake-llm]" in result
assert "hello" in result
assert agent.messages[0].role == "user"
assert agent.messages[-1].role == "assistant"
@@ -21,3 +22,13 @@ def test_load_skills_finds_skill_md(tmp_path) -> None:
skills = agent.load_skills(tmp_path / "skills")
assert skills == ["writing"]
def test_fake_llm_streams_multiple_chunks() -> None:
llm = FakeLLMClient()
from agt.agent import Message
chunks = list(llm.stream_text([Message(role="user", content="x")]))
assert len(chunks) >= 2
assert "".join(chunks).startswith("[fake-llm]")