feat(shipping-notice): 完善处理投影与待办轮询

- 统一处理阶段、Gate 状态及跨页面投影
- 优化订单提取自动推进与待办分类查询
- 完善任务中心待办与批次轮询逻辑
- 补充后端投影、Gate、查询及 Worker 测试
- 新增待办轮询设计文档并更新技术文档
This commit is contained in:
hugo committed 2026-09-14 17:06:11 +08:00
1 parent 9d2fa522fa
commit fbca0b485c
22 files changed
+1454 -225

No files matched your search

@@ -266,6 +266,60 @@ def test_auto_progress_queues_initial_inventory_rpa_once(gate_execution, monkeyp
assert queued[0]['gate_code'] == 'inventory_preparation'
def test_auto_progress_seeds_pending_inventory_preparation_after_routing_pass(
gate_execution, monkeypatch,
):
"""人工指定源使 routing passed 后,必须补种并入队 pending 的库存准备。
[回归] pending 门禁 next_action_code 为空时旧逻辑静默 return,工作台永久显示
「库存文件未准备」;手动选源即定论,应按冻结源执行准备,不得再停在路由。
"""
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'
prior_gate.next_action_code = None
prep = ShippingProcessGate.query.filter_by(
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
).one()
prep.status = 'pending'
prep.next_action_code = None
process_gate_service._refresh_execution_pointers(gate_execution)
db.session.flush()
assert gate_execution.current_gate_code == 'inventory_preparation'
assert prep.next_action_code is None
queued: list[dict[str, object]] = []
monkeypatch.setattr(
process_gate_service,
'queue_gate_attempt',
lambda **kwargs: (queued.append(kwargs), SimpleNamespace(id=91))[1],
)
monkeypatch.setattr(
'app.services.shipping_notice.process_gate_job_service.enqueue_gate_attempt_job',
lambda **_kwargs: None,
)
routing = ShippingProcessGate.query.filter_by(
execution_id=int(gate_execution.id), gate_code='inventory_source_routing',
).one()
process_gate_service._enqueue_auto_progress_after_gate_pass(
execution=gate_execution,
gate=routing,
)
assert prep.next_action_code == 'retry_inventory_preparation'
assert gate_execution.primary_next_action_code == 'retry_inventory_preparation'
assert len(queued) == 1
assert queued[0]['gate_code'] == 'inventory_preparation'
assert queued[0]['input_snapshot']['action_code'] == 'retry_inventory_preparation'
assert queued[0]['input_snapshot']['payload']['trigger'] == 'gate_attempt_passed'
def test_auto_progress_does_not_requeue_failed_inventory_rpa(gate_execution, monkeypatch):
"""已有终态 Attempt 后,库存 RPA 只允许人工重试,不能被自动无限重放。"""
from app.services.shipping_notice import process_gate_service
@@ -334,6 +388,77 @@ def test_auto_progress_does_not_queue_manual_inventory_navigation(gate_execution
assert queued == []
def test_refresh_pointers_skips_stale_invalidated_when_downstream_blocked(gate_execution):
"""已建单成功后又被标 invalidated 的上游,不得盖住下游真实 blocked_manual。
复现:task_creation 已 passed_at + invalidated,inventory_sufficiency=blocked_manual;
刷新指针必须停在库存充足性,而不是「生成订单草稿」。
"""
from datetime import datetime, timezone
from app.services.shipping_notice import process_gate_service
now = datetime.now(timezone.utc).replace(tzinfo=None)
for gate in ShippingProcessGate.query.filter_by(execution_id=int(gate_execution.id)).all():
if gate.gate_code == 'task_creation':
gate.status = 'invalidated'
gate.passed_at = now
gate.invalidated_at = now
gate.blocking_reason_code = 'gate_invalidated'
gate.next_action_code = 'retry_task_creation'
elif gate.gate_code in {
'document_materialization', 'layout_parsing', 'document_profile_routing',
'order_field_extraction', 'field_completeness', 'reservation_validation',
'customer_resolution', 'duplicate_detection', 'field_conflict_resolution',
'order_freeze_readiness', 'inventory_source_routing', 'inventory_preparation',
'inventory_field_mapping', 'inventory_matching',
}:
gate.status = 'passed'
gate.passed_at = now
elif gate.gate_code == 'inventory_sufficiency':
gate.status = 'blocked_manual'
gate.blocking_reason_code = 'inventory_shortage_review_required'
gate.next_action_code = 'open_shortage_review'
elif gate.gate_code == 'excel_readiness':
gate.status = 'blocked_manual'
gate.blocking_reason_code = 'excel_not_ready'
# 其余保持 pending
db.session.flush()
process_gate_service._refresh_execution_pointers(gate_execution)
db.session.flush()
assert gate_execution.current_gate_code == 'inventory_sufficiency'
assert gate_execution.primary_next_action_code == 'open_shortage_review'
assert gate_execution.status == 'blocked'
def test_refresh_pointers_keeps_invalidated_when_downstream_still_passed(gate_execution):
"""故意失效且下游仍为 passed 时,current 必须停在 invalidated,等待重评。"""
from datetime import datetime, timezone
from app.services.shipping_notice import process_gate_service
now = datetime.now(timezone.utc).replace(tzinfo=None)
for gate in ShippingProcessGate.query.filter_by(execution_id=int(gate_execution.id)).all():
if gate.gate_code == 'task_creation':
gate.status = 'invalidated'
gate.passed_at = now
gate.invalidated_at = now
gate.blocking_reason_code = 'gate_invalidated'
gate.next_action_code = 'retry_task_creation'
else:
gate.status = 'passed'
gate.passed_at = now
db.session.flush()
process_gate_service._refresh_execution_pointers(gate_execution)
db.session.flush()
assert gate_execution.current_gate_code == 'task_creation'
assert gate_execution.status == 'blocked'