Files
awoooi/apps/api/tests/test_ollama_endpoint_resolver.py
Your Name c2c0b1ec82
All checks were successful
Code Review / ai-code-review (push) Successful in 10s
CD Pipeline / tests (push) Successful in 1m9s
CD Pipeline / build-and-deploy (push) Successful in 4m21s
CD Pipeline / post-deploy-checks (push) Successful in 1m16s
fix(alerts): let GCP Ollama finish before cloud fallback
2026-05-06 05:27:55 +08:00

68 lines
2.0 KiB
Python

from __future__ import annotations
from types import SimpleNamespace
from src.services.ollama_endpoint_resolver import (
resolve_ollama_selection,
)
def _settings(
*,
primary: str = "http://192.168.0.110:11435",
secondary: str = "http://192.168.0.110:11436",
fallback: str = "http://192.168.0.110:11437",
) -> SimpleNamespace:
return SimpleNamespace(
OLLAMA_URL=primary,
OLLAMA_SECONDARY_URL=secondary,
OLLAMA_FALLBACK_URL=fallback,
)
def test_non_sensitive_workloads_prefer_gcp_a_lane() -> None:
cfg = _settings()
for workload in (
"batch",
"embedding",
"rag",
"code_review",
"shadow",
"canary",
"deep_rca",
"image_analysis",
"hermes",
):
selection = resolve_ollama_selection(workload, config=cfg)
assert selection.url == "http://192.168.0.110:11435"
assert selection.provider_name == "ollama_gcp_a"
assert selection.reason == "primary_interactive_lane"
def test_interactive_workloads_stay_on_gcp_a() -> None:
cfg = _settings()
for workload in ("interactive", "healthcheck", "alert_fast"):
selection = resolve_ollama_selection(workload, config=cfg)
assert selection.url == "http://192.168.0.110:11435"
assert selection.provider_name == "ollama_gcp_a"
def test_local_required_workloads_use_local_lane() -> None:
cfg = _settings()
for workload in ("local_required", "privacy_sensitive", "dr"):
selection = resolve_ollama_selection(workload, config=cfg)
assert selection.url == "http://192.168.0.110:11437"
assert selection.provider_name == "ollama_local"
def test_non_sensitive_workloads_fall_back_to_gcp_b_when_primary_missing() -> None:
cfg = _settings(primary="")
selection = resolve_ollama_selection("embedding", config=cfg)
assert selection.url == "http://192.168.0.110:11436"
assert selection.provider_name == "ollama_gcp_b"
assert selection.reason == "primary_missing_gcp_b_fallback"