Files
syops/backend/tests/test_shipping_xfa_evidence_retention.py
hugoandCursor 84a881b554 feat(shipping-notice): 落地 XFA 统一视觉拆分确认门禁与处理投影收敛
闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。
同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 10:21:25 +08:00

59 lines
1.9 KiB
Python

"""
tests/test_shipping_xfa_evidence_retention.py
用途:阶段 5 evidence_only 保留率——MATNR 第 2/4/5 行 100%。
依赖:xfa_validation.compute_evidence_retention_rate、formal_multiline helpers。
逻辑:正式提取后断言期望行号全部保留;人为缺行时保留率 < 1.0。
"""
from __future__ import annotations
import pytest
from app.services.shipping_notice.document_layout.xfa_dataset import parse_xfa_datasets
from app.services.shipping_notice.document_layout.xfa_profile_extraction import extract_xfa_profile
from app.services.shipping_notice.document_layout.xfa_validation import (
compute_evidence_retention_rate,
)
from tests.test_shipping_xfa_formal_multiline_extraction import (
_confirmed_matnr_rule_set,
_multiline_datasets_xml,
_raw_profile,
_schema_definition,
)
pytestmark = pytest.mark.pure_unit
EXPECTED_EVIDENCE_LINES = {2, 4, 5}
def test_matnr_lines_2_4_5_evidence_retention_100_percent():
"""关键断言:第 2/4/5 行 evidence_only 保留率 100%。"""
analysis = parse_xfa_datasets(_multiline_datasets_xml())
result = extract_xfa_profile(
raw_profile=_raw_profile(split_rules=[_confirmed_matnr_rule_set()]),
dataset_analysis=analysis,
schema_definition=_schema_definition(),
document_id=1,
packet_checksum='pkt-evidence-retain',
)
rate = compute_evidence_retention_rate(
extraction=result,
expected_line_nos=EXPECTED_EVIDENCE_LINES,
)
assert rate == 1.0
def test_missing_evidence_line_lowers_retention_rate():
"""关键断言:缺少期望证据行时保留率低于 100%。"""
rate = compute_evidence_retention_rate(
evidence_segments=[
{'line_no': 2, 'normalized_text': 'CAB'},
{'line_no': 4, 'normalized_text': 'Cust'},
# 故意缺少第 5 行
],
expected_line_nos=EXPECTED_EVIDENCE_LINES,
)
assert rate < 1.0
assert abs(rate - (2 / 3)) < 1e-6