Files
syops/backend/tests/test_shipping_workflow_recovery.py

72 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
backend/tests/test_shipping_workflow_recovery.py
用途:验收订单抽取 Job 超时回收后 WorkflowItem 同步契约(co8 账本已下线,恒为无操作)。
依赖:app fixture、_seed_run_input、sync_workflow_items_after_extraction_job_recovery、ensure_workflow_items_for_run。
逻辑:模拟 Job queued/failed 回收,断言 WorkflowItem 相关同步恒为 0 / 空列表,进度以 Run/OrderTask 投影为准。
"""
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import patch
from app import db
from app.services.shipping_notice.order_extraction_run_service import (
create_order_extraction_run,
ensure_workflow_items_for_run,
sync_workflow_items_after_extraction_job_recovery,
)
from tests.test_shipping_order_extraction_runs import _seed_run_input
def test_sync_workflow_items_after_extraction_recovery_to_queued(app):
"""co8 后台账已 DROP:Job 回收为 queued 时 WorkflowItem 同步为无操作(恒 0)。"""
with app.app_context():
user, agent, session, intake, document = _seed_run_input(suffix='WFR-Q')
with patch(
'app.services.shipping_notice.order_extraction_run_service.schedule_order_extraction_layouts',
return_value=False,
):
run, _ = create_order_extraction_run(
user=user,
agent_id=agent.id,
conversation_id=session.session_id,
intake_nos=[intake.intake_no],
)
db.session.commit()
job = SimpleNamespace(status='queued', business_ref=run.run_no, id=1)
updated = sync_workflow_items_after_extraction_job_recovery(run=run, job=job)
db.session.commit()
# 关键断言:账本已下线,无 WorkflowItem 可回收,同步恒为 0(状态以 Run/OrderTask 投影为准)。
assert updated == 0
def test_sync_workflow_items_after_extraction_recovery_to_failed(app):
"""co8 后台账已 DROP:ensure_workflow_items_for_run 不再物化 WorkflowItem。"""
with app.app_context():
user, agent, session, intake, document = _seed_run_input(suffix='WFR-F')
with patch(
'app.services.shipping_notice.order_extraction_run_service.schedule_order_extraction_layouts',
return_value=True,
):
run, _ = create_order_extraction_run(
user=user,
agent_id=agent.id,
conversation_id=session.session_id,
intake_nos=[intake.intake_no],
)
items = ensure_workflow_items_for_run(run, stage_when_ready='queued')
# 关键断言:账本已下线,不再为 Run 物化 WorkflowItem,恒返回空列表。
assert items == []
db.session.commit()
job = SimpleNamespace(status='failed', business_ref=run.run_no, id=2)
updated = sync_workflow_items_after_extraction_job_recovery(run=run, job=job)
db.session.commit()
# 关键断言:终态失败回收同样不再改动 WorkflowItem,同步恒为 0。
assert updated == 0