Skip to content

Commit 1fa7b87

Browse files
committed
avoid brittle equality
1 parent 1256193 commit 1fa7b87

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/unit/app/endpoints/test_query.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,13 @@ async def test_query_endpoint_handler_with_referenced_documents(mocker):
263263
# Assert the response contains referenced documents
264264
assert response.response == llm_response
265265
assert response.conversation_id == conversation_id
266-
assert response.referenced_documents == referenced_documents
266+
# Avoid brittle equality on Pydantic models; compare fields instead
267+
assert [(str(d.doc_url), d.doc_title) for d in response.referenced_documents] == [
268+
("https://example.com/doc1", "Doc1"),
269+
("https://example.com/doc2", "Doc2"),
270+
]
267271
assert all(isinstance(d, ReferencedDocument) for d in response.referenced_documents)
268272
assert len(response.referenced_documents) == 2
269-
assert response.referenced_documents[0].doc_title == "Doc1"
270-
assert response.referenced_documents[1].doc_title == "Doc2"
271273

272274
# Assert the metric for successful LLM calls is incremented
273275
mock_metric.labels("fake_provider_id", "fake_model_id").inc.assert_called_once()
@@ -1680,8 +1682,8 @@ def test_process_knowledge_search_content_with_non_dict_metadata(mocker):
16801682
# Verify metadata_map remains empty (no document_id in string)
16811683
assert len(metadata_map) == 0
16821684

1683-
# No exception should be logged since string is valid literal
1684-
mock_logger.debug.assert_not_called()
1685+
# No exception should be logged since string is a valid literal and simply ignored
1686+
mock_logger.exception.assert_not_called()
16851687

16861688

16871689
def test_process_knowledge_search_content_with_metadata_missing_document_id(mocker):
@@ -2019,6 +2021,10 @@ async def test_retrieve_response_skips_invalid_docs_url(prepare_agent_mocks, moc
20192021
or "Skipping invalid referenced document" in str(call)
20202022
for call in mock_logger.warning.call_args_list
20212023
)
2024+
# Verify the bad URL is included in the log message for extra confidence
2025+
assert any(
2026+
"not-a-valid-url" in str(call) for call in mock_logger.warning.call_args_list
2027+
)
20222028

20232029

20242030
@pytest.mark.asyncio

0 commit comments

Comments
 (0)