Files
awoooi/apps/api/tests/test_phase22_nemotron_collab.py

65 lines
2.1 KiB
Python

"""Legacy Nemotron collaboration is shadow metadata, never production routing."""
from __future__ import annotations
import inspect
from unittest.mock import AsyncMock
import pytest
from src.services import openclaw as openclaw_module
from src.services.openclaw import OpenClawService
def test_legacy_feature_flag_remains_for_config_compatibility() -> None:
from src.core.config import Settings
assert "ENABLE_NEMOTRON_COLLABORATION" in Settings.model_fields
assert "NEMOTRON_TIMEOUT_SECONDS" in Settings.model_fields
@pytest.mark.asyncio
async def test_legacy_flags_cannot_make_nemotron_executable(
monkeypatch: pytest.MonkeyPatch,
) -> None:
service = object.__new__(OpenClawService)
proposal = {"risk_level": "critical", "reasoning": "test"}
generate = AsyncMock(return_value=(proposal, "ollama_gcp_a", True))
nemotron = AsyncMock()
gemini_proxy = AsyncMock()
monkeypatch.setattr(service, "generate_incident_proposal", generate)
monkeypatch.setattr(service, "_call_nemotron_tools", nemotron)
monkeypatch.setattr(service, "_call_nemotron_tools_via_gemini", gemini_proxy)
monkeypatch.setattr(
openclaw_module.settings,
"ALERT_AI_STRICT_PROVIDER_CHAIN",
False,
)
monkeypatch.setattr(
openclaw_module.settings,
"ENABLE_NEMOTRON_COLLABORATION",
True,
)
result = await service.generate_incident_proposal_with_tools(
"INC-1",
"P0",
[{"alert_name": "HostHighCpuLoad"}],
["awoooi-api"],
)
assert result == (proposal, "ollama_gcp_a", True)
assert proposal["nemotron_enabled"] is False
assert proposal["nemotron_validation"] == "strict_provider_chain"
nemotron.assert_not_awaited()
gemini_proxy.assert_not_awaited()
def test_production_method_returns_before_legacy_shadow_implementation() -> None:
source = inspect.getsource(OpenClawService.generate_incident_proposal_with_tools)
strict_return = source.find("return proposal, provider, success")
legacy_call = source.find("_call_nemotron_tools(")
assert strict_return != -1
assert legacy_call == -1 or strict_return < legacy_call