|
2 | 2 |
|
3 | 3 | # pylint: disable=too-many-lines |
4 | 4 |
|
| 5 | +from collections.abc import Generator |
5 | 6 | from pathlib import Path |
6 | 7 | from typing import Any |
7 | | -from collections.abc import Generator |
8 | | -from pydantic import ValidationError |
9 | 8 |
|
10 | 9 | import pytest |
| 10 | +from pydantic import ValidationError |
| 11 | + |
| 12 | +import constants |
| 13 | +from cache.in_memory_cache import InMemoryCache |
| 14 | +from cache.sqlite_cache import SQLiteCache |
11 | 15 | from configuration import AppConfig, LogicError |
12 | 16 | from models.config import CustomProfile, ModelContextProtocolServer |
13 | | -from cache.sqlite_cache import SQLiteCache |
14 | | -from cache.in_memory_cache import InMemoryCache |
15 | 17 |
|
16 | 18 |
|
17 | 19 | # pylint: disable=broad-exception-caught,protected-access |
@@ -954,11 +956,61 @@ def test_load_configuration_with_incomplete_azure_entra_id_raises(tmpdir: Path) |
954 | 956 | cfg.load_configuration(str(cfg_filename)) |
955 | 957 |
|
956 | 958 |
|
957 | | -def test_rag_id_mapping_empty_when_no_byok(minimal_config: AppConfig) -> None: |
958 | | - """Test that rag_id_mapping returns empty dict when no BYOK RAG configured.""" |
| 959 | +def test_rag_id_mapping_excludes_solr_when_okp_not_configured( |
| 960 | + minimal_config: AppConfig, |
| 961 | +) -> None: |
| 962 | + """Test that rag_id_mapping does not include OKP/Solr when OKP is not in rag config.""" |
959 | 963 | assert minimal_config.rag_id_mapping == {} |
960 | 964 |
|
961 | 965 |
|
| 966 | +def test_rag_id_mapping_includes_solr_when_okp_in_inline() -> None: |
| 967 | + """Test that rag_id_mapping includes OKP/Solr mapping when OKP is in rag.inline.""" |
| 968 | + cfg = AppConfig() |
| 969 | + cfg.init_from_dict( |
| 970 | + { |
| 971 | + "name": "test", |
| 972 | + "service": {"host": "localhost", "port": 8080}, |
| 973 | + "llama_stack": { |
| 974 | + "api_key": "k", |
| 975 | + "url": "http://test.com:1234", |
| 976 | + "use_as_library_client": False, |
| 977 | + }, |
| 978 | + "user_data_collection": {}, |
| 979 | + "authentication": {"module": "noop"}, |
| 980 | + "rag": {"inline": [constants.OKP_RAG_ID]}, |
| 981 | + } |
| 982 | + ) |
| 983 | + assert constants.SOLR_DEFAULT_VECTOR_STORE_ID in cfg.rag_id_mapping |
| 984 | + assert ( |
| 985 | + cfg.rag_id_mapping[constants.SOLR_DEFAULT_VECTOR_STORE_ID] |
| 986 | + == constants.OKP_RAG_ID |
| 987 | + ) |
| 988 | + |
| 989 | + |
| 990 | +def test_rag_id_mapping_includes_solr_when_okp_in_tool() -> None: |
| 991 | + """Test that rag_id_mapping includes OKP/Solr mapping when OKP is in rag.tool.""" |
| 992 | + cfg = AppConfig() |
| 993 | + cfg.init_from_dict( |
| 994 | + { |
| 995 | + "name": "test", |
| 996 | + "service": {"host": "localhost", "port": 8080}, |
| 997 | + "llama_stack": { |
| 998 | + "api_key": "k", |
| 999 | + "url": "http://test.com:1234", |
| 1000 | + "use_as_library_client": False, |
| 1001 | + }, |
| 1002 | + "user_data_collection": {}, |
| 1003 | + "authentication": {"module": "noop"}, |
| 1004 | + "rag": {"tool": [constants.OKP_RAG_ID]}, |
| 1005 | + } |
| 1006 | + ) |
| 1007 | + assert constants.SOLR_DEFAULT_VECTOR_STORE_ID in cfg.rag_id_mapping |
| 1008 | + assert ( |
| 1009 | + cfg.rag_id_mapping[constants.SOLR_DEFAULT_VECTOR_STORE_ID] |
| 1010 | + == constants.OKP_RAG_ID |
| 1011 | + ) |
| 1012 | + |
| 1013 | + |
962 | 1014 | def test_rag_id_mapping_with_byok(tmp_path: Path) -> None: |
963 | 1015 | """Test that rag_id_mapping builds correct mapping from BYOK config.""" |
964 | 1016 | db_file = tmp_path / "test.db" |
@@ -987,6 +1039,41 @@ def test_rag_id_mapping_with_byok(tmp_path: Path) -> None: |
987 | 1039 | assert cfg.rag_id_mapping == {"vs-001": "my-kb"} |
988 | 1040 |
|
989 | 1041 |
|
| 1042 | +def test_rag_id_mapping_with_byok_and_okp(tmp_path: Path) -> None: |
| 1043 | + """Test that rag_id_mapping includes both BYOK and OKP entries when OKP is configured.""" |
| 1044 | + db_file = tmp_path / "test.db" |
| 1045 | + db_file.touch() |
| 1046 | + cfg = AppConfig() |
| 1047 | + cfg.init_from_dict( |
| 1048 | + { |
| 1049 | + "name": "test", |
| 1050 | + "service": {"host": "localhost", "port": 8080}, |
| 1051 | + "llama_stack": { |
| 1052 | + "api_key": "k", |
| 1053 | + "url": "http://test.com:1234", |
| 1054 | + "use_as_library_client": False, |
| 1055 | + }, |
| 1056 | + "user_data_collection": {}, |
| 1057 | + "authentication": {"module": "noop"}, |
| 1058 | + "rag": {"inline": [constants.OKP_RAG_ID]}, |
| 1059 | + "byok_rag": [ |
| 1060 | + { |
| 1061 | + "rag_id": "my-kb", |
| 1062 | + "vector_db_id": "vs-001", |
| 1063 | + "db_path": str(db_file), |
| 1064 | + }, |
| 1065 | + ], |
| 1066 | + } |
| 1067 | + ) |
| 1068 | + assert "vs-001" in cfg.rag_id_mapping |
| 1069 | + assert cfg.rag_id_mapping["vs-001"] == "my-kb" |
| 1070 | + assert constants.SOLR_DEFAULT_VECTOR_STORE_ID in cfg.rag_id_mapping |
| 1071 | + assert ( |
| 1072 | + cfg.rag_id_mapping[constants.SOLR_DEFAULT_VECTOR_STORE_ID] |
| 1073 | + == constants.OKP_RAG_ID |
| 1074 | + ) |
| 1075 | + |
| 1076 | + |
990 | 1077 | def test_resolve_index_name_with_mapping(minimal_config: AppConfig) -> None: |
991 | 1078 | """Test resolve_index_name uses mapping when available.""" |
992 | 1079 | mapping = {"vs-x": "user-friendly-name"} |
|
0 commit comments