- xiaohe:默认转发 default_agent(settings.json default_agent,兼容 myclaude 拼写), 子命令 init(首用引导 workspace 路径+骨架+sync+启动器)/ sync(runtime→workspace 哈希三态同步:新增/覆盖/本地改动跳过;git 检出拒绝) - settings.py:~/.xiaohe/agent/settings.json 优先,config.json settings 段兜底 - get_workspace_root:env > settings > project_root/workspace > ~/workspace - build_cli 增 offer_install:缺二进制时交互提示安装(claude/codex 有 install_cmd) - 测试 +11(settings/sync 引擎三态/幂等/git 拒绝)
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
"""Tests for myagents.settings."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from myagents import settings as settings_mod
|
|
|
|
|
|
@pytest.fixture()
|
|
def fake_config_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
config_dir = tmp_path / ".xiaohe" / "agent"
|
|
monkeypatch.setattr(settings_mod, "CONFIG_DIR", config_dir)
|
|
monkeypatch.setattr(settings_mod, "SETTINGS_PATH", config_dir / "settings.json")
|
|
monkeypatch.setattr(
|
|
settings_mod, "LEGACY_CONFIG_PATH", config_dir / "config.json"
|
|
)
|
|
return config_dir
|
|
|
|
|
|
class TestLoadSettings:
|
|
def test_empty_when_no_files(self, fake_config_dir: Path) -> None:
|
|
assert settings_mod.load_settings() == {}
|
|
|
|
def test_settings_json_wins_over_legacy(self, fake_config_dir: Path) -> None:
|
|
fake_config_dir.mkdir(parents=True)
|
|
(fake_config_dir / "config.json").write_text(
|
|
json.dumps({"keys": {}, "settings": {"a": "legacy", "b": "legacy"}})
|
|
)
|
|
(fake_config_dir / "settings.json").write_text(json.dumps({"b": "new"}))
|
|
assert settings_mod.load_settings() == {"a": "legacy", "b": "new"}
|
|
|
|
def test_corrupt_files_yield_empty(self, fake_config_dir: Path) -> None:
|
|
fake_config_dir.mkdir(parents=True)
|
|
(fake_config_dir / "settings.json").write_text("{not json")
|
|
assert settings_mod.load_settings() == {}
|
|
|
|
|
|
class TestSaveAndSet:
|
|
def test_set_setting_roundtrip(self, fake_config_dir: Path) -> None:
|
|
settings_mod.set_setting("workspace_root", "/tmp/ws")
|
|
assert settings_mod.get_setting("workspace_root") == "/tmp/ws"
|
|
on_disk = json.loads((fake_config_dir / "settings.json").read_text())
|
|
assert on_disk == {"workspace_root": "/tmp/ws"}
|
|
|
|
def test_get_setting_default(self, fake_config_dir: Path) -> None:
|
|
assert settings_mod.get_setting("missing", "dflt") == "dflt"
|