Skip to content

Commit c5eecbb

Browse files
authored
Merge pull request #1866 from tisnik/lcore-2504-added-missing-unit-test
LCORE-2504: Added missing unit test
2 parents 5e90d3f + 83cb012 commit c5eecbb

1 file changed

Lines changed: 226 additions & 0 deletions

File tree

tests/unit/models/config/test_dump_configuration.py

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import constants
1313
from models.config import (
1414
ByokRag,
15+
CompactionConfiguration,
1516
Configuration,
1617
CORSConfiguration,
1718
DatabaseConfiguration,
@@ -2303,3 +2304,228 @@ def test_dump_configuration_retry_count_settings(tmp_path: Path) -> None:
23032304
},
23042305
"skills": None,
23052306
}
2307+
2308+
2309+
def test_dump_configuration_specific_compaction_values(tmp_path: Path) -> None:
2310+
"""
2311+
Test that the Configuration object can be serialized to a JSON file and
2312+
that the resulting file contains all expected sections and values.
2313+
2314+
Please note that redaction process is not in place.
2315+
2316+
Parameters:
2317+
----------
2318+
tmp_path (Path): Directory where the test JSON file will be written.
2319+
"""
2320+
cfg = Configuration(
2321+
name="test_name",
2322+
service=ServiceConfiguration(
2323+
tls_config=TLSConfiguration(
2324+
tls_certificate_path=Path("tests/configuration/server.crt"),
2325+
tls_key_path=Path("tests/configuration/server.key"),
2326+
tls_key_password=Path("tests/configuration/password"),
2327+
),
2328+
cors=CORSConfiguration(
2329+
allow_origins=["foo_origin", "bar_origin", "baz_origin"],
2330+
allow_credentials=False,
2331+
allow_methods=["foo_method", "bar_method", "baz_method"],
2332+
allow_headers=["foo_header", "bar_header", "baz_header"],
2333+
),
2334+
),
2335+
llama_stack=LlamaStackConfiguration(
2336+
use_as_library_client=True,
2337+
library_client_config_path="tests/configuration/run.yaml",
2338+
api_key=SecretStr("whatever"),
2339+
),
2340+
user_data_collection=UserDataCollection(
2341+
feedback_enabled=False, feedback_storage=None
2342+
),
2343+
database=DatabaseConfiguration(
2344+
sqlite=None,
2345+
postgres=PostgreSQLDatabaseConfiguration(
2346+
db="lightspeed_stack",
2347+
user="ls_user",
2348+
password=SecretStr("ls_password"),
2349+
port=5432,
2350+
ca_cert_path=None,
2351+
ssl_mode="require",
2352+
gss_encmode="disable",
2353+
),
2354+
),
2355+
mcp_servers=[],
2356+
customization=None,
2357+
inference=InferenceConfiguration(
2358+
default_provider="default_provider",
2359+
default_model="default_model",
2360+
),
2361+
compaction=CompactionConfiguration(
2362+
enabled=True,
2363+
threshold_ratio=0.5,
2364+
token_floor=1024,
2365+
buffer_turns=8,
2366+
buffer_max_ratio=0.5,
2367+
),
2368+
)
2369+
assert cfg is not None
2370+
dump_file = tmp_path / "test.json"
2371+
cfg.dump(dump_file)
2372+
2373+
with open(dump_file, "r", encoding="utf-8") as fin:
2374+
content = json.load(fin)
2375+
# content should be loaded
2376+
assert content is not None
2377+
2378+
# all sections must exists
2379+
assert "name" in content
2380+
assert "service" in content
2381+
assert "llama_stack" in content
2382+
assert "user_data_collection" in content
2383+
assert "mcp_servers" in content
2384+
assert "authentication" in content
2385+
assert "authorization" in content
2386+
assert "customization" in content
2387+
assert "inference" in content
2388+
assert "database" in content
2389+
assert "byok_rag" in content
2390+
assert "quota_handlers" in content
2391+
assert "azure_entra_id" in content
2392+
assert "reranker" in content
2393+
assert "compaction" in content
2394+
2395+
# check the whole deserialized JSON file content
2396+
assert content == {
2397+
"name": "test_name",
2398+
"service": {
2399+
"host": "localhost",
2400+
"port": 8080,
2401+
"base_url": None,
2402+
"auth_enabled": False,
2403+
"workers": 1,
2404+
"color_log": True,
2405+
"access_log": True,
2406+
"tls_config": {
2407+
"tls_certificate_path": "tests/configuration/server.crt",
2408+
"tls_key_password": "tests/configuration/password",
2409+
"tls_key_path": "tests/configuration/server.key",
2410+
},
2411+
"root_path": "",
2412+
"cors": {
2413+
"allow_credentials": False,
2414+
"allow_headers": [
2415+
"foo_header",
2416+
"bar_header",
2417+
"baz_header",
2418+
],
2419+
"allow_methods": [
2420+
"foo_method",
2421+
"bar_method",
2422+
"baz_method",
2423+
],
2424+
"allow_origins": [
2425+
"foo_origin",
2426+
"bar_origin",
2427+
"baz_origin",
2428+
],
2429+
},
2430+
},
2431+
"llama_stack": {
2432+
"url": None,
2433+
"use_as_library_client": True,
2434+
"api_key": "**********",
2435+
"library_client_config_path": "tests/configuration/run.yaml",
2436+
"timeout": 180,
2437+
"allow_degraded_mode": False,
2438+
"max_retries": constants.DEFAULT_MAX_RETRIES,
2439+
"retry_delay": constants.DEFAULT_RETRY_DELAY,
2440+
},
2441+
"user_data_collection": {
2442+
"feedback_enabled": False,
2443+
"feedback_storage": None,
2444+
"transcripts_enabled": False,
2445+
"transcripts_storage": None,
2446+
},
2447+
"mcp_servers": [],
2448+
"authentication": {
2449+
"module": "noop",
2450+
"skip_tls_verification": False,
2451+
"skip_for_health_probes": False,
2452+
"skip_for_metrics": False,
2453+
"k8s_ca_cert_path": None,
2454+
"k8s_cluster_api": None,
2455+
"jwk_config": None,
2456+
"api_key_config": None,
2457+
"rh_identity_config": None,
2458+
},
2459+
"customization": None,
2460+
"inference": {
2461+
"default_provider": "default_provider",
2462+
"default_model": "default_model",
2463+
"context_windows": {},
2464+
},
2465+
"database": {
2466+
"sqlite": None,
2467+
"postgres": {
2468+
"host": "localhost",
2469+
"port": 5432,
2470+
"db": "lightspeed_stack",
2471+
"user": "ls_user",
2472+
"password": "**********",
2473+
"ssl_mode": "require",
2474+
"gss_encmode": "disable",
2475+
"namespace": "public",
2476+
"ca_cert_path": None,
2477+
},
2478+
},
2479+
"authorization": None,
2480+
"conversation_cache": {
2481+
"memory": None,
2482+
"postgres": None,
2483+
"sqlite": None,
2484+
"type": None,
2485+
},
2486+
"compaction": {
2487+
"enabled": True,
2488+
"threshold_ratio": 0.5,
2489+
"token_floor": 1024,
2490+
"buffer_turns": 8,
2491+
"buffer_max_ratio": 0.5,
2492+
},
2493+
"approvals": _DEFAULT_APPROVALS_DUMP,
2494+
"byok_rag": [],
2495+
"quota_handlers": {
2496+
"sqlite": None,
2497+
"postgres": None,
2498+
"limiters": [],
2499+
"scheduler": {
2500+
"period": 1,
2501+
"database_reconnection_count": 10,
2502+
"database_reconnection_delay": 1,
2503+
},
2504+
"enable_token_history": False,
2505+
},
2506+
"a2a_state": {
2507+
"sqlite": None,
2508+
"postgres": None,
2509+
},
2510+
"azure_entra_id": None,
2511+
"rag": {
2512+
"inline": [],
2513+
"tool": [],
2514+
},
2515+
"okp": {
2516+
"rhokp_url": None,
2517+
"offline": True,
2518+
"chunk_filter_query": None,
2519+
},
2520+
"rlsapi_v1": {
2521+
"allow_verbose_infer": False,
2522+
"quota_subject": None,
2523+
},
2524+
"splunk": None,
2525+
"deployment_environment": "development",
2526+
"reranker": {
2527+
"enabled": False,
2528+
"model": "cross-encoder/ms-marco-MiniLM-L6-v2",
2529+
},
2530+
"skills": None,
2531+
}

0 commit comments

Comments
 (0)