fix(p3.2): model_version_tracker 改 pure unit test + probe 改善
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 2m7s

Engineer 重寫 test_model_version_tracker:
- 用 _make_fake_ctx (asynccontextmanager) 完整 mock get_db_context
- 移除 @pytest.mark.integration(整 class)
- patch probe_all_providers + get_db_context 雙路徑
- 4 testcases 全綠,無真實 PG 依賴

model_version_probe.py 配套改善(match 新 test mock 預期)

Tests: 19 passed (probe 15 + tracker 4)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-04-27 14:58:46 +08:00
parent ed205489c1
commit 8d6e086254
2 changed files with 65 additions and 140 deletions

View File

@@ -20,6 +20,8 @@ from datetime import datetime, timedelta, timezone
import structlog
from src.core.config import settings
logger = structlog.get_logger(__name__)
TAIPEI_TZ = timezone(timedelta(hours=8))
@@ -91,8 +93,6 @@ async def probe_gemini_version() -> ProviderVersionInfo:
Raises:
RuntimeError: GEMINI_API_KEY 未設定
"""
from src.core.config import settings
api_key = settings.GEMINI_API_KEY
if not api_key:
raise RuntimeError("GEMINI_API_KEY not configured")
@@ -147,8 +147,6 @@ async def probe_claude_version() -> ProviderVersionInfo:
Raises:
RuntimeError: CLAUDE_API_KEY 未設定
"""
from src.core.config import settings
api_key = settings.CLAUDE_API_KEY
if not api_key:
raise RuntimeError("CLAUDE_API_KEY not configured")
@@ -182,8 +180,6 @@ async def probe_openclaw_nemo_version() -> ProviderVersionInfo:
RuntimeError: OPENCLAW_DEFAULT_MODEL 未設定
httpx.HTTPError: 連線失敗
"""
from src.core.config import settings
model = settings.OPENCLAW_DEFAULT_MODEL
if not model:
raise RuntimeError("OPENCLAW_DEFAULT_MODEL not configured")
@@ -238,8 +234,6 @@ async def probe_all_providers() -> list[ProviderVersionInfo]:
- 使用 return_exceptions=True 確保任一 provider 失敗不影響其他
- 每個 exception 都有對應的 log warning
"""
from src.core.config import settings
tasks = [
probe_ollama_version(settings.OLLAMA_URL, settings.OLLAMA_HEALTH_CHECK_MODEL),
probe_ollama_version(