feat(shipping-notice): 实现对话级批量重试自动推进功能,优化库存与PDF匹配逻辑

- 新增对话级批量重试自动推进的完整链路:后端服务、API、数据投影逻辑
- 前端新增对话级重试按钮、多语言国际化支持与API类型定义
- 优化行级库存重试控制,新增retryable字段统一管控重试按钮展示,清理废弃的view_fulfillment_detail动作,标准化前端动作码排序逻辑
- 修复PDF坐标匹配的fail-close防护逻辑,避免生成伪精确匹配分数
- 调整订单确认后流程,提前进入库存获取阶段,移除冗余的确认建单按钮,优化用户流转体验
- 新增对应单元测试用例覆盖核心业务逻辑
This commit is contained in:
hugo committed 2026-08-07 16:30:45 +08:00
1 parent fd6a23f870
commit 1008911a7e
41 files changed
+3956 -1256

No files matched your search

@@ -0,0 +1,63 @@
"""
tests/test_conversation_retry_auto_progress.py
用途:锁定对话级重试自动推进的 eligible 判定、跳过原因与汇总结构。
依赖:conversation_retry_auto_progress_service。
逻辑:纯单元测跳过映射与 summary;不依赖完整 DB 工厂。
"""
from __future__ import annotations
from app.services.shipping_notice.conversation_retry_auto_progress_service import (
ACTION_RETRY_AUTO_PROGRESS,
_skip_reason_from_automation,
_summarize_items,
project_conversation_allowed_actions,
)
def test_skip_reason_maps_queued_and_not_retryable():
"""queued → already_running;retryable=false → not_retryable。"""
assert _skip_reason_from_automation(
{'status': 'queued', 'retryable': False},
task_missing=False,
) == 'already_running'
assert _skip_reason_from_automation(
{'status': 'waiting_to_start', 'retryable': False},
task_missing=False,
) == 'not_retryable'
assert _skip_reason_from_automation(
{'status': 'failed', 'retryable': True},
task_missing=False,
) is None
def test_manual_fallback_human_owner_still_retryable():
"""manual_fallback 虽 owner=human,但 retryable 时不得跳过。"""
assert _skip_reason_from_automation(
{'status': 'manual_fallback', 'retryable': True, 'owner_type': 'human'},
task_missing=False,
) is None
def test_task_missing_always_skipped():
assert _skip_reason_from_automation(
{'status': 'failed', 'retryable': True},
task_missing=True,
) == 'task_missing'
def test_summarize_items_counts_outcomes():
summary = _summarize_items([
{'outcome': 'queued'},
{'outcome': 'queued'},
{'outcome': 'skipped', 'reason_code': 'already_running'},
{'outcome': 'failed'},
])
assert summary == {'total': 4, 'retried': 2, 'skipped': 1, 'failed': 1}
def test_project_conversation_allowed_actions_empty_without_conversation():
"""无 conversation_id 时不返回禁用空按钮。"""
assert project_conversation_allowed_actions(user_id=1, conversation_id='') == []
assert ACTION_RETRY_AUTO_PROGRESS == 'retry_auto_progress'
@@ -12,7 +12,6 @@ from app.services.shipping_notice.line_inventory_match_projection import (
ACTION_CLOSE,
ACTION_RETRY_MATCHING,
ACTION_RETRY_PREPARATION,
ACTION_VIEW_FULFILLMENT,
normalize_match_quantities,
project_line_inventory_view,
project_user_line_status,
@@ -120,8 +119,8 @@ def test_shortage_actions_preparation_and_close_only():
assert line == [ACTION_CLOSE]
def test_wave_created_only_view_detail():
"""已入波次仅查看履约详情。"""
def test_wave_created_hides_line_actions():
"""已入波次不再下发 view_fulfillment_detail。"""
line = resolve_line_allowed_actions(
has_formal_ot=True,
stored_line_status='task_created',
@@ -136,7 +135,7 @@ def test_wave_created_only_view_detail():
user_line_status='wave_created',
)
assert inv == []
assert line == [ACTION_VIEW_FULFILLMENT]
assert line == []
def test_result_missing_projects_file_missing_and_retry_prep():
@@ -0,0 +1,75 @@
"""
tests/test_task_retry_decision_service.py
用途:锁定统一重试决策树的只读分支(noop / fetch)与行级 retryable。
依赖:task_retry_decision_service、line_inventory_match_projection。
逻辑:不启全量 Flask;验证决策优先级。
"""
from __future__ import annotations
from types import SimpleNamespace
from app.services.shipping_notice.line_inventory_match_projection import project_line_retryable
from app.services.shipping_notice.task_retry_decision_service import (
ACTION_FETCH_INVENTORY,
ACTION_NOOP,
decide_retry_action_only,
)
def _task(**kwargs):
defaults = {
'task_no': 'OT-1',
'id': 1,
'process_status': 'parsed',
'pending_human_reason': None,
'inventory_lines_json': None,
'inventory_snapshot_id': None,
'inventory_source_status': 'resolved',
'inventory_source_code': 'DSB_SLC',
'inventory_source_confirmed_by': None,
'order_data_version': 3,
}
defaults.update(kwargs)
return SimpleNamespace(**defaults)
def test_project_line_retryable_hides_shortage_and_running():
assert project_line_retryable(
inventory_allowed_actions=['retry_inventory_preparation'],
user_line_status='shortage',
) is False
assert project_line_retryable(
inventory_allowed_actions=['retry_inventory_preparation'],
user_line_status='inventory_file_missing',
inventory_rpa_running=True,
) is False
assert project_line_retryable(
inventory_allowed_actions=['retry_inventory_preparation'],
user_line_status='inventory_file_missing',
) is True
def test_decide_completed_is_noop():
task = _task(process_status='completed')
decided = decide_retry_action_only(task, scope='task')
assert decided['action'] == ACTION_NOOP
assert decided['reason_code'] == 'already_completed'
def test_decide_missing_snapshot_fetch(monkeypatch):
task = _task(process_status='parsed', inventory_snapshot_id=None, inventory_lines_json=None)
monkeypatch.setattr(
'app.services.shipping_notice.inventory_source_gate.is_inventory_source_stable',
lambda _t: True,
)
decided = decide_retry_action_only(task, scope='task')
assert decided['action'] == ACTION_FETCH_INVENTORY
def test_decide_rpa_pending_already_running():
task = _task(pending_human_reason='rpa_pending', process_status='waiting_inventory')
decided = decide_retry_action_only(task, scope='task')
assert decided['action'] == ACTION_NOOP
assert decided['reason_code'] == 'already_running'