Skip to content

Commit 2109790

Browse files
authored
Merge pull request #2076 from max-svistunov/lcore-2339-legacy-two-file-config-deprecation-warn
LCORE-2339: warn at startup when legacy two-file config is used
2 parents ae6ecf3 + 6f6516e commit 2109790

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

src/lightspeed_stack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ def main() -> None:
159159
"Llama stack configuration: %s", configuration.llama_stack_configuration
160160
)
161161

162+
# Deprecation schedule (Decision S2): the legacy two-file path keeps
163+
# working through 0.6 with this single startup WARN and is removed in 0.7.
164+
if configuration.llama_stack_configuration.library_client_config_path is not None:
165+
logger.warning(
166+
"DEPRECATED: the two-file configuration "
167+
"(llama_stack.library_client_config_path + external run.yaml) is "
168+
"deprecated and will be removed in release 0.7. Migrate to the "
169+
"unified lightspeed-stack.yaml: https://lightspeed-core.github.io"
170+
"/lightspeed-stack/design/llama-stack-config-merge"
171+
"/llama-stack-config-merge.html#migration--backwards-compatibility"
172+
)
173+
162174
# -d or --dump-configuration CLI flags are used to dump the actual configuration
163175
# to a JSON file w/o doing any other operation
164176
if args.dump_configuration:

tests/unit/test_lightspeed_stack.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
"""Unit tests for functions defined in src/lightspeed_stack.py."""
22

3+
import logging
34
from pathlib import Path
45

56
import pytest
67
import yaml
78

9+
import lightspeed_stack
10+
from configuration import AppConfig
811
from lightspeed_stack import create_argument_parser, main
912

13+
LEGACY_DEPRECATION_MARKER = "DEPRECATED: the two-file configuration"
14+
15+
COMMON_CONFIG_SECTIONS = """
16+
name: test
17+
service:
18+
host: localhost
19+
port: 8080
20+
auth_enabled: false
21+
workers: 1
22+
color_log: true
23+
access_log: true
24+
user_data_collection:
25+
feedback_enabled: false
26+
mcp_servers: []
27+
"""
28+
1029

1130
def test_create_argument_parser() -> None:
1231
"""Test for create_argument_parser function.
@@ -97,3 +116,82 @@ def test_main_migrate_config_requires_run_yaml_and_output(
97116
)
98117
with pytest.raises(SystemExit):
99118
main()
119+
120+
121+
def run_main_with_config(
122+
config_yaml: str,
123+
tmp_path: Path,
124+
monkeypatch: pytest.MonkeyPatch,
125+
) -> None:
126+
"""Run main() against a config file, with the runners stubbed out.
127+
128+
Writes ``config_yaml`` to a temporary file, points argv at it, replaces
129+
the module-level configuration singleton with a fresh AppConfig (so the
130+
shared singleton is not mutated for other tests), and stubs the quota
131+
scheduler and uvicorn runners.
132+
"""
133+
cfg_file = tmp_path / "lightspeed-stack.yaml"
134+
cfg_file.write_text(config_yaml, encoding="utf-8")
135+
monkeypatch.setattr("sys.argv", ["lightspeed-stack", "-c", str(cfg_file)])
136+
monkeypatch.setattr(lightspeed_stack, "configuration", AppConfig())
137+
monkeypatch.setattr(lightspeed_stack, "start_quota_scheduler", lambda _: None)
138+
monkeypatch.setattr(lightspeed_stack, "start_uvicorn", lambda _: None)
139+
main()
140+
141+
142+
def test_main_warns_on_legacy_two_file_config(
143+
tmp_path: Path,
144+
monkeypatch: pytest.MonkeyPatch,
145+
caplog: pytest.LogCaptureFixture,
146+
) -> None:
147+
"""A legacy library_client_config_path config emits one deprecation WARN."""
148+
run_yaml = tmp_path / "run.yaml"
149+
run_yaml.write_text("version: 2\n", encoding="utf-8")
150+
config_yaml = COMMON_CONFIG_SECTIONS + f"""
151+
llama_stack:
152+
use_as_library_client: true
153+
library_client_config_path: {run_yaml}
154+
"""
155+
with caplog.at_level(logging.WARNING):
156+
run_main_with_config(config_yaml, tmp_path, monkeypatch)
157+
warnings = [
158+
r for r in caplog.records if LEGACY_DEPRECATION_MARKER in r.getMessage()
159+
]
160+
assert len(warnings) == 1
161+
assert warnings[0].levelno == logging.WARNING
162+
# the WARN carries a stable link to the migration doc
163+
assert "#migration--backwards-compatibility" in warnings[0].getMessage()
164+
165+
166+
def test_main_does_not_warn_in_unified_mode(
167+
tmp_path: Path,
168+
monkeypatch: pytest.MonkeyPatch,
169+
caplog: pytest.LogCaptureFixture,
170+
) -> None:
171+
"""A unified-mode config (llama_stack.config) emits no deprecation WARN."""
172+
config_yaml = COMMON_CONFIG_SECTIONS + """
173+
llama_stack:
174+
use_as_library_client: true
175+
config:
176+
baseline: default
177+
"""
178+
with caplog.at_level(logging.WARNING):
179+
run_main_with_config(config_yaml, tmp_path, monkeypatch)
180+
assert not any(LEGACY_DEPRECATION_MARKER in r.getMessage() for r in caplog.records)
181+
182+
183+
def test_main_does_not_warn_in_server_mode(
184+
tmp_path: Path,
185+
monkeypatch: pytest.MonkeyPatch,
186+
caplog: pytest.LogCaptureFixture,
187+
) -> None:
188+
"""A server-mode config (url, no legacy fields) emits no deprecation WARN."""
189+
config_yaml = COMMON_CONFIG_SECTIONS + """
190+
llama_stack:
191+
use_as_library_client: false
192+
url: http://localhost:8321
193+
api_key: xyzzy
194+
"""
195+
with caplog.at_level(logging.WARNING):
196+
run_main_with_config(config_yaml, tmp_path, monkeypatch)
197+
assert not any(LEGACY_DEPRECATION_MARKER in r.getMessage() for r in caplog.records)

0 commit comments

Comments
 (0)