|
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 |
@@ -947,11 +949,61 @@ def test_load_configuration_with_incomplete_azure_entra_id_raises(tmpdir: Path) |
947 | 949 | cfg.load_configuration(str(cfg_filename)) |
948 | 950 |
|
949 | 951 |
|
950 | | -def test_rag_id_mapping_empty_when_no_byok(minimal_config: AppConfig) -> None: |
951 | | - """Test that rag_id_mapping returns empty dict when no BYOK RAG configured.""" |
| 952 | +def test_rag_id_mapping_excludes_solr_when_okp_not_configured( |
| 953 | + minimal_config: AppConfig, |
| 954 | +) -> None: |
| 955 | + """Test that rag_id_mapping does not include OKP/Solr when OKP is not in rag config.""" |
952 | 956 | assert minimal_config.rag_id_mapping == {} |
953 | 957 |
|
954 | 958 |
|
| 959 | +def test_rag_id_mapping_includes_solr_when_okp_in_inline() -> None: |
| 960 | + """Test that rag_id_mapping includes OKP/Solr mapping when OKP is in rag.inline.""" |
| 961 | + cfg = AppConfig() |
| 962 | + cfg.init_from_dict( |
| 963 | + { |
| 964 | + "name": "test", |
| 965 | + "service": {"host": "localhost", "port": 8080}, |
| 966 | + "llama_stack": { |
| 967 | + "api_key": "k", |
| 968 | + "url": "http://test.com:1234", |
| 969 | + "use_as_library_client": False, |
| 970 | + }, |
| 971 | + "user_data_collection": {}, |
| 972 | + "authentication": {"module": "noop"}, |
| 973 | + "rag": {"inline": [constants.OKP_RAG_ID]}, |
| 974 | + } |
| 975 | + ) |
| 976 | + assert constants.SOLR_DEFAULT_VECTOR_STORE_ID in cfg.rag_id_mapping |
| 977 | + assert ( |
| 978 | + cfg.rag_id_mapping[constants.SOLR_DEFAULT_VECTOR_STORE_ID] |
| 979 | + == constants.OKP_RAG_ID |
| 980 | + ) |
| 981 | + |
| 982 | + |
| 983 | +def test_rag_id_mapping_includes_solr_when_okp_in_tool() -> None: |
| 984 | + """Test that rag_id_mapping includes OKP/Solr mapping when OKP is in rag.tool.""" |
| 985 | + cfg = AppConfig() |
| 986 | + cfg.init_from_dict( |
| 987 | + { |
| 988 | + "name": "test", |
| 989 | + "service": {"host": "localhost", "port": 8080}, |
| 990 | + "llama_stack": { |
| 991 | + "api_key": "k", |
| 992 | + "url": "http://test.com:1234", |
| 993 | + "use_as_library_client": False, |
| 994 | + }, |
| 995 | + "user_data_collection": {}, |
| 996 | + "authentication": {"module": "noop"}, |
| 997 | + "rag": {"tool": [constants.OKP_RAG_ID]}, |
| 998 | + } |
| 999 | + ) |
| 1000 | + assert constants.SOLR_DEFAULT_VECTOR_STORE_ID in cfg.rag_id_mapping |
| 1001 | + assert ( |
| 1002 | + cfg.rag_id_mapping[constants.SOLR_DEFAULT_VECTOR_STORE_ID] |
| 1003 | + == constants.OKP_RAG_ID |
| 1004 | + ) |
| 1005 | + |
| 1006 | + |
955 | 1007 | def test_rag_id_mapping_with_byok(tmp_path: Path) -> None: |
956 | 1008 | """Test that rag_id_mapping builds correct mapping from BYOK config.""" |
957 | 1009 | db_file = tmp_path / "test.db" |
@@ -980,6 +1032,41 @@ def test_rag_id_mapping_with_byok(tmp_path: Path) -> None: |
980 | 1032 | assert cfg.rag_id_mapping == {"vs-001": "my-kb"} |
981 | 1033 |
|
982 | 1034 |
|
| 1035 | +def test_rag_id_mapping_with_byok_and_okp(tmp_path: Path) -> None: |
| 1036 | + """Test that rag_id_mapping includes both BYOK and OKP entries when OKP is configured.""" |
| 1037 | + db_file = tmp_path / "test.db" |
| 1038 | + db_file.touch() |
| 1039 | + cfg = AppConfig() |
| 1040 | + cfg.init_from_dict( |
| 1041 | + { |
| 1042 | + "name": "test", |
| 1043 | + "service": {"host": "localhost", "port": 8080}, |
| 1044 | + "llama_stack": { |
| 1045 | + "api_key": "k", |
| 1046 | + "url": "http://test.com:1234", |
| 1047 | + "use_as_library_client": False, |
| 1048 | + }, |
| 1049 | + "user_data_collection": {}, |
| 1050 | + "authentication": {"module": "noop"}, |
| 1051 | + "rag": {"inline": [constants.OKP_RAG_ID]}, |
| 1052 | + "byok_rag": [ |
| 1053 | + { |
| 1054 | + "rag_id": "my-kb", |
| 1055 | + "vector_db_id": "vs-001", |
| 1056 | + "db_path": str(db_file), |
| 1057 | + }, |
| 1058 | + ], |
| 1059 | + } |
| 1060 | + ) |
| 1061 | + assert "vs-001" in cfg.rag_id_mapping |
| 1062 | + assert cfg.rag_id_mapping["vs-001"] == "my-kb" |
| 1063 | + assert constants.SOLR_DEFAULT_VECTOR_STORE_ID in cfg.rag_id_mapping |
| 1064 | + assert ( |
| 1065 | + cfg.rag_id_mapping[constants.SOLR_DEFAULT_VECTOR_STORE_ID] |
| 1066 | + == constants.OKP_RAG_ID |
| 1067 | + ) |
| 1068 | + |
| 1069 | + |
983 | 1070 | def test_resolve_index_name_with_mapping(minimal_config: AppConfig) -> None: |
984 | 1071 | """Test resolve_index_name uses mapping when available.""" |
985 | 1072 | mapping = {"vs-x": "user-friendly-name"} |
|
0 commit comments