chore: Phase3 Word 解析收尾(尾随换行/import 排序/契约注释)

This commit is contained in:
lhl
2026-08-10 23:39:53 +08:00
parent 16921ecbb4
commit 31167c9314
4 changed files with 7 additions and 4 deletions
+1
View File
@@ -67,3 +67,4 @@
| 2026-08-10 | Agent 实现 | Phase3 Task3 实现:RuleDocParser 规则文档 Markdown 化与分类。新建 src/genesis/parsers/rule_doc_parser.pybody 级遍历保段落/表格交错顺序;Heading N→#×N;列表双通道检测 List 样式或 ・/-/• 前缀;表格→GFM;空段→空行;file_type 固定 word、hash=sha256 hex;复用 _word_common.heading_level 无本地重复)与 tests/test_rule_doc_parser.py 按 brief 6 用例;覆盖补齐:test_parse_empty_document 增加 doc.add_paragraph("") 使空段分支(原 new_document 无任何 w:p 不进分支)达 100%TDD 验证 REDModuleNotFoundError: No module named 'genesis.parsers.rule_doc_parser')→ GREEN(聚焦 6 passed);pytest 全量 146 passed 覆盖 100.00%886 stmts/218 br),fail_under=99 达标 | src/genesis/parsers/rule_doc_parser.py, tests/test_rule_doc_parser.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
| 2026-08-10 | Agent 实现 | Phase3 Task4 实现:SourceParser 门面全量输入聚合。新建 src/genesis/parsers/source_aggregator.py(角色显式传参无隐式猜测;requirements 校验 .xlsx/.xls 后缀聚合 tables/commentstemplate 校验 .docx 用 WordTemplateParser 解析;write_instruction+rule 校验 .docx 按 category='write' 归入 rule_docs;不存在抛 FileNotFoundError、未知扩展名抛 ValueError('不支持的文件类型: ...')image_analyses=[]/existing_system=None 固定)与 tests/test_source_aggregator.py 按 brief 6 用例 + 补 4 用例(模板未知扩展名、规则路径文件缺失、requirements/规则无扩展名兜底 '无扩展名' 文案,覆盖 51/62 行缺失与 or 表达式分支)达 100%TDD 验证 REDModuleNotFoundError: No module named 'genesis.parsers.source_aggregator')→ GREEN(聚焦 10 passed);pytest 全量 156 passed 覆盖 100.00%929 stmts/236 br),fail_under=99 达标 | src/genesis/parsers/source_aggregator.py, tests/test_source_aggregator.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
| 2026-08-10 | 测试验证 | Phase3 Task5 实现:真实样本 Word 解析集成测试。tests/test_real_samples.py 追加 4 用例(保留现有 4 个 Excel 用例与 _x 辅助):模板→7 H1(はじめに…バッチ一覧)+section:introduction/doc_title 占位符+template_start 书签;记入規則→category=write/file_type=word/# 1. 機能一覧の書き方/- 機能ID は F001 から連番で付与する。(・前缀双通道检测);做成説明書→category=write/# 2. 機能一覧;全量组装→tables 非空+template 非空+rule_docs==2 且全 write;聚焦测试 8 passed 无 skippytest 全量 160 passed 覆盖 100.00%929 stmts/236 br),fail_under=99 达标 | tests/test_real_samples.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
| 2026-08-10 | 测试验证 | Phase3 Word 解析最终评审收尾:3 文件补尾随换行、test_real_samples import 排序、SourceParser docstring 契约优先级注释 | src/genesis/parsers/source_aggregator.py, tests/test_source_aggregator.py, tests/test_real_samples.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
+3 -1
View File
@@ -28,6 +28,8 @@ class SourceParser:
write_instruction_paths: list[str | Path] | None = None,
rule_paths: list[str | Path] | None = None,
) -> StructuredSource:
"""扩展名校验先于存在性校验(不存在的文件若扩展名未知将抛出 ValueError 而非 FileNotFoundError)。"""
requirement_paths = requirement_paths or []
write_instruction_paths = write_instruction_paths or []
rule_paths = rule_paths or []
@@ -70,4 +72,4 @@ class SourceParser:
image_analyses=[],
existing_system=None,
comments=comments,
)
)
+2 -2
View File
@@ -3,9 +3,9 @@ from pathlib import Path
import pytest
from genesis.parsers.excel_parser import ExcelParser
from genesis.parsers.word_template_parser import WordTemplateParser
from genesis.parsers.rule_doc_parser import RuleDocParser
from genesis.parsers.source_aggregator import SourceParser
from genesis.parsers.word_template_parser import WordTemplateParser
SAMPLES = Path(__file__).resolve().parents[1] / "samples"
@@ -120,4 +120,4 @@ def test_source_parser_full_sample_assembly():
assert result.tables
assert result.template is not None
assert len(result.rule_docs) == 2
assert all(r.category == "write" for r in result.rule_docs)
assert all(r.category == "write" for r in result.rule_docs)
+1 -1
View File
@@ -95,4 +95,4 @@ def test_parse_extensionless_rule(tmp_path):
bad = tmp_path / "note"
bad.write_text("hello", encoding="utf-8")
with pytest.raises(ValueError, match="无扩展名"):
SourceParser().parse(rule_paths=[bad])
SourceParser().parse(rule_paths=[bad])