fix(shipping-notice): 修复抽取失败摘要卡死与 PO scope 持久化校验
sync 仅对 auto poll 提前 complete,retry_inventory_preparation 交外层统一收口,防止 Attempt already finished 误成技术失败
This commit is contained in:
1 parent
a2931e0095
commit
76729df27c
9 files changed
+287
-25
No files matched your search
@@ -631,6 +631,110 @@ def test_business_sync_reuses_same_gate_active_attempt(app):
|
||||
assert ShippingProcessGateAttempt.query.filter_by(gate_id=int(gate.id)).count() == 1
|
||||
|
||||
|
||||
def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complete(app):
|
||||
"""库存已就绪时,sync 不得提前收口 retry_inventory_preparation Attempt。
|
||||
|
||||
回归:OT 自动推进复用 ready 快照后,handler 内 sync 见 has_inventory_lines=True
|
||||
若提前 complete,外层 execute_queued_attempt 再 complete 会抛
|
||||
Attempt already finished,Job rollback 后收成 technical_failure_present,
|
||||
界面卡在获取库存(真实单 OT-20260908-95514841)。
|
||||
|
||||
契约:非 poll 的活动准备 Attempt 由外层统一 complete;sync 只返回、不收口。
|
||||
"""
|
||||
from app.services.shipping_notice.process_gate_service import (
|
||||
complete_gate_attempt,
|
||||
mark_attempt_running,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
_user, review_case_id, task_id = _seed_workflow_version(suffix='invreadyouter')
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
review_case_id=review_case_id,
|
||||
task_id=task_id,
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
trigger_type='auto',
|
||||
actor_type='system',
|
||||
actor_id=None,
|
||||
idempotency_key='inv-ready-outer-complete',
|
||||
input_snapshot={
|
||||
'action_code': 'retry_inventory_preparation',
|
||||
'payload': {'trigger': 'gate_attempt_passed'},
|
||||
},
|
||||
)
|
||||
mark_attempt_running(attempt_id=int(attempt.id), worker_id='inv-ready-outer')
|
||||
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
'has_inventory_lines': True,
|
||||
'derived_fulfillment_status': 'inventory_ready',
|
||||
},
|
||||
idempotency_key='inv-ready-must-not-early-complete',
|
||||
)
|
||||
|
||||
db.session.refresh(attempt)
|
||||
assert gate.status == 'running'
|
||||
assert attempt.status == 'running'
|
||||
assert ShippingProcessGateAttempt.query.filter_by(gate_id=int(gate.id)).count() == 1
|
||||
|
||||
# [断言] 外层唯一收口可成功;不得再抛 Attempt already finished。
|
||||
completed = complete_gate_attempt(
|
||||
attempt_id=int(attempt.id),
|
||||
outcome='passed',
|
||||
effective_result_json={'findings': [], 'tool_status': 'ok'},
|
||||
output_snapshot={'action_code': 'retry_inventory_preparation'},
|
||||
)
|
||||
assert completed.status == 'passed'
|
||||
db.session.refresh(attempt)
|
||||
assert attempt.status == 'succeeded'
|
||||
|
||||
|
||||
def test_inventory_ready_sync_still_completes_auto_poll_attempt(app):
|
||||
"""poll_inventory_preparation 无外层 complete,sync 在库存就绪时仍须收口。"""
|
||||
from app.services.shipping_notice.process_gate_service import mark_attempt_running
|
||||
|
||||
with app.app_context():
|
||||
_user, review_case_id, task_id = _seed_workflow_version(suffix='invreadypoll')
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
review_case_id=review_case_id,
|
||||
task_id=task_id,
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
trigger_type='auto',
|
||||
actor_type='system',
|
||||
actor_id='external-wait-poll',
|
||||
idempotency_key='inv-ready-poll-complete',
|
||||
input_snapshot={
|
||||
'action_code': 'poll_inventory_preparation',
|
||||
'payload': {'poll': True},
|
||||
},
|
||||
)
|
||||
mark_attempt_running(attempt_id=int(attempt.id), worker_id='inv-ready-poll')
|
||||
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
'has_inventory_lines': True,
|
||||
},
|
||||
idempotency_key='inv-ready-poll-must-complete',
|
||||
)
|
||||
|
||||
db.session.refresh(attempt)
|
||||
assert gate.status == 'passed'
|
||||
assert attempt.status == 'succeeded'
|
||||
|
||||
|
||||
def test_business_sync_does_not_swallow_passed_when_gate_has_active_user_attempt(app):
|
||||
"""活动 Attempt 不得吞掉 sync 的 passed 结论。
|
||||
|
||||
|
||||
Reference in new issue
Block a user