feat(contract): 采购合同对比agent
Signed-off-by: sophie <sophie> Signed-off-by: sophie <sophie>
This commit is contained in:
1 parent
ffccf19ba2
commit
0503ff76a6
90 files changed
+16729
-1344
No files matched your search
@@ -0,0 +1,737 @@
|
||||
"""
|
||||
tests/services/procurement_contract/test_analyze.py
|
||||
|
||||
用途:采购合同清洗、条款结构化、规则叠加、可读性校验与比对结果字段断言。
|
||||
依赖:procurement_contract.analyze。
|
||||
逻辑:保证缺字占位/乱码不会写入 old_text/new_text;条款 title 供前端展示。
|
||||
"""
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.procurement_contract import analyze, rule_service
|
||||
|
||||
|
||||
def test_readable_text_rejects_pdf_missing_glyph_placeholders():
|
||||
"""缺字占位主导的抽取结果必须判定为不可读。"""
|
||||
assert not analyze._is_readable_extracted_text("□□□□□合同条款□□□□□")
|
||||
|
||||
|
||||
def test_compare_uses_difference_title_instead_of_rule_title():
|
||||
"""对比项标题应描述实际差异类别,不得套用单份审核规则标题。"""
|
||||
result = analyze.analyze_compare(
|
||||
"付款:验收后30日内支付。",
|
||||
"付款:验收后90日内支付。",
|
||||
rules=[
|
||||
{
|
||||
"title": "付款条款",
|
||||
"clause_category": "payment",
|
||||
"keywords": ["付款"],
|
||||
"risk_level": "high",
|
||||
"risk_hint": "付款期限延长",
|
||||
"suggestion": "恢复原付款期限",
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
# 断言:规则仅提供风险参考;标题和报告围绕真实付款差异。
|
||||
clause = result["clauses_json"][0]
|
||||
assert clause["title"] == "付款条件变更"
|
||||
assert clause["old_text"] == "付款:验收后30日内支付。"
|
||||
assert clause["new_text"] == "付款:验收后90日内支付。"
|
||||
assert clause["comparison_readable"] is True
|
||||
assert clause["suggestion"] == ""
|
||||
assert clause["negotiation_text"] == ""
|
||||
|
||||
|
||||
def test_compare_classifies_equipment_schedule_as_commercial_without_legal_risk():
|
||||
"""合同号、主体和设备清单变化应保留为商业待确认,不计入法律风险。"""
|
||||
result = analyze.analyze_compare(
|
||||
"采购合同\n合同编号:TMP-001\n设备名称:冲切机\n型号:A1\n数量:1台\n单价:100元",
|
||||
"采购合同\n合同编号:VENDOR-889\n设备名称:冲切机\n型号:B2\n数量:2台\n单价:200元",
|
||||
rules=[],
|
||||
)
|
||||
# 断言:交易基础信息变化供业务确认,不污染高中低风险统计。
|
||||
assert result["clauses_json"][0]["change_class"] in {"metadata", "commercial"}
|
||||
assert result["high_risk_count"] == 0
|
||||
assert result["medium_risk_count"] == 0
|
||||
assert result["low_risk_count"] == 0
|
||||
|
||||
|
||||
def test_compare_ignores_truncated_equipment_table_header_without_values():
|
||||
"""同一设备表仅因 OCR 漏取后半段表头时,不得产生合同内容变更。"""
|
||||
result = analyze.analyze_compare(
|
||||
"序号|设备名称|品牌|型号|数量|单价|总价",
|
||||
"序号|设备名称|品牌",
|
||||
rules=[],
|
||||
)
|
||||
|
||||
# 断言:纯表头没有业务值,短表头又是长表头的有序子集,应计为 OCR 噪声。
|
||||
assert result["clauses_json"] == []
|
||||
assert result["total_change_count"] == 0
|
||||
assert result["summary_json"]["comparison_quality"]["ignored_ocr_noise"] == 1
|
||||
|
||||
|
||||
def test_compare_keeps_equipment_table_value_change_when_header_matches():
|
||||
"""设备表金额、数量等字段值变化必须保留,不能被表头容错规则吞掉。"""
|
||||
result = analyze.analyze_compare(
|
||||
"序号|设备名称|品牌|型号|数量|单价|总价\n1|贴标设备|煜英|非标定制|1|24000|24000",
|
||||
"序号|设备名称|品牌|型号|数量|单价|总价\n1|贴标设备|煜英|非标定制|2|24000|48000",
|
||||
rules=[],
|
||||
)
|
||||
|
||||
# 断言:数量和总价均为业务事实,仍需显示为商业信息变更。
|
||||
assert result["total_change_count"] == 1
|
||||
assert result["clauses_json"][0]["change_class"] == "commercial"
|
||||
|
||||
|
||||
def test_compare_ignores_split_total_row_when_amounts_match_in_both_contracts():
|
||||
"""同一合计行仅因表格列拆分不一致时,不得误报为金额修改。"""
|
||||
result = analyze.analyze_compare(
|
||||
"设备数量:2\n设备总价:¥44,000\n合计|2|¥44,000",
|
||||
"设备数量:2\n设备总价:¥44,000\n合计",
|
||||
rules=[],
|
||||
)
|
||||
|
||||
# 断言:金额事实在双方全文一致,只有合计行列拆分不同,应计为抽取噪声。
|
||||
assert result["clauses_json"] == []
|
||||
assert result["total_change_count"] == 0
|
||||
assert result["summary_json"]["comparison_quality"]["ignored_ocr_noise"] == 1
|
||||
|
||||
|
||||
def test_compare_keeps_split_total_row_when_amount_differs():
|
||||
"""合计金额未在双方全文一致出现时,不能按表格拆列噪声过滤。"""
|
||||
result = analyze.analyze_compare(
|
||||
"设备数量:2\n设备总价:¥44,000\n合计|2|¥44,000",
|
||||
"设备数量:2\n设备总价:¥45,000\n合计",
|
||||
rules=[],
|
||||
)
|
||||
|
||||
# 断言:44,000 与 45,000 不一致,必须保留真实金额差异。
|
||||
assert result["total_change_count"] >= 1
|
||||
|
||||
|
||||
def test_compare_ignores_nonsemantic_markdown_and_ocr_fragments():
|
||||
"""Markdown 标记和单字符 OCR 残片不能成为合同新增项。"""
|
||||
for fragment in ("##", "人>", "乙", "v"):
|
||||
result = analyze.analyze_compare("第一条 合同正文", f"第一条 合同正文\n{fragment}", rules=[])
|
||||
|
||||
# 断言:残片不含独立字段、金额或义务,必须完全排除在差异清单外。
|
||||
assert result["clauses_json"] == []
|
||||
assert result["total_change_count"] == 0
|
||||
|
||||
|
||||
def test_compare_ignores_truncated_duplicate_supplier_name_fragment():
|
||||
"""签章区新增的 OCR 截断供应商名不应被误报为合同新增内容。"""
|
||||
supplier = "如玖军棱科技苏州有限公司"
|
||||
result = analyze.analyze_compare(
|
||||
f"乙方:{supplier}\n第一条 合同正文",
|
||||
f"乙方:{supplier}\n第一条 合同正文\n如兮军棱科技(苏",
|
||||
rules=[],
|
||||
)
|
||||
|
||||
# 断言:共同供应商名只多出一个错字截断片段,应计为 OCR 噪声。
|
||||
assert result["clauses_json"] == []
|
||||
assert result["total_change_count"] == 0
|
||||
assert result["summary_json"]["comparison_quality"]["ignored_ocr_noise"] == 1
|
||||
|
||||
|
||||
def test_supplier_fragment_filter_does_not_hide_actual_supplier_change():
|
||||
"""原回传合同的供应商主体不一致时,即使有短片段也不得作为重复名称过滤。"""
|
||||
assert not analyze._is_truncated_duplicate_supplier_fragment_change(
|
||||
"",
|
||||
"新供应商科技(苏",
|
||||
"乙方:原供应商科技苏州有限公司",
|
||||
"乙方:新供应商科技苏州有限公司\n新供应商科技(苏",
|
||||
)
|
||||
|
||||
def test_compare_keeps_distinct_payment_fragments():
|
||||
"""同一付款主题下不同句子的账期变化应分别保留,避免漏报。"""
|
||||
result = analyze.analyze_compare(
|
||||
"付款:验收后30日支付。\n发票:收到专票后付款。",
|
||||
"付款:验收后90日支付。\n发票:收到专票后60日付款。",
|
||||
rules=[
|
||||
{
|
||||
"title": "付款需绑定验收与发票",
|
||||
"clause_category": "payment",
|
||||
"keywords": ["付款", "验收", "发票"],
|
||||
"risk_level": "high",
|
||||
"risk_hint": "付款条件被放宽",
|
||||
"suggestion": "恢复模板付款条件",
|
||||
}
|
||||
],
|
||||
)
|
||||
assert len(result["clauses_json"]) == 2
|
||||
assert all(row["title"] == "付款条件变更" for row in result["clauses_json"])
|
||||
|
||||
|
||||
def test_compare_classifies_equivalent_clause_numbering_as_format_without_risk():
|
||||
"""中文/阿拉伯数字等价的编号变化只能算格式,不得触发付款高风险规则。"""
|
||||
result = analyze.analyze_compare(
|
||||
"3、付款方式:验收后30日支付。",
|
||||
"三、付款方式:验收后30日支付。",
|
||||
rules=[
|
||||
{
|
||||
"title": "付款需绑定验收与发票",
|
||||
"clause_category": "payment",
|
||||
"keywords": ["付款"],
|
||||
"risk_level": "high",
|
||||
"risk_hint": "付款条件变更",
|
||||
"suggestion": "恢复模板付款条件",
|
||||
}
|
||||
],
|
||||
)
|
||||
# 断言:风险评估建立在语义变化上,而不是原始字符 Diff。
|
||||
assert result["clauses_json"] == []
|
||||
assert result["high_risk_count"] == 0
|
||||
|
||||
|
||||
def test_compare_classifies_price_schedule_as_commercial_without_legal_risk():
|
||||
"""数量和单价修改应归入商业待确认,不默认为法律高风险。"""
|
||||
result = analyze.analyze_compare(
|
||||
"设备名称:空压机。数量:1台。单价:100元。",
|
||||
"设备名称:空压机。数量:2台。单价:200元。",
|
||||
rules=[],
|
||||
)
|
||||
assert result["clauses_json"][0]["change_class"] == "commercial"
|
||||
assert result["clauses_json"][0]["risk_level"] == "ok"
|
||||
|
||||
|
||||
def test_compare_keeps_payment_term_change_as_obligation_risk():
|
||||
"""付款账期放宽改变采购方权利义务,仍应进入风险判断。"""
|
||||
result = analyze.analyze_compare(
|
||||
"付款方式:验收后30日支付。",
|
||||
"付款方式:验收后90日支付。",
|
||||
rules=[
|
||||
{
|
||||
"title": "付款需绑定验收与发票",
|
||||
"clause_category": "payment",
|
||||
"keywords": ["付款"],
|
||||
"risk_level": "high",
|
||||
"risk_hint": "付款条件放宽",
|
||||
"suggestion": "恢复模板付款期限",
|
||||
}
|
||||
],
|
||||
)
|
||||
assert result["clauses_json"][0]["change_class"] == "obligation"
|
||||
assert result["clauses_json"][0]["risk_level"] == "high"
|
||||
|
||||
|
||||
def test_compare_classifies_warranty_period_change_by_changed_field():
|
||||
"""同句包含质保款和支付时,质保期限数字变化仍必须归类为质保差异。"""
|
||||
original = "质保款(总价款的0%)¥0.00元,从验收合格日起算6个月质保期满后,乙方无违约行为后支付。"
|
||||
returned = "质保款(总价款的0%)¥0.00元,从验收合格日起算12个月质保期满后,乙方无违约行为后支付。"
|
||||
result = analyze.analyze_compare(
|
||||
original,
|
||||
returned,
|
||||
rules=[
|
||||
{
|
||||
"title": "付款需绑定验收与发票",
|
||||
"clause_category": "payment",
|
||||
"risk_level": "high",
|
||||
"risk_hint": "付款条件不足",
|
||||
"suggestion": "恢复付款条件",
|
||||
"negotiation_text": "恢复我司付款条款",
|
||||
},
|
||||
{
|
||||
"title": "质保期限要求",
|
||||
"clause_category": "warranty",
|
||||
"risk_level": "medium",
|
||||
},
|
||||
],
|
||||
)
|
||||
# 断言:页面和报告只陈述质保差异,不出现无关付款建议或沟通话术。
|
||||
assert len(result["clauses_json"]) == 1
|
||||
clause = result["clauses_json"][0]
|
||||
assert clause["clause_category"] == "warranty"
|
||||
assert clause["title"] == "质保与售后变更"
|
||||
assert clause["suggestion"] == ""
|
||||
assert clause["negotiation_text"] == ""
|
||||
assert "差异项清单" in result["report_text"]
|
||||
assert "我方原文" in result["report_text"]
|
||||
assert "回传内容" in result["report_text"]
|
||||
assert "6个月" in result["report_text"]
|
||||
assert "12个月" in result["report_text"]
|
||||
assert "付款需绑定验收与发票" not in result["report_text"]
|
||||
assert "沟通话术" not in result["report_text"]
|
||||
|
||||
|
||||
def test_compare_ignores_cleaner_role_markers_and_spacing_only_changes():
|
||||
"""清洗器的模板/合同标记、空白与排版差异不得生成任何变更记录。"""
|
||||
result = analyze.analyze_compare(
|
||||
"template\n2. 本合同之任何增修应以书面为之,并以双方盖公章的方式签订。",
|
||||
"contract\n2.本合同之任何增修应以书面为之,并以双方盖公章的方式签订。",
|
||||
rules=[],
|
||||
)
|
||||
# 断言:以语义归一键比对后,仅表达差异不进入结果列表。
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
|
||||
def test_compare_ignores_standalone_numbering_fragment_insert():
|
||||
"""A detached table or clause serial number must not become a contract-change record."""
|
||||
result = analyze.analyze_compare(
|
||||
"第一条 付款方式:验收后30日内支付。",
|
||||
"第一条 付款方式:验收后30日内支付。\n1",
|
||||
rules=[],
|
||||
)
|
||||
|
||||
# The isolated `1` has no field, amount, unit, or obligation and is counted only as OCR noise.
|
||||
assert result["clauses_json"] == []
|
||||
assert result["total_change_count"] == 0
|
||||
assert result["summary_json"]["comparison_quality"]["ignored_ocr_noise"] == 1
|
||||
|
||||
|
||||
def test_compare_ignores_renumbered_clause_when_body_is_unchanged():
|
||||
"""供应商插入条款540e的重新编号不应使后续所有条款错位成为修改。"""
|
||||
result = analyze.analyze_compare(
|
||||
"11、 违约责任\n乙方违约应承担赔偿责任。",
|
||||
"一、违约责任\n乙方违约应承担赔偿责任。",
|
||||
rules=[],
|
||||
)
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
def test_safe_comparison_text_clears_unreadable_blobs():
|
||||
"""缺字占位 / 私用区主导的片段不得写入对照列。"""
|
||||
assert analyze._safe_comparison_text("□" * 40) == ""
|
||||
assert analyze._safe_comparison_text("\ue000" * 40) == ""
|
||||
assert analyze._safe_comparison_text("付款:验收后30日内支付。") == "付款:验收后30日内支付。"
|
||||
|
||||
|
||||
def test_extract_party_fields_reads_seller_and_contract_no():
|
||||
"""乙方(卖方)与合同编号须从合同抬头抽取为供应商与业务合同号。"""
|
||||
text = (
|
||||
"甲方(买方):苏州和信精密科技有限公司\n"
|
||||
"乙方(卖方):邢台恒阔机械制造有限公司\n"
|
||||
"合同编号:HX-PO-20260709-0002\n"
|
||||
"第一条 甲方向乙方所购买的……"
|
||||
)
|
||||
party = analyze.extract_party_fields(text)
|
||||
# 断言:卖方公司名与合同编号被正确识别
|
||||
assert party["supplier_name"] == "邢台恒阔机械制造有限公司"
|
||||
assert party["contract_no"] == "HX-PO-20260709-0002"
|
||||
|
||||
|
||||
def test_compare_short_circuits_binary_placeholder_text():
|
||||
"""任一侧为 [binary:] 占位时不应产出虚假变更行。"""
|
||||
result = analyze.analyze_compare(
|
||||
"[binary:a.pdf] PDF 文本编码不兼容或未能提取正文;请上传 Word 或可检索文本的 PDF。",
|
||||
"付款:验收后30日内支付。",
|
||||
rules=[],
|
||||
)
|
||||
assert result["clauses_json"] == []
|
||||
assert result["summary_json"]["text_extraction_warning"] == "pdf_unreadable"
|
||||
|
||||
|
||||
def test_split_paragraphs_breaks_single_line_pdf_page_into_clause_units():
|
||||
"""单行 PDF 页须按句拆分,避免一整页落入一个 Diff 单元格。"""
|
||||
parts = analyze._split_paragraphs(
|
||||
"□□□□设备买卖合同。付款:验收后30日内支付。质保期12个月。"
|
||||
)
|
||||
|
||||
# 缺字占位已清洗,各句独立成段。
|
||||
assert parts == ["设备买卖合同。", "付款:验收后30日内支付。", "质保期12个月。"]
|
||||
|
||||
|
||||
def test_clean_contract_text_removes_repeated_header_and_page_number():
|
||||
"""重复页眉和独立页码应删除,正式条款内容必须保留。"""
|
||||
raw = (
|
||||
"采购合同(内部)\n第1页\n第一条 交付期限为30日。\n"
|
||||
"采购合同(内部)\n第2页\n第二条 验收期为10日。\n"
|
||||
"采购合同(内部)\n第3页\n第三条 质保期为12个月。"
|
||||
)
|
||||
cleaned = analyze.clean_contract_text(raw)
|
||||
# 关键断言:重复短页眉被识别为噪音,条款编号及业务数值未被改写。
|
||||
assert "采购合同(内部)" not in cleaned
|
||||
assert "第一条 交付期限为30日。" in cleaned
|
||||
assert "第三条 质保期为12个月。" in cleaned
|
||||
|
||||
|
||||
def test_clean_contract_text_removes_inline_page_number_and_page_image_marker():
|
||||
"""扫描清洗器的分页图片标记及粘在正文中的页码不得进入 Diff。"""
|
||||
cleaned = analyze.clean_contract_text(
|
||||
"![page-image-1]\n付款条款。 第 1页 共 6页 交货条款。"
|
||||
)
|
||||
assert "page-image" not in cleaned
|
||||
assert "第 1页 共 6页" not in cleaned
|
||||
assert "付款条款" in cleaned
|
||||
|
||||
|
||||
def test_clean_contract_text_normalizes_mineru_html_table_without_tag_attributes():
|
||||
"""MinerU 表格应只保留单元格内容,rowspan/colspan 不得进入合同改动对照。"""
|
||||
cleaned = analyze.clean_contract_text(
|
||||
"<table><tr><td rowspan=1 colspan=2>设备名称</td><td colspan=1>数量</td></tr>"
|
||||
"<tr><td rowspan=1 colspan=2>切割机</td><td colspan=1>2</td></tr></table>"
|
||||
)
|
||||
# 关键断言:可比文本保留表格业务值,不携带 MinerU HTML 布局属性。
|
||||
assert cleaned == "设备名称 | 数量\n切割机 | 2"
|
||||
assert "rowspan" not in cleaned
|
||||
assert "<td" not in cleaned
|
||||
|
||||
|
||||
def test_clean_contract_text_removes_duplicate_mineru_signature_party_line():
|
||||
"""签章区乙方名称已在抬头出现时不应形成伪删除条款。"""
|
||||
cleaned = analyze.clean_contract_text(
|
||||
"卖方:宏博气体设备(苏州)有限公司(以下简称乙方)\n"
|
||||
"签署日期:2026年7月1日\n乙方:宏博气体设备(苏州)有限公司"
|
||||
)
|
||||
# 关键断言:卖方抬头保留,签章区重复主体行被剥离。
|
||||
assert cleaned.count("宏博气体设备(苏州)有限公司") == 1
|
||||
|
||||
|
||||
def test_structure_contract_clauses_preserves_order_and_category():
|
||||
"""结构化条款必须保留原顺序、编号,并按领域关键词标注类别。"""
|
||||
clauses = analyze.structure_contract_clauses(
|
||||
"第一条 付款\n甲方验收后30日内支付。\n第二条 验收\n甲方应书面确认验收结果。"
|
||||
)
|
||||
# 断言:Dify 可通过稳定 clause_id 遍历全部条款并引用证据。
|
||||
assert [item["clause_id"] for item in clauses] == ["clause-0001", "clause-0002"]
|
||||
assert clauses[0]["clause_no"] == "第一条"
|
||||
assert clauses[0]["category"] == "payment"
|
||||
assert clauses[1]["category"] == "acceptance"
|
||||
|
||||
|
||||
def test_compare_adds_full_contract_rule_scan_without_inflating_change_count():
|
||||
"""模板无差异时仍应追加缺项红线,但模板变更数保持为零。"""
|
||||
text = "第一条 货物应在30日内交付。"
|
||||
rules = [
|
||||
{
|
||||
"code": "IP_REQUIRED",
|
||||
"title": "知识产权保障",
|
||||
"clause_category": "ip",
|
||||
"keywords": ["知识产权"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "high",
|
||||
"risk_hint": "缺少知识产权保障条款",
|
||||
"suggestion": "补充供应商侵权赔偿责任",
|
||||
}
|
||||
]
|
||||
result = analyze.analyze_compare(text, text, rules=rules)
|
||||
result = analyze.append_solo_rule_findings(result, text, rules=rules)
|
||||
# 断言:规则风险被补齐,但不能把规则风险数误当模板变更数。
|
||||
assert result["total_change_count"] == 0
|
||||
assert result["high_risk_count"] >= 1
|
||||
ip_findings = [item for item in result["clauses_json"] if item["clause_no"] == "IP_REQUIRED"]
|
||||
assert len(ip_findings) == 1
|
||||
assert ip_findings[0]["change_type"] == "rule_scan"
|
||||
|
||||
|
||||
def test_extraction_quality_flags_ocr_noise_without_rejecting_readable_chinese():
|
||||
"""正文可读但数字含圈号/希腊字母时应降级质量,不能当作高可信文本。"""
|
||||
quality = analyze.extraction_quality("付款:¥108,OO0 元,交货期为 2026 年 ⑧ 月 ⑳ 日。")
|
||||
assert quality["level"] in {"medium", "low"}
|
||||
assert quality["warning"] in {"ocr_noise_detected", "text_quality_low"}
|
||||
|
||||
|
||||
def test_compare_ignores_high_similarity_ocr_character_noise():
|
||||
"""标点和单个 OCR 错字且关键数值一致时不应报告为合同修改。"""
|
||||
result = analyze.analyze_compare(
|
||||
"第八条 质保。维修价格需符合市场行情。",
|
||||
"第八条 质保,维修价格需符合市场行情c",
|
||||
rules=[],
|
||||
)
|
||||
assert result["clauses_json"] == []
|
||||
assert result["summary_json"]["comparison_quality"]["ignored_ocr_noise"] == 1
|
||||
|
||||
|
||||
def test_compare_keeps_explicit_numeric_change_despite_high_text_similarity():
|
||||
"""付款期限等明确数字变化不能被 OCR 容错吞掉。"""
|
||||
result = analyze.analyze_compare(
|
||||
"付款方式:验收合格后30日内支付。",
|
||||
"付款方式:验收合格后90日内支付。",
|
||||
rules=[],
|
||||
)
|
||||
assert len(result["clauses_json"]) == 1
|
||||
assert result["clauses_json"][0]["change_class"] == "obligation"
|
||||
|
||||
|
||||
def test_compare_ignores_ocr_corrupted_list_number():
|
||||
"""列表编号 4) 被 OCR 为 0 时不应认定履约义务发生变化。"""
|
||||
result = analyze.analyze_compare(
|
||||
"4) 买方发出的任何合理的延期交货指示;",
|
||||
"0 买方发出的任何合理的延期交货指示;",
|
||||
rules=[],
|
||||
)
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
|
||||
def test_compare_marks_corrupted_percentage_as_needing_confirmation():
|
||||
"""比例数字被识别为普通汉字时不进结果卡,只记入手动复核建议统计。"""
|
||||
result = analyze.analyze_compare(
|
||||
"质保款(总价款的0%)¥0.00元,质保期12个月。",
|
||||
"质保款(总价款的维%)¥0.OO元,质保期12个月。",
|
||||
rules=[],
|
||||
)
|
||||
assert all(row.get("change_type") != "ocr_uncertain" for row in result["clauses_json"])
|
||||
assert result["total_change_count"] == 0
|
||||
quality = result["summary_json"]["comparison_quality"]
|
||||
assert quality["needs_confirmation"] == 0
|
||||
assert quality["confirmation_fragments"] >= 1 or quality["ignored_ocr_noise"] >= 1
|
||||
|
||||
|
||||
def test_compare_ignores_ocr_corrupted_metadata_in_noisy_contract():
|
||||
"""合同号和主体名称的 OCR 乱码不应逐条要求采购确认。"""
|
||||
filler = "设备采购合同约定双方应共同遵守。" * 40
|
||||
result = analyze.analyze_compare(
|
||||
f"合同号:5203-2607090002\n买方:苏州和信精密科技有限公司\n{filler}",
|
||||
f"合同号:羽Os刁GO⒛90002\n买方:苏州和信精密科技有限公司\n{filler}",
|
||||
rules=[],
|
||||
)
|
||||
# 断言:抬头 OCR 噪声被统计但不进入待确认或正式改动。
|
||||
quality = result["summary_json"]["comparison_quality"]
|
||||
assert quality["needs_confirmation"] == 0
|
||||
assert quality["ignored_ocr_noise"] >= 1
|
||||
assert result["total_change_count"] == 0
|
||||
|
||||
|
||||
def test_compare_keeps_readable_contract_number_change_in_noisy_contract():
|
||||
"""清晰可读的合同编号变化仍应作为基础信息改动保留。"""
|
||||
filler = "扫描版本α。设备采购合同约定双方应共同遵守。" * 40
|
||||
result = analyze.analyze_compare(
|
||||
f"合同号:5203-2607090002\n{filler}",
|
||||
f"合同号:5203-2607090003\n{filler}",
|
||||
rules=[],
|
||||
)
|
||||
# 断言:只有含 OCR 可疑字形的抬头差异才忽略,明确数字变化不能被吞掉。
|
||||
changes = [row for row in result["clauses_json"] if row.get("change_type") == "modify"]
|
||||
assert len(changes) == 1
|
||||
assert changes[0].get("validation_status") != "needs_review"
|
||||
assert result["total_change_count"] == 1
|
||||
|
||||
|
||||
def test_compare_groups_multiple_payment_ocr_fragments_into_one_confirmation():
|
||||
"""同一付款主题的多个 OCR 数字异常不进结果卡,只累计确认片段数。"""
|
||||
filler = "扫描版本α。本合同经双方签署后生效并共同遵守。" * 40
|
||||
result = analyze.analyze_compare(
|
||||
f"{filler}\n预付款为总价款的30%。\n验收款于验收后30日内支付。",
|
||||
f"{filler}\n预付款为总价款的3哪%。\n验收款于验收后卫日内支付。",
|
||||
rules=[],
|
||||
)
|
||||
pending = [row for row in result["clauses_json"] if row["change_type"] == "ocr_uncertain"]
|
||||
assert pending == []
|
||||
assert result["summary_json"]["comparison_quality"]["confirmation_fragments"] >= 1
|
||||
assert result["summary_json"]["comparison_quality"]["needs_confirmation"] == 0
|
||||
|
||||
|
||||
def test_compare_ignores_noncritical_ocr_typo_in_noisy_contract():
|
||||
"""非关键普通错字在长篇扫描合同中不应生成待确认项。"""
|
||||
filler = "扫描版本α。设备采购合同约定双方应共同遵守。" * 40
|
||||
result = analyze.analyze_compare(
|
||||
f"{filler}\n包装材料应符合正常运输要求。",
|
||||
f"{filler}\n包装材科应符合正常运输要求。",
|
||||
rules=[],
|
||||
)
|
||||
quality = result["summary_json"]["comparison_quality"]
|
||||
assert quality["needs_confirmation"] == 0
|
||||
assert quality["ignored_ocr_noise"] >= 1
|
||||
|
||||
|
||||
def test_compare_ignores_short_mixed_ocr_garbage_insert():
|
||||
"""正文表格附近的印章/字体乱码不得作为供应商新增条款展示。"""
|
||||
result = analyze.analyze_compare(
|
||||
"专用控制平台 I5 工控 1 套 专用电脑",
|
||||
"专用控制平台 I5 工控 1 套 专用电脑\n1 惠 C 市 WW n3",
|
||||
rules=[],
|
||||
)
|
||||
# 断言:短乱码只计入已忽略噪声,不进入改动项或风险统计。
|
||||
assert result["clauses_json"] == []
|
||||
assert result["total_change_count"] == 0
|
||||
assert result["summary_json"]["comparison_quality"]["ignored_ocr_noise"] == 1
|
||||
|
||||
|
||||
def test_compare_keeps_short_commercial_values_and_contract_terms():
|
||||
"""型号、数量、金额、期限等合法短文本不能被短乱码门禁误删。"""
|
||||
cases = (
|
||||
"型号:BD-BLC1313",
|
||||
"1 台 ABC 3000W",
|
||||
"金额100元",
|
||||
"验收后30天支付",
|
||||
"质保期2年",
|
||||
)
|
||||
for added_text in cases:
|
||||
result = analyze.analyze_compare("设备配置如下", f"设备配置如下\n{added_text}", rules=[])
|
||||
# 断言:每种具有明确业务语义的短新增值均保留一条差异。
|
||||
assert len(result["clauses_json"]) == 1, added_text
|
||||
assert result["clauses_json"][0]["change_type"] == "insert", added_text
|
||||
|
||||
|
||||
def test_compare_ignores_document_end_marker_fragment():
|
||||
"""“以下无正文”等签章页结束语抽取不完整时不应计为合同修改。"""
|
||||
result = analyze.analyze_compare("(以下无正文)", "(以下", rules=[])
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
|
||||
def test_compare_ignores_signature_block_alignment_noise():
|
||||
"""签章页的主体名称和签署日期错位不应计为条款修改。"""
|
||||
result = analyze.analyze_compare("乙方:供应商有限公司", "签署日期:", rules=[])
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
|
||||
def test_compare_ignores_duplicate_party_name_from_signature_section():
|
||||
"""乙方名称已在抬头出现时,签章区重复行的删除不应成为合同改动。"""
|
||||
template = "卖方:宏博气体设备(苏州)有限公司\n签署日期:2026年7月1日\n乙方:宏博气体设备(苏州)有限公司"
|
||||
contract = "卖方:宏博气体设备(苏州)有限公司\n签署日期:2026年7月1日"
|
||||
result = analyze.analyze_compare(template, contract, rules=[])
|
||||
# 关键断言:主体信息重复仅属签章版式,不进入采购改动项。
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
|
||||
def test_compare_ignores_end_signature_misaligned_to_existing_warranty_summary():
|
||||
"""签署日期与正文已出现的保固摘要错配时,不得伪造质保修改。"""
|
||||
template = "保固售服:整机保修1年,碳分子筛质保3年。\n签署日期:年月日"
|
||||
contract = "保固售服:整机保修1年,碳分子筛质保3年。\n签署日期:年月日\n保固售服:整机保修1年,碳分子筛质保3年。"
|
||||
result = analyze.analyze_compare(template, contract, rules=[])
|
||||
# 关键断言:同一摘要已在正文存在,尾部抽取错位不应产生中风险。
|
||||
assert result["clauses_json"] == []
|
||||
|
||||
|
||||
def test_compare_keeps_liability_change_despite_payment_prefix_and_signature():
|
||||
"""同段付款未变但违约金改写、或同行含签署日期时,必须检出实质变更。"""
|
||||
# 断言:focused 截断不得吞掉同段违约金改动。
|
||||
result = analyze.analyze_compare(
|
||||
"付款:验收后30日支付。\n迟延交货违约金按每日合同价款的千分之五计。",
|
||||
"付款:验收后30日支付。\n迟延交货违约金按每日合同价款的千分之一计。",
|
||||
rules=[],
|
||||
)
|
||||
assert len(result["clauses_json"]) >= 1
|
||||
assert any("千分" in f"{row.get('old_text')}{row.get('new_text')}" for row in result["clauses_json"])
|
||||
lights = {item["key"]: item for item in result["summary_json"]["focus_lights"]}
|
||||
assert lights["liability"]["status"] == "changed"
|
||||
|
||||
# 断言:签章词不得吞掉同段违约金改动。
|
||||
signed = analyze.analyze_compare(
|
||||
"迟延交货违约金按每日合同价款的千分之五计。签署日期:2026年1月1日",
|
||||
"迟延交货违约金按每日合同价款的千分之一计。签署日期:2026年1月1日",
|
||||
rules=[],
|
||||
)
|
||||
assert len(signed["clauses_json"]) >= 1
|
||||
assert signed["clauses_json"][0]["risk_level"] in {"high", "medium"}
|
||||
|
||||
|
||||
def test_compare_detects_chinese_per_mille_change():
|
||||
"""中文「千分之五→千分之一」必须识别为实质数字变更。"""
|
||||
result = analyze.analyze_compare(
|
||||
"乙方逾期交付的,每逾期一日按合同总价千分之五支付违约金。",
|
||||
"乙方逾期交付的,每逾期一日按合同总价千分之一支付违约金。",
|
||||
rules=[],
|
||||
)
|
||||
assert len(result["clauses_json"]) == 1
|
||||
assert result["clauses_json"][0]["change_class"] == "obligation"
|
||||
assert result["clauses_json"][0]["risk_level"] in {"high", "medium"}
|
||||
|
||||
|
||||
def test_compare_jurisdiction_change_is_at_least_medium():
|
||||
"""管辖地由甲方改为乙方时,即使无管理端规则也应达到中高风险。"""
|
||||
result = analyze.analyze_compare(
|
||||
"因本合同而生的争议,双方同意以甲方所在地人民法院作为第一审管辖法院。",
|
||||
"因本合同而生的争议,双方同意以乙方所在地人民法院作为第一审管辖法院。",
|
||||
rules=[],
|
||||
)
|
||||
assert len(result["clauses_json"]) == 1
|
||||
assert result["clauses_json"][0]["change_class"] == "obligation"
|
||||
assert result["clauses_json"][0]["risk_level"] in {"high", "medium"}
|
||||
lights = {item["key"]: item for item in result["summary_json"]["focus_lights"]}
|
||||
assert lights["dispute"]["status"] == "changed"
|
||||
|
||||
|
||||
def test_structure_contract_clauses_recognizes_chinese_list_heading():
|
||||
"""一、二、形式的主条款必须独立切分,不能与合同抬头粘在同一段。"""
|
||||
clauses = analyze.structure_contract_clauses(
|
||||
"设备买卖合同\n一、付款方式\n验收合格后付款。\n二、交货期限\n签约后30日交货。"
|
||||
)
|
||||
numbered = [item for item in clauses if item["clause_no"] in {"一、", "二、"}]
|
||||
assert [item["clause_no"] for item in numbered] == ["一、", "二、"]
|
||||
|
||||
|
||||
def test_solo_policy_flags_missing_procurement_focus_terms():
|
||||
"""卖方自有合同缺少采购五项重点保障时应给出确定性风险项。"""
|
||||
result = analyze.analyze_solo("设备名称:方管矫直机。总价:28000元。", rules=[])
|
||||
codes = {item["clause_no"] for item in result["clauses_json"]}
|
||||
assert {
|
||||
"POLICY_PAYMENT_CONDITIONS",
|
||||
"POLICY_DELIVERY_DEADLINE",
|
||||
"POLICY_WARRANTY_TERM",
|
||||
"POLICY_JURISDICTION",
|
||||
"POLICY_DELAY_PENALTY",
|
||||
}.issubset(codes)
|
||||
|
||||
|
||||
def test_solo_policy_accepts_clear_five_per_mille_delay_penalty():
|
||||
"""每日合同总价千分之五的逾期交付违约金达到采购基线,不应新增该项风险。"""
|
||||
text = (
|
||||
"付款:设备到货并验收合格,收到发票后支付。\n"
|
||||
"交货期限:签约后30个工作日。\n"
|
||||
"质保期:验收合格后12个月。\n"
|
||||
"争议由甲方所在地人民法院管辖。\n"
|
||||
"乙方逾期交付的,每逾期一日按合同总价5‰支付违约金。"
|
||||
)
|
||||
result = analyze.analyze_solo(text, rules=[])
|
||||
codes = {item["clause_no"] for item in result["clauses_json"]}
|
||||
assert "POLICY_DELAY_PENALTY" not in codes
|
||||
|
||||
|
||||
def test_solo_policy_accepts_chinese_five_per_mille_delay_penalty():
|
||||
"""“每延迟一日按千分之五”应识别为达到采购基线。"""
|
||||
text = "乙方迟延履行交货义务时,每延迟一日按设备总价款千分之五支付违约金。"
|
||||
result = analyze.analyze_solo(text, rules=[])
|
||||
codes = {item["clause_no"] for item in result["clauses_json"]}
|
||||
assert "POLICY_DELAY_PENALTY" not in codes
|
||||
|
||||
|
||||
def test_solo_policy_marks_ocr_delivery_date_for_confirmation_not_high_risk():
|
||||
"""交期数字受 OCR 污染时应进入待确认,不能计入高风险。"""
|
||||
text = "交货期限:乙方应于2026年⊥月⒛日前交货。"
|
||||
result = analyze.analyze_solo(text, rules=[])
|
||||
item = next(row for row in result["clauses_json"] if row["clause_no"] == "POLICY_DELIVERY_DEADLINE")
|
||||
assert item["validation_status"] == "needs_review"
|
||||
assert result["high_risk_count"] == 3
|
||||
|
||||
|
||||
def test_compound_payment_rule_requires_acceptance_and_invoice():
|
||||
"""付款组合规则不能因仅出现“付款”一词就判定通过。"""
|
||||
rule = {
|
||||
"code": "payment_acceptance_required",
|
||||
"title": "付款需绑定验收与发票",
|
||||
"clause_category": "payment",
|
||||
"keywords": ["付款", "验收", "发票"],
|
||||
"trigger_type": "keyword_missing",
|
||||
"risk_level": "high",
|
||||
}
|
||||
assert analyze._triggered(rule, "合同约定签约后立即付款。") is True
|
||||
assert analyze._triggered(rule, "货到并验收合格,收到发票后付款。") is False
|
||||
|
||||
|
||||
def test_custom_rule_categories_are_limited_to_supported_result_groups():
|
||||
"""自定义规则只能使用受支持分类,避免自由文本破坏风险聚合和策略去重。"""
|
||||
# 关键断言:标准分类可通过;未知分类必须在保存前被拒绝。
|
||||
assert rule_service._validate_clause_category("PAYMENT") == "payment"
|
||||
try:
|
||||
rule_service._validate_clause_category("free_text_category")
|
||||
except ValidationError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("未知条款分类必须被拒绝")
|
||||
|
||||
|
||||
def test_builtin_rule_codes_are_reserved_for_compound_procurement_checks():
|
||||
"""内置编码不能被自定义规则复用,避免关键词配置意外改写付款等组合判断。"""
|
||||
# 关键断言:前端不传 code 创建自定义规则;若旧客户端传入内置编码,服务端必须拒绝。
|
||||
assert "payment_acceptance_required" in rule_service.BUILTIN_RULE_CODES
|
||||
|
||||
|
||||
def test_structure_contract_clauses_uses_heading_and_parent_category():
|
||||
"""交货和保固子条款应继承父级主题,不被正文中的付款或验收词抢占。"""
|
||||
clauses = analyze.structure_contract_clauses(
|
||||
"四、交货\n1.交货期限为30日,买方未付款时顺延。\n九、保固\n1.整机保固从验收合格日起12个月。"
|
||||
)
|
||||
delivery = next(row for row in clauses if "交货期限" in row["text"])
|
||||
warranty = next(row for row in clauses if "整机保固" in row["text"])
|
||||
assert delivery["category"] == "delivery"
|
||||
assert warranty["category"] == "warranty"
|
||||
|
||||
|
||||
def test_compare_keeps_multiple_distinct_payment_changes():
|
||||
"""同一付款类别的预付款比例和付款期限变化必须分别保留。"""
|
||||
result = analyze.analyze_compare(
|
||||
"付款期限:验收后30日支付。\n预付款:签约后支付30%。",
|
||||
"付款期限:验收后90日支付。\n预付款:签约后支付50%。",
|
||||
rules=[],
|
||||
)
|
||||
assert result["total_change_count"] == 2
|
||||
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
backend/tests/services/procurement_contract/test_artifact_archive.py
|
||||
|
||||
用途:验证采购合同审核产物的 MinIO 私有归档、manifest 提交和按需恢复。
|
||||
依赖:procurement_contract.artifact_archive、Flask 最小应用。
|
||||
逻辑:以内存 MinIO 替身覆盖上传和下载,确保只有完整 manifest 才能恢复文件,归档后本地可安全清理。
|
||||
"""
|
||||
|
||||
import io
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from app.services.procurement_contract import artifact_archive
|
||||
|
||||
|
||||
class _MemoryResponse:
|
||||
"""模拟 MinIO 读取响应,兼容 close/release_conn 生命周期。"""
|
||||
|
||||
def __init__(self, data: bytes):
|
||||
self._stream = io.BytesIO(data)
|
||||
|
||||
def read(self) -> bytes:
|
||||
return self._stream.read()
|
||||
|
||||
def close(self) -> None:
|
||||
self._stream.close()
|
||||
|
||||
def release_conn(self) -> None:
|
||||
return None
|
||||
|
||||
|
||||
class _MemoryMinio:
|
||||
"""最小私有对象存储替身,记录 bucket、对象与最终 manifest 写入顺序。"""
|
||||
|
||||
def __init__(self):
|
||||
self.buckets: set[str] = set()
|
||||
self.objects: dict[tuple[str, str], bytes] = {}
|
||||
self.put_keys: list[str] = []
|
||||
|
||||
def bucket_exists(self, bucket: str) -> bool:
|
||||
return bucket in self.buckets
|
||||
|
||||
def make_bucket(self, bucket: str) -> None:
|
||||
self.buckets.add(bucket)
|
||||
|
||||
def put_object(self, bucket, key, stream, length, content_type):
|
||||
self.objects[(bucket, key)] = stream.read(length)
|
||||
self.put_keys.append(key)
|
||||
|
||||
def get_object(self, bucket: str, key: str) -> _MemoryResponse:
|
||||
return _MemoryResponse(self.objects[(bucket, key)])
|
||||
|
||||
|
||||
def _archive_app() -> Flask:
|
||||
"""提供合同归档开关和独立存储目录。"""
|
||||
app = Flask(__name__)
|
||||
app.config.update(
|
||||
PROCUREMENT_CONTRACT_STORAGE_ROOT="unused-in-unit-test",
|
||||
PROCUREMENT_CONTRACT_ARCHIVE_ENABLED=True,
|
||||
PROCUREMENT_CONTRACT_ARCHIVE_BUCKET="procurement-contract",
|
||||
PROCUREMENT_CONTRACT_ARCHIVE_CLEANUP_LOCAL=True,
|
||||
MINIO_ENDPOINT="minio:9000",
|
||||
MINIO_ACCESS_KEY="test",
|
||||
MINIO_SECRET_KEY="test",
|
||||
MINIO_SECURE=False,
|
||||
)
|
||||
return app
|
||||
|
||||
|
||||
def test_archive_uploads_all_files_then_manifest_and_restores_missing_file(monkeypatch):
|
||||
"""归档必须先上传文件后提交 manifest,恢复时校验 checksum。"""
|
||||
review_no = "CR-TEST-ARCHIVE"
|
||||
document_data = "付款条件:验收后30日付款。".encode("utf-8")
|
||||
result_data = b'{"total_change_count": 0}'
|
||||
document = SimpleNamespace(
|
||||
relative_to=lambda _root: Path("cleaned/contract/document.md"),
|
||||
read_bytes=lambda: document_data,
|
||||
is_file=lambda: True,
|
||||
name="document.md",
|
||||
)
|
||||
result = SimpleNamespace(
|
||||
relative_to=lambda _root: Path("result/merged_result.json"),
|
||||
read_bytes=lambda: result_data,
|
||||
is_file=lambda: True,
|
||||
name="merged_result.json",
|
||||
)
|
||||
root = SimpleNamespace(is_dir=lambda: True, rglob=lambda _pattern: [document, result])
|
||||
storage = _MemoryMinio()
|
||||
monkeypatch.setattr(artifact_archive, "_archive_client", lambda: storage)
|
||||
monkeypatch.setattr(artifact_archive, "_review_root", lambda _review_no: root)
|
||||
|
||||
with _archive_app().app_context():
|
||||
meta = artifact_archive.archive_review_artifacts(review_no)
|
||||
# 关键断言:manifest 最后写入,只有它代表完整可恢复归档。
|
||||
assert storage.put_keys[-1].endswith("/_manifest.json")
|
||||
assert meta["status"] == "archived"
|
||||
|
||||
assert storage.objects[("procurement-contract", f"reviews/{review_no}/cleaned/contract/document.md")] == document_data
|
||||
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
backend/tests/services/procurement_contract/test_comparison_regions.py
|
||||
|
||||
Purpose: Verify comparison-region validation, partitioning, metadata extraction, and attachment summaries.
|
||||
Dependencies: procurement_contract.comparison_regions pure helpers.
|
||||
Flow: Tests model the V4 body/signature/attachment sequence without database or external converters.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.procurement_contract import comparison_regions
|
||||
|
||||
|
||||
def _config():
|
||||
"""Return an isolated V4 config for mutation-safe tests."""
|
||||
return comparison_regions.default_comparison_region_config()
|
||||
|
||||
|
||||
def test_validate_rejects_unknown_attachment_policy():
|
||||
"""An unknown attachment policy must use the unified validation error contract."""
|
||||
config = _config()
|
||||
config["attachment_policy"] = "content_diff"
|
||||
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
comparison_regions.validate_comparison_region_config(config)
|
||||
|
||||
# The assertion protects the stable business error code exposed by Admin API.
|
||||
assert exc_info.value.code == "PROCUREMENT_CONTRACT.INVALID_COMPARISON_REGION_CONFIG"
|
||||
|
||||
|
||||
def test_partition_excludes_header_signature_and_attachment_content():
|
||||
"""Only substantive body text remains after a successful V4 partition."""
|
||||
pages = [
|
||||
"设备买卖合同\n版本:04\n合同号:A-001\n买方:和信公司\n卖方:供应商甲\n兹因甲方向乙方购买设备\n第一条 价格不变。",
|
||||
"第二条 交货期为30日。\n本合同一式两份,由双方各持一份。",
|
||||
"甲方:和信公司 乙方:供应商甲\n盖章\n签署日期:2026年7月24日",
|
||||
"性能需求表\n设备配置内容不参与审核",
|
||||
]
|
||||
text = "\n".join(pages)
|
||||
|
||||
partition = comparison_regions.partition_document(text, pages, _config())
|
||||
|
||||
# Body changes remain reviewable, while seal and attachment text are outside the body scope.
|
||||
assert partition is not None
|
||||
assert "交货期为30日" in partition.body
|
||||
assert "盖章" not in partition.body
|
||||
assert "设备配置内容" not in partition.body
|
||||
assert partition.attachment_pages == 1
|
||||
assert partition.metadata["contract_no"] == "A-001"
|
||||
assert partition.metadata["seller"] == "供应商甲"
|
||||
|
||||
|
||||
def test_partition_requires_both_body_anchors_for_safe_fallback():
|
||||
"""Missing end anchors must return None rather than silently truncating clauses."""
|
||||
pages = ["合同号:A-001\n兹因甲方向乙方购买设备\n第一条 价格不变。"]
|
||||
|
||||
partition = comparison_regions.partition_document(pages[0], pages, _config())
|
||||
|
||||
# None is the explicit signal for review_service to call the legacy full-document diff.
|
||||
assert partition is None
|
||||
|
||||
|
||||
def test_diagnose_partition_reports_missing_page_text_for_scanned_contract():
|
||||
"""A scan with OCR body text but no page text must identify the pagination prerequisite."""
|
||||
text = (
|
||||
"合同号:A-001\n兹因甲方向乙方购买设备\n第一条 价格不变。\n"
|
||||
"本合同一式两份。\n甲方:和信公司\n盖章"
|
||||
)
|
||||
|
||||
diagnostic = comparison_regions.diagnose_partition(text, ["", ""], _config())
|
||||
|
||||
# The reason distinguishes scan pagination loss from a configuration or anchor mismatch.
|
||||
assert diagnostic["page_text_available"] is False
|
||||
assert diagnostic["body_start_anchor"] == "兹因甲方向乙方购买设备"
|
||||
assert diagnostic["body_end_anchor"] == "本合同一式两份"
|
||||
assert diagnostic["fallback_reason"] == "page_text_unavailable"
|
||||
|
||||
|
||||
def test_attachment_comparison_reports_pages_only():
|
||||
"""Attachment summaries contain counts and never expose attachment content."""
|
||||
result = comparison_regions.build_attachment_comparison(0, 2)
|
||||
|
||||
# Added pages are informational and do not have any clause/evidence payload.
|
||||
assert result == {
|
||||
"status": "added",
|
||||
"original_pages": 0,
|
||||
"returned_pages": 2,
|
||||
"added_pages": 2,
|
||||
"removed_pages": 0,
|
||||
}
|
||||
|
||||
|
||||
def test_same_attachment_page_count_ignores_content_changes():
|
||||
"""Different attachment text is intentionally irrelevant when physical page counts match."""
|
||||
result = comparison_regions.build_attachment_comparison(1, 1)
|
||||
|
||||
# No content field exists and equal page counts produce an unchanged informational summary.
|
||||
assert result["status"] == "unchanged"
|
||||
assert result["added_pages"] == 0
|
||||
assert result["removed_pages"] == 0
|
||||
|
||||
|
||||
def test_missing_signature_terms_forces_safe_fallback():
|
||||
"""A body-end phrase alone cannot justify dropping all following text without a signature signal."""
|
||||
pages = [
|
||||
"合同号:A-001\n买方:和信公司\n卖方:供应商甲\n兹因甲方向乙方购买设备\n第一条 价格不变。",
|
||||
"第二条 交货期为30日。\n本合同一式两份,由双方各持一份。\n补充履约条款仍应审核。",
|
||||
]
|
||||
|
||||
partition = comparison_regions.partition_document("\n".join(pages), pages, _config())
|
||||
|
||||
# None ensures the supplemental substantive clause remains in the legacy full-document comparison.
|
||||
assert partition is None
|
||||
|
||||
|
||||
def test_metadata_comparison_is_structured_not_clause_diff():
|
||||
"""Header changes receive field statuses outside the clause schema."""
|
||||
result = comparison_regions.build_metadata_comparison(
|
||||
{"contract_no": "A-001", "seller": "供应商甲"},
|
||||
{"contract_no": "A-002", "seller": "供应商甲"},
|
||||
)
|
||||
|
||||
# Only the changed contract number is marked changed; unchanged parties stay visible for reference.
|
||||
assert result["contract_no"]["status"] == "changed"
|
||||
assert result["seller"]["status"] == "unchanged"
|
||||
@@ -0,0 +1,181 @@
|
||||
"""
|
||||
tests/services/procurement_contract/test_llm_enhancer.py
|
||||
|
||||
用途:采购合同 Dify 新风险结果的证据校验、风险升级和待确认状态断言。
|
||||
依赖:procurement_contract.llm_enhancer。
|
||||
逻辑:直接测试纯合并函数,不访问数据库或真实 Dify,锁住结果治理契约。
|
||||
"""
|
||||
|
||||
from app.services.procurement_contract import llm_enhancer
|
||||
|
||||
|
||||
def _base_result() -> dict:
|
||||
"""构造一个已有中风险规则发现的最小确定性结果。"""
|
||||
return {
|
||||
"summary_json": {"mode": "solo"},
|
||||
"clauses_json": [
|
||||
{
|
||||
"clause_no": "RULE-1",
|
||||
"title": "付款期限",
|
||||
"risk_level": "medium",
|
||||
"detail": "付款条件需要确认",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_merge_review_output_validates_evidence_and_escalates_existing_risk():
|
||||
"""有效原文证据应成为 confirmed,新模型等级可提高但不能降低已有风险。"""
|
||||
result = llm_enhancer._merge_review_output(
|
||||
_base_result(),
|
||||
{
|
||||
"RULE-1": {
|
||||
"llm_reason": "付款前置条件不足",
|
||||
"llm_model_risk_level": "high",
|
||||
"llm_confidence": 0.9,
|
||||
}
|
||||
},
|
||||
[
|
||||
{
|
||||
"clause_id": "clause-0001",
|
||||
"clause_no": "第八条",
|
||||
"title": "默示验收",
|
||||
"risk_level": "high",
|
||||
"professional_reason": "沉默被视为验收合格",
|
||||
"evidence": "三日内未提出异议视为验收合格",
|
||||
"confidence": 0.88,
|
||||
}
|
||||
],
|
||||
clean_text="第八条 三日内未提出异议视为验收合格。",
|
||||
structured_clauses=[
|
||||
{
|
||||
"clause_id": "clause-0001",
|
||||
"clause_no": "第八条",
|
||||
"category": "acceptance",
|
||||
"text": "第八条 三日内未提出异议视为验收合格。",
|
||||
}
|
||||
],
|
||||
)
|
||||
# 断言:已有规则风险只升不降;新风险证据和条款均有效。
|
||||
assert result["clauses_json"][0]["risk_level"] == "high"
|
||||
assert result["clauses_json"][1]["validation_status"] == "confirmed"
|
||||
|
||||
|
||||
def test_merge_review_output_marks_missing_evidence_for_review():
|
||||
"""模型引用不存在的证据时不得标成已确认结论。"""
|
||||
result = llm_enhancer._merge_review_output(
|
||||
_base_result(),
|
||||
{},
|
||||
[
|
||||
{
|
||||
"clause_no": "第八条",
|
||||
"title": "不存在的免责内容",
|
||||
"risk_level": "high",
|
||||
"professional_reason": "模型候选风险",
|
||||
"evidence": "供应商不承担任何责任",
|
||||
}
|
||||
],
|
||||
clean_text="第八条 双方应按约履行。",
|
||||
structured_clauses=[
|
||||
{
|
||||
"clause_id": "clause-0001",
|
||||
"clause_no": "第八条",
|
||||
"category": "liability",
|
||||
"text": "第八条 双方应按约履行。",
|
||||
}
|
||||
],
|
||||
)
|
||||
# 断言:条款编号存在但证据不在原文中,必须进入待确认状态。
|
||||
assert result["clauses_json"][1]["validation_status"] == "needs_review"
|
||||
assert result["summary_json"]["llm_new_findings"]["needs_review"] == 1
|
||||
|
||||
|
||||
def test_needs_review_llm_finding_is_excluded_from_risk_counts():
|
||||
"""证据未验证的模型候选项只能进入待确认,不得污染高中低风险统计。"""
|
||||
from app.services.procurement_contract import analyze
|
||||
|
||||
result = llm_enhancer._merge_review_output(
|
||||
{"summary_json": {"mode": "solo"}, "clauses_json": []},
|
||||
{},
|
||||
[{
|
||||
"clause_id": "clause-0001",
|
||||
"title": "待确认风险",
|
||||
"risk_level": "high",
|
||||
"evidence": "不存在的原文",
|
||||
}],
|
||||
clean_text="第一条 双方应按约履行。",
|
||||
structured_clauses=[{
|
||||
"clause_id": "clause-0001",
|
||||
"clause_no": "第一条",
|
||||
"category": "other",
|
||||
"text": "第一条 双方应按约履行。",
|
||||
}],
|
||||
)
|
||||
rebuilt = analyze.rebuild_result(result)
|
||||
assert rebuilt["clauses_json"][0]["validation_status"] == "needs_review"
|
||||
assert rebuilt["high_risk_count"] == 0
|
||||
|
||||
|
||||
def test_llm_can_reject_deterministic_false_positive_with_verified_evidence():
|
||||
"""模型仅在真实原文和高置信度同时满足时,才可撤销确定性误报。"""
|
||||
result = llm_enhancer._merge_review_output(
|
||||
_base_result(),
|
||||
{
|
||||
"RULE-1": {
|
||||
"llm_decision": "reject",
|
||||
"llm_evidence": "验收合格并收到发票后90日付款",
|
||||
"llm_reason": "原文已明确付款前置条件",
|
||||
"llm_confidence": 0.92,
|
||||
"llm_model_risk_level": "ok",
|
||||
}
|
||||
},
|
||||
[],
|
||||
clean_text="付款条款:验收合格并收到发票后90日付款。",
|
||||
structured_clauses=[],
|
||||
)
|
||||
assert result["clauses_json"][0]["risk_level"] == "ok"
|
||||
assert result["clauses_json"][0]["validation_status"] == "confirmed"
|
||||
|
||||
|
||||
def test_llm_cannot_reject_finding_without_verified_evidence():
|
||||
"""证据不在合同原文时,reject 不能降低已有确定性风险。"""
|
||||
result = llm_enhancer._merge_review_output(
|
||||
_base_result(),
|
||||
{
|
||||
"RULE-1": {
|
||||
"llm_decision": "reject",
|
||||
"llm_evidence": "不存在的付款原文",
|
||||
"llm_confidence": 0.99,
|
||||
"llm_model_risk_level": "ok",
|
||||
}
|
||||
},
|
||||
[],
|
||||
clean_text="付款条款需要双方确认。",
|
||||
structured_clauses=[],
|
||||
)
|
||||
assert result["clauses_json"][0]["risk_level"] == "medium"
|
||||
|
||||
|
||||
def test_chatflow_provider_override_takes_priority_over_agent_app_type(monkeypatch):
|
||||
"""复用Chatflow时环境变量应覆盖HXOPS Agent页面的Workflow类型。"""
|
||||
class FakeAgent:
|
||||
dify_app_type = "workflow"
|
||||
|
||||
monkeypatch.setattr(llm_enhancer.Config, "PROCUREMENT_CONTRACT_LLM_PROVIDER", "chatflow")
|
||||
# 断言:无需把原会话Chatflow改为Workflow,合同后台调用也会走chat-messages。
|
||||
assert llm_enhancer._review_provider(FakeAgent()) == "chatflow"
|
||||
|
||||
|
||||
def test_chatflow_answer_json_uses_same_review_output_contract():
|
||||
"""Chatflow最终Answer中的JSON应被解析成已有项增强和独立风险。"""
|
||||
enhancements, new_items = llm_enhancer._extract_review_output(
|
||||
{
|
||||
"answer": (
|
||||
'{"items":[{"id":"RULE-1","professional_reason":"付款风险"}],'
|
||||
'"new_items":[{"id":"llm-1","title":"免责条款"}]}'
|
||||
)
|
||||
}
|
||||
)
|
||||
# 断言:Chatflow与Workflow只在传输层不同,最终结构化审核协议保持一致。
|
||||
assert enhancements["RULE-1"]["llm_reason"] == "付款风险"
|
||||
assert new_items[0]["title"] == "免责条款"
|
||||
@@ -0,0 +1,121 @@
|
||||
"""
|
||||
tests/services/procurement_contract/test_pdf_annotation.py
|
||||
|
||||
用途:验证采购合同 PDF 证据锚定、坐标字段和高亮批注输出。
|
||||
依赖:procurement_contract.pdf_annotation、pypdfium2、pypdf。
|
||||
逻辑:覆盖文本型 PDF 精确高亮,以及扫描 PDF 按 OCR 分页正文添加页级批注意见。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
|
||||
from pypdf import PdfReader, PdfWriter
|
||||
from pypdf.generic import DictionaryObject, DecodedStreamObject, NameObject
|
||||
|
||||
from app.services.procurement_contract import pdf_annotation
|
||||
|
||||
|
||||
def _sample_pdf_bytes() -> bytes:
|
||||
"""用 PDF 标准 Helvetica 字体生成带可搜索文本层的单页测试 PDF。"""
|
||||
writer = PdfWriter()
|
||||
page = writer.add_blank_page(width=595, height=842)
|
||||
font = DictionaryObject(
|
||||
{
|
||||
NameObject("/Type"): NameObject("/Font"),
|
||||
NameObject("/Subtype"): NameObject("/Type1"),
|
||||
NameObject("/BaseFont"): NameObject("/Helvetica"),
|
||||
}
|
||||
)
|
||||
font_ref = writer._add_object(font)
|
||||
page[NameObject("/Resources")] = DictionaryObject(
|
||||
{NameObject("/Font"): DictionaryObject({NameObject("/F1"): font_ref})}
|
||||
)
|
||||
stream = DecodedStreamObject()
|
||||
stream.set_data(b"BT /F1 14 Tf 72 720 Td (Seller delay penalty is 5 per mille per day.) Tj ET")
|
||||
page[NameObject("/Contents")] = writer._add_object(stream)
|
||||
buffer = io.BytesIO()
|
||||
writer.write(buffer)
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
def test_anchor_and_annotate_pdf_contract_evidence():
|
||||
"""锚定命中后必须返回第一页坐标,并生成至少一个标准 PDF 高亮批注。"""
|
||||
pdf_bytes = _sample_pdf_bytes()
|
||||
|
||||
item = {
|
||||
"title": "Delay penalty",
|
||||
"risk_level": "high",
|
||||
"detail": "Penalty is below policy baseline.",
|
||||
"evidence": "Seller delay penalty is 5 per mille per day.",
|
||||
}
|
||||
anchor = pdf_annotation.locate_pdf_evidence(pdf_bytes, item)
|
||||
# 断言:原文证据被定位到第一页,且坐标可以直接供 PDF Highlight 使用。
|
||||
assert anchor is not None
|
||||
assert anchor["page_no"] == 1
|
||||
assert anchor["rects"]
|
||||
assert anchor["confidence"] >= 0.82
|
||||
|
||||
item["evidence_anchor"] = anchor
|
||||
annotated = pdf_annotation.build_annotated_pdf_bytes(pdf_bytes, [item])
|
||||
reader = PdfReader(io.BytesIO(annotated))
|
||||
assert len(reader.pages[0].get("/Annots", [])) >= 1
|
||||
|
||||
|
||||
def test_enrich_result_marks_non_pdf_as_unsupported():
|
||||
"""Word 合同不支持 PDF 坐标时只写状态,不影响审核结果。"""
|
||||
result = {"summary_json": {}, "clauses_json": [{"risk_level": "high", "evidence": "sample"}]}
|
||||
enriched = pdf_annotation.enrich_result_with_pdf_anchors(
|
||||
result,
|
||||
filename="contract.docx",
|
||||
pdf_bytes=b"not-a-pdf",
|
||||
)
|
||||
assert enriched["summary_json"]["evidence_anchoring"]["status"] == "unsupported"
|
||||
|
||||
|
||||
def test_annotate_scanned_pdf_from_ocr_page_text():
|
||||
"""扫描 PDF 无文本坐标时,应按 page-image OCR 文本命中页码并添加页级批注。"""
|
||||
pdf_bytes = _sample_pdf_bytes()
|
||||
item = {
|
||||
"title": "Delivery deadline",
|
||||
"risk_level": "high",
|
||||
"detail": "Deadline needs confirmation.",
|
||||
"evidence": "Seller shall deliver before 2026-08-20.",
|
||||
}
|
||||
clean_text = (
|
||||
"![page-image-1]\nOther clauses.\n"
|
||||
"![page-image-2]\nSeller shall deliver before 2026-08-20.\n"
|
||||
)
|
||||
|
||||
anchor = pdf_annotation.locate_ocr_evidence_page(clean_text, item)
|
||||
assert anchor is not None
|
||||
assert anchor["page_no"] == 2
|
||||
assert anchor["rects"] == []
|
||||
assert anchor["method"] == "ocr_page"
|
||||
|
||||
writer = PdfWriter()
|
||||
writer.add_blank_page(width=595, height=842)
|
||||
writer.add_blank_page(width=595, height=842)
|
||||
buffer = io.BytesIO()
|
||||
writer.write(buffer)
|
||||
annotated = pdf_annotation.build_annotated_pdf_bytes(
|
||||
buffer.getvalue(),
|
||||
[item],
|
||||
clean_text=clean_text,
|
||||
)
|
||||
reader = PdfReader(io.BytesIO(annotated))
|
||||
assert not reader.pages[0].get("/Annots", [])
|
||||
assert len(reader.pages[1].get("/Annots", [])) >= 1
|
||||
|
||||
|
||||
def test_annotate_returns_original_pdf_when_no_finding_can_be_anchored():
|
||||
"""没有可定位证据时下载仍应成功,返回未加批注的合同副本。"""
|
||||
pdf_bytes = _sample_pdf_bytes()
|
||||
annotated = pdf_annotation.build_annotated_pdf_bytes(
|
||||
pdf_bytes,
|
||||
[{"title": "Unanchored", "risk_level": "medium", "new_text": "合同中不存在的文字"}],
|
||||
)
|
||||
reader = PdfReader(io.BytesIO(annotated))
|
||||
# 关键断言:原页保留,且没有凭空生成批注。
|
||||
assert len(reader.pages) == 1
|
||||
assert not reader.pages[0].get("/Annots", [])
|
||||
@@ -0,0 +1,146 @@
|
||||
"""
|
||||
backend/tests/services/procurement_contract/test_preprocessing.py
|
||||
|
||||
用途:验证采购合同调用 MinerU 的请求协议、Markdown 读取与故障回退前提。
|
||||
依赖:procurement_contract.preprocessing、Flask 最小应用上下文。
|
||||
逻辑:模拟测试环境 MinerU 的 `/file_parse` 返回,确保 PDF 解析产物可审计且不依赖服务端文件名。
|
||||
"""
|
||||
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
|
||||
from app.services.procurement_contract import preprocessing
|
||||
|
||||
|
||||
class _MineruResponse:
|
||||
"""模拟 requests.Response,仅暴露 MinerU 客户端需要的状态和 JSON 接口。"""
|
||||
|
||||
def __init__(self, payload: dict):
|
||||
self.payload = payload
|
||||
|
||||
def raise_for_status(self) -> None:
|
||||
return None
|
||||
|
||||
def json(self) -> dict:
|
||||
return self.payload
|
||||
|
||||
|
||||
class _SourcePdf:
|
||||
"""模拟待上传的 PDF,避免测试依赖受限的本机临时目录。"""
|
||||
|
||||
name = "seller.pdf"
|
||||
|
||||
def open(self, mode: str):
|
||||
assert mode == "rb"
|
||||
|
||||
class _Handle(BytesIO):
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
self.close()
|
||||
return False
|
||||
|
||||
return _Handle(b"%PDF-1.4 test")
|
||||
|
||||
|
||||
class _Artifact:
|
||||
"""保存 MinerU 审计产物的内存替身。"""
|
||||
|
||||
def __init__(self, store: dict[str, str], name: str):
|
||||
self.store = store
|
||||
self.name = name
|
||||
|
||||
def write_text(self, content: str, *, encoding: str) -> None:
|
||||
assert encoding == "utf-8"
|
||||
self.store[self.name] = content
|
||||
|
||||
|
||||
class _OutputDir:
|
||||
"""模拟清洗目录,仅记录 MinerU 产生的 JSON 与 Markdown。"""
|
||||
|
||||
def __init__(self):
|
||||
self.files: dict[str, str] = {}
|
||||
|
||||
def __truediv__(self, name: str) -> _Artifact:
|
||||
return _Artifact(self.files, name)
|
||||
|
||||
|
||||
def _mineru_app() -> Flask:
|
||||
"""构造最小配置,隔离 MinerU 单元测试的文件输出目录。"""
|
||||
app = Flask(__name__)
|
||||
app.config.update(
|
||||
PROCUREMENT_CONTRACT_MINERU_API_URL="http://host.docker.internal:8100",
|
||||
PROCUREMENT_CONTRACT_MINERU_BACKEND="pipeline",
|
||||
PROCUREMENT_CONTRACT_MINERU_PARSE_METHOD="auto",
|
||||
PROCUREMENT_CONTRACT_MINERU_CONNECT_TIMEOUT_SECONDS=5,
|
||||
PROCUREMENT_CONTRACT_MINERU_READ_TIMEOUT_SECONDS=300,
|
||||
)
|
||||
return app
|
||||
|
||||
|
||||
def test_mineru_parse_pdf_reads_markdown_and_persists_response(monkeypatch):
|
||||
"""MinerU 成功时必须使用 files 字段,并保存原始响应供问题追溯。"""
|
||||
seen: dict = {}
|
||||
|
||||
def fake_post(url, *, data, files, timeout):
|
||||
seen.update({"url": url, "data": data, "files": files, "timeout": timeout})
|
||||
return _MineruResponse(
|
||||
{
|
||||
"status": "completed",
|
||||
"backend": "pipeline",
|
||||
"version": "3.1.14",
|
||||
"results": {"seller": {"md_content": "## 三、付款方式\n\n预付款为30%。"}},
|
||||
}
|
||||
)
|
||||
|
||||
monkeypatch.setattr(preprocessing.requests, "post", fake_post)
|
||||
source = _SourcePdf()
|
||||
output = _OutputDir()
|
||||
with _mineru_app().app_context():
|
||||
markdown, meta = preprocessing._mineru_parse_pdf(source, output)
|
||||
|
||||
# 关键断言:协议与测试环境 OpenAPI 一致,单文件结果不依赖 results 的文件名键。
|
||||
assert markdown == "## 三、付款方式\n\n预付款为30%。"
|
||||
assert seen["url"] == "http://host.docker.internal:8100/file_parse"
|
||||
assert seen["data"]["lang_list"] == "ch"
|
||||
assert seen["data"]["backend"] == "pipeline"
|
||||
assert seen["files"][0][0] == "files"
|
||||
assert meta == {
|
||||
"provider": "mineru",
|
||||
"backend": "pipeline",
|
||||
"version": "3.1.14",
|
||||
"parse_method": "auto",
|
||||
"result_artifact": "mineru_result.json",
|
||||
}
|
||||
assert output.files["mineru_document.md"] == markdown
|
||||
assert '"status": "completed"' in output.files["mineru_result.json"]
|
||||
|
||||
|
||||
def test_mineru_parse_pdf_rejects_incomplete_task_result(monkeypatch):
|
||||
"""MinerU 未完成或未返回 Markdown 时必须抛错,调用方才能安全回退旧解析器。"""
|
||||
monkeypatch.setattr(
|
||||
preprocessing.requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: _MineruResponse({"status": "failed", "error": "model unavailable"}),
|
||||
)
|
||||
with _mineru_app().app_context(), pytest.raises(RuntimeError, match="did not complete"):
|
||||
preprocessing._mineru_parse_pdf(_SourcePdf(), _OutputDir())
|
||||
|
||||
|
||||
def test_extract_page_texts_uses_mineru_logical_page_when_pdf_has_no_text_layer(monkeypatch):
|
||||
"""Readable MinerU OCR must still let comparison regions find body anchors on scanned PDFs."""
|
||||
monkeypatch.setattr(preprocessing, "_extract_pdf_page_texts", lambda _path: ["", ""])
|
||||
|
||||
pages, warning = preprocessing._extract_page_texts(
|
||||
Path("seller.pdf"),
|
||||
_OutputDir(),
|
||||
"兹因甲方向乙方购买设备\n第一条 价格不变。\n本合同一式两份。\n甲方:和信公司",
|
||||
)
|
||||
|
||||
# The logical page is only an anchor fallback; physical attachment page counts remain unavailable.
|
||||
assert pages == ["兹因甲方向乙方购买设备\n第一条 价格不变。\n本合同一式两份。\n甲方:和信公司"]
|
||||
assert warning == "PDF native page text unavailable; used MinerU logical page for body boundaries"
|
||||
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
tests/services/procurement_contract/test_review_service.py
|
||||
|
||||
用途:验证采购合同审核创建阶段的文件输入门禁。
|
||||
依赖:review_service、ValidationError。
|
||||
逻辑:在访问文件资产或数据库前,确保比对模式必须显式提供我方原合同,禁止回退默认模板。
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.procurement_contract import review_service
|
||||
|
||||
|
||||
def test_compare_review_requires_uploaded_original_contract():
|
||||
"""比对模式缺少我方原合同时应立即拒绝,防止静默使用库内默认模板。"""
|
||||
with pytest.raises(ValidationError, match="original_contract_asset_no is required"):
|
||||
review_service.start_review(
|
||||
user_id=1,
|
||||
review_mode="compare",
|
||||
contract_asset_no="FA-SELLER-RETURN",
|
||||
)
|
||||
Reference in new issue
Block a user