fix(writer): 防静默丢章告警 + 占位符正则宽容化(大小写/全角冒号)
This commit is contained in:
@@ -83,3 +83,28 @@ def test_generate_delegates_to_factory_when_engine_none(monkeypatch, tmp_path):
|
||||
assert len(contents) == 1
|
||||
loaded = Document(str(out))
|
||||
assert "自动生成的内容" in "\n".join(p.text for p in loaded.paragraphs)
|
||||
|
||||
|
||||
def test_generate_warns_on_unanchored_heading(tmp_path, caplog):
|
||||
# 防静默丢章:无 {{section:id}} 锚点的章 → 打 WARNING 并列出章名
|
||||
tpl = tmp_path / "tpl.docx"
|
||||
out = tmp_path / "out.docx"
|
||||
doc = Document()
|
||||
doc.add_paragraph("附録", style="Heading 1")
|
||||
doc.save(str(tpl))
|
||||
parsed = ParsedTemplate(
|
||||
file_name=str(tpl),
|
||||
sections=[ChapterMarker(type="heading", name="附録", level=1)],
|
||||
placeholders={},
|
||||
styles={"defined": ["Heading 1"], "used": ["Heading 1"]},
|
||||
)
|
||||
orch = WriteOrchestrator()
|
||||
with caplog.at_level("WARNING", logger="genesis.writer.orchestrator"):
|
||||
orch.generate(
|
||||
SimpleNamespace(template=parsed),
|
||||
str(out),
|
||||
samples_dir="nonexistent_dir_xyz",
|
||||
engine=FakeEngine(),
|
||||
template_path=str(tpl),
|
||||
)
|
||||
assert any("附録" in r.message for r in caplog.records)
|
||||
|
||||
Reference in New Issue
Block a user