fix(assistant): #91 le SSE renvoie le modele reellement utilise (tag fournisseur - modele complet)
CI / lint (push) Successful in 1m24s
CI / security (push) Successful in 58s
CI / test (push) Successful in 2m21s
CI / build (push) Successful in 52s
CI / e2e (push) Successful in 10m38s

This commit is contained in:
2026-09-15 20:46:58 -04:00
parent daf9ff3b2d
commit 19e12fa22e
4 changed files with 89 additions and 2 deletions
+57
View File
@@ -967,3 +967,60 @@ class TestBooksLMAgentEndpoint:
assert executed.get("ran") is True
assert "C'est fait." in resp2.text
assert "event: message" in resp2.text
def test_agent_message_reports_effective_model(self, bookslm_client, monkeypatch):
"""The SSE payload carries the model really used, not the raw request.
The client may leave `model` empty (provider default) — reporting it
verbatim left the "provider · model" tag in the UI with the provider
only.
"""
import re
import backend.bookslm_routes as routes
from backend.ai import PROVIDERS
from backend.ai_chat import LLMResponse
async def fake_chat_completion(messages, **kwargs):
return LLMResponse(content="Bonjour.")
monkeypatch.setattr(routes, "chat_completion", fake_chat_completion)
monkeypatch.setattr(routes, "_resolve_provider_name", lambda requested: "openrouter")
token, _ = _login_bookslm(bookslm_client)
resp = bookslm_client.post(
"/api/ai/bookslm/agent",
json={"vault": "TestVault", "directory": "", "message": "salut", "mode": "directory"},
headers={"Authorization": f"Bearer {token}"},
)
assert resp.status_code == 200
match = re.search(r"event: message\ndata: (.*)", resp.text)
assert match, resp.text
data = json.loads(match.group(1))
assert data["provider"] == "openrouter"
expected = PROVIDERS.get("openrouter", {}).get("model", "") or ""
assert data["model"] == expected, data
assert data["model"], "provider default model must not be reported empty"
class TestEffectiveModel:
"""Unit tests for the provider/model tag payload helper."""
def test_requested_model_wins(self):
from backend.bookslm_routes import _effective_model
assert _effective_model("openrouter", "openai/gpt-4o-mini") == "openai/gpt-4o-mini"
def test_falls_back_to_provider_default(self):
from backend.ai import PROVIDERS
from backend.bookslm_routes import _effective_model
default = PROVIDERS.get("openrouter", {}).get("model", "")
assert _effective_model("openrouter", None) == default
assert _effective_model("openrouter", "") == default
def test_unknown_provider_or_missing_provider_is_empty(self):
from backend.bookslm_routes import _effective_model
assert _effective_model("nope-not-a-provider", None) == ""
assert _effective_model(None, None) == ""