chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -173,6 +173,106 @@ def test_ensure_execution_creates_all_contract_gates(gate_execution):
|
||||
|
||||
|
||||
|
||||
def test_ensure_execution_for_task_ignores_superseded_execution(app):
|
||||
|
||||
"""Task 指针指向已替代 Execution 时必须创建新正式链,不能复用历史 Gate。"""
|
||||
|
||||
with app.app_context():
|
||||
|
||||
_user, _review_case_id, task_id = _seed_workflow_version(suffix='superseded-task')
|
||||
|
||||
old = ensure_execution_for_workflow_version(task_id=task_id, actor_type='system')
|
||||
|
||||
old.status = 'superseded'
|
||||
|
||||
db.session.flush()
|
||||
|
||||
current = ensure_execution_for_workflow_version(task_id=task_id, actor_type='system')
|
||||
|
||||
assert current.id != old.id
|
||||
|
||||
assert current.status == 'active'
|
||||
|
||||
|
||||
|
||||
def test_auto_progress_does_not_queue_manual_inventory_retry(gate_execution, monkeypatch):
|
||||
|
||||
"""自动推进不得把用户恢复动作 retry_inventory_preparation 重新触发为 RPA。"""
|
||||
|
||||
from app.services.shipping_notice import process_gate_service
|
||||
|
||||
for prior_gate in (
|
||||
ShippingProcessGate.query
|
||||
.filter(
|
||||
ShippingProcessGate.execution_id == int(gate_execution.id),
|
||||
ShippingProcessGate.sequence_no < 13,
|
||||
)
|
||||
.all()
|
||||
):
|
||||
prior_gate.status = 'passed'
|
||||
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
|
||||
).one()
|
||||
gate.status = 'blocked_retryable'
|
||||
gate.next_action_code = 'retry_inventory_preparation'
|
||||
process_gate_service._refresh_execution_pointers(gate_execution)
|
||||
db.session.flush()
|
||||
|
||||
queued: list[dict[str, object]] = []
|
||||
monkeypatch.setattr(
|
||||
process_gate_service,
|
||||
'queue_gate_attempt',
|
||||
lambda **kwargs: queued.append(kwargs),
|
||||
)
|
||||
|
||||
process_gate_service._enqueue_auto_progress_after_gate_pass(
|
||||
execution=gate_execution,
|
||||
gate=gate,
|
||||
)
|
||||
|
||||
assert queued == []
|
||||
|
||||
|
||||
def test_auto_progress_does_not_queue_manual_inventory_navigation(gate_execution, monkeypatch):
|
||||
"""库存已入库后的 upload_inventory_file 是导航动作,不能被自动续跑执行。"""
|
||||
from app.services.shipping_notice import process_gate_service
|
||||
|
||||
for prior_gate in (
|
||||
ShippingProcessGate.query
|
||||
.filter(
|
||||
ShippingProcessGate.execution_id == int(gate_execution.id),
|
||||
ShippingProcessGate.sequence_no < 13,
|
||||
)
|
||||
.all()
|
||||
):
|
||||
prior_gate.status = 'passed'
|
||||
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
|
||||
).one()
|
||||
gate.status = 'blocked_manual'
|
||||
gate.blocking_reason_code = 'inventory_rpa_timeout'
|
||||
gate.next_action_code = 'upload_inventory_file'
|
||||
process_gate_service._refresh_execution_pointers(gate_execution)
|
||||
db.session.flush()
|
||||
|
||||
queued: list[dict[str, object]] = []
|
||||
monkeypatch.setattr(
|
||||
process_gate_service,
|
||||
'queue_gate_attempt',
|
||||
lambda **kwargs: queued.append(kwargs),
|
||||
)
|
||||
|
||||
process_gate_service._enqueue_auto_progress_after_gate_pass(
|
||||
execution=gate_execution,
|
||||
gate=gate,
|
||||
)
|
||||
|
||||
assert queued == []
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_fingerprint_skip_does_not_rerun_passed_gate(gate_execution):
|
||||
@@ -684,3 +784,29 @@ def test_idempotent_key_conflicts_across_execution(app):
|
||||
)
|
||||
|
||||
assert exc.value.code == 'SHIPPING.PROCESS_GATE_IDEMPOTENCY_CONFLICT'
|
||||
|
||||
|
||||
def test_superseded_execution_rejects_late_business_gate_result(app):
|
||||
"""候选版本已替换后,迟到结果不得重新写回旧 Gate。"""
|
||||
from app.core.errors import ConflictError
|
||||
|
||||
with app.app_context():
|
||||
_user, review_case_id, task_id = _seed_workflow_version(suffix='superseded-sync')
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
review_case_id=review_case_id,
|
||||
task_id=task_id,
|
||||
)
|
||||
execution.status = 'superseded'
|
||||
db.session.flush()
|
||||
|
||||
with pytest.raises(ConflictError) as exc:
|
||||
sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
passed=False,
|
||||
blocking_reason_code='inventory_preparation_failed',
|
||||
effective_result_json={'findings': []},
|
||||
idempotency_key='late-result-must-not-write-superseded-execution',
|
||||
)
|
||||
|
||||
assert exc.value.code == 'SHIPPING.PROCESS_EXECUTION_SUPERSEDED'
|
||||
Reference in new issue
Block a user