feat(shipping-notice): 完成货代发货通知全门禁恢复MVP收口
完成全门禁恢复MVP版本交付:调整自动上传与重试配置,重构正式执行链路;修复多处代码bug,新增测试与审计工具;更新全流程文档与契约规范。
This commit is contained in:
1 parent
8e0bbf7a81
commit
c94d173f92
181 files changed
+12947
-1724
No files matched your search
@@ -16,6 +16,7 @@ from app.services.shipping_notice.process_gate_contract import (
|
||||
PROCESS_GATE_DEFINITIONS,
|
||||
PROCESS_GATE_REASON_OWNING_GATE,
|
||||
assert_process_gate_contract_integrity,
|
||||
action_presentation,
|
||||
field_quality_may_block,
|
||||
owning_gate_for_reason,
|
||||
primary_next_action_for_gate,
|
||||
@@ -59,6 +60,22 @@ def test_inventory_source_routing_primary_retry_action():
|
||||
assert action == 'retry_with_latest_rules'
|
||||
|
||||
|
||||
def test_inventory_sufficiency_actions_keep_business_specific_labels():
|
||||
"""库存缺口恢复必须保留精确业务动作,禁止客户端降级为统一“重试”。"""
|
||||
assert action_presentation('open_shortage_review') == {
|
||||
'code': 'open_shortage_review',
|
||||
'label_key': 'workspace.shippingNotice.processGate.actionCodes.open_shortage_review',
|
||||
'kind': 'current_gate',
|
||||
'dispatch': 'navigation',
|
||||
}
|
||||
assert action_presentation('retry_inventory_from_matching') == {
|
||||
'code': 'retry_inventory_from_matching',
|
||||
'label_key': 'workspace.shippingNotice.processGate.actionCodes.retry_inventory_from_matching',
|
||||
'kind': 'recovery',
|
||||
'dispatch': 'mutation',
|
||||
}
|
||||
|
||||
|
||||
def test_process_gate_reason_ownership_is_unique():
|
||||
"""
|
||||
每个阻断原因码恰好映射一个 owning_gate,覆盖率 100%。
|
||||
@@ -83,6 +100,205 @@ def test_field_quality_block_eligibility():
|
||||
assert field_quality_may_block(required=False, auto_create_key_field=False) is False
|
||||
|
||||
|
||||
def test_projection_marks_apx_gate_as_readonly_without_executable_actions(app, monkeypatch):
|
||||
"""APX 历史 Gate 只可审计展示,不能再投影为可恢复业务 Gate。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
gate = SimpleNamespace(
|
||||
id=1, gate_code='inventory_candidates_calculated', sequence_no=1,
|
||||
status='pending', evaluation_version=1, input_fingerprint=None,
|
||||
blocking_reason_code=None, blocking_reason_json=None,
|
||||
recommendation_json=None, effective_result_json={}, findings_json=None,
|
||||
next_action_code=None, passed_at=None, invalidated_at=None,
|
||||
latest_attempt_id=None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
projection.ShippingProcessGateAttempt.query,
|
||||
'get',
|
||||
lambda _id: None,
|
||||
raising=False,
|
||||
)
|
||||
payload = projection.serialize_process_gate(gate, include_diagnostics=False)
|
||||
assert payload['gate_code'] == 'inventory_candidates_calculated'
|
||||
assert payload['legacy_readonly'] is True
|
||||
assert payload['allowed_actions'] == []
|
||||
assert payload['recovery_targets'] == []
|
||||
assert len(PROCESS_GATE_DEFINITIONS) == 20
|
||||
|
||||
|
||||
def test_user_gate_summary_marks_apx_execution_readonly(app, monkeypatch):
|
||||
"""APX Execution 不能向用户下发主动作或恢复目标。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='APX-1', status='blocked', current_gate_code='inventory_candidates_calculated',
|
||||
last_passed_gate_code=None, primary_next_action_code=None, responsible_party='system',
|
||||
lock_version=1, review_case_id=None, task_id=1, updated_at=None,
|
||||
)
|
||||
gate = SimpleNamespace(
|
||||
id=1, gate_code='inventory_candidates_calculated', sequence_no=1, status='blocked_retryable',
|
||||
evaluation_version=1, input_fingerprint=None, blocking_reason_code='inventory_candidates_required',
|
||||
blocking_reason_json=None, recommendation_json=None, effective_result_json={},
|
||||
next_action_code=None, passed_at=None, invalidated_at=None, latest_attempt_id=None,
|
||||
)
|
||||
query = projection.ShippingProcessGate.query
|
||||
monkeypatch.setattr(query, 'filter_by', lambda **_kwargs: query)
|
||||
monkeypatch.setattr(query, 'order_by', lambda *_args: query)
|
||||
monkeypatch.setattr(query, 'all', lambda: [gate])
|
||||
monkeypatch.setattr(projection.ShippingProcessGateAttempt.query, 'get', lambda _id: None, raising=False)
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
assert summary['status'] == 'legacy_readonly'
|
||||
assert summary['legacy_readonly'] is True
|
||||
assert summary['next_action_code'] is None
|
||||
assert summary['allowed_actions'] == []
|
||||
|
||||
|
||||
def test_inventory_matching_recovery_keeps_review_entry_when_primary_is_technical(app, monkeypatch):
|
||||
"""库存匹配技术重试被隐藏时,跨阶段 RecoveryPlan 仍必须保留人工复核入口。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-INV-1', status='blocked',
|
||||
current_gate_code='inventory_matching', primary_next_action_code='retry_inventory_matching',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
projection,
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-INV-1', 'status': 'blocked',
|
||||
'primary_next_action_code': 'retry_inventory_matching',
|
||||
'responsible_party': 'worker',
|
||||
'current_gate': {
|
||||
'gate_code': 'inventory_matching',
|
||||
'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'inventory_match_incomplete',
|
||||
'next_action_code': 'retry_inventory_matching',
|
||||
},
|
||||
'recovery_targets': [
|
||||
{'action_code': 'retry_inventory_from_preparation', 'target_gate': 'inventory_preparation'},
|
||||
],
|
||||
'gates': [], 'active_recovery_plans': [],
|
||||
},
|
||||
)
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
|
||||
assert summary['current_blocking_gate']['gate_code'] == 'inventory_matching'
|
||||
assert summary['next_action_code'] == 'open_inventory_match_review'
|
||||
assert summary['owner_type'] == 'human'
|
||||
assert summary['technical_auto_only'] is False
|
||||
assert summary['allowed_actions'] == [
|
||||
'open_inventory_match_review',
|
||||
'retry_inventory_from_preparation',
|
||||
]
|
||||
|
||||
|
||||
def test_user_gate_summary_exposes_sanitized_failure_detail_for_any_gate(app, monkeypatch):
|
||||
"""所有 Gate 均应把当前 Attempt 的脱敏失败详情投影给用户,而非只显示泛化原因。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-FAIL-1', status='blocked',
|
||||
current_gate_code='artifact_generation', primary_next_action_code='regenerate_excel_artifact',
|
||||
responsible_party='system', lock_version=1, review_case_id=None, task_id=None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
projection,
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-FAIL-1', 'status': 'blocked',
|
||||
'primary_next_action_code': 'regenerate_excel_artifact',
|
||||
'responsible_party': 'system', 'recovery_targets': [], 'gates': [],
|
||||
'active_recovery_plans': [],
|
||||
'current_gate': {
|
||||
'gate_code': 'artifact_generation', 'status': 'blocked_retryable',
|
||||
'blocking_reason_code': 'artifact_generation_failed',
|
||||
'next_action_code': 'regenerate_excel_artifact',
|
||||
'latest_attempt': {
|
||||
'attempt_no': 7,
|
||||
'status': 'failed',
|
||||
'error_code': 'SHIPPING.EXCEL_ARTIFACT_WRITE_FAILED',
|
||||
'error_summary': r'Excel 写入失败 at C:\worker\output.xlsx password=secret',
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
assert summary['failure_detail'] is not None
|
||||
assert 'Excel 写入失败' in summary['failure_detail']
|
||||
assert '[path]' in summary['failure_detail']
|
||||
assert 'secret' not in summary['failure_detail']
|
||||
|
||||
|
||||
def test_user_gate_summary_repairs_stale_rpa_action_for_gate19(app, monkeypatch):
|
||||
"""历史 Gate 19 即使持久化了人工待办动作,也必须投影为 RPA 重试。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-RPA-STALE', status='blocked',
|
||||
current_gate_code='freight_upload_rpa',
|
||||
primary_next_action_code='regenerate_manual_upload_todo',
|
||||
responsible_party='worker', lock_version=1, review_case_id=None, task_id=None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
projection,
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-RPA-STALE', 'status': 'blocked',
|
||||
'primary_next_action_code': 'regenerate_manual_upload_todo',
|
||||
'responsible_party': 'worker', 'recovery_targets': [],
|
||||
'active_recovery_plans': [], 'gates': [],
|
||||
'current_gate': {
|
||||
'gate_code': 'freight_upload_rpa', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'upload_platform_rejected',
|
||||
'next_action_code': 'regenerate_manual_upload_todo',
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
assert summary['next_action_code'] == 'retry_freight_upload_rpa'
|
||||
assert summary['owner_type'] == 'human'
|
||||
|
||||
|
||||
def test_user_gate_summary_exposes_manual_gate_rpa_retry(app, monkeypatch):
|
||||
"""Gate 20 人工交接也可显式重试 RPA,且不依赖 AUTO_UPLOAD 配置。"""
|
||||
from types import SimpleNamespace
|
||||
from app.services.shipping_notice import process_gate_projection as projection
|
||||
|
||||
execution = SimpleNamespace(
|
||||
id=1, execution_no='EXE-MANUAL-RPA', status='blocked',
|
||||
current_gate_code='manual_upload_handoff',
|
||||
primary_next_action_code='regenerate_manual_upload_todo',
|
||||
responsible_party='owner', lock_version=1, review_case_id=None, task_id=None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
projection,
|
||||
'serialize_process_execution',
|
||||
lambda _execution, include_diagnostics=False: {
|
||||
'execution_no': 'EXE-MANUAL-RPA', 'status': 'blocked',
|
||||
'primary_next_action_code': 'regenerate_manual_upload_todo',
|
||||
'responsible_party': 'owner', 'recovery_targets': [],
|
||||
'active_recovery_plans': [], 'gates': [],
|
||||
'current_gate': {
|
||||
'gate_code': 'manual_upload_handoff', 'status': 'blocked_manual',
|
||||
'blocking_reason_code': 'manual_upload_pending',
|
||||
'next_action_code': 'regenerate_manual_upload_todo',
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
summary = projection.project_user_gate_summary(execution)
|
||||
assert summary['next_action_code'] == 'retry_freight_upload_rpa'
|
||||
assert summary['owner_type'] == 'human'
|
||||
|
||||
|
||||
def test_process_gate_dependency_integrity_and_excel_only_scope():
|
||||
"""
|
||||
校验依赖图完整性,并锁定「仅重生 Excel」不得失效库存匹配。
|
||||
|
||||
Reference in new issue
Block a user