mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-09 12:40:59 +00:00
fix(config): preserve typed list environment overrides
This commit is contained in:
@@ -186,9 +186,14 @@ def _apply_env_overrides_to_config(cfg: dict) -> dict:
|
|||||||
# At the final key
|
# At the final key
|
||||||
if key in current:
|
if key in current:
|
||||||
if isinstance(current[key], list):
|
if isinstance(current[key], list):
|
||||||
# Convert comma-separated string to list
|
# Convert comma-separated values while preserving the
|
||||||
# e.g., SYSTEM__DISABLED_ADAPTERS="aiocqhttp,dingtalk"
|
# element type declared by a non-empty config default.
|
||||||
current[key] = [item.strip() for item in env_value.split(',') if item.strip()]
|
items = [item.strip() for item in env_value.split(',') if item.strip()]
|
||||||
|
if current[key]:
|
||||||
|
exemplar = current[key][0]
|
||||||
|
current[key] = [convert_value(item, exemplar) for item in items]
|
||||||
|
else:
|
||||||
|
current[key] = items
|
||||||
elif isinstance(current[key], dict):
|
elif isinstance(current[key], dict):
|
||||||
# Skip dict types
|
# Skip dict types
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -152,6 +152,19 @@ class TestApplyEnvOverridesToConfig:
|
|||||||
|
|
||||||
assert result['system']['disabled_adapters'] == ['aiocqhttp', 'dingtalk', 'telegram']
|
assert result['system']['disabled_adapters'] == ['aiocqhttp', 'dingtalk', 'telegram']
|
||||||
|
|
||||||
|
def test_override_integer_list_preserves_item_type(self):
|
||||||
|
"""Comma-separated overrides inherit the existing list item type."""
|
||||||
|
load_config = get_load_config_module()
|
||||||
|
|
||||||
|
cfg = {'vdb': {'pgvector': {'allowed_dimensions': [384, 512]}}}
|
||||||
|
env = {'VDB__PGVECTOR__ALLOWED_DIMENSIONS': '384,512,768'}
|
||||||
|
|
||||||
|
with patch.dict(os.environ, env, clear=True):
|
||||||
|
result = load_config._apply_env_overrides_to_config(cfg)
|
||||||
|
|
||||||
|
assert result['vdb']['pgvector']['allowed_dimensions'] == [384, 512, 768]
|
||||||
|
assert all(isinstance(item, int) for item in result['vdb']['pgvector']['allowed_dimensions'])
|
||||||
|
|
||||||
def test_override_list_value_empty_items(self):
|
def test_override_list_value_empty_items(self):
|
||||||
"""Test that empty items in comma-separated list are filtered."""
|
"""Test that empty items in comma-separated list are filtered."""
|
||||||
load_config = get_load_config_module()
|
load_config = get_load_config_module()
|
||||||
|
|||||||
Reference in New Issue
Block a user