fix(api): enforce global ollama endpoint order
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user