22
33from pathlib import Path
44
5+ from typing import Any
6+
57import pytest
68import yaml
79
10+ from pydantic import SecretStr
11+
812from models .config import (
913 ByokRag ,
1014 Configuration ,
2731
2832def test_construct_vector_dbs_section_init () -> None :
2933 """Test the function construct_vector_dbs_section for no vector_dbs configured before."""
30- ls_config = {}
31- byok_rag = []
34+ ls_config : dict [ str , Any ] = {}
35+ byok_rag : list [ ByokRag ] = []
3236 output = construct_vector_dbs_section (ls_config , byok_rag )
3337 assert len (output ) == 0
3438
@@ -51,7 +55,7 @@ def test_construct_vector_dbs_section_init_with_existing_data() -> None:
5155 },
5256 ]
5357 }
54- byok_rag = []
58+ byok_rag : list [ ByokRag ] = []
5559 output = construct_vector_dbs_section (ls_config , byok_rag )
5660 assert len (output ) == 2
5761 assert output [0 ] == {
@@ -70,17 +74,17 @@ def test_construct_vector_dbs_section_init_with_existing_data() -> None:
7074
7175def test_construct_vector_dbs_section_append () -> None :
7276 """Test the function construct_vector_dbs_section for no vector_dbs configured before."""
73- ls_config = {}
74- byok_rag = [
77+ ls_config : dict [ str , Any ] = {}
78+ byok_rag : list [ ByokRag ] = [
7579 ByokRag (
7680 rag_id = "rag_id_1" ,
7781 vector_db_id = "vector_db_id_1" ,
78- db_path = "tests/configuration/rag.txt" ,
82+ db_path = Path ( "tests/configuration/rag.txt" ) ,
7983 ),
8084 ByokRag (
8185 rag_id = "rag_id_2" ,
8286 vector_db_id = "vector_db_id_2" ,
83- db_path = "tests/configuration/rag.txt" ,
87+ db_path = Path ( "tests/configuration/rag.txt" ) ,
8488 ),
8589 ]
8690 output = construct_vector_dbs_section (ls_config , byok_rag )
@@ -121,12 +125,12 @@ def test_construct_vector_dbs_section_full_merge() -> None:
121125 ByokRag (
122126 rag_id = "rag_id_1" ,
123127 vector_db_id = "vector_db_id_1" ,
124- db_path = "tests/configuration/rag.txt" ,
128+ db_path = Path ( "tests/configuration/rag.txt" ) ,
125129 ),
126130 ByokRag (
127131 rag_id = "rag_id_2" ,
128132 vector_db_id = "vector_db_id_2" ,
129- db_path = "tests/configuration/rag.txt" ,
133+ db_path = Path ( "tests/configuration/rag.txt" ) ,
130134 ),
131135 ]
132136 output = construct_vector_dbs_section (ls_config , byok_rag )
@@ -159,8 +163,8 @@ def test_construct_vector_dbs_section_full_merge() -> None:
159163
160164def test_construct_vector_io_providers_section_init () -> None :
161165 """Test construct_vector_io_providers_section for no vector_io_providers configured before."""
162- ls_config = {"providers" : {}}
163- byok_rag = []
166+ ls_config : dict [ str , Any ] = {"providers" : {}}
167+ byok_rag : list [ ByokRag ] = []
164168 output = construct_vector_io_providers_section (ls_config , byok_rag )
165169 assert len (output ) == 0
166170
@@ -181,7 +185,7 @@ def test_construct_vector_io_providers_section_init_with_existing_data() -> None
181185 ]
182186 }
183187 }
184- byok_rag = []
188+ byok_rag : list [ ByokRag ] = []
185189 output = construct_vector_io_providers_section (ls_config , byok_rag )
186190 assert len (output ) == 2
187191 assert output [0 ] == {
@@ -196,17 +200,17 @@ def test_construct_vector_io_providers_section_init_with_existing_data() -> None
196200
197201def test_construct_vector_io_providers_section_append () -> None :
198202 """Test construct_vector_io_providers_section for no vector_io_providers configured before."""
199- ls_config = {"providers" : {}}
203+ ls_config : dict [ str , Any ] = {"providers" : {}}
200204 byok_rag = [
201205 ByokRag (
202206 rag_id = "rag_id_1" ,
203207 vector_db_id = "vector_db_id_1" ,
204- db_path = "tests/configuration/rag.txt" ,
208+ db_path = Path ( "tests/configuration/rag.txt" ) ,
205209 ),
206210 ByokRag (
207211 rag_id = "rag_id_2" ,
208212 vector_db_id = "vector_db_id_2" ,
209- db_path = "tests/configuration/rag.txt" ,
213+ db_path = Path ( "tests/configuration/rag.txt" ) ,
210214 ),
211215 ]
212216 output = construct_vector_io_providers_section (ls_config , byok_rag )
@@ -255,12 +259,12 @@ def test_construct_vector_io_providers_section_full_merge() -> None:
255259 ByokRag (
256260 rag_id = "rag_id_1" ,
257261 vector_db_id = "vector_db_id_1" ,
258- db_path = "tests/configuration/rag.txt" ,
262+ db_path = Path ( "tests/configuration/rag.txt" ) ,
259263 ),
260264 ByokRag (
261265 rag_id = "rag_id_2" ,
262266 vector_db_id = "vector_db_id_2" ,
263- db_path = "tests/configuration/rag.txt" ,
267+ db_path = Path ( "tests/configuration/rag.txt" ) ,
264268 ),
265269 ]
266270 output = construct_vector_io_providers_section (ls_config , byok_rag )
@@ -305,7 +309,7 @@ def test_generate_configuration_no_input_file(tmpdir: Path) -> None:
305309 llama_stack = LlamaStackConfiguration (
306310 use_as_library_client = True ,
307311 library_client_config_path = "tests/configuration/run.yaml" ,
308- api_key = "whatever" ,
312+ api_key = SecretStr ( "whatever" ) ,
309313 ),
310314 user_data_collection = UserDataCollection (
311315 feedback_enabled = False , feedback_storage = None
@@ -314,7 +318,7 @@ def test_generate_configuration_no_input_file(tmpdir: Path) -> None:
314318 outfile = tmpdir / "run.xml"
315319 # try to generate new configuration file
316320 with pytest .raises (FileNotFoundError , match = "No such file" ):
317- generate_configuration ("/does/not/exist" , outfile , cfg )
321+ generate_configuration ("/does/not/exist" , str ( outfile ) , cfg )
318322
319323
320324def test_generate_configuration_proper_input_file_no_byok (tmpdir : Path ) -> None :
@@ -325,15 +329,15 @@ def test_generate_configuration_proper_input_file_no_byok(tmpdir: Path) -> None:
325329 llama_stack = LlamaStackConfiguration (
326330 use_as_library_client = True ,
327331 library_client_config_path = "tests/configuration/run.yaml" ,
328- api_key = "whatever" ,
332+ api_key = SecretStr ( "whatever" ) ,
329333 ),
330334 user_data_collection = UserDataCollection (
331335 feedback_enabled = False , feedback_storage = None
332336 ),
333337 )
334338 outfile = tmpdir / "run.xml"
335339 # try to generate new configuration file
336- generate_configuration ("tests/configuration/run.yaml" , outfile , cfg )
340+ generate_configuration ("tests/configuration/run.yaml" , str ( outfile ) , cfg )
337341
338342 with open (outfile , "r" , encoding = "utf-8" ) as fin :
339343 generated = yaml .safe_load (fin )
@@ -350,7 +354,7 @@ def test_generate_configuration_proper_input_file_configured_byok(tmpdir: Path)
350354 llama_stack = LlamaStackConfiguration (
351355 use_as_library_client = True ,
352356 library_client_config_path = "tests/configuration/run.yaml" ,
353- api_key = "whatever" ,
357+ api_key = SecretStr ( "whatever" ) ,
354358 ),
355359 user_data_collection = UserDataCollection (
356360 feedback_enabled = False , feedback_storage = None
@@ -359,18 +363,18 @@ def test_generate_configuration_proper_input_file_configured_byok(tmpdir: Path)
359363 ByokRag (
360364 rag_id = "rag_id_1" ,
361365 vector_db_id = "vector_db_id_1" ,
362- db_path = "tests/configuration/rag.txt" ,
366+ db_path = Path ( "tests/configuration/rag.txt" ) ,
363367 ),
364368 ByokRag (
365369 rag_id = "rag_id_2" ,
366370 vector_db_id = "vector_db_id_2" ,
367- db_path = "tests/configuration/rag.txt" ,
371+ db_path = Path ( "tests/configuration/rag.txt" ) ,
368372 ),
369373 ],
370374 )
371375 outfile = tmpdir / "run.xml"
372376 # try to generate new configuration file
373- generate_configuration ("tests/configuration/run.yaml" , outfile , cfg )
377+ generate_configuration ("tests/configuration/run.yaml" , str ( outfile ) , cfg )
374378
375379 with open (outfile , "r" , encoding = "utf-8" ) as fin :
376380 generated = yaml .safe_load (fin )
0 commit comments