fix: correct integration test assertions for semantic search
- test_search_by_content: format_search_result() does not include body_text, so check for the expected message_id instead. - test_search_no_results: vector cosine similarity always returns nearest neighbors; use a date filter far in the future to guarantee zero results instead.
This commit is contained in:
@@ -132,11 +132,17 @@ def qdrant_setup():
|
||||
|
||||
class TestSearchEmails:
|
||||
def test_search_by_content(self, qdrant_setup):
|
||||
"""Search for emails about Python/programming."""
|
||||
"""Semantic search returns the most relevant email first.
|
||||
|
||||
Searching for 'Python programming' should match email 001
|
||||
which discusses Python and vector databases.
|
||||
"""
|
||||
result = search_emails(query="Python programming")
|
||||
assert result["count"] >= 1
|
||||
assert "results" in result
|
||||
assert any("Python" in r.get("body_text", "") for r in result["results"])
|
||||
# The top result should be email 001 (most semantically relevant)
|
||||
messages = [r["message_id"] for r in result["results"]]
|
||||
assert "<test-001@example.com>" in messages
|
||||
|
||||
def test_search_with_participant_filter(self, qdrant_setup):
|
||||
"""Search emails sent by alice."""
|
||||
@@ -153,9 +159,17 @@ class TestSearchEmails:
|
||||
date = r.get("date", "")
|
||||
assert date >= "2026-02-01"
|
||||
|
||||
def test_search_no_results(self, qdrant_setup):
|
||||
"""Search for something that doesn't exist."""
|
||||
result = search_emails(query="gobbledygookxyz123")
|
||||
def test_search_no_results_by_date(self, qdrant_setup):
|
||||
"""Search with a filter that matches no emails returns empty results.
|
||||
|
||||
With semantic (vector) search, any text query always has nearest
|
||||
neighbors, so we use a date filter that matches nothing instead.
|
||||
"""
|
||||
result = search_emails(
|
||||
query="anything",
|
||||
start_date="2099-01-01",
|
||||
end_date="2099-12-31",
|
||||
)
|
||||
assert result["count"] == 0
|
||||
assert result["results"] == []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user