feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ffc0d4a430
commit
39fe3c05f2
453 files changed
+17945
-8646
No files matched your search
@@ -182,8 +182,8 @@ def test_existing_execution_gate_sequence_is_reconciled_to_current_contract(gate
|
||||
db.session.flush()
|
||||
gates['task_creation'].sequence_no = 12
|
||||
gates['order_freeze_readiness'].sequence_no = 10
|
||||
gates['inventory_source_routing'].sequence_no = 11
|
||||
gates['inventory_preparation'].sequence_no = 13
|
||||
gates['onhand_source_routing'].sequence_no = 11
|
||||
gates['onhand_preparation'].sequence_no = 13
|
||||
db.session.flush()
|
||||
|
||||
ensure_process_gates_for_execution(gate_execution)
|
||||
@@ -191,8 +191,8 @@ def test_existing_execution_gate_sequence_is_reconciled_to_current_contract(gate
|
||||
|
||||
assert gates['task_creation'].sequence_no == 10
|
||||
assert gates['order_freeze_readiness'].sequence_no == 11
|
||||
assert gates['inventory_source_routing'].sequence_no == 12
|
||||
assert gates['inventory_preparation'].sequence_no == 13
|
||||
assert gates['onhand_source_routing'].sequence_no == 12
|
||||
assert gates['onhand_preparation'].sequence_no == 13
|
||||
|
||||
assert set(gates) == set(PROCESS_GATE_CODES)
|
||||
|
||||
@@ -239,10 +239,10 @@ def test_auto_progress_queues_initial_inventory_rpa_once(gate_execution, monkeyp
|
||||
prior_gate.status = 'passed'
|
||||
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
|
||||
execution_id=int(gate_execution.id), gate_code='onhand_preparation',
|
||||
).one()
|
||||
gate.status = 'blocked_retryable'
|
||||
gate.next_action_code = 'retry_inventory_preparation'
|
||||
gate.next_action_code = 'retry_onhand_preparation'
|
||||
process_gate_service._refresh_execution_pointers(gate_execution)
|
||||
db.session.flush()
|
||||
|
||||
@@ -263,7 +263,7 @@ def test_auto_progress_queues_initial_inventory_rpa_once(gate_execution, monkeyp
|
||||
)
|
||||
|
||||
assert len(queued) == 1
|
||||
assert queued[0]['gate_code'] == 'inventory_preparation'
|
||||
assert queued[0]['gate_code'] == 'onhand_preparation'
|
||||
|
||||
|
||||
def test_auto_progress_seeds_pending_inventory_preparation_after_routing_pass(
|
||||
@@ -284,13 +284,13 @@ def test_auto_progress_seeds_pending_inventory_preparation_after_routing_pass(
|
||||
prior_gate.next_action_code = None
|
||||
|
||||
prep = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
|
||||
execution_id=int(gate_execution.id), gate_code='onhand_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 gate_execution.current_gate_code == 'onhand_preparation'
|
||||
assert prep.next_action_code is None
|
||||
|
||||
queued: list[dict[str, object]] = []
|
||||
@@ -305,25 +305,25 @@ def test_auto_progress_seeds_pending_inventory_preparation_after_routing_pass(
|
||||
)
|
||||
|
||||
routing = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_source_routing',
|
||||
execution_id=int(gate_execution.id), gate_code='onhand_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 prep.next_action_code == 'retry_onhand_preparation'
|
||||
assert gate_execution.primary_next_action_code == 'retry_onhand_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]['gate_code'] == 'onhand_preparation'
|
||||
assert queued[0]['input_snapshot']['action_code'] == 'retry_onhand_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
|
||||
from app.models import ShippingOrderTask, ShippingTaskInventoryRpaAttempt
|
||||
from app.models import ShippingOrderTask, FreightRpaOnhandTaskAttempt
|
||||
|
||||
for prior_gate in ShippingProcessGate.query.filter(
|
||||
ShippingProcessGate.execution_id == int(gate_execution.id),
|
||||
@@ -331,12 +331,12 @@ def test_auto_progress_does_not_requeue_failed_inventory_rpa(gate_execution, mon
|
||||
).all():
|
||||
prior_gate.status = 'passed'
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
|
||||
execution_id=int(gate_execution.id), gate_code='onhand_preparation',
|
||||
).one()
|
||||
gate.status = 'blocked_retryable'
|
||||
gate.next_action_code = 'retry_inventory_preparation'
|
||||
gate.next_action_code = 'retry_onhand_preparation'
|
||||
task = db.session.get(ShippingOrderTask, int(gate_execution.task_id))
|
||||
db.session.add(ShippingTaskInventoryRpaAttempt(
|
||||
db.session.add(FreightRpaOnhandTaskAttempt(
|
||||
task_no=task.task_no, source_code='TEST', attempt_no=1, source_run_no='PSR-FAILED',
|
||||
status='failed', trigger_file_path='C:/trigger.json', execution_phase='trigger_written',
|
||||
))
|
||||
@@ -351,7 +351,7 @@ def test_auto_progress_does_not_requeue_failed_inventory_rpa(gate_execution, mon
|
||||
|
||||
|
||||
def test_auto_progress_does_not_queue_manual_inventory_navigation(gate_execution, monkeypatch):
|
||||
"""库存已入库后的 upload_inventory_file 是导航动作,不能被自动续跑执行。"""
|
||||
"""库存已入库后的 upload_onhand_file 是导航动作,不能被自动续跑执行。"""
|
||||
from app.services.shipping_notice import process_gate_service
|
||||
|
||||
for prior_gate in (
|
||||
@@ -365,11 +365,11 @@ def test_auto_progress_does_not_queue_manual_inventory_navigation(gate_execution
|
||||
prior_gate.status = 'passed'
|
||||
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=int(gate_execution.id), gate_code='inventory_preparation',
|
||||
execution_id=int(gate_execution.id), gate_code='onhand_preparation',
|
||||
).one()
|
||||
gate.status = 'blocked_manual'
|
||||
gate.blocking_reason_code = 'inventory_rpa_timeout'
|
||||
gate.next_action_code = 'upload_inventory_file'
|
||||
gate.blocking_reason_code = 'onhand_rpa_timeout'
|
||||
gate.next_action_code = 'upload_onhand_file'
|
||||
process_gate_service._refresh_execution_pointers(gate_execution)
|
||||
db.session.flush()
|
||||
|
||||
@@ -391,7 +391,7 @@ def test_auto_progress_does_not_queue_manual_inventory_navigation(gate_execution
|
||||
def test_refresh_pointers_skips_stale_invalidated_when_downstream_blocked(gate_execution):
|
||||
"""已建单成功后又被标 invalidated 的上游,不得盖住下游真实 blocked_manual。
|
||||
|
||||
复现:task_creation 已 passed_at + invalidated,inventory_sufficiency=blocked_manual;
|
||||
复现:task_creation 已 passed_at + invalidated,onhand_sufficiency=blocked_manual;
|
||||
刷新指针必须停在库存充足性,而不是「生成订单草稿」。
|
||||
"""
|
||||
from datetime import datetime, timezone
|
||||
@@ -410,12 +410,12 @@ def test_refresh_pointers_skips_stale_invalidated_when_downstream_blocked(gate_e
|
||||
'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',
|
||||
'order_freeze_readiness', 'onhand_source_routing', 'onhand_preparation',
|
||||
'onhand_field_mapping', 'onhand_matching',
|
||||
}:
|
||||
gate.status = 'passed'
|
||||
gate.passed_at = now
|
||||
elif gate.gate_code == 'inventory_sufficiency':
|
||||
elif gate.gate_code == 'onhand_sufficiency':
|
||||
gate.status = 'blocked_manual'
|
||||
gate.blocking_reason_code = 'inventory_shortage_review_required'
|
||||
gate.next_action_code = 'open_shortage_review'
|
||||
@@ -428,7 +428,7 @@ def test_refresh_pointers_skips_stale_invalidated_when_downstream_blocked(gate_e
|
||||
process_gate_service._refresh_execution_pointers(gate_execution)
|
||||
db.session.flush()
|
||||
|
||||
assert gate_execution.current_gate_code == 'inventory_sufficiency'
|
||||
assert gate_execution.current_gate_code == 'onhand_sufficiency'
|
||||
assert gate_execution.primary_next_action_code == 'open_shortage_review'
|
||||
assert gate_execution.status == 'blocked'
|
||||
|
||||
@@ -479,12 +479,12 @@ def test_refresh_pointers_bumps_task_progress_version_without_notice(gate_execut
|
||||
'document_materialization', 'layout_parsing', 'document_profile_routing',
|
||||
'order_field_extraction', 'field_completeness', 'reservation_validation',
|
||||
'customer_resolution', 'duplicate_detection', 'field_conflict_resolution',
|
||||
'task_creation', 'order_freeze_readiness', 'inventory_source_routing',
|
||||
'inventory_preparation', 'inventory_field_mapping', 'inventory_matching',
|
||||
'task_creation', 'order_freeze_readiness', 'onhand_source_routing',
|
||||
'onhand_preparation', 'onhand_field_mapping', 'onhand_matching',
|
||||
}:
|
||||
gate.status = 'passed'
|
||||
gate.passed_at = now
|
||||
elif gate.gate_code == 'inventory_sufficiency':
|
||||
elif gate.gate_code == 'onhand_sufficiency':
|
||||
gate.status = 'blocked_manual'
|
||||
gate.blocking_reason_code = 'inventory_shortage_review_required'
|
||||
gate.next_action_code = 'open_shortage_review'
|
||||
@@ -498,7 +498,7 @@ def test_refresh_pointers_bumps_task_progress_version_without_notice(gate_execut
|
||||
db.session.flush()
|
||||
|
||||
# 关键断言:缺口落定属于真实事实变化,无 Notice 也必须经中央写入口推进版本。
|
||||
assert gate_execution.current_gate_code == 'inventory_sufficiency'
|
||||
assert gate_execution.current_gate_code == 'onhand_sufficiency'
|
||||
assert gate_execution.status == 'blocked'
|
||||
assert int(task.progress_version or 1) == version_before + 1
|
||||
|
||||
@@ -590,7 +590,7 @@ def test_upstream_invalidation_only_targets_dependents(gate_execution):
|
||||
|
||||
execution=gate_execution,
|
||||
|
||||
gate_code='inventory_matching',
|
||||
gate_code='onhand_matching',
|
||||
|
||||
passed=True,
|
||||
|
||||
@@ -610,7 +610,7 @@ def test_upstream_invalidation_only_targets_dependents(gate_execution):
|
||||
|
||||
)
|
||||
|
||||
assert 'inventory_matching' in invalidated
|
||||
assert 'onhand_matching' in invalidated
|
||||
|
||||
assert 'document_materialization' not in invalidated
|
||||
|
||||
@@ -782,13 +782,13 @@ def test_business_sync_reuses_same_gate_active_attempt(app):
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
trigger_type='user_retry',
|
||||
actor_type='user',
|
||||
actor_id=1,
|
||||
idempotency_key='active-fact-sync',
|
||||
input_snapshot={
|
||||
'action_code': 'retry_inventory_preparation',
|
||||
'action_code': 'retry_onhand_preparation',
|
||||
'payload': {'actor_user_id': 1},
|
||||
},
|
||||
)
|
||||
@@ -797,7 +797,7 @@ def test_business_sync_reuses_same_gate_active_attempt(app):
|
||||
mark_attempt_running(attempt_id=int(attempt.id), worker_id='active-fact-sync')
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
passed=False,
|
||||
blocking_reason_code='inventory_file_missing',
|
||||
effective_result_json={'findings': [], 'has_inventory_lines': False},
|
||||
@@ -809,7 +809,7 @@ def test_business_sync_reuses_same_gate_active_attempt(app):
|
||||
|
||||
|
||||
def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complete(app):
|
||||
"""库存已就绪时,sync 不得提前收口 retry_inventory_preparation Attempt。
|
||||
"""库存已就绪时,sync 不得提前收口 retry_onhand_preparation Attempt。
|
||||
|
||||
回归:OT 自动推进复用 ready 快照后,handler 内 sync 见 has_inventory_lines=True
|
||||
若提前 complete,外层 execute_queued_attempt 再 complete 会抛
|
||||
@@ -831,13 +831,13 @@ def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complet
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
trigger_type='auto',
|
||||
actor_type='system',
|
||||
actor_id=None,
|
||||
idempotency_key='inv-ready-outer-complete',
|
||||
input_snapshot={
|
||||
'action_code': 'retry_inventory_preparation',
|
||||
'action_code': 'retry_onhand_preparation',
|
||||
'payload': {'trigger': 'gate_attempt_passed'},
|
||||
},
|
||||
)
|
||||
@@ -845,7 +845,7 @@ def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complet
|
||||
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
@@ -865,7 +865,7 @@ def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complet
|
||||
attempt_id=int(attempt.id),
|
||||
outcome='passed',
|
||||
effective_result_json={'findings': [], 'tool_status': 'ok'},
|
||||
output_snapshot={'action_code': 'retry_inventory_preparation'},
|
||||
output_snapshot={'action_code': 'retry_onhand_preparation'},
|
||||
)
|
||||
assert completed.status == 'passed'
|
||||
db.session.refresh(attempt)
|
||||
@@ -873,7 +873,7 @@ def test_inventory_ready_sync_leaves_retry_preparation_attempt_for_outer_complet
|
||||
|
||||
|
||||
def test_inventory_ready_sync_still_completes_auto_poll_attempt(app):
|
||||
"""poll_inventory_preparation 无外层 complete,sync 在库存就绪时仍须收口。"""
|
||||
"""poll_onhand_preparation 无外层 complete,sync 在库存就绪时仍须收口。"""
|
||||
from app.services.shipping_notice.process_gate_service import mark_attempt_running
|
||||
|
||||
with app.app_context():
|
||||
@@ -884,13 +884,13 @@ def test_inventory_ready_sync_still_completes_auto_poll_attempt(app):
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_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',
|
||||
'action_code': 'poll_onhand_preparation',
|
||||
'payload': {'poll': True},
|
||||
},
|
||||
)
|
||||
@@ -898,7 +898,7 @@ def test_inventory_ready_sync_still_completes_auto_poll_attempt(app):
|
||||
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
@@ -915,14 +915,14 @@ def test_inventory_ready_sync_still_completes_auto_poll_attempt(app):
|
||||
def test_business_sync_does_not_swallow_passed_when_gate_has_active_user_attempt(app):
|
||||
"""活动 Attempt 不得吞掉 sync 的 passed 结论。
|
||||
|
||||
核心回归:真实任务 SN-20260831-9F25A698 / gate inventory_matching 曾因
|
||||
同一秒存在管理员手动 override_line_inventory_source(running)而让
|
||||
核心回归:真实任务 SN-20260831-9F25A698 / gate onhand_matching 曾因
|
||||
同一秒存在管理员手动 override_line_onhand_source(running)而让
|
||||
sync_fulfillment_gates_from_task 的 match_passed=True 被 active_attempt
|
||||
短路 `return gate` 丢弃;随后手动动作失败把 gate 覆盖成 blocked_retryable,
|
||||
右侧前端误显示「自动处理失败」。
|
||||
|
||||
契约:当业务事实判定为 passed 时,即使该 gate 上存在一个并发的、非本轮
|
||||
inventory_preparation 自动轮询的 Attempt,sync 也必须把 passed 写入 gate
|
||||
onhand_preparation 自动轮询的 Attempt,sync 也必须把 passed 写入 gate
|
||||
(完成该活动 Attempt 收口),而不是静默返回导致真相被覆盖。
|
||||
"""
|
||||
from app.services.shipping_notice.process_gate_service import complete_gate_attempt, mark_attempt_running
|
||||
@@ -936,19 +936,19 @@ def test_business_sync_does_not_swallow_passed_when_gate_has_active_user_attempt
|
||||
# 模拟并发占用的用户手动 Attempt(非 inventory_preparation 自动轮询)。
|
||||
user_attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_matching',
|
||||
gate_code='onhand_matching',
|
||||
trigger_type='user_manual',
|
||||
actor_type='user',
|
||||
actor_id=1,
|
||||
idempotency_key='concurrent-user-override',
|
||||
input_snapshot={'action_code': 'override_line_inventory_source'},
|
||||
input_snapshot={'action_code': 'override_line_onhand_source'},
|
||||
)
|
||||
mark_attempt_running(attempt_id=int(user_attempt.id), worker_id='concurrent-user')
|
||||
|
||||
# 此时业务事实判定 passed(例如 match_status='fulfillable')。
|
||||
gate = sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_matching',
|
||||
gate_code='onhand_matching',
|
||||
passed=True,
|
||||
effective_result_json={
|
||||
'findings': [],
|
||||
@@ -1233,7 +1233,7 @@ def test_superseded_execution_rejects_late_business_gate_result(app):
|
||||
with pytest.raises(ConflictError) as exc:
|
||||
sync_gate_from_business_result(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
passed=False,
|
||||
blocking_reason_code='inventory_preparation_failed',
|
||||
effective_result_json={'findings': []},
|
||||
|
||||
Reference in new issue
Block a user