fixed the RAg in test pipeline issue

This commit is contained in:
belviskhoremk
2026-04-26 18:51:48 +00:00
parent 205d9d7901
commit 97a501097d
14 changed files with 249 additions and 57 deletions

View File

@@ -206,9 +206,11 @@ class TestChatHandoff:
assert resp.status_code == 200
assert resp.json()["handoff"] is True
def test_handoff_not_triggered_without_keyword_match(self, client):
def test_handoff_not_triggered_when_high_confidence_no_keyword(self, client):
# High confidence + no keyword match → no handoff
chatbot = _make_chatbot(handoff_enabled=True, handoff_keywords=["human"])
rag_result = {"response": "Sure!", "sources": [], "model": "m", "tokens_used": 5}
rag_result = {"response": "We open at 9am.", "sources": [], "confidence_score": 0.85,
"model": "m", "tokens_used": 5}
with patch("app.routers.chat.get_supabase") as mock_sb, \
patch("app.routers.chat.rag_engine") as mock_rag:
@@ -219,6 +221,22 @@ class TestChatHandoff:
assert resp.status_code == 200
assert resp.json()["handoff"] is False
def test_handoff_triggered_by_low_confidence(self, client):
# Low confidence (no sources) triggers handoff even without a keyword
chatbot = _make_chatbot(handoff_enabled=True, handoff_keywords=["human"])
rag_result = {"response": "I'm not sure.", "sources": [], "confidence_score": 0.1,
"model": "m", "tokens_used": 5}
with patch("app.routers.chat.get_supabase") as mock_sb, \
patch("app.routers.chat.rag_engine") as mock_rag:
mock_rag.process_query = AsyncMock(return_value=rag_result)
mock_sb.return_value = _make_chat_sb(chatbot=chatbot)
resp = client.post("/api/v1/chat/cb-1", json={"message": "Tell me about quantum physics", "language": "en"})
assert resp.status_code == 200
assert resp.json()["handoff"] is True
assert resp.json()["low_confidence"] is True
class TestChatHistory:
def test_history_returns_empty_for_unknown_session(self, client):