Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions tests/unit/models/config/test_dump_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PostgreSQLDatabaseConfiguration,
CORSConfiguration,
Configuration,
ByokRag,
QuotaHandlersConfiguration,
QuotaLimiterConfiguration,
QuotaSchedulerConfiguration,
Expand Down Expand Up @@ -499,3 +500,181 @@ def test_dump_configuration_with_quota_limiters(tmp_path: Path) -> None:
"enable_token_history": True,
},
}


def test_dump_configuration_byok(tmp_path: Path) -> None:
"""
Test that the Configuration object can be serialized to a JSON file and
that the resulting file contains all expected sections and values.
"""
cfg = Configuration(
name="test_name",
service=ServiceConfiguration(
tls_config=TLSConfiguration(
tls_certificate_path=Path("tests/configuration/server.crt"),
tls_key_path=Path("tests/configuration/server.key"),
tls_key_password=Path("tests/configuration/password"),
),
cors=CORSConfiguration(
allow_origins=["foo_origin", "bar_origin", "baz_origin"],
allow_credentials=False,
allow_methods=["foo_method", "bar_method", "baz_method"],
allow_headers=["foo_header", "bar_header", "baz_header"],
),
),
llama_stack=LlamaStackConfiguration(
use_as_library_client=True,
library_client_config_path="tests/configuration/run.yaml",
api_key=SecretStr("whatever"),
),
user_data_collection=UserDataCollection(
feedback_enabled=False, feedback_storage=None
),
database=DatabaseConfiguration(
sqlite=None,
postgres=PostgreSQLDatabaseConfiguration(
db="lightspeed_stack",
user="ls_user",
password=SecretStr("ls_password"),
port=5432,
ca_cert_path=None,
ssl_mode="require",
gss_encmode="disable",
),
),
mcp_servers=[],
customization=None,
inference=InferenceConfiguration(
default_provider="default_provider",
default_model="default_model",
),
byok_rag=[
ByokRag(
rag_id="rag_id",
vector_db_id="vector_db_id",
db_path="tests/configuration/rag.txt",
),
],
)
assert cfg is not None
dump_file = tmp_path / "test.json"
cfg.dump(dump_file)

with open(dump_file, "r", encoding="utf-8") as fin:
content = json.load(fin)
# content should be loaded
assert content is not None

# all sections must exists
assert "name" in content
assert "service" in content
assert "llama_stack" in content
assert "user_data_collection" in content
assert "mcp_servers" in content
assert "authentication" in content
assert "authorization" in content
assert "customization" in content
assert "inference" in content
assert "database" in content
assert "byok_rag" in content
assert "quota_handlers" in content

# check the whole deserialized JSON file content
assert content == {
"name": "test_name",
"service": {
"host": "localhost",
"port": 8080,
"auth_enabled": False,
"workers": 1,
"color_log": True,
"access_log": True,
"tls_config": {
"tls_certificate_path": "tests/configuration/server.crt",
"tls_key_password": "tests/configuration/password",
"tls_key_path": "tests/configuration/server.key",
},
"cors": {
"allow_credentials": False,
"allow_headers": [
"foo_header",
"bar_header",
"baz_header",
],
"allow_methods": [
"foo_method",
"bar_method",
"baz_method",
],
"allow_origins": [
"foo_origin",
"bar_origin",
"baz_origin",
],
},
},
"llama_stack": {
"url": None,
"use_as_library_client": True,
"api_key": "**********",
"library_client_config_path": "tests/configuration/run.yaml",
},
"user_data_collection": {
"feedback_enabled": False,
"feedback_storage": None,
"transcripts_enabled": False,
"transcripts_storage": None,
},
"mcp_servers": [],
"authentication": {
"module": "noop",
"skip_tls_verification": False,
"k8s_ca_cert_path": None,
"k8s_cluster_api": None,
"jwk_config": None,
"rh_identity_config": None,
},
"customization": None,
"inference": {
"default_provider": "default_provider",
"default_model": "default_model",
},
"database": {
"sqlite": None,
"postgres": {
"host": "localhost",
"port": 5432,
"db": "lightspeed_stack",
"user": "ls_user",
"password": "**********",
"ssl_mode": "require",
"gss_encmode": "disable",
"namespace": "lightspeed-stack",
"ca_cert_path": None,
},
},
"authorization": None,
"conversation_cache": {
"memory": None,
"postgres": None,
"sqlite": None,
"type": None,
},
"byok_rag": [
{
"db_path": "tests/configuration/rag.txt",
"embedding_dimension": 768,
"embedding_model": "sentence-transformers/all-mpnet-base-v2",
"rag_id": "rag_id",
"rag_type": "inline::faiss",
"vector_db_id": "vector_db_id",
},
],
"quota_handlers": {
"sqlite": None,
"postgres": None,
"limiters": [],
"scheduler": {"period": 1},
"enable_token_history": False,
},
}
Loading