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
@@ -10,9 +10,9 @@ import pytest
|
||||
from sqlalchemy import UniqueConstraint
|
||||
|
||||
from app.models import (
|
||||
ShippingInventoryMapping,
|
||||
ShippingInventoryPreparationAttempt,
|
||||
ShippingInventoryPreparationSourceAttempt,
|
||||
FreightRpaOnhandMapping,
|
||||
ShippingOnhandPreparationAttempt,
|
||||
ShippingOnhandPreparationSourceAttempt,
|
||||
ShippingOrderTask,
|
||||
ShippingProcessRecoveryPlan,
|
||||
)
|
||||
@@ -41,11 +41,11 @@ def test_excel_regeneration_invalidation_preserves_inventory_facts(app):
|
||||
from app.models import (
|
||||
ShippingExcelTemplate,
|
||||
ShippingExportArtifact,
|
||||
ShippingInventoryParsingProfile,
|
||||
ShippingInventoryVerification,
|
||||
FreightRpaParsingProfile,
|
||||
ShippingOnhandVerification,
|
||||
ShippingNotice,
|
||||
ShippingOrderTask,
|
||||
ShippingNoticeLineInventoryMatch,
|
||||
ShippingNoticeLineOnhandMatch,
|
||||
ShippingOrderExtraction,
|
||||
ShippingOrderSchema,
|
||||
ShippingOrderSchemaVersion,
|
||||
@@ -62,7 +62,7 @@ def test_excel_regeneration_invalidation_preserves_inventory_facts(app):
|
||||
storage_bucket='test', storage_key='test/template.xlsx', original_filename='template.xlsx',
|
||||
file_checksum='a' * 64, definition_json={},
|
||||
)
|
||||
profile = ShippingInventoryParsingProfile(
|
||||
profile = FreightRpaParsingProfile(
|
||||
profile_code='REGEN-ONLY', display_name='Regen only', version=1,
|
||||
status='published', file_format='xlsx', definition_json={},
|
||||
)
|
||||
@@ -97,10 +97,10 @@ def test_excel_regeneration_invalidation_preserves_inventory_facts(app):
|
||||
part_number='PN-1', po_number_normalized='PO-1', required_qty=1,
|
||||
status='artifact_reserved', current_artifact_id=None,
|
||||
)
|
||||
verification = ShippingInventoryVerification(task_id=owner.id, status='completed', result_json={})
|
||||
match = ShippingNoticeLineInventoryMatch(
|
||||
verification = ShippingOnhandVerification(task_id=owner.id, status='completed', result_json={})
|
||||
match = ShippingNoticeLineOnhandMatch(
|
||||
task_id=owner.id, snapshot_line_id=1, line_no=1,
|
||||
match_result='matched', inventory_status='ready', is_current=True,
|
||||
match_result='matched', onhand_status='ready', is_current=True,
|
||||
)
|
||||
db.session.add_all([artifact, reservation, verification, match])
|
||||
db.session.flush()
|
||||
@@ -137,18 +137,18 @@ def test_excel_regeneration_invalidation_preserves_inventory_facts(app):
|
||||
|
||||
def test_inventory_preparation_is_task_round_with_per_source_uniqueness():
|
||||
"""准备轮次和逐源 Attempt 均必须保留不可混淆的唯一范围。"""
|
||||
assert 'uq_shipping_inventory_preparation_task_attempt' in _unique_names(ShippingInventoryPreparationAttempt)
|
||||
assert 'uq_shipping_inventory_preparation_source_attempt' in _unique_names(ShippingInventoryPreparationSourceAttempt)
|
||||
assert 'uq_shipping_inventory_preparation_task_attempt' in _unique_names(ShippingOnhandPreparationAttempt)
|
||||
assert 'uq_shipping_inventory_preparation_source_attempt' in _unique_names(ShippingOnhandPreparationSourceAttempt)
|
||||
assert {'source_code', 'status', 'inventory_file_id', 'rpa_attempt_id'} <= set(
|
||||
ShippingInventoryPreparationSourceAttempt.__table__.c.keys()
|
||||
ShippingOnhandPreparationSourceAttempt.__table__.c.keys()
|
||||
)
|
||||
|
||||
|
||||
def test_rpa_attempt_status_updates_its_bound_preparation_source(app):
|
||||
"""RPA 回调必须更新既有 SourceAttempt,并聚合 PreparationAttempt 状态。"""
|
||||
from app import db
|
||||
from app.models import ShippingNotice, ShippingTaskInventoryRpaAttempt
|
||||
from app.services.shipping_notice.inventory_recovery_service import (
|
||||
from app.models import ShippingNotice, FreightRpaOnhandTaskAttempt
|
||||
from app.services.shipping_notice.onhand_recovery_service import (
|
||||
create_inventory_preparation_round,
|
||||
sync_inventory_preparation_round,
|
||||
sync_preparation_source_from_rpa_attempt,
|
||||
@@ -159,9 +159,9 @@ def test_rpa_attempt_status_updates_its_bound_preparation_source(app):
|
||||
db.session.flush()
|
||||
preparation = create_inventory_preparation_round(
|
||||
task=task, execution_id=88, recovery_plan_id=None,
|
||||
action_code='retry_inventory_preparation', source_codes=['DBS'], gate_attempt_id=301,
|
||||
action_code='retry_onhand_preparation', source_codes=['DBS'], gate_attempt_id=301,
|
||||
)
|
||||
rpa = ShippingTaskInventoryRpaAttempt(
|
||||
rpa = FreightRpaOnhandTaskAttempt(
|
||||
task_no=task.task_no, source_code='DBS', attempt_no=1, source_run_no='PSR-LINEAGE-1',
|
||||
status='queued', lease_token='lease-lineage', extra_json={}, callback_payload_json={},
|
||||
)
|
||||
@@ -188,9 +188,9 @@ def test_rpa_callback_completes_waiting_preparation_recovery_plan(app):
|
||||
from app.models import (
|
||||
ShippingNotice,
|
||||
ShippingProcessExecution,
|
||||
ShippingTaskInventoryRpaAttempt,
|
||||
FreightRpaOnhandTaskAttempt,
|
||||
)
|
||||
from app.services.shipping_notice.inventory_recovery_service import (
|
||||
from app.services.shipping_notice.onhand_recovery_service import (
|
||||
create_inventory_preparation_round,
|
||||
sync_inventory_preparation_round,
|
||||
sync_preparation_source_from_rpa_attempt,
|
||||
@@ -201,14 +201,14 @@ def test_rpa_callback_completes_waiting_preparation_recovery_plan(app):
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-PREP-PLAN-COMPLETE', task_id=int(task.id), status='active',
|
||||
current_gate_code='inventory_preparation',
|
||||
current_gate_code='onhand_preparation',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
plan = ShippingProcessRecoveryPlan(
|
||||
plan_no='RCP-PREP-PLAN-COMPLETE', execution_id=int(execution.id),
|
||||
current_gate='inventory_matching', action_code='retry_inventory_from_preparation',
|
||||
target_gate='inventory_preparation', resume_after_gate='inventory_matching',
|
||||
current_gate='onhand_matching', action_code='retry_onhand_from_preparation',
|
||||
target_gate='onhand_preparation', resume_after_gate='onhand_matching',
|
||||
status='waiting_external', invalidation_plan_json={},
|
||||
idempotency_key='prep-plan-complete', actor_type='user',
|
||||
)
|
||||
@@ -216,9 +216,9 @@ def test_rpa_callback_completes_waiting_preparation_recovery_plan(app):
|
||||
db.session.flush()
|
||||
preparation = create_inventory_preparation_round(
|
||||
task=task, execution_id=int(execution.id), recovery_plan_id=int(plan.id),
|
||||
action_code='retry_inventory_from_preparation', source_codes=['DBS'], gate_attempt_id=None,
|
||||
action_code='retry_onhand_from_preparation', source_codes=['DBS'], gate_attempt_id=None,
|
||||
)
|
||||
rpa = ShippingTaskInventoryRpaAttempt(
|
||||
rpa = FreightRpaOnhandTaskAttempt(
|
||||
task_no=task.task_no, source_code='DBS', attempt_no=1, source_run_no='PSR-PREP-PLAN-COMPLETE',
|
||||
status='queued', lease_token='lease-prep-plan', extra_json={}, callback_payload_json={},
|
||||
)
|
||||
@@ -240,13 +240,13 @@ def test_rpa_callback_completes_waiting_preparation_recovery_plan(app):
|
||||
def test_per_source_summary_exposes_attempt_id_for_preparation_lineage(app):
|
||||
"""新建 RPA Attempt 的汇总必须返回主键,准备轮次才能被回调准确收口。"""
|
||||
from app import db
|
||||
from app.models import ShippingNotice, ShippingTaskInventoryRpaAttempt
|
||||
from app.models import ShippingNotice, FreightRpaOnhandTaskAttempt
|
||||
from app.services.shipping_notice.per_source_rpa_service import _attempts_summary
|
||||
|
||||
task = ShippingNotice(task_no='SN-PREP-SUMMARY-ID')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
attempt = ShippingTaskInventoryRpaAttempt(
|
||||
attempt = FreightRpaOnhandTaskAttempt(
|
||||
task_no=task.task_no, source_code='DBS', attempt_no=1,
|
||||
source_run_no='PSR-PREP-SUMMARY-ID', status='queued',
|
||||
lease_token='lease-prep-summary', extra_json={}, callback_payload_json={},
|
||||
@@ -270,10 +270,10 @@ def test_preparation_trigger_identity_includes_gate_and_callback(monkeypatch, ap
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
execution = ensure_execution_for_workflow_version(task_id=int(task.id), actor_type='system')
|
||||
execution.current_gate_code = 'inventory_preparation'
|
||||
execution.current_gate_code = 'onhand_preparation'
|
||||
task.active_process_execution_id = int(execution.id)
|
||||
db.session.flush()
|
||||
gate = ShippingProcessGate.query.filter_by(execution_id=int(execution.id), gate_code='inventory_preparation').first()
|
||||
gate = ShippingProcessGate.query.filter_by(execution_id=int(execution.id), gate_code='onhand_preparation').first()
|
||||
assert gate is not None
|
||||
db.session.commit()
|
||||
captured = {}
|
||||
@@ -284,8 +284,8 @@ def test_preparation_trigger_identity_includes_gate_and_callback(monkeypatch, ap
|
||||
{'run_no': run_no, 'sources': [dict(item) for item in sources], 'payload': dict(payload or {})}
|
||||
) or 'trigger.json',
|
||||
)
|
||||
monkeypatch.setattr('app.services.shipping_notice.inventory_source_rules.task_rpa_inventory_source', lambda task: {'source_code': 'DBS', 'warehouse_id': 'WH-1'})
|
||||
monkeypatch.setattr(per_source_rpa_service, 'task_frozen_inventory_source_codes', lambda task: ['DBS'])
|
||||
monkeypatch.setattr('app.services.shipping_notice.onhand_source_rules.task_rpa_inventory_source', lambda task: {'source_code': 'DBS', 'warehouse_id': 'WH-1'})
|
||||
monkeypatch.setattr(per_source_rpa_service, 'task_frozen_onhand_source_codes', lambda task: ['DBS'])
|
||||
monkeypatch.setattr(per_source_rpa_service, '_snapshot_ready_for_source', lambda *args, **kwargs: False)
|
||||
monkeypatch.setattr(per_source_rpa_service, '_latest_attempt', lambda *args, **kwargs: None)
|
||||
result = per_source_rpa_service.ensure_all_required_sources_prepared(task, mode='auto')
|
||||
@@ -306,20 +306,20 @@ def test_missing_inventory_trigger_is_failed_not_pending(monkeypatch, app):
|
||||
task = ShippingNotice(task_no='SN-PREP-TRIGGER-MISSING')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
monkeypatch.setattr(per_source_rpa_service, 'task_frozen_inventory_source_codes', lambda task: ['DBS'])
|
||||
monkeypatch.setattr(per_source_rpa_service, 'task_frozen_onhand_source_codes', lambda task: ['DBS'])
|
||||
monkeypatch.setattr(per_source_rpa_service, '_snapshot_ready_for_source', lambda *args, **kwargs: False)
|
||||
monkeypatch.setattr(per_source_rpa_service, '_latest_attempt', lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(per_source_rpa_service, 'write_inventory_export_batch_trigger', lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_source_repository.get_database_inventory_source',
|
||||
'app.services.shipping_notice.onhand_source_repository.get_database_inventory_source',
|
||||
lambda code, **kwargs: {'source_code': code, 'warehouse_id': 'WH-1'},
|
||||
)
|
||||
result = per_source_rpa_service.ensure_all_required_sources_prepared(task, mode='retry_rpa')
|
||||
assert result.pending_source_codes == []
|
||||
assert result.failed_source_codes == ['DBS']
|
||||
# 读取真实数据库记录,避免被用于构造场景的 monkeypatch 查询函数遮蔽。
|
||||
from app.models import ShippingTaskInventoryRpaAttempt
|
||||
attempt = ShippingTaskInventoryRpaAttempt.query.filter_by(
|
||||
from app.models import FreightRpaOnhandTaskAttempt
|
||||
attempt = FreightRpaOnhandTaskAttempt.query.filter_by(
|
||||
task_no=task.task_no, source_code='DBS', attempt_no=1,
|
||||
).one()
|
||||
assert attempt.status == 'failed'
|
||||
@@ -337,7 +337,7 @@ def test_formal_gate_inventory_retry_requires_pre_frozen_facts(monkeypatch, app)
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-PREP-FREEZE-OPERATOR', task_id=task.id,
|
||||
current_gate_code='inventory_preparation', status='blocked',
|
||||
current_gate_code='onhand_preparation', status='blocked',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
@@ -348,11 +348,11 @@ def test_formal_gate_inventory_retry_requires_pre_frozen_facts(monkeypatch, app)
|
||||
lambda task, **kwargs: seen.update(kwargs) or object(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_recovery_service.create_inventory_preparation_round',
|
||||
'app.services.shipping_notice.onhand_recovery_service.create_inventory_preparation_round',
|
||||
lambda **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
'app.services.shipping_notice.onhand_workflow.ensure_onhand',
|
||||
lambda payload: {'status': 'running', 'data': {'rpa': {}}},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -360,10 +360,10 @@ def test_formal_gate_inventory_retry_requires_pre_frozen_facts(monkeypatch, app)
|
||||
lambda **kwargs: None,
|
||||
)
|
||||
|
||||
gate = type('Gate', (), {'gate_code': 'inventory_preparation', 'status': 'blocked_manual', 'blocking_reason_code': None})()
|
||||
gate = type('Gate', (), {'gate_code': 'onhand_preparation', 'status': 'blocked_manual', 'blocking_reason_code': None})()
|
||||
result = process_gate_executor._handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={'action_code': 'retry_inventory_preparation', 'operator_id': 77},
|
||||
payload={'action_code': 'retry_onhand_preparation', 'operator_id': 77},
|
||||
)
|
||||
assert seen == {}
|
||||
assert result['outcome'] == 'blocked_retryable'
|
||||
@@ -374,22 +374,22 @@ def test_per_source_callback_rejects_candidate_set_identity_mismatch(app):
|
||||
"""旧 CandidateSet 回调必须在写入库存事实前被拒绝。"""
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingInventoryCandidateSet,
|
||||
ShippingOnhandCandidateSet,
|
||||
ShippingNotice,
|
||||
ShippingTaskInventoryRpaAttempt,
|
||||
FreightRpaOnhandTaskAttempt,
|
||||
)
|
||||
from app.services.shipping_notice.per_source_rpa_service import per_source_callback_handler
|
||||
|
||||
task = ShippingNotice(task_no='SN-PREP-CALLBACK-IDENTITY')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
current = ShippingInventoryCandidateSet(
|
||||
current = ShippingOnhandCandidateSet(
|
||||
task_id=task.id, set_version=2, lifecycle_status='frozen', input_fingerprint='b' * 64,
|
||||
)
|
||||
db.session.add(current)
|
||||
db.session.flush()
|
||||
task.active_inventory_candidate_set_id = current.id
|
||||
attempt = ShippingTaskInventoryRpaAttempt(
|
||||
attempt = FreightRpaOnhandTaskAttempt(
|
||||
task_no=task.task_no,
|
||||
source_code='DBS',
|
||||
attempt_no=1,
|
||||
@@ -437,7 +437,7 @@ def test_rpa_report_inventory_fails_closed_on_per_source_identity_mismatch(app,
|
||||
"""统一单源回调入口遇到身份错配时必须拒绝且不得落入旧库存写入路径。"""
|
||||
from app import db
|
||||
from app.models import ShippingOrderTask, ShippingTaskEvent
|
||||
from app.services.shipping_notice import inventory_rpa_workflow
|
||||
from app.services.shipping_notice import onhand_rpa_workflow
|
||||
|
||||
task = ShippingOrderTask(task_no='SNCALLBACKIDENTITYENTRY', user_id=1, source_type='direct_pdf')
|
||||
db.session.add(task)
|
||||
@@ -445,7 +445,7 @@ def test_rpa_report_inventory_fails_closed_on_per_source_identity_mismatch(app,
|
||||
db.session.commit()
|
||||
|
||||
monkeypatch.setattr(
|
||||
inventory_rpa_workflow,
|
||||
onhand_rpa_workflow,
|
||||
'_validate_single_source_v2_contract',
|
||||
lambda task, payload: None,
|
||||
)
|
||||
@@ -455,12 +455,12 @@ def test_rpa_report_inventory_fails_closed_on_per_source_identity_mismatch(app,
|
||||
)
|
||||
legacy_called = {'value': False}
|
||||
monkeypatch.setattr(
|
||||
inventory_rpa_workflow,
|
||||
onhand_rpa_workflow,
|
||||
'_lock_task_for_rpa_callback',
|
||||
lambda task: legacy_called.__setitem__('value', True) or task,
|
||||
)
|
||||
|
||||
response = inventory_rpa_workflow.rpa_report_inventory({
|
||||
response = onhand_rpa_workflow.rpa_report_inventory({
|
||||
'schema_version': 'freight_rpa.onhand.v1',
|
||||
'callback_id': 'PSR-SNCALLBACKIDENTITYENTRY-DBS-A1-X:C1',
|
||||
'task_no': task.task_no,
|
||||
@@ -489,7 +489,7 @@ def test_rpa_report_inventory_parses_per_source_run_with_hyphenated_task_no(app,
|
||||
"""PSR run_no 中 task_no 可含连字符,入口仍必须解析出真实 source_code。"""
|
||||
from app import db
|
||||
from app.models import ShippingOrderTask
|
||||
from app.services.shipping_notice import inventory_rpa_workflow
|
||||
from app.services.shipping_notice import onhand_rpa_workflow
|
||||
|
||||
task = ShippingOrderTask(task_no='SN-2026-001', user_id=1, source_type='direct_pdf')
|
||||
db.session.add(task)
|
||||
@@ -497,13 +497,13 @@ def test_rpa_report_inventory_parses_per_source_run_with_hyphenated_task_no(app,
|
||||
db.session.commit()
|
||||
captured = {}
|
||||
|
||||
monkeypatch.setattr(inventory_rpa_workflow, '_validate_single_source_v2_contract', lambda task, payload: None)
|
||||
monkeypatch.setattr(onhand_rpa_workflow, '_validate_single_source_v2_contract', lambda task, payload: None)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.per_source_rpa_service.per_source_callback_handler',
|
||||
lambda task, source_code, run_no, callback_payload: captured.update(source_code=source_code, run_no=run_no) or ('identity_mismatch', object()),
|
||||
)
|
||||
|
||||
inventory_rpa_workflow.rpa_report_inventory({
|
||||
onhand_rpa_workflow.rpa_report_inventory({
|
||||
'schema_version': 'freight_rpa.onhand.v1',
|
||||
'callback_id': 'PSR-SN-2026-001-DBS-A1-X:C1',
|
||||
'task_no': task.task_no,
|
||||
@@ -526,7 +526,7 @@ def test_rpa_report_inventory_batch_fails_closed_on_per_source_identity_mismatch
|
||||
"""异步批量处理体必须先通过逐源身份校验,不能先入库再拒绝。"""
|
||||
from app import db
|
||||
from app.models import ShippingOrderTask, ShippingTaskEvent
|
||||
from app.services.shipping_notice import inventory_rpa_workflow
|
||||
from app.services.shipping_notice import onhand_rpa_workflow
|
||||
|
||||
task = ShippingOrderTask(task_no='SNCALLBACKBATCHIDENTITY', user_id=1, source_type='direct_pdf')
|
||||
db.session.add(task)
|
||||
@@ -539,13 +539,13 @@ def test_rpa_report_inventory_batch_fails_closed_on_per_source_identity_mismatch
|
||||
)
|
||||
legacy_called = {'value': False}
|
||||
monkeypatch.setattr(
|
||||
inventory_rpa_workflow,
|
||||
onhand_rpa_workflow,
|
||||
'_lock_task_for_rpa_callback',
|
||||
lambda task: legacy_called.__setitem__('value', True) or task,
|
||||
)
|
||||
|
||||
# HTTP 入口只负责受控收件和入队;身份围栏属于 Worker 正式处理体。
|
||||
response = inventory_rpa_workflow.process_rpa_report_inventory_batch({
|
||||
response = onhand_rpa_workflow.process_rpa_report_inventory_batch({
|
||||
'schema_version': 'freight_rpa.onhand.v1',
|
||||
'callback_id': 'batch-callback-identity',
|
||||
'batch_run_no': 'BATCH-CALLBACK-IDENTITY',
|
||||
@@ -570,7 +570,7 @@ def test_rpa_report_inventory_batch_fails_closed_on_per_source_identity_mismatch
|
||||
|
||||
def test_batch_callback_inherits_authenticated_top_level_schema_version():
|
||||
"""Worker 将 schema_version 放在 batch 顶层时,结果项仍须通过逐源身份校验。"""
|
||||
from app.services.shipping_notice.inventory_rpa_workflow import _merge_batch_callback_item
|
||||
from app.services.shipping_notice.onhand_rpa_workflow import _merge_batch_callback_item
|
||||
|
||||
merged = _merge_batch_callback_item(
|
||||
{
|
||||
@@ -604,7 +604,7 @@ def test_inventory_rpa_exhausted_history_is_retryable_not_waiting_external(app):
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-RPA-FAILED-GATE', task_id=task.id, status='waiting_external',
|
||||
current_gate_code='inventory_preparation',
|
||||
current_gate_code='onhand_preparation',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
@@ -612,16 +612,16 @@ def test_inventory_rpa_exhausted_history_is_retryable_not_waiting_external(app):
|
||||
sync_fulfillment_gates_from_task(execution=execution)
|
||||
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id, gate_code='inventory_preparation',
|
||||
execution_id=execution.id, gate_code='onhand_preparation',
|
||||
).one()
|
||||
auto_poll = 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='shipping-auto-progress:rpa-failed-poll',
|
||||
input_snapshot={'action_code': 'poll_inventory_preparation'},
|
||||
input_snapshot={'action_code': 'poll_onhand_preparation'},
|
||||
)
|
||||
db.session.flush()
|
||||
|
||||
@@ -636,7 +636,7 @@ def test_inventory_rpa_exhausted_history_is_retryable_not_waiting_external(app):
|
||||
ShippingProcessGateAttempt.status.in_(('queued', 'running')),
|
||||
).count() == 0
|
||||
assert gate.status == 'blocked_retryable'
|
||||
assert gate.blocking_reason_code == 'inventory_rpa_exhausted'
|
||||
assert gate.blocking_reason_code == 'onhand_rpa_exhausted'
|
||||
db.session.refresh(execution)
|
||||
# Gate 已进入可人工恢复的 blocked_manual;Execution 仍保持 active,
|
||||
# 由当前业务阶段/Gate 投影表达阻断,不再回写旧的 execution blocked 状态。
|
||||
@@ -647,11 +647,11 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
|
||||
"""迟到成功回调已落库存行时,历史 RPA 耗尽不得把准备 Gate 回退为人工上传。"""
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingInventoryFile,
|
||||
FreightRpaOnhandReportFile,
|
||||
ShippingOrderTask,
|
||||
ShippingProcessGate,
|
||||
ShippingProcessGateAttempt,
|
||||
ShippingTaskInventoryLink,
|
||||
ShippingTaskOnhandLink,
|
||||
)
|
||||
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
|
||||
@@ -662,16 +662,16 @@ 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',
|
||||
inv_file = FreightRpaOnhandReportFile(
|
||||
onhand_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'}],
|
||||
onhand_lines_json=[{'part_number': 'PN-1', 'warehouse_id': 'WH-1'}],
|
||||
mapping_confirmed=True,
|
||||
)
|
||||
db.session.add(inv_file)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingTaskInventoryLink(
|
||||
task_id=task.id, inventory_file_id=inv_file.id, is_active=True,
|
||||
db.session.add(ShippingTaskOnhandLink(
|
||||
task_id=task.id, onhand_file_id=inv_file.id, is_active=True,
|
||||
))
|
||||
db.session.flush()
|
||||
execution = ensure_execution_for_workflow_version(task_id=int(task.id))
|
||||
@@ -681,11 +681,11 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
|
||||
).all():
|
||||
attempt.status = 'superseded'
|
||||
for gate in ShippingProcessGate.query.filter_by(execution_id=int(execution.id)).all():
|
||||
if gate.gate_code == 'inventory_preparation':
|
||||
if gate.gate_code == 'onhand_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.blocking_reason_code = 'onhand_rpa_exhausted'
|
||||
gate.next_action_code = 'retry_onhand_preparation'
|
||||
elif gate.gate_code in {'onhand_field_mapping', 'onhand_matching'}:
|
||||
gate.status = 'pending'
|
||||
gate.next_action_code = None
|
||||
elif int(gate.sequence_no) < 13:
|
||||
@@ -695,10 +695,10 @@ def test_ready_inventory_snapshot_overrides_stale_rpa_exhausted_gate(app):
|
||||
sync_fulfillment_gates_from_task(execution=execution)
|
||||
|
||||
preparation = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id, gate_code='inventory_preparation',
|
||||
execution_id=execution.id, gate_code='onhand_preparation',
|
||||
).one()
|
||||
matching = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id, gate_code='inventory_matching',
|
||||
execution_id=execution.id, gate_code='onhand_matching',
|
||||
).one()
|
||||
# 领域事实已有库存行时,不得把尚未执行的 matching 投影成 match_failed(--)。
|
||||
assert matching.status != 'blocked_retryable'
|
||||
@@ -724,23 +724,23 @@ def test_external_wait_skips_stale_preparation_poll_after_gate_switch(app):
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-STALE-PREP-POLL', task_id=task.id, status='active',
|
||||
current_gate_code='inventory_matching',
|
||||
current_gate_code='onhand_matching',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
sync_fulfillment_gates_from_task(execution=execution)
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id, gate_code='inventory_matching',
|
||||
execution_id=execution.id, gate_code='onhand_matching',
|
||||
).one()
|
||||
gate.status = 'waiting_external'
|
||||
gate.next_action_code = 'poll_inventory_preparation'
|
||||
gate.next_action_code = 'poll_onhand_preparation'
|
||||
gate.effective_result_json = {'waiting_since': datetime.utcnow().isoformat()}
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code=gate.gate_code,
|
||||
trigger_type='user_retry', actor_type='system', actor_id='test',
|
||||
idempotency_key='stale-preparation-poll',
|
||||
input_snapshot={'action_code': 'retry_inventory_from_preparation', 'payload': {}},
|
||||
input_snapshot={'action_code': 'retry_onhand_from_preparation', 'payload': {}},
|
||||
)
|
||||
db.session.flush()
|
||||
|
||||
@@ -762,12 +762,12 @@ def test_inventory_external_wait_poll_reuses_single_gate_attempt(app):
|
||||
db.session.flush()
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='SPE-SINGLE-POLL-ATTEMPT', task_id=task.id, status='waiting_external',
|
||||
current_gate_code='inventory_preparation',
|
||||
current_gate_code='onhand_preparation',
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
gate = ShippingProcessGate(
|
||||
execution_id=execution.id, gate_code='inventory_preparation', sequence_no=13,
|
||||
execution_id=execution.id, gate_code='onhand_preparation', sequence_no=13,
|
||||
status='waiting_external', effective_result_json={'waiting_since': datetime.utcnow().isoformat()},
|
||||
)
|
||||
db.session.add(gate)
|
||||
@@ -777,7 +777,7 @@ def test_inventory_external_wait_poll_reuses_single_gate_attempt(app):
|
||||
gate_code=gate.gate_code,
|
||||
trigger_type='system_requeue', actor_type='system', actor_id='test',
|
||||
idempotency_key='single-poll-attempt',
|
||||
input_snapshot={'action_code': 'poll_inventory_preparation', 'payload': {}},
|
||||
input_snapshot={'action_code': 'poll_onhand_preparation', 'payload': {}},
|
||||
)
|
||||
gate.status = 'waiting_external'
|
||||
attempt.status = 'succeeded'
|
||||
@@ -832,9 +832,9 @@ def test_inventory_preparation_poll_keeps_callback_timeout_without_reinvoking_rp
|
||||
"""已失败的准备轮次被旧 poll 领取时,必须保留超时并禁止再次调 RPA。"""
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingInventoryCandidateSet,
|
||||
ShippingInventoryCandidateSource,
|
||||
ShippingInventoryPreparationAttempt,
|
||||
ShippingOnhandCandidateSet,
|
||||
ShippingOnhandCandidateSource,
|
||||
ShippingOnhandPreparationAttempt,
|
||||
ShippingProcessGate,
|
||||
ShippingTaskEvent,
|
||||
)
|
||||
@@ -853,31 +853,31 @@ def test_inventory_preparation_poll_keeps_callback_timeout_without_reinvoking_rp
|
||||
db.session.flush()
|
||||
execution = ensure_execution_for_workflow_version(
|
||||
task_id=task.id,
|
||||
start_gate_code='inventory_preparation',
|
||||
start_gate_code='onhand_preparation',
|
||||
)
|
||||
task.active_process_execution_id = execution.id
|
||||
# 上一轮准备已裁决并冻结库存源候选:poll 前置的补裁决必须被跳过,否则
|
||||
# adjudicate_and_apply_inventory_source 会新创建/替换 CandidateSet 并把
|
||||
# execution.candidate_set_id 刷新为新的 id(≠ 本轮失败 Preparation 的 candidate_set_id),
|
||||
# 导致 failed_preparation 过滤不到而误调 RPA。
|
||||
candidate = ShippingInventoryCandidateSet(
|
||||
candidate = ShippingOnhandCandidateSet(
|
||||
task_id=task.id, set_version=1, lifecycle_status='frozen',
|
||||
input_fingerprint='b' * 64,
|
||||
)
|
||||
db.session.add(candidate)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingInventoryCandidateSource(
|
||||
db.session.add(ShippingOnhandCandidateSource(
|
||||
candidate_set_id=candidate.id, source_code='DSV360_AWSDU',
|
||||
candidate_order=1, candidate_origin='rule',
|
||||
))
|
||||
from app.models import ShippingInventoryCandidateLine
|
||||
db.session.add(ShippingInventoryCandidateLine(
|
||||
from app.models import ShippingOnhandCandidateLine
|
||||
db.session.add(ShippingOnhandCandidateLine(
|
||||
candidate_set_id=candidate.id, line_no=1, source_codes_json=['DSV360_AWSDU'],
|
||||
))
|
||||
db.session.flush()
|
||||
task.active_inventory_candidate_set_id = candidate.id
|
||||
execution.candidate_set_id = candidate.id
|
||||
preparation = ShippingInventoryPreparationAttempt(
|
||||
preparation = ShippingOnhandPreparationAttempt(
|
||||
task_id=task.id,
|
||||
execution_id=execution.id,
|
||||
attempt_no=1,
|
||||
@@ -890,7 +890,7 @@ def test_inventory_preparation_poll_keeps_callback_timeout_without_reinvoking_rp
|
||||
preparation,
|
||||
ShippingTaskEvent(
|
||||
task_id=task.id,
|
||||
event_type='inventory_rpa_failed',
|
||||
event_type='onhand_rpa_failed',
|
||||
detail_json={'error': 'Crane scheduled report not ready for download within 300000ms'},
|
||||
),
|
||||
])
|
||||
@@ -898,24 +898,24 @@ def test_inventory_preparation_poll_keeps_callback_timeout_without_reinvoking_rp
|
||||
sync_fulfillment_gates_from_task(execution=execution)
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id,
|
||||
gate_code='inventory_preparation',
|
||||
gate_code='onhand_preparation',
|
||||
).one()
|
||||
assert gate.status == 'blocked_retryable'
|
||||
assert gate.blocking_reason_code == 'inventory_rpa_timeout'
|
||||
assert gate.blocking_reason_code == 'onhand_rpa_timeout'
|
||||
|
||||
rpa_calls = {'count': 0}
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
'app.services.shipping_notice.onhand_workflow.ensure_onhand',
|
||||
lambda _payload: rpa_calls.__setitem__('count', rpa_calls['count'] + 1),
|
||||
)
|
||||
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='poll-keeps-rpa-timeout-1',
|
||||
input_snapshot={'action_code': 'poll_inventory_preparation', 'payload': {'poll': True}},
|
||||
input_snapshot={'action_code': 'poll_onhand_preparation', 'payload': {'poll': True}},
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
@@ -926,8 +926,8 @@ def test_inventory_preparation_poll_keeps_callback_timeout_without_reinvoking_rp
|
||||
assert result['skipped'] is False
|
||||
assert rpa_calls['count'] == 0
|
||||
assert gate.status == 'blocked_retryable'
|
||||
assert gate.blocking_reason_code == 'inventory_rpa_timeout'
|
||||
assert gate.next_action_code == 'retry_inventory_preparation'
|
||||
assert gate.blocking_reason_code == 'onhand_rpa_timeout'
|
||||
assert gate.next_action_code == 'retry_onhand_preparation'
|
||||
assert execution.status == 'blocked'
|
||||
|
||||
|
||||
@@ -935,9 +935,9 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
"""正式库存准备 Gate 执行必须创建 Preparation/Source lineage 并据此通过 Gate。"""
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingInventoryCandidateSet,
|
||||
ShippingInventoryCandidateSource,
|
||||
ShippingInventoryPreparationAttempt,
|
||||
ShippingOnhandCandidateSet,
|
||||
ShippingOnhandCandidateSource,
|
||||
ShippingOnhandPreparationAttempt,
|
||||
ShippingOrderTask,
|
||||
ShippingProcessGate,
|
||||
ShippingProcessGateAttempt,
|
||||
@@ -957,34 +957,34 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
candidate = ShippingInventoryCandidateSet(
|
||||
candidate = ShippingOnhandCandidateSet(
|
||||
task_id=task.id, set_version=1, lifecycle_status='frozen', input_fingerprint='c' * 64,
|
||||
)
|
||||
db.session.add(candidate)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingInventoryCandidateSource(
|
||||
db.session.add(ShippingOnhandCandidateSource(
|
||||
candidate_set_id=candidate.id, source_code='DBS', candidate_order=1, candidate_origin='rule',
|
||||
))
|
||||
from app.models import ShippingInventoryCandidateLine
|
||||
db.session.add(ShippingInventoryCandidateLine(
|
||||
from app.models import ShippingOnhandCandidateLine
|
||||
db.session.add(ShippingOnhandCandidateLine(
|
||||
candidate_set_id=candidate.id, line_no=1, source_codes_json=['DBS'],
|
||||
))
|
||||
db.session.flush()
|
||||
task.active_inventory_candidate_set_id = candidate.id
|
||||
execution = ensure_execution_for_workflow_version(task_id=task.id, actor_type='system')
|
||||
execution.candidate_set_id = candidate.id
|
||||
execution.current_gate_code = 'inventory_preparation'
|
||||
execution.current_gate_code = 'onhand_preparation'
|
||||
task.active_process_execution_id = execution.id
|
||||
gate = ShippingProcessGate.query.filter_by(
|
||||
execution_id=execution.id, gate_code='inventory_preparation',
|
||||
execution_id=execution.id, gate_code='onhand_preparation',
|
||||
).one()
|
||||
gate.status = 'pending'
|
||||
gate.next_action_code = 'retry_inventory_preparation'
|
||||
gate.next_action_code = 'retry_onhand_preparation'
|
||||
db.session.commit()
|
||||
|
||||
captured_payload = {}
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
'app.services.shipping_notice.onhand_workflow.ensure_onhand',
|
||||
lambda payload: captured_payload.update(payload) or {
|
||||
'status': 'success',
|
||||
'data': {
|
||||
@@ -1000,18 +1000,18 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
)
|
||||
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='test',
|
||||
idempotency_key='formal-prep-lineage-1',
|
||||
input_snapshot={'action_code': 'retry_inventory_preparation', 'payload': {}},
|
||||
input_snapshot={'action_code': 'retry_onhand_preparation', 'payload': {}},
|
||||
)
|
||||
result = claim_and_run_gate_attempt(attempt_id=attempt.id, worker_id='lineage-worker')
|
||||
|
||||
db.session.refresh(attempt)
|
||||
db.session.refresh(gate)
|
||||
preparation = ShippingInventoryPreparationAttempt.query.filter_by(
|
||||
preparation = ShippingOnhandPreparationAttempt.query.filter_by(
|
||||
task_id=task.id, execution_id=execution.id, gate_attempt_id=attempt.id,
|
||||
).one()
|
||||
assert result.get('skipped') is False
|
||||
@@ -1024,7 +1024,7 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
|
||||
assert preparation.source_attempts[0].status == 'ready'
|
||||
assert preparation.source_attempts[0].rpa_attempt_id is None
|
||||
db.session.refresh(execution)
|
||||
assert execution.current_gate_code != 'inventory_preparation'
|
||||
assert execution.current_gate_code != 'onhand_preparation'
|
||||
|
||||
|
||||
def test_formal_start_gate_stops_at_customer_resolution_before_inventory(app):
|
||||
@@ -1032,7 +1032,7 @@ def test_formal_start_gate_stops_at_customer_resolution_before_inventory(app):
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingCustomerShadowResolution,
|
||||
ShippingInventoryCandidateSet,
|
||||
ShippingOnhandCandidateSet,
|
||||
ShippingOrderCandidate,
|
||||
ShippingOrderIntake,
|
||||
ShippingOrderTask,
|
||||
@@ -1070,7 +1070,7 @@ def test_formal_start_gate_stops_at_customer_resolution_before_inventory(app):
|
||||
resolution_context_json={},
|
||||
))
|
||||
db.session.flush()
|
||||
candidate = ShippingInventoryCandidateSet(
|
||||
candidate = ShippingOnhandCandidateSet(
|
||||
task_id=task.id, set_version=1, lifecycle_status='frozen', input_fingerprint='d' * 64,
|
||||
)
|
||||
db.session.add(candidate)
|
||||
@@ -1082,7 +1082,7 @@ def test_formal_start_gate_stops_at_customer_resolution_before_inventory(app):
|
||||
def test_formal_start_gate_stops_at_field_conflict_before_inventory(app):
|
||||
"""正式起始 Gate 必须优先反映尚未解决的订单字段冲突。"""
|
||||
from app import db
|
||||
from app.models import ShippingInventoryCandidateSet, ShippingOrderTask, ShippingTaskFieldConflict
|
||||
from app.models import ShippingOnhandCandidateSet, ShippingOrderTask, ShippingTaskFieldConflict
|
||||
from app.services.shipping_notice.auto_progress_controller import determine_formal_start_gate
|
||||
|
||||
task = ShippingOrderTask(
|
||||
@@ -1097,7 +1097,7 @@ def test_formal_start_gate_stops_at_field_conflict_before_inventory(app):
|
||||
db.session.add(ShippingTaskFieldConflict(
|
||||
task_id=task.id, field_name='part_number', status='open',
|
||||
))
|
||||
candidate = ShippingInventoryCandidateSet(
|
||||
candidate = ShippingOnhandCandidateSet(
|
||||
task_id=task.id, set_version=1, lifecycle_status='frozen', input_fingerprint='e' * 64,
|
||||
)
|
||||
db.session.add(candidate)
|
||||
@@ -1109,14 +1109,14 @@ def test_formal_start_gate_stops_at_field_conflict_before_inventory(app):
|
||||
def test_candidate_refreeze_invalidates_formal_gate_attempt_and_job(app):
|
||||
"""候选重冻结必须同时终止旧正式 GateAttempt 与其 Job。"""
|
||||
from app import db
|
||||
from app.models import Job, ShippingInventoryCandidateSet, ShippingNotice, ShippingProcessGateAttempt
|
||||
from app.models import Job, ShippingOnhandCandidateSet, ShippingNotice, ShippingProcessGateAttempt
|
||||
from app.services.shipping_notice.auto_progress_controller import supersede_auto_progress_for_candidate_refreeze
|
||||
from app.services.shipping_notice.process_gate_service import ensure_execution_for_workflow_version, queue_gate_attempt
|
||||
|
||||
task = ShippingNotice(task_no='SNCANDIDATEREFREEZEATTEMPT')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
old_candidate = ShippingInventoryCandidateSet(
|
||||
old_candidate = ShippingOnhandCandidateSet(
|
||||
task_id=task.id, set_version=1, lifecycle_status='frozen', input_fingerprint='f' * 64,
|
||||
)
|
||||
db.session.add(old_candidate)
|
||||
@@ -1128,10 +1128,10 @@ def test_candidate_refreeze_invalidates_formal_gate_attempt_and_job(app):
|
||||
db.session.flush()
|
||||
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='test',
|
||||
idempotency_key='candidate-refreeze-attempt-1',
|
||||
input_snapshot={'action_code': 'retry_inventory_preparation', 'payload': {}},
|
||||
input_snapshot={'action_code': 'retry_onhand_preparation', 'payload': {}},
|
||||
)
|
||||
job = Job.query.filter_by(id=attempt.job_id).one_or_none()
|
||||
if job is None:
|
||||
@@ -1185,9 +1185,9 @@ def test_legacy_workspace_forwarding_audit_is_structured(app):
|
||||
|
||||
def test_inventory_mapping_is_versioned_and_immutable_by_shape():
|
||||
"""Mapping 必须按文件+版本唯一,旧版本通过 superseded_by_id 留谱系。"""
|
||||
assert 'uq_shipping_inventory_mapping_file_version' in _unique_names(ShippingInventoryMapping)
|
||||
assert 'uq_shipping_inventory_mapping_file_version' in _unique_names(FreightRpaOnhandMapping)
|
||||
assert {'version', 'status', 'mapping_json', 'input_fingerprint', 'superseded_by_id'} <= set(
|
||||
ShippingInventoryMapping.__table__.c.keys()
|
||||
FreightRpaOnhandMapping.__table__.c.keys()
|
||||
)
|
||||
|
||||
|
||||
@@ -1200,21 +1200,21 @@ def test_process_execution_projection_exposes_server_owned_recovery_targets(app)
|
||||
with app.app_context():
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='EXE-PROJECTION-RECOVERY', status='blocked',
|
||||
current_gate_code='inventory_matching', lock_version=1,
|
||||
current_gate_code='onhand_matching', lock_version=1,
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingProcessGate(
|
||||
execution_id=execution.id, gate_code='inventory_matching', sequence_no=15,
|
||||
execution_id=execution.id, gate_code='onhand_matching', sequence_no=15,
|
||||
status='blocked_manual', evaluation_version=2,
|
||||
))
|
||||
db.session.flush()
|
||||
projection = serialize_process_execution(execution)
|
||||
targets = {item['action_code']: item for item in projection['recovery_targets']}
|
||||
gate_targets = {item['action_code']: item for item in projection['current_gate']['recovery_targets']}
|
||||
assert targets['retry_inventory_from_preparation']['target_gate'] == 'inventory_preparation'
|
||||
assert gate_targets['retry_inventory_from_preparation']['target_gate'] == 'inventory_preparation'
|
||||
assert targets['retry_inventory_from_field_mapping']['resume_after_gate'] == 'inventory_matching'
|
||||
assert targets['retry_onhand_from_preparation']['target_gate'] == 'onhand_preparation'
|
||||
assert gate_targets['retry_onhand_from_preparation']['target_gate'] == 'onhand_preparation'
|
||||
assert targets['retry_onhand_from_field_mapping']['resume_after_gate'] == 'onhand_matching'
|
||||
assert projection['active_recovery_plans'] == []
|
||||
|
||||
|
||||
@@ -1231,12 +1231,12 @@ def test_process_execution_projection_batch_loads_latest_attempts(app):
|
||||
with app.app_context():
|
||||
execution = ShippingProcessExecution(
|
||||
execution_no='EXE-BATCH-ATTEMPT', status='blocked',
|
||||
current_gate_code='inventory_matching', lock_version=1,
|
||||
current_gate_code='onhand_matching', lock_version=1,
|
||||
)
|
||||
db.session.add(execution)
|
||||
db.session.flush()
|
||||
gate = ShippingProcessGate(
|
||||
execution_id=execution.id, gate_code='inventory_matching', sequence_no=15,
|
||||
execution_id=execution.id, gate_code='onhand_matching', sequence_no=15,
|
||||
status='blocked_manual', evaluation_version=2,
|
||||
)
|
||||
db.session.add(gate)
|
||||
@@ -1273,8 +1273,8 @@ def test_recovery_plan_outcome_mapping_is_terminal_or_waiting():
|
||||
|
||||
class Plan:
|
||||
status = 'queued'
|
||||
action_code = 'retry_inventory_from_preparation'
|
||||
resume_after_gate = 'inventory_sufficiency'
|
||||
action_code = 'retry_onhand_from_preparation'
|
||||
resume_after_gate = 'onhand_sufficiency'
|
||||
started_at = None
|
||||
completed_at = None
|
||||
failure_code = None
|
||||
@@ -1297,8 +1297,8 @@ def test_current_inventory_rematch_shortage_completes_recovery_plan():
|
||||
|
||||
class Plan:
|
||||
status = 'queued'
|
||||
action_code = 'retry_inventory_from_matching'
|
||||
resume_after_gate = 'inventory_sufficiency'
|
||||
action_code = 'retry_onhand_from_matching'
|
||||
resume_after_gate = 'onhand_sufficiency'
|
||||
started_at = None
|
||||
completed_at = None
|
||||
failure_code = None
|
||||
@@ -1479,13 +1479,13 @@ def test_inventory_rematch_shortage_is_business_result_not_technical_failure(mon
|
||||
lambda _task: False,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.line_inventory_match_projection.load_current_match_facts_by_task',
|
||||
'app.services.shipping_notice.line_onhand_match_projection.load_current_match_facts_by_task',
|
||||
lambda _task_id: {1: {'available_qty': 14, 'shortage_qty': 16}},
|
||||
)
|
||||
|
||||
result = _handle_retry_inventory_matching(
|
||||
execution=SimpleNamespace(task_id=13),
|
||||
gate=SimpleNamespace(gate_code='inventory_sufficiency'),
|
||||
gate=SimpleNamespace(gate_code='onhand_sufficiency'),
|
||||
payload={'actor_user_id': 1},
|
||||
)
|
||||
|
||||
@@ -1518,15 +1518,15 @@ def test_field_mapping_recovery_does_not_create_preparation_round(monkeypatch):
|
||||
'get',
|
||||
lambda _model, _id: SimpleNamespace(
|
||||
execution_id=1,
|
||||
current_gate='inventory_matching',
|
||||
action_code='retry_inventory_from_field_mapping',
|
||||
target_gate='inventory_field_mapping',
|
||||
resume_after_gate='inventory_matching',
|
||||
current_gate='onhand_matching',
|
||||
action_code='retry_onhand_from_field_mapping',
|
||||
target_gate='onhand_field_mapping',
|
||||
resume_after_gate='onhand_matching',
|
||||
),
|
||||
)
|
||||
result = executor._dispatch_action(
|
||||
execution=SimpleNamespace(id=1), gate=SimpleNamespace(gate_code='inventory_matching'),
|
||||
action_code='retry_inventory_from_field_mapping', payload={'recovery_plan_id': 7},
|
||||
execution=SimpleNamespace(id=1), gate=SimpleNamespace(gate_code='onhand_matching'),
|
||||
action_code='retry_onhand_from_field_mapping', payload={'recovery_plan_id': 7},
|
||||
)
|
||||
assert result['outcome'] == 'blocked_manual'
|
||||
assert called['preparation'] == 0
|
||||
@@ -1551,7 +1551,7 @@ def test_field_mapping_recovery_resumes_matching_after_mapping_passes(monkeypatc
|
||||
lambda **_: called.__setitem__('matching', called['matching'] + 1) or {'outcome': 'passed'},
|
||||
)
|
||||
result = _handle_retry_inventory_from_field_mapping(
|
||||
execution=object(), gate=SimpleNamespace(gate_code='inventory_matching'), payload={},
|
||||
execution=object(), gate=SimpleNamespace(gate_code='onhand_matching'), payload={},
|
||||
)
|
||||
assert result['outcome'] == 'passed'
|
||||
assert called['matching'] == 1
|
||||
@@ -1603,11 +1603,11 @@ def test_inventory_preparation_retry_rejects_legacy_task_without_snapshot(monkey
|
||||
lambda target, **kwargs: captured.update(target=target, **kwargs) or setattr(target, 'order_snapshot_id', 901),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_recovery_service.create_inventory_preparation_round',
|
||||
'app.services.shipping_notice.onhand_recovery_service.create_inventory_preparation_round',
|
||||
lambda **_: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
'app.services.shipping_notice.onhand_workflow.ensure_onhand',
|
||||
lambda _payload: {'status': 'running', 'message': 'waiting RPA'},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -1625,8 +1625,8 @@ def test_inventory_preparation_retry_rejects_legacy_task_without_snapshot(monkey
|
||||
|
||||
result = _handle_retry_inventory_preparation(
|
||||
execution=SimpleNamespace(task_id=13, id=21),
|
||||
gate=SimpleNamespace(gate_code='inventory_preparation'),
|
||||
payload={'action_code': 'retry_inventory_preparation', 'actor_user_id': 5},
|
||||
gate=SimpleNamespace(gate_code='onhand_preparation'),
|
||||
payload={'action_code': 'retry_onhand_preparation', 'actor_user_id': 5},
|
||||
)
|
||||
|
||||
# 关键断言:正式 Gate 入口不补冻结,也不进入库存 RPA。
|
||||
@@ -1637,7 +1637,7 @@ def test_inventory_preparation_retry_rejects_legacy_task_without_snapshot(monkey
|
||||
|
||||
|
||||
def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
"""库存准备执行器按已有动作码映射 ensure_inventory mode,禁止人工入口一律 retry_rpa。"""
|
||||
"""库存准备执行器按已有动作码映射 ensure_onhand mode,禁止人工入口一律 retry_rpa。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice.process_gate_executor import _handle_retry_inventory_preparation
|
||||
|
||||
@@ -1658,19 +1658,19 @@ def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
lambda _task: SimpleNamespace(id=77),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_candidate_projection.get_active_candidate_set',
|
||||
'app.services.shipping_notice.onhand_candidate_projection.get_active_candidate_set',
|
||||
lambda _task: candidate_set,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_candidate_projection.get_active_candidate_lines',
|
||||
'app.services.shipping_notice.onhand_candidate_projection.get_active_candidate_lines',
|
||||
lambda _task: [line],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_candidate_projection.get_active_candidate_sources',
|
||||
'app.services.shipping_notice.onhand_candidate_projection.get_active_candidate_sources',
|
||||
lambda _task: sources,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_recovery_service.create_inventory_preparation_round',
|
||||
'app.services.shipping_notice.onhand_recovery_service.create_inventory_preparation_round',
|
||||
lambda **_: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -1678,7 +1678,7 @@ def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
lambda **_: {},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.shipping_notice.inventory_workflow.ensure_inventory',
|
||||
'app.services.shipping_notice.onhand_workflow.ensure_onhand',
|
||||
lambda payload: captured.append(dict(payload)) or {'status': 'running', 'data': {'rpa': {}}},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
@@ -1695,7 +1695,7 @@ def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
)
|
||||
# poll 路径会查失败 Attempt;无失败行时继续 ensure_inventory。
|
||||
monkeypatch.setattr(
|
||||
'app.models.ShippingInventoryPreparationAttempt.query',
|
||||
'app.models.ShippingOnhandPreparationAttempt.query',
|
||||
SimpleNamespace(
|
||||
filter_by=lambda **_: SimpleNamespace(
|
||||
filter=lambda *_a, **_k: SimpleNamespace(
|
||||
@@ -1707,12 +1707,12 @@ def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
)
|
||||
|
||||
execution = SimpleNamespace(task_id=1, id=21, candidate_set_id=None)
|
||||
gate = SimpleNamespace(gate_code='inventory_preparation')
|
||||
gate = SimpleNamespace(gate_code='onhand_preparation')
|
||||
|
||||
captured.clear()
|
||||
_handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={'action_code': 'retry_inventory_preparation', 'actor_user_id': 5},
|
||||
payload={'action_code': 'retry_onhand_preparation', 'actor_user_id': 5},
|
||||
)
|
||||
# 显式强制 RPA 码 → mode=retry_rpa。
|
||||
assert captured[-1].get('mode') == 'retry_rpa'
|
||||
@@ -1720,7 +1720,7 @@ def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
captured.clear()
|
||||
_handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={'action_code': 'poll_inventory_preparation', 'actor_user_id': 5},
|
||||
payload={'action_code': 'poll_onhand_preparation', 'actor_user_id': 5},
|
||||
)
|
||||
# 只读轮询:默认 auto,禁止自动再试。
|
||||
assert captured[-1].get('mode') in (None, 'auto')
|
||||
@@ -1730,7 +1730,7 @@ def test_inventory_preparation_mode_maps_by_action_code(monkeypatch):
|
||||
_handle_retry_inventory_preparation(
|
||||
execution=execution, gate=gate,
|
||||
payload={
|
||||
'action_code': 'retry_inventory_preparation',
|
||||
'action_code': 'retry_onhand_preparation',
|
||||
'trigger': 'gate_attempt_passed',
|
||||
'actor_user_id': 5,
|
||||
},
|
||||
@@ -1759,12 +1759,12 @@ def test_manual_business_block_is_a_successful_attempt(app):
|
||||
)
|
||||
attempt = queue_gate_attempt(
|
||||
execution_no=execution.execution_no,
|
||||
gate_code='inventory_sufficiency',
|
||||
gate_code='onhand_sufficiency',
|
||||
trigger_type='user_retry',
|
||||
actor_type='user',
|
||||
actor_id=1,
|
||||
idempotency_key='manual-block-success',
|
||||
input_snapshot={'action_code': 'retry_inventory_from_matching', 'payload': {}},
|
||||
input_snapshot={'action_code': 'retry_onhand_from_matching', 'payload': {}},
|
||||
)
|
||||
mark_attempt_running(attempt_id=int(attempt.id), worker_id='test')
|
||||
gate = complete_gate_attempt(
|
||||
|
||||
Reference in new issue
Block a user