This commit is contained in:
hylin 2026-09-02 15:20:53 -04:00 committed by GitHub
commit 7ef87c55fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View file

@ -1151,6 +1151,12 @@ def run_server(
general_settings = _config.get("general_settings", {})
if general_settings is None:
general_settings = {}
elif not isinstance(general_settings, dict):
raise ValueError(
"`general_settings` in the proxy config must be a mapping "
f"(got {type(general_settings).__name__}). Check the "
"`general_settings:` block in your config file."
)
### LOAD KEY MANAGEMENT SETTINGS FIRST (needed for custom secret manager) ###
key_management_settings: Final = general_settings.get("key_management_settings", None)
if key_management_settings is not None:

View file

@ -2622,3 +2622,31 @@ class TestTokenAuthCliFlags:
assert result.exit_code == 0, f"exit_code={result.exit_code}, output={result.output}"
assert "ENTRA_TOKEN" not in (database_url or "")
assert toggle is None
@pytest.mark.xdist_group("proxy_cli")
class TestGeneralSettingsShape:
"""`general_settings` is read straight from user YAML. A non-mapping value
(a bare string when the block is malformed, or `null` from an empty block)
used to reach `general_settings.get(...)` and blow up at startup with an
opaque `AttributeError: 'str' object has no attribute 'get'`. Startup must
either tolerate it (None -> {}) or fail with a message pointing at the config.
"""
def test_null_general_settings_is_tolerated(self, tmp_path):
"""An empty `general_settings:` block parses as None and must not crash."""
config_path = tmp_path / "config.yaml"
config_path.write_text(yaml.dump({"model_list": [], "general_settings": None}))
captured = _run_server_and_capture_urls(str(config_path))
assert captured["DATABASE_URL"].startswith("postgresql://t:t@localhost:5432/t")
def test_string_general_settings_fails_with_actionable_error(self, tmp_path):
"""A non-mapping value must fail fast, not as a cryptic AttributeError."""
config_path = tmp_path / "config.yaml"
config_path.write_text(
yaml.dump({"model_list": [], "general_settings": "database_url"})
)
with pytest.raises(ValueError, match=r"general_settings.*must be a mapping"):
_run_server_and_capture_urls(str(config_path))