fix: 完善 UT 覆盖,统一 pytest 测试发现 - Closes #2
CI / test (pull_request) Successful in 9s

- 新建 pytest.ini 统一 test discovery(tests/ + skills/ir_generation_skill/tests/)
- test_step1~3 转换为 pytest 兼容格式,无输出文件时自动 skip
- 新增 tests/test_detect_conflicts.py(18 个纯函数单测)
- 新增 tests/test_config.py(7 个配置模块单测)
- CI 改为 pytest -v 使用 pytest.ini testpaths
- DEV_AGENT.md 新增 PR 提交规范

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 00:07:07 +08:00
parent 618364e744
commit 682dedb4b4
11 changed files with 619 additions and 32 deletions
@@ -227,6 +227,77 @@ def run_all_tests():
return total_failures == 0
# ═══════════════════════════════════════════════════════════════════════════════
# pytest discovery support
# ═══════════════════════════════════════════════════════════════════════════════
import pytest # noqa: E402
def _load_ir_final_or_skip():
"""Load ir_final.json or return None."""
try:
return config.load_json(config.IR_FINAL_JSON)
except FileNotFoundError:
return None
def _load_audit_report_or_skip():
"""Load ir_audit_report.md or return None."""
try:
with open(config.IR_AUDIT_REPORT_MD, "r", encoding="utf-8") as f:
return f.read()
except FileNotFoundError:
return None
def test_step3_top_level_structure():
"""pytest: ir_final must have required top-level fields."""
ir = _load_ir_final_or_skip()
if ir is None:
pytest.skip("ir_final.json not found — run step3_merge_and_audit.py first")
errors = check_top_level_structure(ir)
assert not errors, f"top-level structure errors: {errors}"
def test_step3_rule_ids():
"""pytest: rule_ids must be unique and follow naming convention."""
ir = _load_ir_final_or_skip()
if ir is None:
pytest.skip("ir_final.json not found")
errors = check_rule_ids(ir)
assert not errors, f"rule_id errors: {errors[:5]}"
def test_step3_rule_paths():
"""pytest: every rule must have a non-empty path array."""
ir = _load_ir_final_or_skip()
if ir is None:
pytest.skip("ir_final.json not found")
rules = ir.get("rules", [])
errors = check_rule_paths(rules)
assert not errors, f"rule path errors: {errors[:5]}"
def test_step3_rule_completeness():
"""pytest: each rule must have all required fields."""
ir = _load_ir_final_or_skip()
if ir is None:
pytest.skip("ir_final.json not found")
rules = ir.get("rules", [])
errors = check_rule_completeness(rules)
assert not errors, f"rule completeness errors: {errors[:5]}"
def test_step3_audit_report():
"""pytest: audit report must have all required sections."""
report = _load_audit_report_or_skip()
if report is None:
pytest.skip("ir_audit_report.md not found — run step3_merge_and_audit.py first")
errors = check_audit_report(report)
assert not errors, f"audit report errors: {errors[:5]}"
if __name__ == "__main__":
success = run_all_tests()
sys.exit(0 if success else 1)