Merge branch 'hugo-shipping-notice' into dev
# Conflicts: # docs/features/shipping-notice/process-gate-recovery-contract.md
This commit is contained in:
commit
e6449c5535
12 files changed
+639
-77
No files matched your search
@@ -0,0 +1,148 @@
|
||||
"""
|
||||
tests/test_shipping_process_gate_recovery_action_contract.py
|
||||
|
||||
用途:锁定 Gate 恢复动作投影「单一裁决」契约——库存 RPA 失败统一下发
|
||||
「重新获取库存」(retry_inventory_preparation),不再因 inventory_preparation
|
||||
Gate 的 responsible_party='worker' 被历史「worker/retry_ 技术动作屏蔽」规则
|
||||
降级为人工上传入口 (upload_inventory_file)。
|
||||
|
||||
依赖:process_gate_projection._resolve_recovery_next_action。
|
||||
逻辑:pure_unit 纯单测(不建 Flask/DB);以阻断原因码 / Gate 状态为输入,
|
||||
断言业务用户主恢复动作 next_action_code 与 technical_auto_only 标志。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.shipping_notice.process_gate_projection import (
|
||||
_resolve_recovery_next_action,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def _mk(blocking: dict, *, primary_next_action_code=None, recovery_targets=None,
|
||||
responsible_party='worker') -> dict:
|
||||
"""构造 _resolve_recovery_next_action 所需的 full / blocking 投影输入。"""
|
||||
full = {
|
||||
'primary_next_action_code': primary_next_action_code,
|
||||
'responsible_party': responsible_party,
|
||||
'recovery_targets': recovery_targets or [],
|
||||
}
|
||||
return full, blocking
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_file_empty_blocked_manual_resolves_to_retry():
|
||||
"""核心回归:inventory_file_empty + blocked_manual 必须下发「重新获取库存」。
|
||||
|
||||
真实任务 SN-20260811-717D2EAD 曾因 Gate 状态被写成 blocked_manual 而投影出
|
||||
upload_inventory_file;原因码 inventory_file_empty 在契约中属 retryable_tech,
|
||||
业务用户应可直接重试而非被迫人工上传。
|
||||
"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_file_empty'},
|
||||
primary_next_action_code='upload_inventory_file',
|
||||
)
|
||||
action, tech_only = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
assert tech_only is False
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
@pytest.mark.parametrize('reason', [
|
||||
'inventory_file_empty',
|
||||
'inventory_preparation_failed',
|
||||
'inventory_rpa_timeout',
|
||||
'inventory_rpa_login_failed',
|
||||
'inventory_rpa_export_failed',
|
||||
'inventory_file_identity_mismatch',
|
||||
'inventory_file_missing',
|
||||
'inventory_rpa_exhausted',
|
||||
])
|
||||
def test_all_inventory_rpa_retry_reasons_expose_retry_action(reason):
|
||||
"""全部库存 RPA 失败原因(无论 blocked_manual / blocked_retryable)均下发「重新获取库存」。"""
|
||||
for status in ('blocked_manual', 'blocked_retryable'):
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': status,
|
||||
'blocking_reason_code': reason},
|
||||
)
|
||||
action, tech_only = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation', (reason, status)
|
||||
assert tech_only is False
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_rpa_exhausted_falls_back_to_manual_upload():
|
||||
"""历史耗尽码仍允许用户手动重新获取库存。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_rpa_exhausted'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_file_missing_falls_back_to_manual_upload():
|
||||
"""缺库存文件时仍优先允许用户手动重新获取库存。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_file_missing'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_freight_upload_rpa_failure_keeps_retry_entry():
|
||||
"""货代上传 RPA 失败保持统一 RPA 重试入口(既有行为不回退)。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'freight_upload_rpa', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'upload_rpa_failed'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_freight_upload_rpa'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_matching_recovery_target_navigates_to_review():
|
||||
"""inventory_matching 有 RecoveryPlan 时保留复核入口(既有兜底不回退)。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_matching', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_failed'},
|
||||
recovery_targets=[{'action_code': 'retry_inventory_matching'}],
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'open_inventory_match_review'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_preparation_retryable_without_reason_uses_contract_action():
|
||||
"""无特定原因码、仅 blocked_retryable 时沿用 Gate 合同默认动作(retry_inventory_preparation)。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'blocked_retryable',
|
||||
'blocking_reason_code': None},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'retry_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_inventory_preparation_waiting_keeps_refresh_action():
|
||||
"""RPA 正在执行时只允许刷新进度,不能重复提交获取库存。"""
|
||||
full, blocking = _mk(
|
||||
{'gate_code': 'inventory_preparation', 'status': 'waiting_external',
|
||||
'blocking_reason_code': 'inventory_rpa_queued'},
|
||||
)
|
||||
action, _ = _resolve_recovery_next_action(blocking=blocking, full=full, execution=None)
|
||||
assert action == 'poll_inventory_preparation'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_no_blocking_returns_no_action():
|
||||
"""无当前阻断时不下发给任何主恢复动作。"""
|
||||
full, _ = _mk({'gate_code': 'inventory_preparation', 'status': 'passed'})
|
||||
action, _ = _resolve_recovery_next_action(blocking=None, full=full, execution=None)
|
||||
assert action is None
|
||||
@@ -348,9 +348,10 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
gate.next_action_code = 'retry_inventory_preparation'
|
||||
db.session.commit()
|
||||
|
||||
captured_payload = {}
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
lambda payload: {
|
||||
lambda payload: captured_payload.update(payload) or {
|
||||
'status': 'success',
|
||||
'data': {
|
||||
'rpa': {
|
||||
@@ -380,6 +381,7 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
task_id=task.id, execution_id=execution.id, gate_attempt_id=attempt.id,
|
||||
).one()
|
||||
assert result.get('skipped') is False
|
||||
assert captured_payload['mode'] == 'retry_rpa'
|
||||
assert attempt.status == 'succeeded'
|
||||
assert gate.status == 'passed'
|
||||
assert preparation.status == 'succeeded'
|
||||
|
||||
Reference in new issue
Block a user