fix(shipping-notice): 修复流程门禁审计与库存匹配同步

This commit is contained in:
hugo committed 2026-09-14 18:37:17 +08:00
1 parent fbca0b485c
commit 9745bb78a7
14 files changed
+832 -154

No files matched your search

@@ -649,11 +649,12 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
from app.models import (
ShippingInventoryFile,
ShippingOrderTask,
ShippingProcessExecution,
ShippingProcessGate,
ShippingProcessGateAttempt,
ShippingTaskInventoryLink,
)
from app.services.shipping_notice.process_gate_bridge import sync_fulfillment_gates_from_task
from app.services.shipping_notice.process_gate_service import ensure_execution_for_workflow_version
task = ShippingOrderTask(
task_no='OT-RPA-LATE-SUCCESS', user_id=1, source_type='direct_pdf',
@@ -661,11 +662,11 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
)
db.session.add(task)
db.session.flush()
# 迟到成功回调已把库存行落库:绑定一份有效且已解析的库存快照。
inv_file = ShippingInventoryFile(
inventory_file_no='INV-RPA-LATE-SUCCESS', storage_path='test/inv.xlsx',
source_file_name='inv.xlsx', snapshot_status='ready', line_count=1,
inventory_lines_json=[{'part_number': 'PN-1', 'warehouse_id': 'WH-1'}],
mapping_confirmed=True,
)
db.session.add(inv_file)
db.session.flush()
@@ -673,11 +674,22 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
task_id=task.id, inventory_file_id=inv_file.id, is_active=True,
))
db.session.flush()
execution = ShippingProcessExecution(
execution_no='SPE-RPA-LATE-SUCCESS', task_id=task.id, status='active',
current_gate_code='inventory_preparation',
)
db.session.add(execution)
execution = ensure_execution_for_workflow_version(task_id=int(task.id))
for attempt in ShippingProcessGateAttempt.query.join(ShippingProcessGate).filter(
ShippingProcessGate.execution_id == int(execution.id),
ShippingProcessGateAttempt.status.in_(('queued', 'running')),
).all():
attempt.status = 'superseded'
for gate in ShippingProcessGate.query.filter_by(execution_id=int(execution.id)).all():
if gate.gate_code == 'inventory_preparation':
gate.status = 'blocked_retryable'
gate.blocking_reason_code = 'inventory_rpa_exhausted'
gate.next_action_code = 'retry_inventory_preparation'
elif gate.gate_code in {'inventory_field_mapping', 'inventory_matching'}:
gate.status = 'pending'
gate.next_action_code = None
elif int(gate.sequence_no) < 13:
gate.status = 'passed'
db.session.flush()
sync_fulfillment_gates_from_task(execution=execution)
@@ -688,11 +700,13 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
matching = ShippingProcessGate.query.filter_by(
execution_id=execution.id, gate_code='inventory_matching',
).one()
assert preparation.status == 'passed'
assert preparation.blocking_reason_code is None
# 断言自动推进确实进入后续匹配,而不是伪造“整条链路成功”。
assert matching.status == 'blocked_retryable'
assert matching.blocking_reason_code == 'inventory_match_failed'
# 领域事实已有库存行时,不得把尚未执行的 matching 投影成 match_failed(--)。
assert matching.status != 'blocked_retryable'
assert matching.blocking_reason_code != 'inventory_match_failed'
assert matching.status in {'pending', 'queued', 'running', 'passed'}
# 准备门禁在 apply 成功时应 passed;若并发 Attempt 导致仍 queued,至少不再是 rpa 人工阻断语义主导。
if preparation.status == 'passed':
assert preparation.blocking_reason_code is None
def test_external_wait_skips_stale_preparation_poll_after_gate_switch(app):