Skip to content

Commit 80257e0

Browse files
authored
Merge pull request #272 from tisnik/docs-models-config
LCORE-247: Docs models config
2 parents 528c27c + d26d47f commit 80257e0

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

src/models/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ class LlamaStackConfiguration(BaseModel):
6565

6666
@model_validator(mode="after")
6767
def check_llama_stack_model(self) -> Self:
68-
"""Check Llama stack configuration."""
68+
"""
69+
Validate the Llama stack configuration after model initialization.
70+
71+
Ensures that either a URL is provided for server mode or library client
72+
mode is explicitly enabled. If library client mode is enabled, verifies
73+
that a configuration file path is specified and points to an existing,
74+
readable file. Raises a ValueError if any required condition is not
75+
met.
76+
77+
Returns:
78+
Self: The validated LlamaStackConfiguration instance.
79+
"""
6980
if self.url is None:
7081
if self.use_as_library_client is None:
7182
raise ValueError(

tests/unit/models/test_config.py

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929

3030

3131
def test_service_configuration_constructor() -> None:
32-
"""Test the ServiceConfiguration constructor."""
32+
"""
33+
Verify that the ServiceConfiguration constructor sets default
34+
values for all fields.
35+
"""
3336
s = ServiceConfiguration()
3437
assert s is not None
3538

@@ -58,7 +61,11 @@ def test_service_configuration_workers_value() -> None:
5861

5962

6063
def test_llama_stack_configuration_constructor() -> None:
61-
"""Test the LLamaStackConfiguration constructor."""
64+
"""
65+
Verify that the LlamaStackConfiguration constructor accepts
66+
valid combinations of parameters and creates instances
67+
successfully.
68+
"""
6269
llama_stack_configuration = LlamaStackConfiguration(
6370
use_as_library_client=True,
6471
library_client_config_path="tests/configuration/run.yaml",
@@ -80,7 +87,11 @@ def test_llama_stack_configuration_constructor() -> None:
8087

8188

8289
def test_llama_stack_configuration_no_run_yaml() -> None:
83-
"""Test the LLamaStackConfiguration constructor when run.yaml file is not a file."""
90+
"""
91+
Verify that constructing a LlamaStackConfiguration with a
92+
non-existent or invalid library_client_config_path raises
93+
InvalidConfigurationError.
94+
"""
8495
with pytest.raises(
8596
InvalidConfigurationError,
8697
match="Llama Stack configuration file 'not a file' is not a file",
@@ -92,7 +103,11 @@ def test_llama_stack_configuration_no_run_yaml() -> None:
92103

93104

94105
def test_llama_stack_wrong_configuration_constructor_no_url() -> None:
95-
"""Test the LLamaStackConfiguration constructor."""
106+
"""
107+
Verify that constructing a LlamaStackConfiguration without
108+
specifying either a URL or enabling library client mode raises
109+
a ValueError.
110+
"""
96111
with pytest.raises(
97112
ValueError,
98113
match="LLama stack URL is not specified and library client mode is not specified",
@@ -308,7 +323,13 @@ def test_model_context_protocol_server_required_fields() -> None:
308323

309324

310325
def test_configuration_empty_mcp_servers() -> None:
311-
"""Test Configuration with empty MCP servers list."""
326+
"""
327+
Test that a Configuration object can be created with an empty
328+
list of MCP servers.
329+
330+
Verifies that the Configuration instance is constructed
331+
successfully and that the mcp_servers attribute is empty.
332+
"""
312333
cfg = Configuration(
313334
name="test_name",
314335
service=ServiceConfiguration(),
@@ -327,7 +348,10 @@ def test_configuration_empty_mcp_servers() -> None:
327348

328349

329350
def test_configuration_single_mcp_server() -> None:
330-
"""Test Configuration with a single MCP server."""
351+
"""
352+
Test that a Configuration object can be created with a single
353+
MCP server and verifies its properties.
354+
"""
331355
mcp_server = ModelContextProtocolServer(
332356
name="test-server", url="http://localhost:8080"
333357
)
@@ -351,7 +375,11 @@ def test_configuration_single_mcp_server() -> None:
351375

352376

353377
def test_configuration_multiple_mcp_servers() -> None:
354-
"""Test Configuration with multiple MCP servers."""
378+
"""
379+
Verify that the Configuration object correctly handles multiple
380+
ModelContextProtocolServer instances in its mcp_servers list,
381+
including custom provider IDs.
382+
"""
355383
mcp_servers = [
356384
ModelContextProtocolServer(name="server1", url="http://localhost:8080"),
357385
ModelContextProtocolServer(
@@ -381,7 +409,11 @@ def test_configuration_multiple_mcp_servers() -> None:
381409

382410

383411
def test_dump_configuration(tmp_path) -> None:
384-
"""Test the ability to dump configuration."""
412+
"""
413+
Test that the Configuration object can be serialized to a JSON
414+
file and that the resulting file contains all expected sections
415+
and values.
416+
"""
385417
cfg = Configuration(
386418
name="test_name",
387419
service=ServiceConfiguration(),
@@ -461,7 +493,14 @@ def test_dump_configuration(tmp_path) -> None:
461493

462494

463495
def test_dump_configuration_with_one_mcp_server(tmp_path) -> None:
464-
"""Test the ability to dump configuration with one MCP server configured."""
496+
"""
497+
Verify that a configuration with a single MCP server can be
498+
serialized to JSON and that all expected fields and values are
499+
present in the output.
500+
501+
Parameters:
502+
tmp_path: Temporary directory path provided by pytest for file output.
503+
"""
465504
mcp_servers = [
466505
ModelContextProtocolServer(name="test-server", url="http://localhost:8080"),
467506
]
@@ -545,7 +584,15 @@ def test_dump_configuration_with_one_mcp_server(tmp_path) -> None:
545584

546585

547586
def test_dump_configuration_with_more_mcp_servers(tmp_path) -> None:
548-
"""Test the ability to dump configuration with more MCP servers configured."""
587+
"""
588+
Test that a configuration with multiple MCP servers can be
589+
serialized to JSON and that all server entries are correctly
590+
included in the output.
591+
592+
Verifies that the dumped configuration file contains all
593+
expected fields and that each MCP server is present with the
594+
correct name, URL, and provider ID.
595+
"""
549596
mcp_servers = [
550597
ModelContextProtocolServer(name="test-server-1", url="http://localhost:8081"),
551598
ModelContextProtocolServer(name="test-server-2", url="http://localhost:8082"),

tests/unit/utils/test_common.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,15 @@ async def test_register_mcp_servers_with_custom_provider(mocker):
244244

245245
@pytest.mark.asyncio
246246
async def test_register_mcp_servers_async_with_library_client(mocker):
247-
"""Test register_mcp_servers_async with library client configuration."""
247+
"""
248+
Test that `register_mcp_servers_async` correctly registers MCP
249+
servers when using the library client configuration.
250+
251+
This test verifies that the function initializes the async
252+
client, checks for existing toolgroups, and registers new MCP
253+
servers as needed when the configuration specifies the use of a
254+
library client.
255+
"""
248256
# Mock the logger
249257
mock_logger = Mock(spec=Logger)
250258

0 commit comments

Comments
 (0)