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

@@ -151,3 +151,53 @@ def test_sync_manual_open_via_claim_and_run(app, monkeypatch):
assert result.get('skipped') is False
db.session.refresh(attempt)
assert attempt.status in {'succeeded', 'failed'}
def test_lock_execution_gate_attempt_parent_before_child(app):
"""[断言] 助手按 Execution→Gate→Attempt 返回隶属一致的三元组;mark/complete 同步改 Gate。"""
from app.models import ShippingProcessGate
from app.services.shipping_notice.process_gate_service import (
_lock_execution_gate_attempt,
complete_gate_attempt,
)
with app.app_context():
_user, review_case_id, task_id = _seed_workflow_version(suffix='lockord1')
execution = ensure_execution_for_workflow_version(
review_case_id=review_case_id,
task_id=task_id,
actor_type='system',
actor_id='lock-order-test',
)
attempt = queue_gate_attempt(
execution_no=execution.execution_no,
gate_code='layout_parsing',
trigger_type='auto',
actor_type='system',
actor_id='w1',
idempotency_key='lock-order-1',
)
locked = _lock_execution_gate_attempt(int(attempt.id))
assert locked is not None
locked_execution, locked_gate, locked_attempt = locked
assert int(locked_execution.id) == int(execution.id)
assert int(locked_gate.execution_id) == int(locked_execution.id)
assert int(locked_attempt.gate_id) == int(locked_gate.id)
mark_attempt_running(
attempt_id=int(attempt.id),
worker_id='worker-lock',
lease_token='token-lock',
lease_expires_at=datetime.utcnow() + timedelta(seconds=60),
)
gate = ShippingProcessGate.query.filter_by(id=int(attempt.gate_id)).one()
assert gate.status == 'running'
complete_gate_attempt(
attempt_id=int(attempt.id),
outcome='passed',
output_snapshot={'ok': True},
)
db.session.refresh(gate)
db.session.refresh(attempt)
assert gate.status == 'passed'
assert attempt.status == 'succeeded'