From 31167c9314422b50832d24909376c2ec78740031 Mon Sep 17 00:00:00 2001 From: lhl Date: Mon, 10 Aug 2026 23:39:53 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20Phase3=20Word=20=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=94=B6=E5=B0=BE=EF=BC=88=E5=B0=BE=E9=9A=8F=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?/import=20=E6=8E=92=E5=BA=8F/=E5=A5=91=E7=BA=A6=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _AI_USAGE_LOG.md | 1 + src/genesis/parsers/source_aggregator.py | 4 +++- tests/test_real_samples.py | 4 ++-- tests/test_source_aggregator.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/_AI_USAGE_LOG.md b/_AI_USAGE_LOG.md index a67afcd..7d19e93 100644 --- a/_AI_USAGE_LOG.md +++ b/_AI_USAGE_LOG.md @@ -67,3 +67,4 @@ | 2026-08-10 | Agent 实现 | Phase3 Task3 实现:RuleDocParser 规则文档 Markdown 化与分类。新建 src/genesis/parsers/rule_doc_parser.py(body 级遍历保段落/表格交错顺序;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 验证 RED(ModuleNotFoundError: 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/comments;template 校验 .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 验证 RED(ModuleNotFoundError: 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 无 skip;pytest 全量 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 | diff --git a/src/genesis/parsers/source_aggregator.py b/src/genesis/parsers/source_aggregator.py index 8d55a92..8568dc5 100644 --- a/src/genesis/parsers/source_aggregator.py +++ b/src/genesis/parsers/source_aggregator.py @@ -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, - ) \ No newline at end of file + ) diff --git a/tests/test_real_samples.py b/tests/test_real_samples.py index 1ab6e02..9a92990 100644 --- a/tests/test_real_samples.py +++ b/tests/test_real_samples.py @@ -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) \ No newline at end of file + assert all(r.category == "write" for r in result.rule_docs) diff --git a/tests/test_source_aggregator.py b/tests/test_source_aggregator.py index fe2623d..9f67e11 100644 --- a/tests/test_source_aggregator.py +++ b/tests/test_source_aggregator.py @@ -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]) \ No newline at end of file + SourceParser().parse(rule_paths=[bad])