""" 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'