feat(shipping-notice): 落地 XFA 统一视觉拆分确认门禁与处理投影收敛
闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。 同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d2b3d74def
commit
84a881b554
195 files changed
+20269
-3463
No files matched your search
@@ -60,8 +60,72 @@ from app.services.shipping_notice.progress_audit_contract import (
|
||||
FIXTURE_ROOT = Path(__file__).resolve().parent / 'fixtures' / 'shipping_xfa'
|
||||
|
||||
|
||||
def _confirmed_visual_binding() -> dict[str, object]:
|
||||
"""最小已确认 visual_binding。"""
|
||||
return {
|
||||
'page_no': 1,
|
||||
'normalized_bbox': {'x0': 0.1, 'y0': 0.1, 'x1': 0.3, 'y1': 0.15},
|
||||
'source': 'manual_draw',
|
||||
'status': 'confirmed',
|
||||
'confidence': 1.0,
|
||||
}
|
||||
|
||||
|
||||
def _sample_xfa_definition(**overrides):
|
||||
"""构造合法 xfa_dataset definition 基线。"""
|
||||
"""构造合法 xfa_dataset definition 基线(bindings-only 正式路径)。"""
|
||||
payload = {
|
||||
'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': ['/data/ITEMS1/DATA'],
|
||||
},
|
||||
'header_mappings': [],
|
||||
'line_mapping': {
|
||||
'row_path': '/data/ITEMS/DATA',
|
||||
'fields': [],
|
||||
},
|
||||
'bindings': [
|
||||
{
|
||||
'binding_id': 'bind-header-po',
|
||||
'field_id': 'f-po',
|
||||
'field_code': 'customer_po_no',
|
||||
'scope': 'header',
|
||||
'value_binding': {
|
||||
'type': 'xfa_dataset',
|
||||
'path_id': 'path-header-ebeln',
|
||||
'data_path': '/data/HEADER/EBELN',
|
||||
},
|
||||
'visual_binding': _confirmed_visual_binding(),
|
||||
},
|
||||
{
|
||||
'binding_id': 'bind-line-mat',
|
||||
'field_id': 'f-mat',
|
||||
'field_code': 'material_no',
|
||||
'scope': 'line',
|
||||
'value_binding': {
|
||||
'type': 'xfa_dataset',
|
||||
'path_id': 'path-line-matnr',
|
||||
'data_path': '/data/ITEMS/DATA/MATNR',
|
||||
},
|
||||
'visual_binding': _confirmed_visual_binding(),
|
||||
},
|
||||
],
|
||||
'cross_checks': {
|
||||
'acroform_enabled': True,
|
||||
'mirror_collection_policy': 'must_match_when_present',
|
||||
'line_amount_formula': 'quantity_times_unit_price',
|
||||
'total_amount_policy': 'must_equal_line_sum',
|
||||
},
|
||||
}
|
||||
payload.update(overrides)
|
||||
return payload
|
||||
|
||||
|
||||
def _legacy_only_xfa_definition(**overrides):
|
||||
"""构造仅含 legacy mappings 的迁移输入(不可经正式 validate)。"""
|
||||
payload = {
|
||||
'template_mode': 'xfa_dataset',
|
||||
'source_contract': {
|
||||
@@ -96,6 +160,7 @@ def _sample_xfa_definition(**overrides):
|
||||
},
|
||||
],
|
||||
},
|
||||
'bindings': [],
|
||||
'cross_checks': {
|
||||
'acroform_enabled': True,
|
||||
'mirror_collection_policy': 'must_match_when_present',
|
||||
@@ -131,6 +196,12 @@ def test_xfa_definition_rejects_coordinate_region_keys():
|
||||
assert model.source_contract.authoritative_line_collection_path == '/data/ITEMS/DATA'
|
||||
|
||||
|
||||
def test_xfa_definition_rejects_legacy_only_without_bindings():
|
||||
"""关键断言:仅 legacy mappings 无 bindings 时正式 validate fail-closed。"""
|
||||
with pytest.raises(ValidationError, match='xfa_legacy_mappings_forbidden'):
|
||||
validate_xfa_dataset_definition(_legacy_only_xfa_definition())
|
||||
|
||||
|
||||
def test_controlled_data_path_rejects_wildcard_function_parent_escape_and_script():
|
||||
"""数据路径语法拒绝通配符、函数、父级逃逸、脚本。"""
|
||||
assert validate_controlled_data_path('/data/HEADER/EBELN') == '/data/HEADER/EBELN'
|
||||
|
||||
Reference in new issue
Block a user