chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑

This commit is contained in:
hugo committed 2026-08-17 19:56:51 +08:00
1 parent 5ef8329bd8
commit 4ec4e57005
183 files changed
+14653 -3936

No files matched your search

@@ -132,6 +132,20 @@ def test_p3_t4_primary_action_matrix(bcode, actions_in, retryable, expected_pa_c
assert got['variant'] == variant, label
@pytest.mark.pure_unit
def test_resolved_field_conflict_has_no_current_task_cta():
"""字段冲突清零后,保存校验留在底栏,当前任务不得再制造 CTA。"""
from app.services.shipping_notice.reconciliation_projector import project_case_primary_action
action = project_case_primary_action(
'waiting_human',
{},
['view', 'validate'],
)
assert action is None
@pytest.mark.pure_unit
def test_p3_t2_allowed_actions_inject_reconcile_and_remove_retry():
"""[P3 T2] 业务阻断 → REMOVE_SET 删除 retry_stp_auto_create 且注入 reconcile_and_progress。"""
@@ -183,6 +197,95 @@ def test_p3_t5_bundle_six_fields_shapes():
assert bundle['primary_action'] is None or isinstance(bundle['primary_action'], dict)
@pytest.mark.pure_unit
def test_case_bundle_prefers_persisted_formal_gate_over_case_draft(monkeypatch):
"""正式 field_completeness 阻断必须覆盖 Case draft 的 idle/order_review_build 推导。"""
from app.services.shipping_notice import reconciliation_projector
case = _fake_case(status='draft', candidate_id=None)
monkeypatch.setattr(
reconciliation_projector,
'_project_case_formal_gate_summary',
lambda _case: {
'current_gate': {
'gate_code': 'field_completeness',
'status': 'blocked_manual',
'blocking_reason_code': 'required_field_missing',
'next_action_code': 'edit_order_fields',
},
'current_blocking_gate': {
'gate_code': 'field_completeness',
'status': 'blocked_manual',
'blocking_reason_code': 'required_field_missing',
'next_action_code': 'edit_order_fields',
},
'blocking_reason_code': 'required_field_missing',
'next_action_code': 'edit_order_fields',
},
)
bundle = reconciliation_projector.project_review_case_projection_bundle(
case,
validation={'can_build': False, 'can_auto_create': False},
post_confirm=None,
is_admin=False,
)
assert bundle['current_gate']['gate_code'] == 'field_completeness'
assert bundle['current_gate']['blocking_reason_code'] == 'required_field_missing'
assert bundle['blocking_reason']['code'] == 'required_field_missing'
assert bundle['user_status'] == 'waiting_human'
@pytest.mark.pure_unit
def test_pending_successor_gate_clears_a_resolved_field_conflict_from_current_task():
"""字段冲突 Gate 已通过后,下游 pending 只能表示系统推进,不能回退旧 STP 冲突。"""
from app.services.shipping_notice.reconciliation_projector import (
_project_case_formal_gate_facts,
)
facts = _project_case_formal_gate_facts({
'current_gate': {
'gate_code': 'inventory_source_routing',
'status': 'pending',
'blocking_reason_code': None,
'next_action_code': None,
},
'current_blocking_gate': None,
'blocking_reason_code': None,
'next_action_code': None,
})
assert facts is not None
current_gate, blocking_reason, user_status = facts
assert current_gate['gate_code'] == 'inventory_source_routing'
assert blocking_reason['code'] is None
assert user_status == 'running'
@pytest.mark.pure_unit
def test_pending_order_freeze_readiness_waits_for_the_user_to_submit_validation():
"""建单前校验未提交时必须提示人工保存,不能伪装为自动处理中。"""
from app.services.shipping_notice.reconciliation_projector import (
_project_case_formal_gate_facts,
)
facts = _project_case_formal_gate_facts({
'current_gate': {
'gate_code': 'order_freeze_readiness',
'status': 'pending',
'blocking_reason_code': None,
'next_action_code': None,
},
})
assert facts is not None
current_gate, blocking_reason, user_status = facts
assert current_gate['gate_code'] == 'order_freeze_readiness'
assert blocking_reason['code'] is None
assert user_status == 'waiting_human'
# ============================================================
# [P4 T6] 管理员权限拦截(纯函数 PRE-CHECK,通过 monkeypatch 替换锁 DB 查询)
# ============================================================