Files
syops/backend/tests/test_shipping_field_highlight_audit.py
hugo 3a9fbac2fc feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估
- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。
- 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。
- 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。
- 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。
- 增强文档与代码注释,反映新的业务逻辑与功能要求。
2026-08-02 19:26:35 +08:00

59 lines
2.4 KiB
Python

"""
tests/test_shipping_field_highlight_audit.py
用途:锁定阶段 5 坐标高亮审计摘要与事件字典完整性。
依赖:order_review_evidence_service.build_highlight_audit_summary、progress_audit_contract。
逻辑:pure_unit;禁止摘要含 PDF 正文/URL/密钥;事件码必须在工作台冻结集合内。
"""
from __future__ import annotations
import pytest
from app.services.shipping_notice.order_review_evidence_service import build_highlight_audit_summary
from app.services.shipping_notice.progress_audit_contract import (
REVIEW_WORKBENCH_ACCESS_ACTIONS,
REVIEW_WORKBENCH_AUDIT_EVENT_TYPES,
)
pytestmark = pytest.mark.pure_unit
def test_highlight_audit_events_are_frozen():
"""坐标相关审计事件与访问 action 必须已冻结。"""
assert 'review_evidence_list_viewed' in REVIEW_WORKBENCH_AUDIT_EVENT_TYPES
assert 'review_evidence_focused' in REVIEW_WORKBENCH_AUDIT_EVENT_TYPES
assert 'review_highlight_diagnostic_viewed' in REVIEW_WORKBENCH_AUDIT_EVENT_TYPES
assert 'review_coordinate_corrected' in REVIEW_WORKBENCH_AUDIT_EVENT_TYPES
assert 'review_field_restored_machine' in REVIEW_WORKBENCH_AUDIT_EVENT_TYPES
assert 'review_version_history_viewed' in REVIEW_WORKBENCH_AUDIT_EVENT_TYPES
assert 'view_order_review_highlight_diagnostic' in REVIEW_WORKBENCH_ACCESS_ACTIONS
def test_highlight_audit_summary_omits_sensitive_payload():
"""审计摘要不得包含 PDF 正文、存储键或 URL。"""
summary = build_highlight_audit_summary({
'evidence_id': 'qty:header:0',
'field_id': 'qty',
'page_no': 1,
'highlight_quality': 'unavailable',
'coordinate_status': 'unavailable',
'highlight_source': 'ocr',
'coordinate_issue_codes': ['ocr_confidence_insufficient'],
'highlight_bbox': None,
'evidence_ref': 'layout:1:p1:table-1:cell-r2-c6',
'table_id': 'table-1',
'cell_id': 'cell-r2-c6',
'quote': 'SECRET-PDF-BODY',
'machine_value': '20',
'storage_key': 'minio://bucket/key',
'url': 'https://example.invalid/secret',
})
raw = str(summary)
assert 'SECRET-PDF-BODY' not in raw
assert 'minio://' not in raw
assert 'https://' not in raw
assert summary['highlight_quality'] == 'unavailable'
assert summary['has_drawable_bbox'] is False
assert 'ocr_confidence_insufficient' in summary['coordinate_issue_codes']