Files
syops/backend/tests/test_line_closure_gate_sync.py
T
hugo 051f80e1e9 fix(shipping-notice): 有效订单值视图贯通履约链并补全行结案豁免
- 新增 effective_order_view:冻结快照+人工修正按(行position×field_id)对位叠加,整行替换后行级叠加保守跳过
- 库存匹配(order_field_purposes)、Excel值(export)、通知行物化(notice_line_service.line_overrides)统一消费有效值
- 行结案close_unfulfillable端到端豁免:聚合/match_completed/整单建通知/滚动导出四处剔除结案行(含有库存结案行)
- 结案决定落库后触发Gate重算(trigger=line_fulfillment_closed),对齐放行路径
- 兜底匹配分支切有效视图基线;全结案聚合口径与门禁一致(unfulfillable)
- 预约门禁断言更新为有效视图契约;文档同步technical.md/funclist(含结案时序规约)
2026-09-18 01:46:47 +08:00

64 lines
3.0 KiB
Python

"""
tests/test_line_closure_gate_sync.py
用途:验证结案决定落库后的 Gate 重算联动(对齐放行路径),含 trigger 透传。
依赖:pytest、order_review_fulfillment_decision_service、fulfillment_workflow、匹配事实夹具。
逻辑:结案使聚合转为满足后,_sync 必须重算任务履约态并以 line_fulfillment_closed 触发编排。
"""
from __future__ import annotations
from types import SimpleNamespace
from app import db
from app.models import ShippingProcessExecution
from app.services.shipping_notice.order_review_fulfillment_decision_service import (
_sync_confirmed_task_fulfillment_gates,
)
from tests.test_effective_order_view import _seed_frozen_order
from tests.test_line_closure_fulfillment import _seed_close_decision, _seed_match_facts
def test_close_decision_syncs_gates_with_closed_trigger(app, monkeypatch):
"""结案行豁免使整单满足后,Gate 同步须重算并以 line_fulfillment_closed 触发编排。"""
with app.app_context():
fixture = _seed_frozen_order()
_seed_match_facts(fixture)
_seed_close_decision(fixture, 1)
# 计划自审补齐:submit_auto_progress 仅在 OT 绑定活动 Execution 时触发,
# 冻结订单夹具默认不带执行实例,须按结案现场补一条 blocked 的最小执行。
execution = ShippingProcessExecution(
execution_no='EXE-CLOSE-GATE-SYNC', task_id=int(fixture.order.id),
status='blocked', current_gate_code='inventory_sufficiency', lock_version=1,
)
db.session.add(execution)
db.session.flush()
fixture.order.active_process_execution_id = int(execution.id)
db.session.flush()
calls = []
def _capture_progress(*args, **kwargs):
calls.append(('submit_auto_progress', kwargs.get('trigger')))
def _capture_enqueue(*args, **kwargs):
calls.append(('enqueue_post_ot_auto_fulfill_job', kwargs.get('trigger')))
# 拦截编排出口:函数内为局部 import,直接 patch 源模块属性即可生效。
monkeypatch.setattr(
'app.services.shipping_notice.auto_progress_controller.submit_auto_progress',
_capture_progress,
)
monkeypatch.setattr(
'app.services.shipping_notice.line_auto_fulfill_coordinator.enqueue_post_ot_auto_fulfill_job',
_capture_enqueue,
)
fake_case = SimpleNamespace(confirmed_task_id=fixture.order.id)
_sync_confirmed_task_fulfillment_gates(
case=fake_case, actor_id=fixture.user.id, trigger='line_fulfillment_closed',
)
payload = fixture.order.step_payload_json or {}
# 断言:任务履约态被重算为满足,且两个编排出口都带结案 trigger。
assert payload['current_match_projection']['match_status'] == 'fulfillable'
assert ('submit_auto_progress', 'line_fulfillment_closed') in calls
assert ('enqueue_post_ot_auto_fulfill_job', 'line_fulfillment_closed') in calls