feat(shipping-notice): 收敛订单处理状态与履约门禁
This commit is contained in:
1 parent
bffcd55b40
commit
70dd0051b8
153 files changed
+10916
-4296
No files matched your search
@@ -1622,6 +1622,103 @@ def test_inventory_preparation_retry_rejects_legacy_task_without_snapshot(monkey
|
||||
assert result['blocking_reason_code'] == 'inventory_source_routing_required'
|
||||
|
||||
|
||||
def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
"""库存准备执行器按已有动作码映射 ensure_inventory mode,禁止人工入口一律 retry_rpa。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice.process_gate_executor import _handle_retry_inventory_preparation
|
||||
|
||||
task = SimpleNamespace(id=1, order_snapshot_id=10, task_no='SN-MODE-MAP')
|
||||
captured: list[dict] = []
|
||||
line = SimpleNamespace(source_codes_json=['DBS'])
|
||||
candidate_set = SimpleNamespace(id=1)
|
||||
sources = [SimpleNamespace(source_code='DBS')]
|
||||
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_executor._resolve_order_task',
|
||||
lambda _execution: task,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_candidate_projection.get_active_candidate_set',
|
||||
lambda _task: candidate_set,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_candidate_projection.get_active_candidate_lines',
|
||||
lambda _task: [line],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_candidate_projection.get_active_candidate_sources',
|
||||
lambda _task: sources,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_recovery_service.create_inventory_preparation_round',
|
||||
lambda **_: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.recovery_invalidation_service.invalidate_inventory_downstream',
|
||||
lambda **_: {},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
lambda payload: captured.append(dict(payload)) or {'status': 'running', 'data': {'rpa': {}}},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_bridge.inventory_preparation_reason_code',
|
||||
lambda _task: 'inventory_preparation_failed',
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_bridge.sync_fulfillment_gates_from_task',
|
||||
lambda **_: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.process_gate_executor._task_payload',
|
||||
lambda _execution, _payload: {'task_id': task.task_no, '_orchestrator_internal_dispatch': True},
|
||||
)
|
||||
# poll 路径会查失败 Attempt;无失败行时继续 ensure_inventory。
|
||||
monkeypatch.setattr(
|
||||
'app.models.ShippingInventoryPreparationAttempt.query',
|
||||
SimpleNamespace(
|
||||
filter_by=lambda **_: SimpleNamespace(
|
||||
filter=lambda *_a, **_k: SimpleNamespace(
|
||||
order_by=lambda *_a, **_k: SimpleNamespace(first=lambda: None),
|
||||
),
|
||||
order_by=lambda *_a, **_k: SimpleNamespace(first=lambda: None),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
execution = SimpleNamespace(task_id=1, id=21, candidate_set_id=None)
|
||||
gate = SimpleNamespace(gate_code='inventory_preparation')
|
||||
|
||||
captured.clear()
|
||||
_handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={'action_code': 'retry_inventory_preparation', 'actor_user_id': 5},
|
||||
)
|
||||
# 显式强制 RPA 码 → mode=retry_rpa。
|
||||
assert captured[-1].get('mode') == 'retry_rpa'
|
||||
|
||||
captured.clear()
|
||||
_handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={'action_code': 'poll_inventory_preparation', 'actor_user_id': 5},
|
||||
)
|
||||
# 只读轮询:默认 auto,禁止自动再试。
|
||||
assert captured[-1].get('mode') in (None, 'auto')
|
||||
assert captured[-1].get('allow_auto_retry') is False
|
||||
|
||||
captured.clear()
|
||||
_handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={
|
||||
'action_code': 'retry_inventory_preparation',
|
||||
'trigger': 'gate_attempt_passed',
|
||||
'actor_user_id': 5,
|
||||
},
|
||||
)
|
||||
# 首次自动投递:不强制 retry_rpa,保留默认 auto(先复用快照)。
|
||||
assert captured[-1].get('mode') in (None, 'auto')
|
||||
|
||||
|
||||
def test_manual_business_block_is_a_successful_attempt(app):
|
||||
"""库存匹配已执行但存在缺口时,Attempt 成功、Gate 保持人工阻断。"""
|
||||
from app import db
|
||||
|
||||
Reference in new issue
Block a user