test(writer/qa): 覆盖 engine=None 委托工厂的真实门禁路径

This commit is contained in:
lhl
2026-08-13 23:13:58 +08:00
parent 2cd3ecd0f3
commit 24b9511d43
3 changed files with 27 additions and 1 deletions
+11
View File
@@ -54,3 +54,14 @@ def test_qa_loop_regenerates_only_failed(tmp_path):
assert report.passed is True
assert engine.calls["A"] == 1 # A 首次即通过,未被重生成
assert engine.calls["B"] == 2 # B 失败后被重生成一次
def test_run_delegates_to_factory_when_engine_none(monkeypatch, tmp_path):
# 门禁真实路径:engine=None 时应委托 build_inference_engine() 构造真实引擎
monkeypatch.setattr("genesis.qa.qa_loop.build_inference_engine", lambda: ImprovingEngine())
tpl = tmp_path / "tpl.docx"
out = tmp_path / "out.docx"
_make_template(str(tpl))
loop = QALoop(max_rounds=3)
report = loop.run(_ss(str(tpl)), str(out), samples_dir="nonexistent_dir_xyz", engine=None)
assert report.passed is True
+14
View File
@@ -69,3 +69,17 @@ def test_generate_with_async_engine_produces_filled_docx(tmp_path):
loaded = Document(str(out))
joined = "\n".join(p.text for p in loaded.paragraphs)
assert "异步引擎内容" in joined
def test_generate_delegates_to_factory_when_engine_none(monkeypatch, tmp_path):
# 门禁真实路径:engine=None 时应委托 build_inference_engine() 构造真实引擎
monkeypatch.setattr("genesis.writer.orchestrator.build_inference_engine", lambda: FakeEngine())
tpl = tmp_path / "tpl.docx"
out = tmp_path / "out.docx"
_make_template(str(tpl))
contents = WriteOrchestrator().generate(
_ss(str(tpl)), str(out), samples_dir="nonexistent_dir_xyz", engine=None
)
assert len(contents) == 1
loaded = Document(str(out))
assert "自动生成的内容" in "\n".join(p.text for p in loaded.paragraphs)