ajuste no contas
This commit is contained in:
47
tests/migration/test_guardrail_llm_client_lifecycle.py
Normal file
47
tests/migration/test_guardrail_llm_client_lifecycle.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
import agent_framework.guardrails.framework_llm_client as module
|
||||
|
||||
|
||||
class _OwnedLLM:
|
||||
def __init__(self):
|
||||
self.closed = False
|
||||
|
||||
async def ainvoke(self, *args, **kwargs):
|
||||
return '{"allowed": true, "reason": ""}'
|
||||
|
||||
async def aclose(self):
|
||||
self.closed = True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_temporary_guardrail_provider_is_closed_inside_owning_event_loop(monkeypatch):
|
||||
llm = _OwnedLLM()
|
||||
monkeypatch.setattr(module, '_ensure_framework_llm', lambda value: llm)
|
||||
monkeypatch.setenv('USE_MOCK_LLM', 'false')
|
||||
|
||||
result = await module.classify_with_framework_llm(
|
||||
None,
|
||||
'AOFERTA',
|
||||
{'text': 'Posso ajudar?', 'context': {}},
|
||||
)
|
||||
|
||||
assert result['allowed'] is True
|
||||
assert llm.closed is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_caller_owned_guardrail_provider_is_not_closed(monkeypatch):
|
||||
llm = _OwnedLLM()
|
||||
monkeypatch.setenv('USE_MOCK_LLM', 'false')
|
||||
|
||||
result = await module.classify_with_framework_llm(
|
||||
llm,
|
||||
'AOFERTA',
|
||||
{'text': 'Posso ajudar?', 'context': {}},
|
||||
)
|
||||
|
||||
assert result['allowed'] is True
|
||||
assert llm.closed is False
|
||||
Reference in New Issue
Block a user