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
@@ -50,13 +50,77 @@ def _schema_definition() -> dict:
|
||||
return {'fields': fields}
|
||||
|
||||
|
||||
def _xfa_binding(
|
||||
*,
|
||||
binding_id: str,
|
||||
field_id: str,
|
||||
field_code: str,
|
||||
scope: str,
|
||||
path_id: str,
|
||||
data_path: str,
|
||||
) -> dict:
|
||||
"""构造最小合法统一 binding(正式提取 bindings-only)。"""
|
||||
return {
|
||||
'binding_id': binding_id,
|
||||
'field_id': field_id,
|
||||
'field_code': field_code,
|
||||
'scope': scope,
|
||||
'value_binding': {
|
||||
'type': 'xfa_dataset',
|
||||
'path_id': path_id,
|
||||
'data_path': data_path,
|
||||
},
|
||||
'visual_binding': {
|
||||
'page_no': 1,
|
||||
'normalized_bbox': {'x0': 0.0, 'y0': 0.0, 'x1': 0.02, 'y1': 0.02},
|
||||
'source': 'suggested',
|
||||
'status': 'suggested',
|
||||
'confidence': 0.0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _raw_profile(*, authoritative: str = '/data/ITEMS/DATA') -> dict:
|
||||
"""构造冻结 XFA Profile。"""
|
||||
"""构造冻结 XFA Profile(bindings-only,无 legacy mappings)。"""
|
||||
analysis = parse_xfa_datasets(load_datasets_fixture())
|
||||
summary = build_signature_summary(
|
||||
template_bytes=b'<template><subform name="form"/></template>',
|
||||
dataset_nodes=analysis.nodes,
|
||||
)
|
||||
bindings = [
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-po', field_id='f-po', field_code='customer_po_no',
|
||||
scope='header', path_id='path-po', data_path='/data/HEADER/EBELN',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-total', field_id='f-total', field_code='total_amount',
|
||||
scope='header', path_id='path-total', data_path='/data/HEADER/TOTAL_AMOUNT',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-mat', field_id='f-mat', field_code='material_no',
|
||||
scope='line', path_id='path-mat', data_path=f'{authoritative}/MATNR',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-qty', field_id='f-qty', field_code='quantity',
|
||||
scope='line', path_id='path-qty', data_path=f'{authoritative}/MENGE',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-price', field_id='f-price', field_code='unit_price',
|
||||
scope='line', path_id='path-price', data_path=f'{authoritative}/NETPR',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-pu', field_id='f-pu', field_code='price_unit',
|
||||
scope='line', path_id='path-pu', data_path=f'{authoritative}/PEINH',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-amt', field_id='f-amt', field_code='amount',
|
||||
scope='line', path_id='path-amt', data_path=f'{authoritative}/AMOUNT',
|
||||
),
|
||||
_xfa_binding(
|
||||
binding_id='bind-m-date', field_id='f-date', field_code='delivery_date',
|
||||
scope='line', path_id='path-date', data_path=f'{authoritative}/EINDT',
|
||||
),
|
||||
]
|
||||
return {
|
||||
'profile_id': 7,
|
||||
'profile_code': 'XFA_GOLDEN',
|
||||
@@ -73,53 +137,12 @@ def _raw_profile(*, authoritative: str = '/data/ITEMS/DATA') -> dict:
|
||||
'authoritative_line_collection_path': authoritative,
|
||||
'mirror_collection_paths': ['/data/ITEMS1/DATA'],
|
||||
},
|
||||
'header_mappings': [
|
||||
{
|
||||
'mapping_id': 'm-po', 'field_id': 'f-po', 'field_code': 'customer_po_no',
|
||||
'data_path': '/data/HEADER/EBELN', 'path_id': 'path-po',
|
||||
'value_type': 'string', 'normalizer_key': 'trim',
|
||||
},
|
||||
{
|
||||
'mapping_id': 'm-total', 'field_id': 'f-total', 'field_code': 'total_amount',
|
||||
'data_path': '/data/HEADER/TOTAL_AMOUNT', 'path_id': 'path-total',
|
||||
'value_type': 'decimal', 'normalizer_key': 'trim',
|
||||
},
|
||||
],
|
||||
'header_mappings': [],
|
||||
'line_mapping': {
|
||||
'row_path': authoritative,
|
||||
'fields': [
|
||||
{
|
||||
'mapping_id': 'm-mat', 'field_id': 'f-mat', 'field_code': 'material_no',
|
||||
'data_path': f'{authoritative}/MATNR', 'path_id': 'path-mat',
|
||||
'value_type': 'string', 'normalizer_key': 'trim',
|
||||
},
|
||||
{
|
||||
'mapping_id': 'm-qty', 'field_id': 'f-qty', 'field_code': 'quantity',
|
||||
'data_path': f'{authoritative}/MENGE', 'path_id': 'path-qty',
|
||||
'value_type': 'decimal', 'normalizer_key': 'trim',
|
||||
},
|
||||
{
|
||||
'mapping_id': 'm-price', 'field_id': 'f-price', 'field_code': 'unit_price',
|
||||
'data_path': f'{authoritative}/NETPR', 'path_id': 'path-price',
|
||||
'value_type': 'decimal', 'normalizer_key': 'trim',
|
||||
},
|
||||
{
|
||||
'mapping_id': 'm-pu', 'field_id': 'f-pu', 'field_code': 'price_unit',
|
||||
'data_path': f'{authoritative}/PEINH', 'path_id': 'path-pu',
|
||||
'value_type': 'integer', 'normalizer_key': 'trim',
|
||||
},
|
||||
{
|
||||
'mapping_id': 'm-amt', 'field_id': 'f-amt', 'field_code': 'amount',
|
||||
'data_path': f'{authoritative}/AMOUNT', 'path_id': 'path-amt',
|
||||
'value_type': 'decimal', 'normalizer_key': 'trim',
|
||||
},
|
||||
{
|
||||
'mapping_id': 'm-date', 'field_id': 'f-date', 'field_code': 'delivery_date',
|
||||
'data_path': f'{authoritative}/EINDT', 'path_id': 'path-date',
|
||||
'value_type': 'date', 'normalizer_key': 'trim',
|
||||
},
|
||||
],
|
||||
'fields': [],
|
||||
},
|
||||
'bindings': bindings,
|
||||
'cross_checks': {
|
||||
'acroform_enabled': True,
|
||||
'mirror_collection_policy': 'must_match_when_present',
|
||||
@@ -179,11 +202,13 @@ def test_authoritative_collection_missing_fails_closed():
|
||||
"""关键断言:权威集合缺失 → needs_review reason。"""
|
||||
analysis = parse_xfa_datasets(load_datasets_fixture())
|
||||
raw_profile = _raw_profile(authoritative='/data/ITEMS/MISSING')
|
||||
# row_path 必须等于 authoritative;手工破坏集合路径以模拟缺失。
|
||||
raw_profile['definition']['source_contract']['authoritative_line_collection_path'] = '/data/ITEMS/MISSING'
|
||||
raw_profile['definition']['line_mapping']['row_path'] = '/data/ITEMS/MISSING'
|
||||
for item in raw_profile['definition']['line_mapping']['fields']:
|
||||
item['data_path'] = item['data_path'].replace('/data/ITEMS/DATA', '/data/ITEMS/MISSING')
|
||||
for item in raw_profile['definition']['bindings']:
|
||||
if item.get('scope') == 'line':
|
||||
item['value_binding']['data_path'] = str(item['value_binding']['data_path']).replace(
|
||||
'/data/ITEMS/DATA', '/data/ITEMS/MISSING',
|
||||
)
|
||||
result = extract_xfa_profile(
|
||||
raw_profile=raw_profile,
|
||||
dataset_analysis=analysis,
|
||||
@@ -216,12 +241,11 @@ def test_netpr_composite_splits_unit_price_and_price_unit():
|
||||
)
|
||||
assert typed == Decimal('898.72')
|
||||
|
||||
# 正式提取:去掉 PEINH 映射后仍应由 NETPR 复合值补齐 price_unit。
|
||||
# 正式提取:去掉 price_unit binding 后仍应由 NETPR 复合值补齐 price_unit。
|
||||
analysis = parse_xfa_datasets(load_datasets_fixture())
|
||||
raw_profile = _raw_profile()
|
||||
raw_profile['definition']['line_mapping']['fields'] = [
|
||||
item
|
||||
for item in raw_profile['definition']['line_mapping']['fields']
|
||||
raw_profile['definition']['bindings'] = [
|
||||
item for item in raw_profile['definition']['bindings']
|
||||
if item.get('field_code') != 'price_unit'
|
||||
]
|
||||
result = extract_xfa_profile(
|
||||
@@ -241,3 +265,39 @@ def test_netpr_composite_splits_unit_price_and_price_unit():
|
||||
if item.get('field_code') == 'unit_price'
|
||||
)
|
||||
assert '898.72 / 1' in str(unit_item.get('quote') or '')
|
||||
|
||||
|
||||
def test_missing_bindings_fails_closed():
|
||||
"""关键断言:无 bindings → xfa_visual_bindings_required。"""
|
||||
analysis = parse_xfa_datasets(load_datasets_fixture())
|
||||
raw_profile = _raw_profile()
|
||||
raw_profile['definition']['bindings'] = []
|
||||
result = extract_xfa_profile(
|
||||
raw_profile=raw_profile,
|
||||
dataset_analysis=analysis,
|
||||
schema_definition=_schema_definition(),
|
||||
document_id=85,
|
||||
packet_checksum='sha256:' + ('a' * 64),
|
||||
)
|
||||
assert result.status == 'failed'
|
||||
assert 'xfa_visual_bindings_required' in result.reason_codes
|
||||
|
||||
|
||||
def test_dual_binding_source_fails_closed():
|
||||
"""关键断言:bindings 与 legacy mappings 共存 → xfa_dual_binding_source。"""
|
||||
analysis = parse_xfa_datasets(load_datasets_fixture())
|
||||
raw_profile = _raw_profile()
|
||||
raw_profile['definition']['header_mappings'] = [{
|
||||
'mapping_id': 'm-po', 'field_id': 'f-po', 'field_code': 'customer_po_no',
|
||||
'data_path': '/data/HEADER/EBELN', 'path_id': 'path-po',
|
||||
'value_type': 'string', 'normalizer_key': 'trim',
|
||||
}]
|
||||
result = extract_xfa_profile(
|
||||
raw_profile=raw_profile,
|
||||
dataset_analysis=analysis,
|
||||
schema_definition=_schema_definition(),
|
||||
document_id=85,
|
||||
packet_checksum='sha256:' + ('a' * 64),
|
||||
)
|
||||
assert result.status == 'failed'
|
||||
assert 'xfa_dual_binding_source' in result.reason_codes
|
||||
Reference in new issue
Block a user