mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-31 16:21:50 +03:00
fix(settings): serialize gateway configuration updates
This commit is contained in:
@@ -3,6 +3,8 @@ from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.config.loader import load_config, save_config
|
||||
from nanobot.config.schema import Config
|
||||
from nanobot.webui.skills_api import (
|
||||
SkillManagementError,
|
||||
delete_webui_skill,
|
||||
@@ -79,8 +81,11 @@ def test_set_webui_skill_enabled_persists_and_updates_runtime(
|
||||
_write_skill(tmp_path, "custom-skill")
|
||||
config = _config()
|
||||
saved: list[object] = []
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.load_config", lambda: config)
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.save_config", saved.append)
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.load_config", lambda _path=None: config)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.webui.skills_api.save_config",
|
||||
lambda value, _path=None: saved.append(value),
|
||||
)
|
||||
disabled: set[str] = set()
|
||||
|
||||
action = set_webui_skill_enabled(
|
||||
@@ -100,6 +105,30 @@ def test_set_webui_skill_enabled_persists_and_updates_runtime(
|
||||
assert saved == [config]
|
||||
|
||||
|
||||
def test_skill_state_uses_explicit_gateway_config(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
workspace = tmp_path / "workspace"
|
||||
_write_skill(workspace, "custom-skill")
|
||||
default_path = tmp_path / "default.json"
|
||||
gateway_path = tmp_path / "gateway.json"
|
||||
save_config(Config(), default_path)
|
||||
save_config(Config(), gateway_path)
|
||||
monkeypatch.setattr("nanobot.config.loader._current_config_path", default_path)
|
||||
|
||||
set_webui_skill_enabled(
|
||||
workspace,
|
||||
"custom-skill",
|
||||
enabled=False,
|
||||
disabled_skills=set(),
|
||||
config_path=gateway_path,
|
||||
)
|
||||
|
||||
assert load_config(default_path).agents.defaults.disabled_skills == []
|
||||
assert load_config(gateway_path).agents.defaults.disabled_skills == ["custom-skill"]
|
||||
|
||||
|
||||
def test_delete_webui_skill_only_deletes_workspace_skills(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
@@ -107,8 +136,11 @@ def test_delete_webui_skill_only_deletes_workspace_skills(
|
||||
directory = _write_skill(tmp_path, "custom-skill")
|
||||
config = _config("custom-skill")
|
||||
saved: list[object] = []
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.load_config", lambda: config)
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.save_config", saved.append)
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.load_config", lambda _path=None: config)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.webui.skills_api.save_config",
|
||||
lambda value, _path=None: saved.append(value),
|
||||
)
|
||||
disabled = {"custom-skill"}
|
||||
|
||||
action = delete_webui_skill(
|
||||
@@ -158,9 +190,9 @@ def test_delete_webui_skill_restores_directory_when_config_save_fails(
|
||||
) -> None:
|
||||
directory = _write_skill(tmp_path, "custom-skill")
|
||||
config = _config("custom-skill")
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.load_config", lambda: config)
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.load_config", lambda _path=None: config)
|
||||
|
||||
def fail_save(_config: object) -> None:
|
||||
def fail_save(_config: object, _path: Path | None = None) -> None:
|
||||
raise OSError("disk full")
|
||||
|
||||
monkeypatch.setattr("nanobot.webui.skills_api.save_config", fail_save)
|
||||
|
||||
Reference in New Issue
Block a user