Files
2026Technology-Competition/tests/test_phase5_renderer.py
T
lhl d9aa3a3325 fix(writer): 修复概要设计书输出塌缩与章间引用缺失,并补 parser 防灾
- Writer: 表格表头行/Table Grid 边框、列表 List Bullet/Number 样式、行内字符格式不再塌缩(外视 #6 反转)
- Writer: 打通章间引用(WriterState 摘要 → 后章 prompt prior_summaries)
- Writer: 删除 _chunk_source 死代码,章节数据经 DataGate 控 token 预算
- Writer: 章节结果落盘快照,命中即跳过 LLM(录制重拍可续跑,损坏快照自动忽略)
- Parser: 按 body 顺序遍历正文+单元格(含嵌套表、合并单元格去重),修复表格内锚点漏检导致的静默丢章
- Parser/服务层: .xls 显式拒绝(可操作提示),上传即校验扩展名,rules 对齐 docx-only
- 测试: 全量 680 通过,覆盖率 99.37%(红线 99%)
2026-09-15 21:30:55 +08:00

39 lines
1.5 KiB
Python

from genesis.writer.renderer import render_chapter_blocks
from genesis.writer.models import ChapterContent, ContentBlock
def _content():
blocks = [
ContentBlock(block_id="1", type="heading", level=2, text="小節"),
ContentBlock(block_id="2", type="paragraph", text="正文"),
ContentBlock(block_id="3", type="table", caption="表1",
headers=["見出しA", "見出しB"], rows=[["a", "b"], ["1", "2"]]),
ContentBlock(block_id="4", type="list", items=["項目一", "項目二"], style="bullet"),
ContentBlock(block_id="5", type="note", text="注意"),
]
return ChapterContent(chapter_id="db_design", version=1, title="DB 設計", blocks=blocks)
def test_render_maps_all_block_types():
out = render_chapter_blocks(_content())
kinds = [b.kind for b in out]
assert kinds == ["heading", "paragraph", "table", "list", "note"]
def test_render_preserves_table_headers_and_caption():
# 外视 #6 反转:表头/标题不再塌缩,须透传至注入器
out = render_chapter_blocks(_content())
table = out[2]
assert table.kind == "table"
assert table.headers == ["見出しA", "見出しB"]
assert table.text == "表1" # caption
assert table.rows == [["a", "b"], ["1", "2"]]
def test_render_preserves_list_items_and_style():
out = render_chapter_blocks(_content())
lst = out[3]
assert lst.kind == "list"
assert lst.items == ["項目一", "項目二"]
assert lst.style == "bullet"