fix(api): bound ai route status checks
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from types import SimpleNamespace
|
||||
@@ -6,6 +7,7 @@ from uuid import UUID
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
import src.services.platform_operator_service as platform_operator_service
|
||||
from src.api.v1.platform.operator_runs import (
|
||||
AiRouteStatusResponse,
|
||||
ListCicdEventsResponse,
|
||||
@@ -1182,6 +1184,36 @@ def test_ai_route_status_response_preserves_route_fields() -> None:
|
||||
assert dumped["selected_provider"] == "ollama_gcp_a"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ai_route_status_times_out_before_slow_provider_checks(monkeypatch) -> None:
|
||||
class SlowFailoverManager:
|
||||
async def select_provider(self, task_type: str = "general") -> None:
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
monkeypatch.setattr(
|
||||
platform_operator_service,
|
||||
"_AI_ROUTE_STATUS_SELECT_TIMEOUT_SECONDS",
|
||||
0.001,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
platform_operator_service,
|
||||
"get_ollama_failover_manager",
|
||||
lambda: SlowFailoverManager(),
|
||||
)
|
||||
|
||||
response = await platform_operator_service.get_ai_route_status("deep_rca")
|
||||
|
||||
assert response["route_reason"] == "route_check_timeout"
|
||||
assert response["route_error"] == "route status timed out after 0.001s"
|
||||
assert response["selected_provider"] is None
|
||||
assert [item["provider_name"] for item in response["policy_order"]] == [
|
||||
"ollama_gcp_a",
|
||||
"ollama_gcp_b",
|
||||
"ollama_local",
|
||||
"gemini",
|
||||
]
|
||||
|
||||
|
||||
def test_ai_route_workload_validation_rejects_unknown_value() -> None:
|
||||
assert _validate_ai_route_workload(" hermes ") == "hermes"
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
|
||||
Reference in New Issue
Block a user