fix(api): enforce global ollama endpoint order
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 5m13s
CD Pipeline / build-and-deploy (push) Successful in 3m31s
CD Pipeline / post-deploy-checks (push) Successful in 1m18s

This commit is contained in:
Your Name
2026-05-19 12:31:56 +08:00
parent 5fa0e1452c
commit 45cd55b2da
7 changed files with 359 additions and 228 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
import httpx
@@ -32,6 +33,14 @@ async def _noop_save(*args: Any, **kwargs: Any) -> None:
return None
def _fake_ollama_order(_workload_type: str) -> tuple[SimpleNamespace, ...]:
return (
SimpleNamespace(url="http://gcp-a:11434", provider_name="ollama_gcp_a"),
SimpleNamespace(url="http://gcp-b:11434", provider_name="ollama_gcp_b"),
SimpleNamespace(url="http://local-111:11434", provider_name="ollama_local"),
)
@pytest.mark.asyncio
async def test_large_pr_uses_local_ollama_when_gemini_fallback_disabled(
monkeypatch: pytest.MonkeyPatch,
@@ -43,8 +52,8 @@ async def test_large_pr_uses_local_ollama_when_gemini_fallback_disabled(
)
monkeypatch.setattr(
review_module,
"resolve_ollama_endpoint",
lambda workload_type: "http://local-111:11434",
"resolve_ollama_order",
_fake_ollama_order,
)
client = _FakeClient()
@@ -68,8 +77,8 @@ async def test_large_pr_uses_local_ollama_when_gemini_fallback_disabled(
)
assert result is not None
assert result["provider"] == "ollama"
assert client.posted_urls == ["http://local-111:11434/api/generate"]
assert result["provider"] == "ollama_gcp_a"
assert client.posted_urls == ["http://gcp-a:11434/api/generate"]
@pytest.mark.asyncio
@@ -83,8 +92,8 @@ async def test_ollama_failure_does_not_fall_back_to_gemini_by_default(
)
monkeypatch.setattr(
review_module,
"resolve_ollama_endpoint",
lambda workload_type: "http://local-111:11434",
"resolve_ollama_order",
_fake_ollama_order,
)
client = _FakeClient(fail=True)
@@ -110,7 +119,11 @@ async def test_ollama_failure_does_not_fall_back_to_gemini_by_default(
assert result is not None
assert result["provider"] == "ollama_unavailable"
assert result["cloud_fallback_skipped"] is True
assert client.posted_urls == ["http://local-111:11434/api/generate"]
assert client.posted_urls == [
"http://gcp-a:11434/api/generate",
"http://gcp-b:11434/api/generate",
"http://local-111:11434/api/generate",
]
@pytest.mark.asyncio