ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s

This commit is contained in:
2026-08-20 13:12:50 +00:00
commit b119135836
10275 changed files with 3284984 additions and 0 deletions
@@ -0,0 +1,17 @@
"""Shared bootstrap for staged-system-prompt regression tests."""
import sys
from pathlib import Path
from types import ModuleType
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
try:
import openai # noqa: F401
except ImportError:
openai_stub = ModuleType("openai")
openai_stub.OpenAI = object
sys.modules["openai"] = openai_stub
@@ -0,0 +1,17 @@
"""Null issues on request_revision must behave like empty list."""
from unittest.mock import MagicMock
from agent import StagedAgent
import tools as T
def test_null_issues_like_empty():
agent = StagedAgent.__new__(StagedAgent)
agent.workspace = T.Workspace()
agent.revision_count = 0
agent.logs = []
agent._log = lambda *a, **k: None
msg, desc = agent._transition_result(T.REQUEST_REVISION, {"issues": None})
assert agent.workspace.review_issues == []
assert desc["issues"] == []
assert "退回" in msg or "问题" in msg
@@ -0,0 +1,30 @@
"""Null ask_clarifying_question.question must coerce to empty string."""
import tools as T
from agent import StagedAgent
from simulated_user import SimulatedUser
def _bare_agent():
ag = object.__new__(StagedAgent)
ag.workspace = T.Workspace()
ag.logs = []
ag.verbose = False
ag.stage = "requirements"
ag.interactive = False
ag.sim_user = SimulatedUser()
return ag
def test_ask_clarifying_null_question_does_not_crash():
ag = _bare_agent()
res = ag._dispatch_tool("ask_clarifying_question", {"question": None})
assert isinstance(res, str)
assert len(res) > 0
def test_ask_clarifying_normal_question_still_answers():
ag = _bare_agent()
res = ag._dispatch_tool(
"ask_clarifying_question", {"question": "需要递归处理子目录吗?"})
assert "递归" in res or "" in res
@@ -0,0 +1,44 @@
"""回归测试:模型对必填工具参数显式传 null 时,工具分发不应崩溃。
此前 write_file 的 content 为 null 时 len(None) -> TypeError
execute_code 的 code 为 null 时在日志切片处就 None[:80] -> TypeError
现在分发处统一把 None 归一化为空串。不实例化 StagedAgent.__init__
(避免 Config 校验 API Key),只测 _dispatch_tool 本身。
"""
import tools as T
from agent import StagedAgent
from simulated_user import SimulatedUser
def _bare_agent():
ag = object.__new__(StagedAgent)
ag.workspace = T.Workspace()
ag.logs = []
ag.verbose = False
ag.stage = "implementation"
ag.interactive = False
ag.sim_user = SimulatedUser()
return ag
def test_write_file_null_content_coerced_to_empty_string():
ag = _bare_agent()
res = ag._dispatch_tool("write_file", {"path": "a.py", "content": None})
assert "已写入文件 a.py" in res
assert ag.workspace.files["a.py"] == ""
def test_execute_code_null_code_coerced_to_empty_string():
ag = _bare_agent()
res = ag._dispatch_tool("execute_code", {"code": None})
assert isinstance(res, str)
assert "退出码: 0" in res
def test_write_file_normal_content_unchanged():
ag = _bare_agent()
res = ag._dispatch_tool(
"write_file", {"path": "a.py", "content": "print('hi')\n"})
assert "已写入文件 a.py" in res
assert ag.workspace.files["a.py"] == "print('hi')\n"