feat(shipping-notice): 收敛复核状态隔离、STP 重试幂等与 XFA 合成预览标注
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
84a881b554
commit
74270adc22
149 files changed
+20111
-3871
No files matched your search
@@ -105,10 +105,12 @@ def test_visual_binding_audit_events_registered():
|
||||
|
||||
|
||||
def test_confirm_visual_binding_writes_before_after_audit(app):
|
||||
"""确认视觉绑定必须写入 before/after 审计摘要。"""
|
||||
"""确认视觉绑定必须写入 before/after 审计摘要,且须携带合成预览 checksum。"""
|
||||
from app.services.shipping_notice import order_document_profile_visual_binding_service as svc
|
||||
from app.services.shipping_notice import order_document_profile_lease_service as lease_service
|
||||
from app.services.shipping_notice.document_layout.xfa_preview_contract import RENDER_MODE
|
||||
|
||||
checksum = 'sha256:' + ('c' * 64)
|
||||
definition = {
|
||||
'template_mode': 'xfa_dataset',
|
||||
'source_contract': {
|
||||
@@ -149,7 +151,7 @@ def test_confirm_visual_binding_writes_before_after_audit(app):
|
||||
with patch.object(svc.db.session, 'flush', lambda: None):
|
||||
with patch.object(svc.db.session, 'commit', lambda: None):
|
||||
with patch.object(svc, 'record_visual_binding_audit') as audit_mock:
|
||||
svc.confirm_xfa_visual_binding(
|
||||
result = svc.confirm_xfa_visual_binding(
|
||||
1,
|
||||
'bind-test-001',
|
||||
visual_binding={
|
||||
@@ -162,6 +164,8 @@ def test_confirm_visual_binding_writes_before_after_audit(app):
|
||||
actor_id=1,
|
||||
browser_session_id='tab',
|
||||
lease_token='lease',
|
||||
preview_render_checksum=checksum,
|
||||
render_mode=RENDER_MODE,
|
||||
)
|
||||
audit_mock.assert_called_once()
|
||||
kwargs = audit_mock.call_args.kwargs
|
||||
@@ -170,3 +174,71 @@ def test_confirm_visual_binding_writes_before_after_audit(app):
|
||||
assert kwargs['after']['status'] == 'confirmed'
|
||||
assert kwargs['before']['normalized_bbox']['x0'] == 0.1
|
||||
assert kwargs['after']['normalized_bbox']['x0'] == 0.11
|
||||
assert result['visual_binding']['preview_render_checksum'] == checksum
|
||||
assert result['visual_binding']['render_mode'] == RENDER_MODE
|
||||
assert result['visual_binding']['confirmed_on'] == RENDER_MODE
|
||||
|
||||
|
||||
def test_confirm_visual_binding_requires_synthetic_preview_checksum(app):
|
||||
"""关键断言:缺 preview_render_checksum / render_mode 时确认 fail-closed。"""
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice import order_document_profile_visual_binding_service as svc
|
||||
from app.services.shipping_notice import order_document_profile_lease_service as lease_service
|
||||
|
||||
definition = {
|
||||
'template_mode': 'xfa_dataset',
|
||||
'source_contract': {
|
||||
'template_packet_checksum': 'sha256:' + ('a' * 64),
|
||||
'dataset_structure_fingerprint': 'sha256:' + ('b' * 64),
|
||||
'dataset_root_path': '/data',
|
||||
'authoritative_line_collection_path': '/data/ITEMS/DATA',
|
||||
'mirror_collection_paths': [],
|
||||
},
|
||||
'header_mappings': [],
|
||||
'line_mapping': {'row_path': '/data/ITEMS/DATA', 'fields': []},
|
||||
'bindings': [{
|
||||
'binding_id': 'bind-test-002',
|
||||
'field_id': 'f-po',
|
||||
'field_code': 'customer_po_no',
|
||||
'scope': 'header',
|
||||
'value_binding': {
|
||||
'type': 'xfa_dataset',
|
||||
'path_id': 'path-ebeln',
|
||||
'data_path': '/data/HEADER/EBELN',
|
||||
},
|
||||
'visual_binding': {
|
||||
'page_no': 1,
|
||||
'normalized_bbox': {'x0': 0.1, 'y0': 0.1, 'x1': 0.3, 'y1': 0.2},
|
||||
'source': 'suggested',
|
||||
'status': 'suggested',
|
||||
'confidence': 0.9,
|
||||
},
|
||||
}],
|
||||
}
|
||||
with patch.object(lease_service, 'require_active_lease', return_value=object()):
|
||||
with patch.object(svc, '_profile') as profile_mock:
|
||||
profile = type('P', (), {
|
||||
'id': 1,
|
||||
'status': 'draft',
|
||||
'template_mode': 'xfa_dataset',
|
||||
'definition_json': definition,
|
||||
})()
|
||||
profile_mock.return_value = profile
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
svc.confirm_xfa_visual_binding(
|
||||
1,
|
||||
'bind-test-002',
|
||||
visual_binding={
|
||||
'page_no': 1,
|
||||
'normalized_bbox': {'x0': 0.11, 'y0': 0.11, 'x1': 0.31, 'y1': 0.21},
|
||||
'source': 'manual_draw',
|
||||
'confidence': 1.0,
|
||||
},
|
||||
path_id=None,
|
||||
actor_id=1,
|
||||
browser_session_id='tab',
|
||||
lease_token='lease',
|
||||
)
|
||||
assert caught.value.code == (
|
||||
'SHIPPING.ORDER_DOCUMENT_PROFILE_XFA_CONFIRM_REQUIRES_SYNTHETIC_PREVIEW'
|
||||
)
|
||||
Reference in new issue
Block a user