- template_mapper: 按 design §6.5 仅 Heading level<=1 起章,H2/H3 归入
父章 sub_headings(此前每个 heading 独立成章,无 {{section:id}} 锚点的
6 个子章生成后被静默丢弃)
- models: ChapterSpec.sub_headings 字段;to_vars 暴露 sub_headings 变量
- writer_agent: prompt 新增【小节约束】(有子节时按小节顺序以 level=2
heading 组织,不得遗漏或新增)
- docx_injector: 注入后删除同章内与已生成标题同名且完全无内容的模板裸
H2/H3(保守策略:带内容的模板子节保留)
- 真实试运行验证:7 章 / 无静默丢弃告警 / 14 个 H2 无重复
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""scripts/run_trial.py 驱动测试(fake 模式,离线确定性,无需 API key)。"""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from scripts.run_trial import main
|
|
|
|
|
|
def test_run_trial_fake_produces_docx_and_report(tmp_path):
|
|
out = tmp_path / "output.docx"
|
|
report = tmp_path / "impact-report.json"
|
|
|
|
result = main([
|
|
"--fake",
|
|
"--output", str(out),
|
|
"--impact-report", str(report),
|
|
])
|
|
|
|
# 章数:真实概要设计书模板按 §6.5 归并后为 7 个 H1 章
|
|
#(H2/H3 子节归入父章,不再独立成章被丢弃)
|
|
assert result["chapters"] == 7
|
|
# 影响调查 summary 与 MVP 基线一致
|
|
assert result["summary"] == {
|
|
"total": 16, "new": 5, "modified": 8, "deleted": 3,
|
|
"unchanged": 50, "warnings": 0,
|
|
}
|
|
assert out.is_file()
|
|
assert report.is_file()
|
|
data = json.loads(report.read_text(encoding="utf-8"))
|
|
assert data["summary"] == result["summary"]
|
|
|
|
|
|
def test_run_trial_fake_docx_contains_injected_text(tmp_path):
|
|
out = tmp_path / "out.docx"
|
|
report = tmp_path / "ir.json"
|
|
|
|
main(["--fake", "--output", str(out), "--impact-report", str(report)])
|
|
|
|
from docx import Document
|
|
joined = "\n".join(p.text for p in Document(str(out)).paragraphs)
|
|
assert "自动生成内容" in joined
|