From 97c5c2aa05b41fdc04a243d046d39a74ce497b7f Mon Sep 17 00:00:00 2001 From: dadachann <185672915+dadachann@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:27:10 +0000 Subject: [PATCH] fix(config): preserve typed list environment overrides --- src/langbot/pkg/core/stages/load_config.py | 11 ++++++++--- tests/unit_tests/core/test_load_config.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/langbot/pkg/core/stages/load_config.py b/src/langbot/pkg/core/stages/load_config.py index a89cb0b48..49c439758 100644 --- a/src/langbot/pkg/core/stages/load_config.py +++ b/src/langbot/pkg/core/stages/load_config.py @@ -186,9 +186,14 @@ def _apply_env_overrides_to_config(cfg: dict) -> dict: # At the final key if key in current: if isinstance(current[key], list): - # Convert comma-separated string to list - # e.g., SYSTEM__DISABLED_ADAPTERS="aiocqhttp,dingtalk" - current[key] = [item.strip() for item in env_value.split(',') if item.strip()] + # Convert comma-separated values while preserving the + # element type declared by a non-empty config default. + 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): # Skip dict types pass diff --git a/tests/unit_tests/core/test_load_config.py b/tests/unit_tests/core/test_load_config.py index b95bc25ba..defbcee9d 100644 --- a/tests/unit_tests/core/test_load_config.py +++ b/tests/unit_tests/core/test_load_config.py @@ -152,6 +152,19 @@ class TestApplyEnvOverridesToConfig: 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): """Test that empty items in comma-separated list are filtered.""" load_config = get_load_config_module()