feat(shipping-notice): 完成货代发货通知全门禁恢复MVP收口
完成全门禁恢复MVP版本交付:调整自动上传与重试配置,重构正式执行链路;修复多处代码bug,新增测试与审计工具;更新全流程文档与契约规范。
This commit is contained in:
1 parent
8e0bbf7a81
commit
c94d173f92
181 files changed
+12947
-1724
No files matched your search
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
用途:验证上传未知状态保护,防止未知回执下重复创建或回写旧 Artifact。
|
||||
依赖:upload_attempt_service、ShippingUploadAttempt 模型。
|
||||
逻辑:覆盖 unknown 状态创建保护和 Artifact superseded 回调拒绝。
|
||||
"""
|
||||
|
||||
from app.core.errors import ConflictError
|
||||
|
||||
|
||||
def test_unknown_upload_blocks_new_idempotency_key_and_superseded_callback(app):
|
||||
"""unknown 必须阻断全新重试键;Artifact superseded 后任何回调只返回冲突。"""
|
||||
from app import db
|
||||
from app.models import ShippingExportArtifact
|
||||
from app.services.shipping_notice.upload_attempt_service import (
|
||||
mark_attempt_result_unknown,
|
||||
start_rpa_attempt,
|
||||
)
|
||||
from tests.test_shipping_upload_attempt import _ready_artifact
|
||||
|
||||
with app.app_context():
|
||||
task, artifact, _reservation = _ready_artifact()
|
||||
attempt = start_rpa_attempt(task, artifact_id=artifact.id)
|
||||
mark_attempt_result_unknown(attempt)
|
||||
try:
|
||||
start_rpa_attempt(task, artifact_id=artifact.id, idempotency_key='fresh-retry-key')
|
||||
except ConflictError as exc:
|
||||
assert exc.code == 'SHIPPING.UPLOAD_RETRY_FORBIDDEN_UNTIL_TERMINAL'
|
||||
else:
|
||||
raise AssertionError('unknown upload must block a fresh retry key')
|
||||
|
||||
artifact.status = 'superseded'
|
||||
db.session.flush()
|
||||
from app.services.shipping_notice.upload_attempt_service import complete_attempt
|
||||
try:
|
||||
complete_attempt(attempt, success=True, callback_id='superseded-callback')
|
||||
except ConflictError as exc:
|
||||
assert exc.code == 'SHIPPING.ARTIFACT_ALREADY_SUPERSEDED'
|
||||
else:
|
||||
raise AssertionError('superseded Artifact must reject callbacks')
|
||||
|
||||
|
||||
def test_upload_unknown_error_codes_are_stable():
|
||||
"""稳定错误码必须区分未知状态与已失效 Artifact。"""
|
||||
assert ConflictError('x', code='SHIPPING.UPLOAD_ATTEMPT_STATUS_UNKNOWN').code == 'SHIPPING.UPLOAD_ATTEMPT_STATUS_UNKNOWN'
|
||||
assert ConflictError('x', code='SHIPPING.ARTIFACT_ALREADY_SUPERSEDED').code == 'SHIPPING.ARTIFACT_ALREADY_SUPERSEDED'
|
||||
|
||||
|
||||
def test_inventory_callback_id_is_checked_before_attempt_identity(app):
|
||||
"""库存回调先按 callback_id 去重,跨 Attempt 重放不得写入另一条 Attempt。"""
|
||||
from app import db
|
||||
from app.models import ShippingNotice, ShippingTaskInventoryRpaAttempt
|
||||
from app.services.shipping_notice.per_source_rpa_service import per_source_callback_handler
|
||||
|
||||
with app.app_context():
|
||||
task = ShippingNotice(task_no='SN-CB-ID-FIRST', source_type='manual', process_status='waiting_inventory')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
first = ShippingTaskInventoryRpaAttempt(
|
||||
task_no=task.task_no, source_code='SRC-A', attempt_no=1,
|
||||
source_run_no='PSR-FIRST', status='failed', callback_id=None,
|
||||
)
|
||||
second = ShippingTaskInventoryRpaAttempt(
|
||||
task_no='SN-CB-ID-OTHER', source_code='SRC-B', attempt_no=1,
|
||||
source_run_no='PSR-SECOND', status='failed', callback_id=None,
|
||||
)
|
||||
db.session.add_all([first, second])
|
||||
db.session.flush()
|
||||
|
||||
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'},
|
||||
)
|
||||
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'},
|
||||
)
|
||||
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'},
|
||||
)
|
||||
assert result == 'callback_conflict'
|
||||
assert handled.id == first.id
|
||||
Reference in new issue
Block a user