refactor(shipping-notice): 收紧通知单与导出上传事实边界

This commit is contained in:
hugo committed 2026-09-04 20:49:03 +08:00
1 parent b5d894a923
commit 8ec028e6a3
12 files changed
+312 -318

No files matched your search

@@ -53,9 +53,14 @@ def test_inventory_callback_id_is_checked_before_attempt_identity(app):
task = ShippingNotice(task_no='SN-CB-ID-FIRST', source_type='manual')
db.session.add(task)
db.session.flush()
# 冻结的逐源 Attempt 须携带完整 v2 身份(lease_token / candidate_set / execution / gate),
# 否则回调会先在 _validate_callback_attempt_identity 被 identity_mismatch 拒绝,
# 无法走到失败分支去写 callback_id。
first = ShippingTaskInventoryRpaAttempt(
task_no=task.task_no, source_code='SRC-A', attempt_no=1,
source_run_no='PSR-FIRST', status='failed', callback_id=None,
lease_token='lease-first',
extra_json={'candidate_set_id': 1, 'execution_id': 1, 'gate_id': 1},
)
second = ShippingTaskInventoryRpaAttempt(
task_no='SN-CB-ID-OTHER', source_code='SRC-B', attempt_no=1,
@@ -64,23 +69,43 @@ def test_inventory_callback_id_is_checked_before_attempt_identity(app):
db.session.add_all([first, second])
db.session.flush()
def _payload(run_no: str, source_code: str, attempt_no: int) -> dict:
"""构造完整 v2 身份围栏的回调 payload。
与 _validate_callback_attempt_identity 的 required 字段一一对应,
使失败回调(error_code)能通过身份校验并回写 callback_id。
"""
return {
'schema_version': 'shipping_inventory_rpa.v2',
'callback_id': 'cb-unique',
'task_no': task.task_no,
'source_code': source_code,
'source_run_no': run_no,
'attempt_no': attempt_no,
'lease_token': 'lease-first',
'candidate_set_id': 1,
'execution_id': 1,
'gate_id': 1,
'error_code': 'RPA_TIMEOUT',
}
result, handled = per_source_callback_handler(
task, source_code='SRC-A', run_no='PSR-FIRST',
callback_payload={'callback_id': 'cb-unique', 'error_code': 'RPA_TIMEOUT'},
callback_payload=_payload('PSR-FIRST', 'SRC-A', 1),
)
assert result == 'failed'
assert handled.id == first.id
result, handled = per_source_callback_handler(
task, source_code='SRC-A', run_no='PSR-FIRST',
callback_payload={'callback_id': 'cb-unique', 'error_code': 'RPA_TIMEOUT'},
callback_payload=_payload('PSR-FIRST', 'SRC-A', 1),
)
assert result == 'idempotent_ok'
assert handled.id == first.id
result, handled = per_source_callback_handler(
task, source_code='SRC-B', run_no='PSR-SECOND',
callback_payload={'callback_id': 'cb-unique', 'error_code': 'RPA_TIMEOUT'},
callback_payload=_payload('PSR-SECOND', 'SRC-B', 1),
)
assert result == 'callback_conflict'
assert handled.id == first.id