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
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:
@@ -0,0 +1,54 @@
|
||||
"""Proofreading must return a dict when the model emits a JSON array or junk."""
|
||||
from agents import _loads_lenient, _report_issues, proofreading_agent
|
||||
|
||||
|
||||
def test_loads_lenient_empty_and_junk_return_none():
|
||||
assert _loads_lenient("") is None
|
||||
assert _loads_lenient("not json") is None
|
||||
assert _loads_lenient('{"a": 1}') == {"a": 1}
|
||||
|
||||
|
||||
def test_report_issues_non_dict():
|
||||
assert _report_issues([]) == []
|
||||
assert _report_issues(None) == []
|
||||
|
||||
|
||||
def test_proofreading_agent_json_array_returns_empty_dict(monkeypatch):
|
||||
calls = []
|
||||
|
||||
def fake_llm_chat(client, tracker, agent, messages, json_mode=False, note=""):
|
||||
calls.append(note)
|
||||
return "[]"
|
||||
|
||||
monkeypatch.setattr("agents.llm_chat", fake_llm_chat)
|
||||
report = proofreading_agent(
|
||||
client=object(),
|
||||
tracker=type("T", (), {"record": lambda *a, **k: None})(),
|
||||
translations={"ch1": "hello"},
|
||||
glossary=[],
|
||||
)
|
||||
assert report == {}
|
||||
assert _report_issues(report) == []
|
||||
assert report.get("chapters_need_revision", []) == []
|
||||
assert calls == ["一致性审校"]
|
||||
|
||||
|
||||
def test_proofreading_agent_valid_object(monkeypatch):
|
||||
payload = {
|
||||
"issues": [{"chapter": "ch1", "detail": "x"}],
|
||||
"chapters_need_revision": ["ch1"],
|
||||
"summary": "ok",
|
||||
}
|
||||
|
||||
def fake_llm_chat(client, tracker, agent, messages, json_mode=False, note=""):
|
||||
import json
|
||||
return json.dumps(payload)
|
||||
|
||||
monkeypatch.setattr("agents.llm_chat", fake_llm_chat)
|
||||
report = proofreading_agent(
|
||||
client=object(),
|
||||
tracker=type("T", (), {"record": lambda *a, **k: None})(),
|
||||
translations={"ch1": "hello"},
|
||||
glossary=[],
|
||||
)
|
||||
assert report == payload
|
||||
Reference in New Issue
Block a user