feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -0,0 +1,91 @@
|
||||
"""
|
||||
tests/test_shipping_xfa_split_audit.py
|
||||
|
||||
用途:锁定 XFA 字段拆分相关审计事件码已注册,且 segment 级 diff 审计会实际写入。
|
||||
依赖:xfa_contract、progress_audit_contract、order_document_profile_service。
|
||||
逻辑:契约级断言 + 对 `_audit_xfa_split_segment_changes` 的 mock 断言;不接真实 PDF。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.services.shipping_notice.document_layout.xfa_contract import XFA_AUDIT_EVENT_TYPES
|
||||
from app.services.shipping_notice.progress_audit_contract import XFA_PROGRESS_EVENT_CODES
|
||||
from app.services.shipping_notice import order_document_profile_service as profiles
|
||||
|
||||
|
||||
REQUIRED_SPLIT_AUDIT_EVENTS = (
|
||||
'xfa_split_rule_suggested',
|
||||
'xfa_split_rule_previewed',
|
||||
'xfa_split_rule_validated',
|
||||
'xfa_split_segment_created',
|
||||
'xfa_split_segment_updated',
|
||||
'xfa_split_segment_deleted',
|
||||
'xfa_segment_mapping_updated',
|
||||
'xfa_profile_draft_saved',
|
||||
'xfa_profile_validation_executed',
|
||||
'xfa_profile_published',
|
||||
'xfa_profile_formal_extracted',
|
||||
'xfa_profile_needs_review',
|
||||
)
|
||||
|
||||
|
||||
def test_split_audit_events_registered_in_contracts():
|
||||
"""拆分映射审计事件必须同时出现在 XFA 契约与进度事件白名单。"""
|
||||
for event in REQUIRED_SPLIT_AUDIT_EVENTS:
|
||||
assert event in XFA_AUDIT_EVENT_TYPES, event
|
||||
assert event in XFA_PROGRESS_EVENT_CODES, event
|
||||
|
||||
|
||||
def _rule_set(*, segment_id: str, handling: str = 'mapped', target: str | None = 'customer_part_number') -> dict:
|
||||
"""构造最小可 diff 的拆分规则集(stages 流水线)。"""
|
||||
return {
|
||||
'rule_id': 'rs-1',
|
||||
'rule_version': 1,
|
||||
'source_path_id': 'path-matnr',
|
||||
'source_field_code': 'MATNR',
|
||||
'strategy': 'pipeline',
|
||||
'rules': [{
|
||||
'rule_id': 'r-1',
|
||||
'order': 1,
|
||||
'stages': [
|
||||
{'stage_id': 'st-split', 'type': 'split_lines', 'line_breaks': ['\n']},
|
||||
{'stage_id': 'st-sel', 'type': 'select_line', 'line_index': 1},
|
||||
],
|
||||
'segment': {
|
||||
'segment_id': segment_id,
|
||||
'segment_code': 'cpn' if segment_id == 'seg-a' else segment_id.replace('-', '_'),
|
||||
'display_name': 'CPN',
|
||||
'handling': handling,
|
||||
'target_field_id': 'f-x' if handling == 'mapped' else None,
|
||||
'target_field_code': target,
|
||||
},
|
||||
}],
|
||||
}
|
||||
|
||||
|
||||
def test_audit_xfa_split_segment_changes_emits_create_update_delete_and_mapping():
|
||||
"""保存前后 definition diff 必须产出 segment 级审计事件(非仅登记事件码)。"""
|
||||
before = {'split_rules': [_rule_set(segment_id='seg-a'), _rule_set(segment_id='seg-b', handling='evidence_only', target=None)]}
|
||||
after = {
|
||||
'split_rules': [
|
||||
_rule_set(segment_id='seg-a', target='part_number'), # mapping 变更
|
||||
_rule_set(segment_id='seg-c', handling='evidence_only', target=None), # 新增
|
||||
# seg-b 删除
|
||||
],
|
||||
}
|
||||
with patch.object(profiles, '_audit') as audit_mock:
|
||||
profiles._audit_xfa_split_segment_changes(
|
||||
profile_id=9,
|
||||
actor_id=7,
|
||||
operation_id='op-split-1',
|
||||
browser_session_id='tab-1',
|
||||
previous_definition=before,
|
||||
next_definition=after,
|
||||
)
|
||||
events = [call.kwargs['event_type'] for call in audit_mock.call_args_list]
|
||||
assert 'xfa_split_segment_created' in events
|
||||
assert 'xfa_split_segment_deleted' in events
|
||||
assert 'xfa_segment_mapping_updated' in events
|
||||
assert all(call.kwargs.get('actor_id') == 7 for call in audit_mock.call_args_list)
|
||||
Reference in new issue
Block a user