feat(agent): v4.12.0 - refonte config 'Agent & IA', fournisseurs actifs/testes dans le panneau, contexte document + guide d'utilisation
This commit is contained in:
+70
-1
@@ -592,4 +592,73 @@ def test_router_run_uses_user_key(client, monkeypatch):
|
||||
"provider": "openai", "model": "gpt-4o-mini"})
|
||||
assert resp.status_code == 200
|
||||
assert created.get("api_key", "") == ""
|
||||
return {}
|
||||
return {}
|
||||
|
||||
|
||||
def test_router_user_key_test_verifies(client, monkeypatch):
|
||||
"""A successful user-key test flags the provider as functional (verified)."""
|
||||
from app.routers import agent as agent_router
|
||||
from app.services.llm_client import LLMResponse
|
||||
|
||||
seen = {}
|
||||
|
||||
class FakeLLM(agent_router.LLMClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
seen.update(kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
async def ping(self, *, model=None):
|
||||
return LLMResponse(text="PONG", model=model or "gpt-4o")
|
||||
|
||||
monkeypatch.setattr(agent_router, "LLMClient", FakeLLM)
|
||||
|
||||
client.put("/api/agent/keys/openai", json={"api_key": "sk-user"})
|
||||
r = client.post("/api/agent/keys/openai/test", json={"model": "gpt-4o-mini"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["ok"] is True
|
||||
assert body["verified"] is True
|
||||
assert seen.get("api_key") == "sk-user"
|
||||
|
||||
# the stored key row now carries verified=True
|
||||
entry = [k for k in client.get("/api/agent/keys").json()["keys"]
|
||||
if k["provider"] == "openai"][0]
|
||||
assert entry["verified"] is True
|
||||
|
||||
# /providers exposes openai as configured + verified + functional
|
||||
prov = client.get("/api/agent/providers").json()
|
||||
p = [x for x in prov["providers"] if x["id"] == "openai"][0]
|
||||
assert p["has_key"] is True
|
||||
assert p["configured"] is True
|
||||
assert p["verified"] is True
|
||||
assert p["functional"] is True
|
||||
|
||||
|
||||
def test_router_user_key_test_failure(client, monkeypatch):
|
||||
"""A failing test keeps the key but marks the provider non-functional."""
|
||||
from app.routers import agent as agent_router
|
||||
|
||||
class FakeLLM(agent_router.LLMClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
async def ping(self, *, model=None):
|
||||
raise PermissionError("Clé API manquante pour le provider « openai »")
|
||||
|
||||
monkeypatch.setattr(agent_router, "LLMClient", FakeLLM)
|
||||
|
||||
client.put("/api/agent/keys/openai", json={"api_key": "sk-user"})
|
||||
r = client.post("/api/agent/keys/openai/test", json={})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["ok"] is False
|
||||
assert body["verified"] is False
|
||||
|
||||
keys = client.get("/api/agent/keys").json()["keys"]
|
||||
entry = [k for k in keys if k["provider"] == "openai"][0]
|
||||
assert entry["verified"] is False
|
||||
assert entry["last_error"]
|
||||
|
||||
prov = client.get("/api/agent/providers").json()
|
||||
p = [x for x in prov["providers"] if x["id"] == "openai"][0]
|
||||
assert p["functional"] is False
|
||||
Reference in New Issue
Block a user