mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
[bug] add list support in setting attributes from env variables (#8295)
This commit is contained in:
parent
05f3840ca5
commit
3606ca87d5
@ -89,8 +89,10 @@ def load_from_env(
|
||||
# Attempt to cast the env var to type hinted in the dataclass
|
||||
if field_type is bool:
|
||||
cast_value = str(value).lower() in ['true', '1']
|
||||
# parse dicts like SANDBOX_RUNTIME_STARTUP_ENV_VARS
|
||||
elif get_origin(field_type) is dict:
|
||||
# parse dicts and lists like SANDBOX_RUNTIME_STARTUP_ENV_VARS and SANDBOX_RUNTIME_EXTRA_BUILD_ARGS │
|
||||
elif (
|
||||
get_origin(field_type) is dict or get_origin(field_type) is list
|
||||
):
|
||||
cast_value = literal_eval(value)
|
||||
else:
|
||||
if field_type is not None:
|
||||
|
||||
@ -344,6 +344,33 @@ user_id = 1001
|
||||
assert default_config.sandbox.user_id == 1001
|
||||
|
||||
|
||||
def test_load_from_env_with_list(monkeypatch, default_config):
|
||||
"""Test loading list values from environment variables, particularly SANDBOX_RUNTIME_EXTRA_BUILD_ARGS."""
|
||||
# Set the environment variable with a list-formatted string
|
||||
monkeypatch.setenv(
|
||||
'SANDBOX_RUNTIME_EXTRA_BUILD_ARGS',
|
||||
'['
|
||||
+ ' "--add-host=host.docker.internal:host-gateway",'
|
||||
+ ' "--build-arg=https_proxy=https://my-proxy:912",'
|
||||
+ ']',
|
||||
)
|
||||
|
||||
# Load configuration from environment
|
||||
load_from_env(default_config, os.environ)
|
||||
|
||||
# Verify that the list was correctly parsed
|
||||
assert isinstance(default_config.sandbox.runtime_extra_build_args, list)
|
||||
assert len(default_config.sandbox.runtime_extra_build_args) == 2
|
||||
assert (
|
||||
'--add-host=host.docker.internal:host-gateway'
|
||||
in default_config.sandbox.runtime_extra_build_args
|
||||
)
|
||||
assert (
|
||||
'--build-arg=https_proxy=https://my-proxy:912'
|
||||
in default_config.sandbox.runtime_extra_build_args
|
||||
)
|
||||
|
||||
|
||||
def test_security_config_from_toml(default_config, temp_toml_file):
|
||||
"""Test loading security specific configurations."""
|
||||
with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user