fix(shipping-notice): 修复订单阶段投影与复核冻结门禁

This commit is contained in:
hugo committed 2026-09-15 10:29:59 +08:00
1 parent 9745bb78a7
commit 44c3bd0e80
8 files changed
+259 -17

No files matched your search

+63 -1
View File
@@ -167,6 +167,67 @@ def test_task_ui_state_stage_context_is_opt_in(app) -> None:
assert "stage_context" in detailed_state
def test_build_task_ui_state_notice_uses_ot_stage_not_freeze_gate_lifecycle(app) -> None:
"""
Notice 路径必须读 OT.stage 做五阶段,禁止仅靠 order_freeze→order_review 兜底。
断言意图:OT.stage=order_creating 时,任务中心/详情与批次同为 fulfillment_prep,
不得因 Notice 无 stage 列 + freeze Gate 显示「订单复核」。
"""
with app.app_context():
from app.services.shipping_notice.process_gate_service import (
ensure_execution_for_workflow_version,
)
from app.services.shipping_notice.ui_state import (
_process_gate_user_summary_for_task,
_task_lifecycle,
)
user = User(
username='ui-notice-ot-stage',
email='ui-notice-ot-stage@example.com',
password_hash='x',
)
db.session.add(user)
db.session.flush()
order_task = ShippingOrderTask(
task_no='OT-UI-NOTICE-OT-STAGE',
user_id=user.id,
source_type='direct_pdf',
status='waiting_review',
stage='order_creating',
progress_version=1,
)
db.session.add(order_task)
db.session.flush()
notice = ShippingNotice(
task_no='SN-UI-NOTICE-OT-STAGE',
user_id=user.id,
source_type='manual',
order_task_id=int(order_task.id),
)
db.session.add(notice)
db.session.flush()
execution = ensure_execution_for_workflow_version(
task_id=int(order_task.id), actor_type='system',
)
execution.status = 'blocked'
execution.current_gate_code = 'order_freeze_readiness'
order_task.active_process_execution_id = int(execution.id)
# ensure_execution 在已有 Notice 时会 sync_order_task_stage_for_notice,
# 可能把 stage 写成 waiting_review;本用例要验证「已写入的 order_creating」权威。
order_task.stage = 'order_creating'
order_task.status = 'waiting_review'
db.session.commit()
process_gate = _process_gate_user_summary_for_task(notice)
lifecycle = _task_lifecycle(task=notice, position=None, process_gate=process_gate)
assert lifecycle['lifecycle_stage'] == 'fulfillment_prep'
assert lifecycle['lifecycle_authority'] == 'processing_stage'
assert lifecycle['lifecycle_stage'] != 'order_review'
def test_build_task_ui_state_without_formal_gate_is_unclassified(app) -> None:
"""无正式 Gate 时位置不能再推导五阶段或任何可写 UI 动作。"""
with app.app_context():
@@ -245,7 +306,8 @@ def test_task_ui_state_formal_gate_overrides_stale_task_fields(app) -> None:
state = build_task_ui_state(task)
assert state['lifecycle_stage'] == 'fulfillment_prep'
assert state['lifecycle_authority'] == 'process_gate'
# Notice/OT 无合法 stage 时由 Gate 抬升为 inventory_matching,权威记为 processing_stage。
assert state['lifecycle_authority'] == 'processing_stage'
assert state['stage']['code'] == 'fulfillment_prep'
assert state['current_step']['code'] == 'fulfillment_prep'
assert [entry['state'] for entry in state['lifecycle_entries']] == [