Skip to content

Commit 914c32e

Browse files
committed
Added new unit tests
1 parent db9cb57 commit 914c32e

2 files changed

Lines changed: 265 additions & 27 deletions

File tree

tests/unit/models/config/test_dump_configuration.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def test_dump_configuration(tmp_path: Path) -> None:
160160
"api_key": "**********",
161161
"library_client_config_path": "tests/configuration/run.yaml",
162162
"timeout": 180,
163+
"allow_degraded_mode": False,
163164
},
164165
"user_data_collection": {
165166
"feedback_enabled": False,
@@ -510,6 +511,7 @@ def test_dump_configuration_with_quota_limiters(tmp_path: Path) -> None:
510511
"api_key": "**********",
511512
"library_client_config_path": "tests/configuration/run.yaml",
512513
"timeout": 180,
514+
"allow_degraded_mode": False,
513515
},
514516
"user_data_collection": {
515517
"feedback_enabled": False,
@@ -759,6 +761,7 @@ def test_dump_configuration_with_quota_limiters_different_values(
759761
"api_key": "**********",
760762
"library_client_config_path": "tests/configuration/run.yaml",
761763
"timeout": 180,
764+
"allow_degraded_mode": False,
762765
},
763766
"user_data_collection": {
764767
"feedback_enabled": False,
@@ -988,6 +991,7 @@ def test_dump_configuration_byok(tmp_path: Path) -> None:
988991
"api_key": "**********",
989992
"library_client_config_path": "tests/configuration/run.yaml",
990993
"timeout": 180,
994+
"allow_degraded_mode": False,
991995
},
992996
"user_data_collection": {
993997
"feedback_enabled": False,
@@ -1207,6 +1211,7 @@ def test_dump_configuration_pg_namespace(tmp_path: Path) -> None:
12071211
"api_key": "**********",
12081212
"library_client_config_path": "tests/configuration/run.yaml",
12091213
"timeout": 180,
1214+
"allow_degraded_mode": False,
12101215
},
12111216
"user_data_collection": {
12121217
"feedback_enabled": False,
@@ -1378,3 +1383,219 @@ def test_dump_configuration_with_skills(tmp_path: Path) -> None:
13781383
"/opt/custom-skills",
13791384
]
13801385
}
1386+
1387+
1388+
def test_dump_configuration_allow_degraded_mode(tmp_path: Path) -> None:
1389+
"""
1390+
Test that the Configuration object can be serialized to a JSON file and
1391+
that the resulting file contains all expected sections and values.
1392+
1393+
Please note that redaction process is not in place.
1394+
1395+
Parameters:
1396+
----------
1397+
tmp_path (Path): Directory where the test JSON file will be written.
1398+
"""
1399+
cfg = Configuration(
1400+
name="test_name",
1401+
service=ServiceConfiguration(
1402+
tls_config=TLSConfiguration(
1403+
tls_certificate_path=Path("tests/configuration/server.crt"),
1404+
tls_key_path=Path("tests/configuration/server.key"),
1405+
tls_key_password=Path("tests/configuration/password"),
1406+
),
1407+
cors=CORSConfiguration(
1408+
allow_origins=["foo_origin", "bar_origin", "baz_origin"],
1409+
allow_credentials=False,
1410+
allow_methods=["foo_method", "bar_method", "baz_method"],
1411+
allow_headers=["foo_header", "bar_header", "baz_header"],
1412+
),
1413+
),
1414+
llama_stack=LlamaStackConfiguration(
1415+
use_as_library_client=False,
1416+
url="http://localhost",
1417+
api_key=SecretStr("whatever"),
1418+
allow_degraded_mode=True,
1419+
),
1420+
user_data_collection=UserDataCollection(
1421+
feedback_enabled=False, feedback_storage=None
1422+
),
1423+
database=DatabaseConfiguration(
1424+
sqlite=None,
1425+
postgres=PostgreSQLDatabaseConfiguration(
1426+
db="lightspeed_stack",
1427+
user="ls_user",
1428+
password=SecretStr("ls_password"),
1429+
port=5432,
1430+
ca_cert_path=None,
1431+
ssl_mode="require",
1432+
gss_encmode="disable",
1433+
),
1434+
),
1435+
mcp_servers=[],
1436+
customization=None,
1437+
inference=InferenceConfiguration(
1438+
default_provider="default_provider",
1439+
default_model="default_model",
1440+
),
1441+
)
1442+
assert cfg is not None
1443+
dump_file = tmp_path / "test.json"
1444+
cfg.dump(dump_file)
1445+
1446+
with open(dump_file, "r", encoding="utf-8") as fin:
1447+
content = json.load(fin)
1448+
# content should be loaded
1449+
assert content is not None
1450+
1451+
# all sections must exists
1452+
assert "name" in content
1453+
assert "service" in content
1454+
assert "llama_stack" in content
1455+
assert "user_data_collection" in content
1456+
assert "mcp_servers" in content
1457+
assert "authentication" in content
1458+
assert "authorization" in content
1459+
assert "customization" in content
1460+
assert "inference" in content
1461+
assert "database" in content
1462+
assert "byok_rag" in content
1463+
assert "quota_handlers" in content
1464+
assert "azure_entra_id" in content
1465+
assert "reranker" in content
1466+
1467+
# check the whole deserialized JSON file content
1468+
assert content == {
1469+
"name": "test_name",
1470+
"service": {
1471+
"host": "localhost",
1472+
"port": 8080,
1473+
"base_url": None,
1474+
"auth_enabled": False,
1475+
"workers": 1,
1476+
"color_log": True,
1477+
"access_log": True,
1478+
"tls_config": {
1479+
"tls_certificate_path": "tests/configuration/server.crt",
1480+
"tls_key_password": "tests/configuration/password",
1481+
"tls_key_path": "tests/configuration/server.key",
1482+
},
1483+
"root_path": "",
1484+
"cors": {
1485+
"allow_credentials": False,
1486+
"allow_headers": [
1487+
"foo_header",
1488+
"bar_header",
1489+
"baz_header",
1490+
],
1491+
"allow_methods": [
1492+
"foo_method",
1493+
"bar_method",
1494+
"baz_method",
1495+
],
1496+
"allow_origins": [
1497+
"foo_origin",
1498+
"bar_origin",
1499+
"baz_origin",
1500+
],
1501+
},
1502+
},
1503+
"llama_stack": {
1504+
"url": "http://localhost/",
1505+
"use_as_library_client": False,
1506+
"api_key": "**********",
1507+
"library_client_config_path": None,
1508+
"timeout": 180,
1509+
"allow_degraded_mode": True,
1510+
},
1511+
"user_data_collection": {
1512+
"feedback_enabled": False,
1513+
"feedback_storage": None,
1514+
"transcripts_enabled": False,
1515+
"transcripts_storage": None,
1516+
},
1517+
"mcp_servers": [],
1518+
"authentication": {
1519+
"module": "noop",
1520+
"skip_tls_verification": False,
1521+
"skip_for_health_probes": False,
1522+
"skip_for_metrics": False,
1523+
"k8s_ca_cert_path": None,
1524+
"k8s_cluster_api": None,
1525+
"jwk_config": None,
1526+
"api_key_config": None,
1527+
"rh_identity_config": None,
1528+
},
1529+
"customization": None,
1530+
"inference": {
1531+
"default_provider": "default_provider",
1532+
"default_model": "default_model",
1533+
"context_windows": {},
1534+
},
1535+
"database": {
1536+
"sqlite": None,
1537+
"postgres": {
1538+
"host": "localhost",
1539+
"port": 5432,
1540+
"db": "lightspeed_stack",
1541+
"user": "ls_user",
1542+
"password": "**********",
1543+
"ssl_mode": "require",
1544+
"gss_encmode": "disable",
1545+
"namespace": "public",
1546+
"ca_cert_path": None,
1547+
},
1548+
},
1549+
"authorization": None,
1550+
"conversation_cache": {
1551+
"memory": None,
1552+
"postgres": None,
1553+
"sqlite": None,
1554+
"type": None,
1555+
},
1556+
"compaction": {
1557+
"enabled": False,
1558+
"threshold_ratio": 0.7,
1559+
"token_floor": 4096,
1560+
"buffer_turns": 4,
1561+
"buffer_max_ratio": 0.3,
1562+
},
1563+
"approvals": _DEFAULT_APPROVALS_DUMP,
1564+
"byok_rag": [],
1565+
"quota_handlers": {
1566+
"sqlite": None,
1567+
"postgres": None,
1568+
"limiters": [],
1569+
"scheduler": {
1570+
"period": 1,
1571+
"database_reconnection_count": 10,
1572+
"database_reconnection_delay": 1,
1573+
},
1574+
"enable_token_history": False,
1575+
},
1576+
"a2a_state": {
1577+
"sqlite": None,
1578+
"postgres": None,
1579+
},
1580+
"azure_entra_id": None,
1581+
"rag": {
1582+
"inline": [],
1583+
"tool": [],
1584+
},
1585+
"okp": {
1586+
"rhokp_url": None,
1587+
"offline": True,
1588+
"chunk_filter_query": None,
1589+
},
1590+
"rlsapi_v1": {
1591+
"allow_verbose_infer": False,
1592+
"quota_subject": None,
1593+
},
1594+
"splunk": None,
1595+
"deployment_environment": "development",
1596+
"reranker": {
1597+
"enabled": False,
1598+
"model": "cross-encoder/ms-marco-MiniLM-L6-v2",
1599+
},
1600+
"skills": None,
1601+
}

tests/unit/models/config/test_llama_stack_configuration.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,61 @@
22

33
import pytest
44
from pydantic import AnyHttpUrl, ValidationError
5+
from pytest_subtests import SubTests
56

67
from models.config import LlamaStackConfiguration
78
from utils.checks import InvalidConfigurationError
89

910

10-
def test_llama_stack_configuration_constructor() -> None:
11+
def test_llama_stack_configuration_constructor(subtests: SubTests) -> None:
1112
"""
1213
Verify that the LlamaStackConfiguration constructor accepts
1314
valid combinations of parameters and creates instances
1415
successfully.
1516
"""
16-
llama_stack_configuration = LlamaStackConfiguration(
17-
use_as_library_client=True,
18-
library_client_config_path="tests/configuration/run.yaml",
19-
url=None,
20-
api_key=None,
21-
timeout=60,
22-
)
23-
assert llama_stack_configuration is not None
24-
25-
llama_stack_configuration = LlamaStackConfiguration(
26-
use_as_library_client=False,
27-
url=AnyHttpUrl("http://localhost"),
28-
library_client_config_path=None,
29-
api_key=None,
30-
timeout=60,
31-
)
32-
assert llama_stack_configuration is not None
33-
34-
llama_stack_configuration = LlamaStackConfiguration(
35-
url="http://localhost"
36-
) # pyright: ignore[reportCallIssue]
37-
assert llama_stack_configuration is not None
17+
with subtests.test(msg="Configuration for library mode"):
18+
llama_stack_configuration = LlamaStackConfiguration(
19+
use_as_library_client=True,
20+
library_client_config_path="tests/configuration/run.yaml",
21+
url=None,
22+
api_key=None,
23+
timeout=60,
24+
)
25+
assert llama_stack_configuration is not None
26+
assert llama_stack_configuration.allow_degraded_mode is False
27+
28+
with subtests.test(msg="Configuration for server mode"):
29+
llama_stack_configuration = LlamaStackConfiguration(
30+
use_as_library_client=False,
31+
url=AnyHttpUrl("http://localhost"),
32+
library_client_config_path=None,
33+
api_key=None,
34+
timeout=60,
35+
)
36+
assert llama_stack_configuration is not None
37+
assert llama_stack_configuration.allow_degraded_mode is False
38+
39+
with subtests.test(msg="Minimal configuration for server mode"):
40+
llama_stack_configuration = LlamaStackConfiguration(
41+
url="http://localhost"
42+
) # pyright: ignore[reportCallIssue]
43+
assert llama_stack_configuration is not None
44+
assert llama_stack_configuration.allow_degraded_mode is False
3845

39-
llama_stack_configuration = LlamaStackConfiguration(
40-
use_as_library_client=False, url="http://localhost", api_key="foo"
41-
) # pyright: ignore[reportCallIssue]
42-
assert llama_stack_configuration is not None
46+
with subtests.test(msg="Full configuration for server mode"):
47+
llama_stack_configuration = LlamaStackConfiguration(
48+
use_as_library_client=False, url="http://localhost", api_key="foo"
49+
) # pyright: ignore[reportCallIssue]
50+
assert llama_stack_configuration is not None
51+
assert llama_stack_configuration.allow_degraded_mode is False
52+
53+
with subtests.test(msg="Degraded mode enabled"):
54+
llama_stack_configuration = LlamaStackConfiguration(
55+
url="http://localhost",
56+
allow_degraded_mode=True,
57+
) # pyright: ignore[reportCallIssue]
58+
assert llama_stack_configuration is not None
59+
assert llama_stack_configuration.allow_degraded_mode is True
4360

4461

4562
def test_llama_stack_configuration_no_run_yaml() -> None:

0 commit comments

Comments
 (0)