Files
syops/backend/tests/test_shipping_projection_cross_surface.py
T
hugo fbca0b485c feat(shipping-notice): 完善处理投影与待办轮询
- 统一处理阶段、Gate 状态及跨页面投影
- 优化订单提取自动推进与待办分类查询
- 完善任务中心待办与批次轮询逻辑
- 补充后端投影、Gate、查询及 Worker 测试
- 新增待办轮询设计文档并更新技术文档
2026-09-14 17:06:11 +08:00

101 lines
4.5 KiB
Python
Raw 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_projection_cross_surface.py
用途:跨面一致性契约——15 阶顺序、OT stage 同步与密度窗口共享同一投影真相。
依赖:progress_audit_contract、order_task_service、frontend progressWindow 对齐的 BE 语义。
逻辑:阶段码集合一致;sync_order_task_processing_state 写入的 stage 必须属于
SHIPPING_PROCESSING_STAGES;inventory_source_resolving 在 waiting_review 之前。
"""
from __future__ import annotations
from app import db
from app.models import ShippingNotice, ShippingOrderTask
from app.services.shipping_notice.order_task_service import sync_order_task_processing_state
from app.services.shipping_notice.progress_audit_contract import (
EML_ONLY_PROCESSING_STAGES,
SHIPPING_PROCESSING_STAGES,
)
from app.services.shipping_notice.lifecycle_projection import (
LIFECYCLE_STAGE_BY_PROCESSING_STAGE,
LIFECYCLE_STAGE_CODES,
)
def test_fifteen_processing_stages_all_map_to_a_lifecycle_stage():
"""统一口径:每个 SHIPPING_PROCESSING_STAGES 细粒度阶段都必须映射到一个合法 5 业务阶段。
该映射是「15 阶权威 → 5 阶展示」的唯一桥梁;遗漏任一值会导致工作台/批次中心
出现未归类阶段,使前后端阶段口径不一致。此处仅作完整性约束,不改变任何阶段语义。
"""
for stage in SHIPPING_PROCESSING_STAGES:
mapped = LIFECYCLE_STAGE_BY_PROCESSING_STAGE.get(stage)
assert mapped is not None, f"SHIPPING_PROCESSING_STAGES.{stage!r} 缺少 15->5 映射"
assert mapped in LIFECYCLE_STAGE_CODES, (
f"映射目标 {mapped!r} 不是合法 5 业务阶段({tuple(LIFECYCLE_STAGE_CODES)})"
)
def test_legacy_step_key_stage_maps_to_fulfillment_prep():
"""OT.stage 若残留 step5_match_inventory,生命周期必须进通知准备而非接收解析。"""
from app.services.shipping_notice.lifecycle_projection import project_lifecycle
result = project_lifecycle(
current_gate={'gate_code': 'task_creation', 'status': 'invalidated'},
blocking_reason={'code': 'gate_invalidated'},
has_candidate_context=True,
processing_stage='step5_match_inventory',
)
# processing_stage 权威高于错误的 task_creation 门禁。
assert result['lifecycle_stage'] == 'fulfillment_prep'
assert result['lifecycle_authority'] == 'processing_stage'
current = next(e for e in result['lifecycle_entries'] if e['state'] == 'current')
assert current['code'] == 'fulfillment_prep'
def test_fifteen_stages_inventory_source_before_review():
"""库存源解析必须排在人工复核与建单之前(跨面共用同一有序元组)。"""
stages = list(SHIPPING_PROCESSING_STAGES)
assert len(stages) == 15
assert stages.index('inventory_source_resolving') < stages.index('waiting_review')
assert stages.index('waiting_review') < stages.index('order_creating')
assert stages.index('inventory_matching') < stages.index('excel_generating')
assert 'email_parsing' in EML_ONLY_PROCESSING_STAGES
assert 'email_adjudicating' in EML_ONLY_PROCESSING_STAGES
def test_sync_order_task_stage_must_be_processing_stage(app):
"""任务工作台与对话投影均读 OT.stage;写入值必须是冻结的 15 阶之一。"""
with app.app_context():
# [BE-05] 订单数据已迁移到 ShippingOrderTask/Extraction;Notice 不再承载
# po_number/order_lines_migration_status。OT 是进度写入口,Notice 通过
# order_task_id 反指 OT,恢复测试原本「通知 + 任务」配对结构。
order_task = ShippingOrderTask(
task_no='OT-CROSS-SURFACE-001',
user_id=1,
stage='waiting_review',
status='waiting_review',
progress_version=1,
)
db.session.add(order_task)
db.session.flush()
notice = ShippingNotice(
task_no='SN-CROSS-SURFACE-001',
source_type='manual',
order_task_id=int(order_task.id),
)
db.session.add(notice)
db.session.flush()
sync_order_task_processing_state(
order_task,
stage='inventory_matching',
status='processing',
)
db.session.commit()
refreshed = db.session.get(ShippingOrderTask, order_task.id)
assert refreshed.stage == 'inventory_matching'
assert refreshed.stage in SHIPPING_PROCESSING_STAGES
assert int(refreshed.progress_version or 0) >= 2