chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -181,6 +181,80 @@ def test_execute_blank_native_pdf_returns_empty_suggestions():
|
||||
assert profile.definition_json['xfa_ocr_automark']['suggestion_count'] == 0
|
||||
|
||||
|
||||
def test_execute_automark_collects_widget_before_failing_unavailable_ocr():
|
||||
"""关键断言:OCR 是强制证据,但其失败不得阻止独立 Widget 采集和审计。"""
|
||||
from app.core.errors import ServiceUnavailableError
|
||||
from app.services.shipping_notice.order_document_profile_xfa_automark_service import (
|
||||
execute_xfa_ocr_automark_job,
|
||||
)
|
||||
|
||||
profile = MagicMock(
|
||||
id=12,
|
||||
status='draft',
|
||||
template_mode='xfa_dataset',
|
||||
definition_json=_definition_with_binding(),
|
||||
)
|
||||
native = {
|
||||
'pages': [{'page_no': 1, 'png_bytes': b'png'}],
|
||||
'page_count': 1,
|
||||
'preview_render_checksum': 'sha256:' + ('d' * 64),
|
||||
'renderer_version': 'hxops.native_pdf.v1',
|
||||
'render_mode': 'native_pdf',
|
||||
}
|
||||
widget = {
|
||||
'field_key': 'path-po',
|
||||
'page_no': 1,
|
||||
'normalized_bbox': {'x0': 0.1, 'y0': 0.2, 'x1': 0.4, 'y1': 0.3},
|
||||
'confidence': 0.95,
|
||||
}
|
||||
merged = {
|
||||
'suggested_visual_bindings': [{
|
||||
**widget,
|
||||
'source': 'acroform_widget',
|
||||
'match_class': 'high',
|
||||
'suggestion_origin': 'widget_template',
|
||||
}],
|
||||
}
|
||||
with patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service._profile',
|
||||
return_value=profile,
|
||||
), patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service._load_native_pdf_pages_for_ocr',
|
||||
return_value=native,
|
||||
), patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service._dataset_targets_flat',
|
||||
return_value=[{'field_key': 'path-po', 'value': 'PO-1'}],
|
||||
), patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service._widget_candidates_for_page',
|
||||
return_value=[widget],
|
||||
), patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service.recognize_preview_page',
|
||||
side_effect=ServiceUnavailableError('OCR unavailable', code='SHIPPING.ORDER_DOCUMENT_PROFILE_XFA_OCR_UNAVAILABLE'),
|
||||
), patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service.merge_visual_binding_suggestions',
|
||||
return_value=merged,
|
||||
) as merge_mock, patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service._audit_automark',
|
||||
) as audit_mock, patch(
|
||||
'app.services.shipping_notice.order_document_profile_xfa_automark_service.db',
|
||||
):
|
||||
with pytest.raises(Exception, match='XFA native PDF OCR is unavailable'):
|
||||
execute_xfa_ocr_automark_job({
|
||||
'profile_id': 12,
|
||||
'document_id': 77,
|
||||
'actor_id': 1,
|
||||
'job_id': 9,
|
||||
})
|
||||
|
||||
# Widget 已独立采集;OCR 缺失时不产生不完整的融合建议。
|
||||
assert merge_mock.call_count == 0
|
||||
assert any(
|
||||
call.kwargs.get('event_type') == 'xfa_ocr_failed'
|
||||
and call.kwargs.get('detail', {}).get('widget_candidate_count') == 1
|
||||
for call in audit_mock.call_args_list
|
||||
)
|
||||
|
||||
|
||||
def test_accept_high_requires_checksum_and_confirms(app):
|
||||
"""关键断言:high 接受走 confirm,且须携带 preview_render_checksum。"""
|
||||
from app.services.shipping_notice import order_document_profile_lease_service as lease_service
|
||||
|
||||
Reference in new issue
Block a user