- 步骤0: 新增中文镜像模板 scripts/make_zh_template.py 与 samples/概要设计书模板_中文.docx(7章锚点原样保留) - 步骤1: config.WriterConfig.output_language→Settings.writer;GenerationContext.output_language + to_vars.language_instruction(zh/ja/auto);writer_agent【语言约束】改引变量;context_builder/orchestrator/run_trial 透传 --output-language - 步骤A: 新建 src/genesis/writer/language.py(detect_script/resolve_expected_language/find_language_violations);WriterAgent.generate_chapter 按期望语言强制、违规重试、耗尽硬失败;max_retries 默认 1→2 - 步骤B: _format_impact 影响调查标签按 output_language 本地化(zh 新建/变更/删除/警告) - 步骤C: eval scorer 第 11 维度 language_consistency(不可验证=满分,不拉低总分);ChapterArtifact.expected_language;QAValidator.validate_doc 透传;QALoop.run 透传 output_language - 测试: test_zh_template/test_language_plumbing/test_writer_language/test_scorer_language/test_language_coverage,并更新 test_phase5_e2e - 全量 pytest 424 passed / 99.15%(覆盖率门槛 99% 达标)
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
import pytest
|
|
from types import SimpleNamespace
|
|
from pathlib import Path
|
|
|
|
from docx import Document
|
|
|
|
from genesis.data_models import StructuredSource
|
|
from genesis.parsers.word_template_parser import WordTemplateParser
|
|
from genesis.qa.qa_loop import QALoop
|
|
|
|
|
|
class FakeEngine:
|
|
def chat_structured(self, *, session_id, prompt, variables, schema, retry_count=2):
|
|
cid = variables.get("title", "x")
|
|
# 日文模板章节(标题含假名)→ 返回日文正文,满足语言一致性强制
|
|
return SimpleNamespace(
|
|
data={
|
|
"title": cid,
|
|
"blocks": [
|
|
{"type": "heading", "level": 2, "text": f"{cid} 小節"},
|
|
{"type": "paragraph", "text": "本機能はFakeLLMにより生成された十分な説明内容であり、書込規則を満たす。"},
|
|
{"type": "table", "caption": "示例表", "rows": [["列1", "列2"], ["値1", "値2"]]},
|
|
],
|
|
},
|
|
status="ok",
|
|
)
|
|
|
|
|
|
def _all_text(doc: Document) -> str:
|
|
parts = [p.text for p in doc.paragraphs]
|
|
for tbl in doc.tables:
|
|
for row in tbl.rows:
|
|
for cell in row.cells:
|
|
parts.append(cell.text)
|
|
return "\n".join(parts)
|
|
|
|
|
|
def test_phase5_e2e_fake_llm(tmp_path):
|
|
template = Path("samples/phase5-slice/template.docx")
|
|
if not template.exists():
|
|
pytest.skip("样本模板缺失,跳过 e2e")
|
|
parsed = WordTemplateParser().parse(str(template))
|
|
ss = StructuredSource(
|
|
template=parsed, tables=[], rule_docs=[], image_analyses=[], existing_system=None, comments=[]
|
|
)
|
|
out = tmp_path / "e2e_out.docx"
|
|
loop = QALoop(max_rounds=2)
|
|
report = loop.run(
|
|
ss, str(out), samples_dir="nonexistent_dir_xyz", engine=FakeEngine(), template_path=str(template)
|
|
)
|
|
assert report.passed is True
|
|
loaded = Document(str(out))
|
|
text = _all_text(loaded)
|
|
assert "本機能はFakeLLMにより生成された十分な説明内容" in text
|
|
assert "示例表" in text
|