Files
awoooi/apps/api/tests/test_drift_interpreter_ollama_first.py
Your Name 2ef54ccc94
All checks were successful
Code Review / ai-code-review (push) Successful in 16s
CD Pipeline / tests (push) Successful in 1m17s
CD Pipeline / build-and-deploy (push) Successful in 4m54s
CD Pipeline / post-deploy-checks (push) Successful in 3m10s
fix(ai): enforce ollama first for drift governance
2026-05-06 19:26:09 +08:00

43 lines
1.3 KiB
Python

from __future__ import annotations
from typing import Any
import pytest
from src.models.drift import DriftIntent
from src.services import openclaw as openclaw_module
from src.services.drift_interpreter import NemotronDriftInterpreter
class _FakeOpenClaw:
def __init__(self) -> None:
self.alert_context: dict[str, Any] | None = None
async def call(
self,
prompt: str,
alert_context: dict[str, Any] | None = None,
) -> tuple[str, str, bool]:
self.alert_context = alert_context
return (
'{"intent":"automated_change","explanation":"HPA 自動調整","risk":"LOW","confidence":0.8}',
"ollama_gcp_a",
True,
)
@pytest.mark.asyncio
async def test_drift_interpreter_declares_ollama_first_governance_lane(
monkeypatch: pytest.MonkeyPatch,
) -> None:
fake_openclaw = _FakeOpenClaw()
monkeypatch.setattr(openclaw_module, "get_openclaw", lambda: fake_openclaw)
result = await NemotronDriftInterpreter()._call_nemotron("請分析漂移")
assert result.intent == DriftIntent.AUTOMATED_CHANGE
assert fake_openclaw.alert_context is not None
assert fake_openclaw.alert_context["enforce_ollama_first"] is True
assert fake_openclaw.alert_context["task_type"] == "diagnose"
assert fake_openclaw.alert_context["allow_gcp_heavy_model"] is True