|
from unittest.mock import patch
|
|
|
|
from pydantic import SecretStr
|
|
|
|
from openhands.core.config.app_config import AppConfig
|
|
from openhands.core.config.llm_config import LLMConfig
|
|
from openhands.core.config.sandbox_config import SandboxConfig
|
|
from openhands.core.config.security_config import SecurityConfig
|
|
from openhands.server.settings import Settings
|
|
|
|
|
|
def test_settings_from_config():
|
|
|
|
mock_app_config = AppConfig(
|
|
default_agent='test-agent',
|
|
max_iterations=100,
|
|
security=SecurityConfig(
|
|
security_analyzer='test-analyzer', confirmation_mode=True
|
|
),
|
|
llms={
|
|
'llm': LLMConfig(
|
|
model='test-model',
|
|
api_key=SecretStr('test-key'),
|
|
base_url='https://test.example.com',
|
|
)
|
|
},
|
|
sandbox=SandboxConfig(remote_runtime_resource_factor=2),
|
|
)
|
|
|
|
with patch(
|
|
'openhands.server.settings.load_app_config', return_value=mock_app_config
|
|
):
|
|
settings = Settings.from_config()
|
|
|
|
assert settings is not None
|
|
assert settings.language == 'en'
|
|
assert settings.agent == 'test-agent'
|
|
assert settings.max_iterations == 100
|
|
assert settings.security_analyzer == 'test-analyzer'
|
|
assert settings.confirmation_mode is True
|
|
assert settings.llm_model == 'test-model'
|
|
assert settings.llm_api_key.get_secret_value() == 'test-key'
|
|
assert settings.llm_base_url == 'https://test.example.com'
|
|
assert settings.remote_runtime_resource_factor == 2
|
|
|
|
|
|
def test_settings_from_config_no_api_key():
|
|
|
|
mock_app_config = AppConfig(
|
|
default_agent='test-agent',
|
|
max_iterations=100,
|
|
security=SecurityConfig(
|
|
security_analyzer='test-analyzer', confirmation_mode=True
|
|
),
|
|
llms={
|
|
'llm': LLMConfig(
|
|
model='test-model', api_key=None, base_url='https://test.example.com'
|
|
)
|
|
},
|
|
sandbox=SandboxConfig(remote_runtime_resource_factor=2),
|
|
)
|
|
|
|
with patch(
|
|
'openhands.server.settings.load_app_config', return_value=mock_app_config
|
|
):
|
|
settings = Settings.from_config()
|
|
assert settings is None
|
|
|