Files
syops/backend/tests/test_line_closure_gate_sync.py
T
hugoandCursor 39fe3c05f2 feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与
枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa
持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀,
上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 10:46:06 +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='onhand_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