feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
tests/services/shipping_notice/test_reconciliation_phase34_contract.py
|
||||
|
||||
用途:Phase 3 统一 Projection 四事实 + Phase 4 管理端 replay 权限 +
|
||||
BRANCH F ownership_anomaly rollback 的合同测试。
|
||||
用途:Phase 3 统一 Projection 四事实 + Phase 4 BRANCH F
|
||||
ownership_anomaly rollback 的合同测试。
|
||||
依赖:recovery_contract、reconciliation_projector、
|
||||
reconciliation_service.reconcile_and_progress(mock 掉 DB 层仅验证纯函数矩阵)。
|
||||
逻辑:
|
||||
@@ -14,9 +14,6 @@ tests/services/shipping_notice/test_reconciliation_phase34_contract.py
|
||||
retryable/failed/running/idle)。
|
||||
[P3 T4] project_case_primary_action 1a~1i CTA 分派矩阵。
|
||||
[P3 T5] project_review_case_projection_bundle 六字段非空(Case + automation + actions)。
|
||||
[P4 T6] reconcile_and_progress PRE-CHECK:
|
||||
a) replay_mode=True + is_admin=False → SHIPPING.RECONCILE_FORCE_CREATE_UNAUTHORIZED 422
|
||||
b) legacy_job_id=999 + is_admin=False → 422
|
||||
[P4 T7] ownership_anomaly BRANCH F:
|
||||
断言触发路径最终 outcome=ownership_anomaly_rejected 且不会脏写
|
||||
(这里只测 ValidationError 降级情形,Review Case 不含旧流程字段)。
|
||||
@@ -287,7 +284,7 @@ def test_pending_order_freeze_readiness_waits_for_the_user_to_submit_validation(
|
||||
|
||||
|
||||
# ============================================================
|
||||
# [P4 T6] 管理员权限拦截(纯函数 PRE-CHECK,通过 monkeypatch 替换锁 DB 查询)
|
||||
# [P4] BRANCH F 归属异常(通过 monkeypatch 替换锁 DB 查询)
|
||||
# ============================================================
|
||||
|
||||
def _mock_case_for_p4(case_no='CASE-2608-0042'):
|
||||
@@ -372,72 +369,6 @@ def _install_minimal_mocks(monkeypatch, case=None, app=None):
|
||||
return case
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_p4_t6a_replay_mode_without_admin_raises(monkeypatch):
|
||||
"""[P4 T6a] replay_mode=True + is_admin=False → 422 SHIPPING.RECONCILE_FORCE_CREATE_UNAUTHORIZED。"""
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice.reconciliation_service import reconcile_and_progress
|
||||
|
||||
_install_minimal_mocks(monkeypatch)
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
reconcile_and_progress(
|
||||
user_id=1,
|
||||
case_no='CASE-2608-0042',
|
||||
operation_id=str(uuid.uuid4()),
|
||||
user_action='auto',
|
||||
is_admin=False,
|
||||
replay_mode=True,
|
||||
)
|
||||
assert exc.value.code == 'SHIPPING.RECONCILE_FORCE_CREATE_UNAUTHORIZED'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_p4_t6b_legacy_job_id_without_admin_raises(monkeypatch):
|
||||
"""[P4 T6b] legacy_job_id=928 + is_admin=False → 422 权限拒绝。"""
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice.reconciliation_service import reconcile_and_progress
|
||||
|
||||
_install_minimal_mocks(monkeypatch)
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
reconcile_and_progress(
|
||||
user_id=1,
|
||||
case_no='CASE-2608-0042',
|
||||
operation_id=str(uuid.uuid4()),
|
||||
user_action='auto',
|
||||
is_admin=False,
|
||||
legacy_job_id=928,
|
||||
)
|
||||
assert exc.value.code == 'SHIPPING.RECONCILE_FORCE_CREATE_UNAUTHORIZED'
|
||||
|
||||
|
||||
@pytest.mark.pure_unit
|
||||
def test_p4_t6c_legacy_job_requires_failed_or_dead(monkeypatch):
|
||||
"""[P4 T6c] legacy_job 必须是 failed/dead,否则 422。"""
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.shipping_notice.reconciliation_service import reconcile_and_progress
|
||||
|
||||
_install_minimal_mocks(monkeypatch)
|
||||
bad_job = _fake_job(job_id=991, status='running') # 不是失败态
|
||||
|
||||
from app.services.shipping_notice import reconciliation_service as mod
|
||||
|
||||
def _get(coll, jid): # noqa: ARG001
|
||||
if str(getattr(coll, '__name__', '')) == 'Job' and jid == 991:
|
||||
return bad_job
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(mod.db.session, 'get', _get)
|
||||
with pytest.raises(ValidationError):
|
||||
reconcile_and_progress(
|
||||
user_id=1,
|
||||
case_no='CASE-2608-0042',
|
||||
operation_id=str(uuid.uuid4()),
|
||||
user_action='auto',
|
||||
is_admin=True,
|
||||
legacy_job_id=991,
|
||||
)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# [P4 T7] BRANCH F ownership_anomaly 422 降级(Review Case 不含旧流程字段)
|
||||
# ============================================================
|
||||
|
||||
Reference in new issue
Block a user