From 2409d861fac6498d9c1e6b484f1cb523f4dc53b6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 May 2026 22:57:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E6=9B=B4=E6=96=B0=20auto=5Frecove?= =?UTF-8?q?ry=20=E6=B8=AC=E8=A9=A6=E6=96=B7=E8=A8=80=E8=87=B3=20ADR-110?= =?UTF-8?q?=EF=BC=88ollama=5F111=20=E2=86=92=20ollama=5Fgcp=5Fa=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - notify_recovery 斷言改為 "ollama_gcp_a"(3 處) - alert_recovery payload["to"] 改為 "ollama" - test_full_recovery_flow 改用 mock alerter 避免打真實 Telegram Bot API Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/api/tests/test_ollama_auto_recovery.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/api/tests/test_ollama_auto_recovery.py b/apps/api/tests/test_ollama_auto_recovery.py index be2b1a29..94d8c799 100644 --- a/apps/api/tests/test_ollama_auto_recovery.py +++ b/apps/api/tests/test_ollama_auto_recovery.py @@ -222,7 +222,11 @@ class TestDebounce: """ 完整場景:OFFLINE → HEALTHY × 3 → 觸發 switch_back """ - svc, mock_monitor, mock_failover = _make_service(current_primary="gemini", stable_count=3) + mock_alerter = AsyncMock() + mock_alerter.alert_recovery = AsyncMock() + svc, mock_monitor, mock_failover = _make_service( + current_primary="gemini", stable_count=3, alerter=mock_alerter + ) mock_monitor.check.side_effect = [ _make_health(HealthStatus.HEALTHY), _make_health(HealthStatus.HEALTHY), @@ -235,7 +239,8 @@ class TestDebounce: # 觸發後 current_primary 應切回 ollama assert svc.current_primary == "ollama" mock_failover.clear_cache.assert_awaited_once() - mock_failover.notify_recovery.assert_called_once_with("ollama_111") + # 2026-05-03 ogt: ADR-110 — notify_recovery 改為 "ollama_gcp_a"(GCP-A Primary) + mock_failover.notify_recovery.assert_called_once_with("ollama_gcp_a") # ============================================================================= @@ -262,7 +267,8 @@ class TestSwitchBackToOllama: async def test_calls_notify_recovery(self): svc, _, mock_failover = _make_service(current_primary="gemini") await svc._switch_back_to_ollama() - mock_failover.notify_recovery.assert_called_once_with("ollama_111") + # 2026-05-03 ogt: ADR-110 — notify_recovery 改為 "ollama_gcp_a"(GCP-A Primary) + mock_failover.notify_recovery.assert_called_once_with("ollama_gcp_a") @pytest.mark.asyncio async def test_calls_telegram_alerter_when_set(self): @@ -277,7 +283,7 @@ class TestSwitchBackToOllama: mock_alerter.alert_recovery.assert_awaited_once() payload = mock_alerter.alert_recovery.call_args[0][0] assert payload["from"] == "gemini" - assert payload["to"] == "ollama_111" + assert payload["to"] == "ollama" # 2026-05-03 ogt: ADR-110 — "to" 改為 "ollama"(不再指定 111) assert payload["stable_count"] == 3 @pytest.mark.asyncio