This commit is contained in:
@@ -173,7 +173,7 @@ def render_roi_report(stats: Dict[str, Any]) -> str:
|
||||
action_emoji = '⚠️' if r['action'] == 'review' else '✅'
|
||||
recommendations_block += f" {action_emoji} {r['caller']}: {r['reason']}\n"
|
||||
except Exception:
|
||||
pass # 反饋查詢失敗不影響月報主流程
|
||||
logger.warning('[ROI] 反饋趨勢查詢失敗,略過月報附加區塊', exc_info=True)
|
||||
|
||||
return (
|
||||
f"📊 <b>ROI 月報 {period}</b>\n"
|
||||
|
||||
@@ -5,6 +5,7 @@ Operation Ollama-First v5.0 / Phase 24 — ROI 月報生成器驗證
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -104,6 +105,38 @@ def test_render_empty_stats():
|
||||
assert '⚠️' in render_roi_report({})
|
||||
|
||||
|
||||
def test_render_roi_report_logs_feedback_block_failure(monkeypatch, caplog):
|
||||
"""反饋趨勢附加區塊失敗時,月報主體仍應產生並留下可追蹤 log。"""
|
||||
from services.roi_report_service import render_roi_report
|
||||
import services.feedback_quality_tracker as fqt
|
||||
|
||||
def _raise_feedback_error(days=30):
|
||||
raise RuntimeError("feedback trend unavailable")
|
||||
|
||||
monkeypatch.setattr(fqt, "compute_caller_quality_trend", _raise_feedback_error)
|
||||
caplog.set_level(logging.WARNING, logger="services.roi_report_service")
|
||||
|
||||
msg = render_roi_report({
|
||||
'period_label': '2026年04月',
|
||||
'gemini_tokens': 35_000_000,
|
||||
'gemini_cost': 14.0,
|
||||
'ollama_calls': 4000,
|
||||
'gemini_calls': 800,
|
||||
'claude_calls': 100,
|
||||
'claude_cost': 5.0,
|
||||
'nim_calls': 100,
|
||||
'rag_total': 800,
|
||||
'rag_saved': 250,
|
||||
'rag_avg_feedback': 4.2,
|
||||
'mcp_total': 180,
|
||||
'mcp_cache_hits': 50,
|
||||
'cache_hit_calls': 150,
|
||||
})
|
||||
|
||||
assert 'ROI 月報 2026年04月' in msg
|
||||
assert '反饋趨勢查詢失敗' in caplog.text
|
||||
|
||||
|
||||
def test_query_last_month_stats_db_fail_returns_empty(monkeypatch):
|
||||
"""DB 失敗應回 {} 不 raise"""
|
||||
from services.roi_report_service import query_last_month_stats
|
||||
|
||||
Reference in New Issue
Block a user