diff --git a/apps/api/tests/test_ollama_auto_recovery.py b/apps/api/tests/test_ollama_auto_recovery.py index 94d8c799..72055ac0 100644 --- a/apps/api/tests/test_ollama_auto_recovery.py +++ b/apps/api/tests/test_ollama_auto_recovery.py @@ -8,7 +8,7 @@ OllamaAutoRecoveryService 單元測試 - P1.1d 測試覆蓋: 1. 111 OFFLINE → HEALTHY × 3 → 觸發 _switch_back_to_ollama 2. 111 OFFLINE → HEALTHY × 2 → OFFLINE → counter 歸零 -3. 中途 SLOW/DEGRADED → counter 歸零 +3. 中途 DEGRADED/OFFLINE → counter 歸零;SLOW 視為可用(GCP 高負載仍優於 Gemini) 4. stop() 優雅取消 task 5. start() 重複呼叫不重複建立 task 6. _switch_back_to_ollama:clear_cache + notify_recovery + Telegram alerter @@ -22,17 +22,16 @@ OllamaAutoRecoveryService 單元測試 - P1.1d from __future__ import annotations import asyncio -from unittest.mock import AsyncMock, MagicMock, call, patch +from unittest.mock import AsyncMock, MagicMock, patch import pytest -from src.services.ollama_health_monitor import HealthReport, HealthStatus from src.services.ollama_auto_recovery import ( OllamaAutoRecoveryService, get_ollama_auto_recovery_service, reset_ollama_auto_recovery_service, ) - +from src.services.ollama_health_monitor import HealthReport, HealthStatus # ============================================================================= # Fixtures / Helpers @@ -115,15 +114,15 @@ class TestCheckAndRecover: assert svc.consecutive_healthy == 0 @pytest.mark.asyncio - async def test_slow_resets_counter(self): - """SLOW → counter 歸零(不算穩定)""" + async def test_slow_increments_counter(self): + """SLOW → counter +1(GCP 高負載仍優於 Gemini fallback)""" svc, mock_monitor, _ = _make_service(current_primary="gemini") svc._consecutive_healthy = 1 mock_monitor.check.return_value = _make_health(HealthStatus.SLOW) await svc._check_and_recover() - assert svc.consecutive_healthy == 0 + assert svc.consecutive_healthy == 2 @pytest.mark.asyncio async def test_degraded_resets_counter(self):