test(writer): cover async engine path in WriterAgent/orchestrator

This commit is contained in:
lhl
2026-08-13 11:49:44 +08:00
parent e2b4faedbe
commit 2770c76ba0
2 changed files with 112 additions and 0 deletions
+22
View File
@@ -47,3 +47,25 @@ def test_generate_produces_filled_docx(tmp_path):
loaded = Document(str(out))
joined = "\n".join(p.text for p in loaded.paragraphs)
assert "自动生成的内容" in joined
class AsyncFakeEngine:
async def chat_structured(self, *, session_id, prompt, variables, schema, retry_count=2):
return SimpleNamespace(
data={"title": variables["title"], "blocks": [{"type": "paragraph", "text": "异步引擎内容"}]},
status="ok",
)
def test_generate_with_async_engine_produces_filled_docx(tmp_path):
tpl = tmp_path / "tpl.docx"
out = tmp_path / "out.docx"
_make_template(str(tpl))
orch = WriteOrchestrator()
contents = orch.generate(
_ss(str(tpl)), str(out), samples_dir="nonexistent_dir_xyz", engine=AsyncFakeEngine()
)
assert isinstance(contents, list) and len(contents) == 1
loaded = Document(str(out))
joined = "\n".join(p.text for p in loaded.paragraphs)
assert "异步引擎内容" in joined