feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码

This commit is contained in:
hugo committed 2026-08-23 00:27:18 +08:00
1 parent 935bf26fa6
commit 7cfd5d167e
230 files changed
+9337 -10989

No files matched your search

@@ -108,7 +108,7 @@ def test_inventory_shortage_gate_projects_a_user_visible_blocking_reason():
def test_normalize_unknown_action_codes():
"""未知 / 别名动作码映射到契约或丢弃。"""
assert normalize_action_code('retry_failed_documents') == 'retry'
assert normalize_action_code('retry_failed_documents') == 'retry_failed_documents'
assert normalize_action_code('open_fulfillment') == 'view_result'
assert normalize_action_code('not_a_real_action') is None
@@ -165,7 +165,10 @@ def test_download_excel_requires_excel_ready_fact():
with_ready = derive_available_actions(
status='blocked',
stage='freight_uploading',
gate={'next_action_code': 'wait_manual_upload'},
gate={
'gate_code': 'manual_upload_handoff',
'next_action_code': 'wait_manual_upload',
},
excel_ready=True,
)
assert 'download_excel' in with_ready
@@ -256,8 +259,8 @@ def test_map_notice_unknown_status_fail_closed():
assert map_notice_to_processing_status_stage(unknown) == ('blocked', 'waiting_review')
def test_derive_available_actions_blocked_without_retry_gate():
"""BE-04: business blocked without retry Gate must not append retry."""
def test_derive_available_actions_without_gate_fails_closed():
"""BE-04: no Gate and no object authorization must not invent an action."""
from app.services.shipping_notice.processing_projection_invariants import (
derive_available_actions,
)
@@ -272,12 +275,11 @@ def test_derive_available_actions_blocked_without_retry_gate():
},
excel_ready=False,
)
assert 'retry' not in actions
assert 'open_inventory_source_review' in actions
assert actions == []
def test_derive_available_actions_failed_adds_retry():
"""BE-04: technical failed should allow retry by default."""
def test_derive_available_actions_failed_without_gate_does_not_add_retry():
"""BE-04: failed status alone cannot authorize a generic retry."""
from app.services.shipping_notice.processing_projection_invariants import (
derive_available_actions,
)
@@ -288,7 +290,7 @@ def test_derive_available_actions_failed_adds_retry():
gate=None,
excel_ready=False,
)
assert 'retry' in actions
assert actions == ['view_result']
def test_retryable_projection_uses_technical_failure_reason_mapping():
@@ -477,8 +479,8 @@ def test_inventory_file_empty_keeps_gate_retry_as_the_only_primary_action():
assert payload['available_actions'] == ['retry_inventory_preparation']
def test_waiting_human_reconcile_action_uses_projected_available_actions():
"""人工阻断存在统一对账动作时,主动作必须从当前投影动作列表中安全选取。"""
def test_waiting_human_reconcile_action_uses_gate_action():
"""人工阻断的统一对账动作必须由正式 Gate 明确下发。"""
payload = apply_user_projection_fields({
'status': 'waiting_review',
'stage': 'inventory_matching',
@@ -486,11 +488,12 @@ def test_waiting_human_reconcile_action_uses_projected_available_actions():
'gate_code': 'inventory_candidates_calculated',
'status': 'blocked',
'blocking_reason_code': 'inventory_candidates_required',
'next_action_code': 'reconcile_and_progress',
},
'available_actions': ['reconcile_and_progress', 'view_details'],
'available_actions': ['view_details'],
})
# 关键断言:该分支不得因未定义局部变量返回 500,且必须选中统一恢复入口。
# 关键断言:只能选中 Gate 明示的统一恢复入口。
assert payload['user_status'] == 'waiting_human'
assert payload['primary_action']['code'] == 'reconcile_and_progress'