feat(governance): surface adr100 slo states
This commit is contained in:
89
apps/api/tests/test_adr100_slo_status_service.py
Normal file
89
apps/api/tests/test_adr100_slo_status_service.py
Normal file
@@ -0,0 +1,89 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from src.services.adr100_slo_status_service import Adr100SloStatusService
|
||||
|
||||
|
||||
class _FakePrometheusResponse:
|
||||
def __init__(self, payload: dict[str, Any]) -> None:
|
||||
self._payload = payload
|
||||
|
||||
def json(self) -> dict[str, Any]:
|
||||
return self._payload
|
||||
|
||||
|
||||
class _FakePrometheusClient:
|
||||
def __init__(self, values: dict[str, str]) -> None:
|
||||
self.values = values
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
async def get(self, *args, **kwargs): # noqa: ANN002, ANN003
|
||||
query = str(kwargs.get("params", {}).get("query", ""))
|
||||
value = self.values.get(query)
|
||||
if value is None:
|
||||
return _FakePrometheusResponse({
|
||||
"status": "success",
|
||||
"data": {"result": []},
|
||||
})
|
||||
return _FakePrometheusResponse({
|
||||
"status": "success",
|
||||
"data": {"result": [{"value": [1778756604, value]}]},
|
||||
})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fetch_report_marks_ratio_slos_low_volume(monkeypatch):
|
||||
values = {
|
||||
"sum(rate(automation_operation_log_total[5m]))": "0",
|
||||
'sum(rate(automation_operation_log_total{outcome="auto_executed"}[5m]))': "0",
|
||||
"sum(rate(approval_records_high_confidence_total[1h]))": "0",
|
||||
"max(knowledge_entries_created_24h) or max(sli:km_growth_rate:24h)": "24",
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"httpx.AsyncClient",
|
||||
lambda *args, **kwargs: _FakePrometheusClient(values),
|
||||
)
|
||||
|
||||
report = await Adr100SloStatusService().fetch_report()
|
||||
|
||||
by_name = {metric["name"]: metric for metric in report["metrics"]}
|
||||
assert by_name["decision_accuracy"]["status"] == "skipped_low_volume"
|
||||
assert by_name["decision_accuracy"]["evaluable"] is False
|
||||
assert by_name["confidence_calibration"]["status"] == "skipped_low_volume"
|
||||
assert by_name["km_growth_rate"]["status"] == "ok"
|
||||
assert by_name["km_growth_rate"]["value"] == 24
|
||||
assert report["overall_status"] == "partial"
|
||||
assert report["overall_compliance"] == 1.0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fetch_report_classifies_hard_red_line_violation(monkeypatch):
|
||||
values = {
|
||||
"sum(rate(automation_operation_log_total[5m]))": "0.02",
|
||||
"sli:autonomy_rate:5m": "0.5",
|
||||
'sum(rate(automation_operation_log_total{outcome="auto_executed"}[5m]))': "0",
|
||||
"sum(rate(approval_records_high_confidence_total[1h]))": "0",
|
||||
"max(knowledge_entries_created_24h) or max(sli:km_growth_rate:24h)": "3",
|
||||
}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"httpx.AsyncClient",
|
||||
lambda *args, **kwargs: _FakePrometheusClient(values),
|
||||
)
|
||||
|
||||
report = await Adr100SloStatusService().fetch_report()
|
||||
|
||||
by_name = {metric["name"]: metric for metric in report["metrics"]}
|
||||
assert by_name["autonomy_rate"]["status"] == "violated"
|
||||
assert by_name["autonomy_rate"]["sample_count"] == 6
|
||||
assert by_name["km_growth_rate"]["status"] == "violated"
|
||||
assert report["overall_status"] == "violated"
|
||||
Reference in New Issue
Block a user