refactor(shipping-notice): 收紧通知单与导出上传事实边界

This commit is contained in:
hugo committed 2026-09-04 20:49:03 +08:00
1 parent b5d894a923
commit 8ec028e6a3
12 files changed
+312 -318

No files matched your search

@@ -13,12 +13,12 @@ tests/test_shipping_uploaded_gate_closure.py
from __future__ import annotations
from app import db
from app.models import ShippingNotice, ShippingProcessExecution, ShippingProcessGate
from app.models import ShippingNotice, ShippingOrderTask, ShippingProcessExecution, ShippingProcessGate, User
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
def _mk_execution(task: ShippingNotice) -> ShippingProcessExecution:
def _mk_execution(task: ShippingOrderTask) -> ShippingProcessExecution:
"""建正式 20-Gate Execution,并把 inventory_sufficiency 置为人工阻断,让任务停留在「通知准备」。"""
execution = ensure_execution_for_workflow_version(task_id=int(task.id))
task.active_process_execution_id = int(execution.id)
@@ -33,12 +33,18 @@ def _mk_execution(task: ShippingNotice) -> ShippingProcessExecution:
return execution
def test_step1a_closes_all_gates_when_uploaded(app):
def test_step1a_closes_all_gates_when_uploaded(app, monkeypatch):
"""upload_status=uploaded → STEP 1A 收口全部前置 Gate,Execution 落到 completed。"""
task = ShippingNotice(task_no='SN-UPLOADED-GATE', upload_status='uploaded', match_status='fulfillable')
user = User(username='uploaded-gate-user', email='uploaded-gate@example.com', password_hash='x')
db.session.add(user); db.session.flush()
task = ShippingOrderTask(task_no='OT-UPLOADED-GATE', user_id=user.id)
db.session.add(task)
db.session.flush()
execution = _mk_execution(task)
monkeypatch.setattr(
'app.services.shipping_notice.process_gate_bridge._derived_fulfillment_status',
lambda _task: 'uploaded',
)
sync_fulfillment_gates_from_task(execution=execution, actor_type='user', actor_id=1)
db.session.commit()
@@ -53,17 +59,18 @@ def test_step1a_closes_all_gates_when_uploaded(app):
assert execution.status == 'completed'
def test_uploaded_fact_closes_gates_despite_stale_upload_pending_reason(app):
def test_uploaded_fact_closes_gates_despite_stale_upload_pending_reason(app, monkeypatch):
"""上传已成功时,历史 upload_rpa_pending 不得将正式 Gate 重新投影为阻断。"""
task = ShippingNotice(
task_no='SN-UPLOADED-STALE-PENDING',
upload_status='uploaded',
pending_human_reason='upload_rpa_pending',
match_status='fulfillable',
)
user = User(username='uploaded-stale-user', email='uploaded-stale@example.com', password_hash='x')
db.session.add(user); db.session.flush()
task = ShippingOrderTask(task_no='OT-UPLOADED-STALE-PENDING', user_id=user.id, pending_human_reason='upload_rpa_pending')
db.session.add(task)
db.session.flush()
execution = _mk_execution(task)
monkeypatch.setattr(
'app.services.shipping_notice.process_gate_bridge._derived_fulfillment_status',
lambda _task: 'uploaded',
)
sync_fulfillment_gates_from_task(execution=execution, actor_type='user', actor_id=1)
db.session.commit()
@@ -75,7 +82,9 @@ def test_uploaded_fact_closes_gates_despite_stale_upload_pending_reason(app):
def test_missing_upload_status_keeps_gate_stuck(app):
"""upload_status != uploaded → STEP 1A 不触发,前置 Gate 保留(阶段投影可被回退)。"""
task = ShippingNotice(task_no='SN-UPLOAD-NOT-SET', upload_status='partial', match_status='fulfillable')
user = User(username='upload-not-set-user', email='upload-not-set@example.com', password_hash='x')
db.session.add(user); db.session.flush()
task = ShippingOrderTask(task_no='OT-UPLOAD-NOT-SET', user_id=user.id)
db.session.add(task)
db.session.flush()
execution = _mk_execution(task)