Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions tests/unit/utils/test_vector_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
class TestIsSolrEnabled:
"""Tests for _is_solr_enabled function."""

def test_solr_enabled_true(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_solr_enabled_true(self, mocker: MockerFixture) -> None:
"""Test when Solr is enabled in configuration."""
config_mock = mocker.Mock(spec=AppConfig)
config_mock.inline_solr_enabled = True
mocker.patch("utils.vector_search.configuration", config_mock)
assert _is_solr_enabled() is True

def test_solr_enabled_false(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_solr_enabled_false(self, mocker: MockerFixture) -> None:
"""Test when Solr is disabled in configuration."""
config_mock = mocker.Mock(spec=AppConfig)
config_mock.inline_solr_enabled = False
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_with_solr_filters(self) -> None:
class TestExtractByokRagChunks:
"""Tests for _extract_byok_rag_chunks function."""

def test_extract_chunks_with_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_extract_chunks_with_metadata(self, mocker: MockerFixture) -> None:
"""Test extraction of chunks with metadata."""
# Create mock chunks
chunk1 = mocker.Mock()
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_extract_chunks_with_metadata(self, mocker) -> None: # type: ignore[no-
assert result[0]["source"] == "test_store"
assert result[0]["doc_id"] == "doc_1"

def test_extract_chunks_without_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_extract_chunks_without_metadata(self, mocker: MockerFixture) -> None:
"""Test extraction of chunks without metadata."""
chunk = mocker.Mock()
chunk.content = "Test content"
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_format_chunk_with_attributes(self) -> None:
class TestExtractSolrDocumentMetadata:
"""Tests for _extract_solr_document_metadata function."""

def test_extract_from_dict_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_extract_from_dict_metadata(self, mocker: MockerFixture) -> None:
"""Test extraction from dict-based metadata."""
chunk = mocker.Mock()
chunk.metadata = {
Expand All @@ -205,9 +205,7 @@ def test_extract_from_dict_metadata(self, mocker) -> None: # type: ignore[no-un
assert title == "Test Document"
assert reference_url == "https://example.com/doc"

def test_extract_from_chunk_metadata_object( # type: ignore[no-untyped-def]
self, mocker
) -> None:
def test_extract_from_chunk_metadata_object(self, mocker: MockerFixture) -> None:
"""Test extraction from typed chunk_metadata object."""
chunk_meta = mocker.Mock()
chunk_meta.doc_id = "doc_456"
Expand All @@ -224,7 +222,7 @@ def test_extract_from_chunk_metadata_object( # type: ignore[no-untyped-def]
assert title == "Another Document"
assert reference_url == "https://example.com/another"

def test_extract_with_missing_fields(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_extract_with_missing_fields(self, mocker: MockerFixture) -> None:
"""Test extraction when some fields are missing."""
chunk = mocker.Mock()
chunk.metadata = {"doc_id": "doc_789"}
Expand Down Expand Up @@ -261,7 +259,7 @@ def test_returns_default_when_rhokp_url_unset(self, mocker: MockerFixture) -> No
class TestBuildDocumentUrl:
"""Tests for _build_document_url function."""

def test_offline_mode_with_doc_id(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_offline_mode_with_doc_id(self, mocker: MockerFixture) -> None:
"""Test URL building in offline mode with doc_id."""
config_mock = mocker.Mock()
config_mock.okp.rhokp_url = "https://mimir.test"
Expand All @@ -283,7 +281,7 @@ def test_online_mode_with_reference_url(self) -> None:
assert doc_url == "https://docs.example.com/page"
assert reference_doc == "https://docs.example.com/page"

def test_online_mode_without_http(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_online_mode_without_http(self, mocker: MockerFixture) -> None:
"""Test online mode when reference_url doesn't start with http."""
config_mock = mocker.Mock()
config_mock.okp.rhokp_url = "https://mimir.test"
Expand All @@ -307,7 +305,7 @@ def test_offline_mode_without_doc_id(self) -> None:
class TestConvertSolrChunksToRagFormat:
"""Tests for _convert_solr_chunks_to_rag_format function."""

def test_convert_with_metadata_offline(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_convert_with_metadata_offline(self, mocker: MockerFixture) -> None:
"""Test conversion with metadata in offline mode."""
chunk = mocker.Mock()
chunk.content = "Test content"
Expand All @@ -320,10 +318,11 @@ def test_convert_with_metadata_offline(self, mocker) -> None: # type: ignore[no
assert result[0].content == "Test content"
assert result[0].source == constants.OKP_RAG_ID
assert result[0].score == 0.85
assert result[0].attributes is not None
assert "doc_url" in result[0].attributes
assert "parent_123" in result[0].attributes["doc_url"]

def test_convert_with_metadata_online(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_convert_with_metadata_online(self, mocker: MockerFixture) -> None:
"""Test conversion with metadata in online mode."""
chunk = mocker.Mock()
chunk.content = "Test content"
Expand All @@ -333,9 +332,10 @@ def test_convert_with_metadata_online(self, mocker) -> None: # type: ignore[no-
result = _convert_solr_chunks_to_rag_format([chunk], [0.75], offline=False)

assert len(result) == 1
assert result[0].attributes is not None
assert result[0].attributes["doc_url"] == "https://example.com/doc"

def test_convert_with_chunk_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_convert_with_chunk_metadata(self, mocker: MockerFixture) -> None:
"""Test conversion with chunk_metadata object."""
chunk_meta = mocker.Mock()
chunk_meta.document_id = "doc_456"
Expand All @@ -348,9 +348,10 @@ def test_convert_with_chunk_metadata(self, mocker) -> None: # type: ignore[no-u
result = _convert_solr_chunks_to_rag_format([chunk], [0.9], offline=True)

assert len(result) == 1
assert result[0].attributes is not None
assert result[0].attributes["document_id"] == "doc_456"

def test_convert_multiple_chunks(self, mocker) -> None: # type: ignore[no-untyped-def]
def test_convert_multiple_chunks(self, mocker: MockerFixture) -> None:
"""Test conversion of multiple chunks."""
chunk1 = mocker.Mock()
chunk1.content = "Content 1"
Expand All @@ -377,7 +378,7 @@ class TestFetchByokRag:
"""Tests for _fetch_byok_rag async function."""

@pytest.mark.asyncio
async def test_byok_no_inline_ids(self, mocker) -> None: # type: ignore[no-untyped-def]
async def test_byok_no_inline_ids(self, mocker: MockerFixture) -> None:
"""Test when no inline BYOK sources are configured."""
config_mock = mocker.Mock(spec=AppConfig)
config_mock.configuration.rag.inline = []
Expand All @@ -392,7 +393,7 @@ async def test_byok_no_inline_ids(self, mocker) -> None: # type: ignore[no-unty
client_mock.vector_io.query.assert_not_called()

@pytest.mark.asyncio
async def test_byok_enabled_success(self, mocker) -> None: # type: ignore[no-untyped-def]
async def test_byok_enabled_success(self, mocker: MockerFixture) -> None:
"""Test successful BYOK RAG fetch when inline IDs are configured."""
# Mock configuration
config_mock = mocker.Mock(spec=AppConfig)
Expand Down Expand Up @@ -430,8 +431,8 @@ async def test_byok_enabled_success(self, mocker) -> None: # type: ignore[no-un
assert len(referenced_docs) > 0

@pytest.mark.asyncio
async def test_user_facing_ids_translated_to_internal_ids( # type: ignore[no-untyped-def]
self, mocker
async def test_user_facing_ids_translated_to_internal_ids(
self, mocker: MockerFixture
) -> None:
"""Test that user-facing rag_ids (vector_store_ids) are translated to llama-stack ids."""
config_mock = mocker.Mock(spec=AppConfig)
Expand Down Expand Up @@ -466,8 +467,8 @@ async def test_user_facing_ids_translated_to_internal_ids( # type: ignore[no-un
)

@pytest.mark.asyncio
async def test_multiple_user_facing_ids_each_translated( # type: ignore[no-untyped-def]
self, mocker
async def test_multiple_user_facing_ids_each_translated(
self, mocker: MockerFixture
) -> None:
"""Test that multiple user-facing rag_ids are each translated to their vector_store_id."""
config_mock = mocker.Mock(spec=AppConfig)
Expand Down Expand Up @@ -517,7 +518,7 @@ class TestFetchSolrRag:
"""Tests for _fetch_solr_rag async function."""

@pytest.mark.asyncio
async def test_solr_disabled(self, mocker) -> None: # type: ignore[no-untyped-def]
async def test_solr_disabled(self, mocker: MockerFixture) -> None:
"""Test when Solr is disabled."""
config_mock = mocker.Mock(spec=AppConfig)
config_mock.inline_solr_enabled = False
Expand All @@ -531,7 +532,7 @@ async def test_solr_disabled(self, mocker) -> None: # type: ignore[no-untyped-d
client_mock.vector_io.query.assert_not_called()

@pytest.mark.asyncio
async def test_solr_enabled_success(self, mocker) -> None: # type: ignore[no-untyped-def]
async def test_solr_enabled_success(self, mocker: MockerFixture) -> None:
"""Test successful Solr RAG fetch."""
# Mock configuration
config_mock = mocker.Mock(spec=AppConfig)
Expand Down Expand Up @@ -566,7 +567,7 @@ class TestBuildRagContext:
"""Tests for build_rag_context async function."""

@pytest.mark.asyncio
async def test_both_sources_disabled(self, mocker) -> None: # type: ignore[no-untyped-def]
async def test_both_sources_disabled(self, mocker: MockerFixture) -> None:
"""Test when both BYOK inline and Solr inline are not configured."""
config_mock = mocker.Mock(spec=AppConfig)
config_mock.configuration.rag.inline = []
Expand All @@ -582,7 +583,7 @@ async def test_both_sources_disabled(self, mocker) -> None: # type: ignore[no-u
assert context.referenced_documents == []

@pytest.mark.asyncio
async def test_byok_enabled_only(self, mocker) -> None: # type: ignore[no-untyped-def]
async def test_byok_enabled_only(self, mocker: MockerFixture) -> None:
"""Test when only inline BYOK is configured."""
# Mock configuration
config_mock = mocker.Mock(spec=AppConfig)
Expand Down
Loading