Skip to content

Commit d7b2dfa

Browse files
authored
Merge pull request #1853 from tisnik/lcore-2320
LCORE-2320: Minimal configuration dump unit tests
2 parents bf9b8a7 + fe9160a commit d7b2dfa

1 file changed

Lines changed: 256 additions & 1 deletion

File tree

tests/unit/models/config/test_dump_configuration.py

Lines changed: 256 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,187 @@
4141
}
4242

4343

44-
def test_dump_configuration(tmp_path: Path) -> None:
44+
def test_dump_configuration_minimal_cfg(tmp_path: Path) -> None:
45+
"""
46+
Test that the Configuration object can be serialized to a JSON file and
47+
that the resulting file contains all expected sections and values.
48+
49+
Please note that redaction process is not in place.
50+
51+
Parameters:
52+
----------
53+
tmp_path (Path): Directory where the test JSON file will be written.
54+
"""
55+
cfg = Configuration(
56+
name="test_name",
57+
service=ServiceConfiguration(
58+
tls_config=TLSConfiguration(
59+
tls_certificate_path=Path("tests/configuration/server.crt"),
60+
tls_key_path=Path("tests/configuration/server.key"),
61+
tls_key_password=Path("tests/configuration/password"),
62+
),
63+
cors=CORSConfiguration(),
64+
),
65+
llama_stack=LlamaStackConfiguration(
66+
use_as_library_client=True,
67+
library_client_config_path="tests/configuration/run.yaml",
68+
api_key=SecretStr("whatever"),
69+
),
70+
user_data_collection=UserDataCollection(
71+
feedback_enabled=False, feedback_storage=None
72+
),
73+
)
74+
assert cfg is not None
75+
dump_file = tmp_path / "test.json"
76+
cfg.dump(dump_file)
77+
78+
with open(dump_file, "r", encoding="utf-8") as fin:
79+
content = json.load(fin)
80+
# content should be loaded
81+
assert content is not None
82+
83+
# all sections must exists
84+
assert "name" in content
85+
assert "service" in content
86+
assert "llama_stack" in content
87+
assert "user_data_collection" in content
88+
assert "mcp_servers" in content
89+
assert "authentication" in content
90+
assert "authorization" in content
91+
assert "customization" in content
92+
assert "inference" in content
93+
assert "database" in content
94+
assert "byok_rag" in content
95+
assert "quota_handlers" in content
96+
assert "azure_entra_id" in content
97+
assert "reranker" in content
98+
99+
# check the whole deserialized JSON file content
100+
assert content == {
101+
"name": "test_name",
102+
"service": {
103+
"host": "localhost",
104+
"port": 8080,
105+
"base_url": None,
106+
"auth_enabled": False,
107+
"workers": 1,
108+
"color_log": True,
109+
"access_log": True,
110+
"tls_config": {
111+
"tls_certificate_path": "tests/configuration/server.crt",
112+
"tls_key_password": "tests/configuration/password",
113+
"tls_key_path": "tests/configuration/server.key",
114+
},
115+
"root_path": "",
116+
"cors": {
117+
"allow_credentials": False,
118+
"allow_headers": [
119+
"*",
120+
],
121+
"allow_methods": [
122+
"*",
123+
],
124+
"allow_origins": [
125+
"*",
126+
],
127+
},
128+
},
129+
"llama_stack": {
130+
"url": None,
131+
"use_as_library_client": True,
132+
"api_key": "**********",
133+
"library_client_config_path": "tests/configuration/run.yaml",
134+
"timeout": 180,
135+
"allow_degraded_mode": False,
136+
"max_retries": constants.DEFAULT_MAX_RETRIES,
137+
"retry_delay": constants.DEFAULT_RETRY_DELAY,
138+
},
139+
"user_data_collection": {
140+
"feedback_enabled": False,
141+
"feedback_storage": None,
142+
"transcripts_enabled": False,
143+
"transcripts_storage": None,
144+
},
145+
"mcp_servers": [],
146+
"authentication": {
147+
"module": "noop",
148+
"skip_tls_verification": False,
149+
"skip_for_health_probes": False,
150+
"skip_for_metrics": False,
151+
"k8s_ca_cert_path": None,
152+
"k8s_cluster_api": None,
153+
"jwk_config": None,
154+
"api_key_config": None,
155+
"rh_identity_config": None,
156+
},
157+
"customization": None,
158+
"inference": {
159+
"default_provider": None,
160+
"default_model": None,
161+
"context_windows": {},
162+
},
163+
"database": {
164+
"sqlite": {
165+
"db_path": "/tmp/lightspeed-stack.db",
166+
},
167+
"postgres": None,
168+
},
169+
"authorization": None,
170+
"conversation_cache": {
171+
"memory": None,
172+
"postgres": None,
173+
"sqlite": None,
174+
"type": None,
175+
},
176+
"compaction": {
177+
"enabled": False,
178+
"threshold_ratio": 0.7,
179+
"token_floor": 4096,
180+
"buffer_turns": 4,
181+
"buffer_max_ratio": 0.3,
182+
},
183+
"approvals": _DEFAULT_APPROVALS_DUMP,
184+
"byok_rag": [],
185+
"quota_handlers": {
186+
"sqlite": None,
187+
"postgres": None,
188+
"limiters": [],
189+
"scheduler": {
190+
"period": 1,
191+
"database_reconnection_count": 10,
192+
"database_reconnection_delay": 1,
193+
},
194+
"enable_token_history": False,
195+
},
196+
"a2a_state": {
197+
"sqlite": None,
198+
"postgres": None,
199+
},
200+
"azure_entra_id": None,
201+
"rag": {
202+
"inline": [],
203+
"tool": [],
204+
},
205+
"okp": {
206+
"rhokp_url": None,
207+
"offline": True,
208+
"chunk_filter_query": None,
209+
},
210+
"rlsapi_v1": {
211+
"allow_verbose_infer": False,
212+
"quota_subject": None,
213+
},
214+
"splunk": None,
215+
"deployment_environment": "development",
216+
"reranker": {
217+
"enabled": False,
218+
"model": "cross-encoder/ms-marco-MiniLM-L6-v2",
219+
},
220+
"skills": None,
221+
}
222+
223+
224+
def test_dump_configuration_valid_values(tmp_path: Path) -> None:
45225
"""
46226
Test that the Configuration object can be serialized to a JSON file and
47227
that the resulting file contains all expected sections and values.
@@ -1317,6 +1497,81 @@ def test_dump_configuration_pg_namespace(tmp_path: Path) -> None:
13171497
}
13181498

13191499

1500+
def test_dump_configuration_with_one_skill(tmp_path: Path) -> None:
1501+
"""
1502+
Test that Configuration with one skill path can be serialized to JSON.
1503+
1504+
Verifies that skills paths are properly dumped and serialized as strings.
1505+
"""
1506+
cfg = Configuration(
1507+
name="test_name",
1508+
service=ServiceConfiguration(
1509+
tls_config=TLSConfiguration(
1510+
tls_certificate_path=Path("tests/configuration/server.crt"),
1511+
tls_key_path=Path("tests/configuration/server.key"),
1512+
tls_key_password=Path("tests/configuration/password"),
1513+
),
1514+
cors=CORSConfiguration(
1515+
allow_origins=["foo_origin", "bar_origin", "baz_origin"],
1516+
allow_credentials=False,
1517+
allow_methods=["foo_method", "bar_method", "baz_method"],
1518+
allow_headers=["foo_header", "bar_header", "baz_header"],
1519+
),
1520+
),
1521+
llama_stack=LlamaStackConfiguration(
1522+
use_as_library_client=True,
1523+
library_client_config_path="tests/configuration/run.yaml",
1524+
api_key=SecretStr("whatever"),
1525+
),
1526+
user_data_collection=UserDataCollection(
1527+
feedback_enabled=False, feedback_storage=None
1528+
),
1529+
database=DatabaseConfiguration(
1530+
sqlite=None,
1531+
postgres=PostgreSQLDatabaseConfiguration(
1532+
db="lightspeed_stack",
1533+
user="ls_user",
1534+
password=SecretStr("ls_password"),
1535+
port=5432,
1536+
ca_cert_path=None,
1537+
ssl_mode="require",
1538+
gss_encmode="disable",
1539+
),
1540+
),
1541+
mcp_servers=[],
1542+
customization=None,
1543+
inference=InferenceConfiguration(
1544+
default_provider="default_provider",
1545+
default_model="default_model",
1546+
),
1547+
skills=SkillsConfiguration(
1548+
paths=[
1549+
"/var/skills/openshift-troubleshooting",
1550+
]
1551+
),
1552+
)
1553+
assert cfg is not None
1554+
dump_file = tmp_path / "test.json"
1555+
cfg.dump(dump_file)
1556+
1557+
with open(dump_file, "r", encoding="utf-8") as fin:
1558+
content = json.load(fin)
1559+
# content should be loaded
1560+
assert content is not None
1561+
1562+
# skills section must exist
1563+
assert "skills" in content
1564+
assert content["skills"] is not None
1565+
assert "paths" in content["skills"]
1566+
1567+
# verify skills paths are properly serialized
1568+
assert content["skills"] == {
1569+
"paths": [
1570+
"/var/skills/openshift-troubleshooting",
1571+
]
1572+
}
1573+
1574+
13201575
def test_dump_configuration_with_skills(tmp_path: Path) -> None:
13211576
"""
13221577
Test that Configuration with skills paths can be serialized to JSON.

0 commit comments

Comments
 (0)