fix(config): reserve implicit default model preset

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Xubin Ren
2026-05-12 20:06:22 +08:00
committed by Xubin Ren
co-authored by Cursor
parent 1d14c2ba40
commit c9b84c7b11
4 changed files with 46 additions and 12 deletions
+2 -2
View File
@@ -284,7 +284,7 @@ def test_from_config_injects_default_preset(tmp_path) -> None:
assert loop.model_presets["default"].model == "openai/gpt-4.1"
def test_from_config_preserves_existing_default_preset(tmp_path) -> None:
def test_from_config_reserves_default_for_agent_defaults(tmp_path) -> None:
from unittest.mock import patch
from nanobot.config.schema import Config
@@ -297,4 +297,4 @@ def test_from_config_preserves_existing_default_preset(tmp_path) -> None:
fake_provider = _provider("openai/gpt-4.1")
with patch("nanobot.providers.factory.make_provider", return_value=fake_provider):
loop = AgentLoop.from_config(config)
assert loop.model_presets["default"].model == "custom-model"
assert loop.model_presets["default"].model == "openai/gpt-4.1"
+31
View File
@@ -39,6 +39,24 @@ def test_resolve_preset_returns_active_preset() -> None:
assert resolved.reasoning_effort == "low"
def test_default_preset_is_agents_defaults_even_when_named_preset_is_active() -> None:
config = Config.model_validate({
"agents": {
"defaults": {
"model": "openai/gpt-4.1",
"provider": "openai",
"modelPreset": "fast",
}
},
"modelPresets": {
"fast": {"model": "openai/gpt-4.1-mini", "provider": "openai"},
},
})
assert config.resolve_preset().model == "openai/gpt-4.1-mini"
assert config.resolve_preset("default").model == "openai/gpt-4.1"
def test_model_presets_accepts_camel_case_root_key() -> None:
config = Config.model_validate({
"modelPresets": {
@@ -79,6 +97,19 @@ def test_validator_rejects_unknown_preset() -> None:
})
def test_model_preset_accepts_explicit_default_name() -> None:
config = Config.model_validate({
"agents": {
"defaults": {
"model": "openai/gpt-4.1",
"modelPreset": "default",
}
}
})
assert config.resolve_preset().model == "openai/gpt-4.1"
def test_resolve_preset_rejects_unknown_named_preset() -> None:
import pytest
with pytest.raises(KeyError, match="model_preset 'missing' not found"):