Break tool config schema import cycle

This commit is contained in:
chengyongru
2026-06-13 21:59:07 +08:00
committed by Xubin Ren
parent 7ff8e02eaf
commit 3a221d74cf
9 changed files with 62 additions and 59 deletions
@@ -0,0 +1,38 @@
import ast
import subprocess
import sys
from pathlib import Path
def test_config_base_import_does_not_load_config_schema():
code = """
import sys
from nanobot.config_base import Base
print("nanobot.config.schema" in sys.modules)
"""
result = subprocess.run(
[sys.executable, "-c", code],
check=True,
capture_output=True,
text=True,
)
assert result.stdout.strip() == "False"
def test_builtin_tool_configs_do_not_depend_on_config_schema_base():
repo = Path(__file__).resolve().parents[2]
tool_paths = sorted((repo / "nanobot/agent/tools").glob("*.py"))
violations = []
for path in tool_paths:
tree = ast.parse(path.read_text(encoding="utf-8"))
for node in ast.walk(tree):
if not isinstance(node, ast.ImportFrom):
continue
if node.module != "nanobot.config.schema":
continue
if any(alias.name == "Base" for alias in node.names):
violations.append(str(path.relative_to(repo)))
assert violations == []
-44
View File
@@ -352,50 +352,6 @@ def test_mcp_wrappers_not_discoverable():
assert MCPPromptWrapper._plugin_discoverable is False
# --- Task 8: Config round-trip tests ---
def test_config_round_trip():
"""Verify config serialization is unchanged after moving config classes."""
from nanobot.config.schema import Config
config_dict = {
"tools": {
"web": {"enable": True, "search": {"provider": "brave", "api_key": "test"}},
"exec": {"enable": False, "timeout": 120, "pathPrepend": "/venv/bin"},
"my": {"allowSet": True},
"imageGeneration": {"enabled": True, "provider": "openrouter"},
}
}
config = Config.model_validate(config_dict)
dumped = config.model_dump(mode="json", by_alias=True)
assert dumped["tools"]["my"]["allowSet"] is True
assert dumped["tools"]["imageGeneration"]["enabled"] is True
assert dumped["tools"]["exec"]["pathPrepend"] == "/venv/bin"
assert config.tools.exec.enable is False
assert config.tools.exec.timeout == 120
assert config.tools.exec.path_prepend == "/venv/bin"
assert config.tools.web.search.provider == "brave"
def test_config_defaults():
"""Verify default values match the original hardcoded schema."""
from nanobot.config.schema import Config
config = Config.model_validate({})
assert config.tools.exec.enable is True
assert config.tools.exec.timeout == 60
assert config.tools.exec.path_prepend == ""
assert config.tools.web.enable is True
assert config.tools.web.search.provider == "duckduckgo"
assert config.tools.my.enable is True
assert config.tools.my.allow_set is False
assert config.tools.image_generation.enabled is False
assert config.tools.cli_apps.enable is True
assert config.tools.restrict_to_workspace is False
# --- Task 10: Integration test ---