The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(config): refuse file-copy tools without backend file tooling; backend-consulted tests
Ben Barclay9909c4f7f959
diff --git a/hermes_cli/backup.py b/hermes_cli/backup.pyindex 37909355780..f85eeebac93 100644--- a/hermes_cli/backup.py+++ b/hermes_cli/backup.py@@ -595,6 +595,8 @@ def run_backup(args) -> bool:the caller turns False into exit status 1 so a cron/systemd timer never publishes a "successful"archive that is missing state.db. Hard failures keep raising ``SystemExit``."""+ from hermes_cli.config_backend import require_file_tooling+ require_file_tooling("`hermes backup`")hermes_root = get_default_hermes_root()if not hermes_root.is_dir():@@ -731,6 +733,8 @@ def _import_member_rel(member: str, prefix: str) -> tuple[str, bool]:def run_import(args) -> Optional[int]:"""Restore a Hermes backup; return 1 on damaged archives or incomplete restores."""+ from hermes_cli.config_backend import require_file_tooling+ require_file_tooling("`hermes import`")zip_path = Path(args.zipfile).expanduser().resolve()if not zip_path.is_file():@@ -1540,6 +1544,8 @@ def restore_quick_snapshot(Returns True if at least one file was restored and the listed auth.jsonwas not refused or skipped."""+ from hermes_cli.config_backend import require_file_tooling+ require_file_tooling("Snapshot restore")from gateway.runtime_ownership import OwnershipConflict, exclusive_maintenancehome = hermes_home or get_hermes_home()try:diff --git a/hermes_cli/config_backend.py b/hermes_cli/config_backend.pyindex 15c4a8264cc..87c71c3630c 100644--- a/hermes_cli/config_backend.py+++ b/hermes_cli/config_backend.py@@ -217,3 +217,11 @@ def write_config_key(config_path: PathLike, key_path: str, value: Any) -> None:def supports_file_tooling() -> bool:"""Gate for tools that copy, edit or back up the config FILE itself (§4.3, §4.7)."""return get_config_backend().supports_file_tooling()+++def require_file_tooling(what: str) -> None:+ """Refuse *what* (a file-copy tool) with a clear message when the backend has no config file."""+ if not supports_file_tooling():+ raise ConfigBackendUnavailable(+ f"{what} copies the local config.yaml, and the {get_config_backend().name!r} config "+ "backend has none. It is not available with this backend.")diff --git a/hermes_cli/profile_distribution.py b/hermes_cli/profile_distribution.pyindex 007b2f41964..d488d06fd18 100644--- a/hermes_cli/profile_distribution.py+++ b/hermes_cli/profile_distribution.py@@ -539,6 +539,8 @@ def _copy_dist_payload(staged: Path, target: Path, manifest: DistributionManifesA top-level owned directory, and an owned container (``_is_container``), is merged perauthored root. ``cron/jobs.json`` is special: it is one multi-record runtime store, soshipped definitions merge by job id instead of replacing the file."""+ from hermes_cli.config_backend import require_file_tooling+ require_file_tooling("Profile distribution install")target.mkdir(parents=True, exist_ok=True)entries = list(_owned_entries(staged, manifest))_refuse_symlinked_targets(target, entries)diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.pyindex a8eead5a0b3..e4e0fba8580 100644--- a/hermes_cli/profiles.py+++ b/hermes_cli/profiles.py@@ -1179,6 +1179,8 @@ def profiles_to_serve(multiplex: bool, *, include_standalone: bool = False,def _resolve_clone_source(clone_from: Optional[str]) -> Path:"""Directory to clone from: the named profile, or the active profile when ``None``."""+ from hermes_cli.config_backend import require_file_tooling+ require_file_tooling("Profile clone")if clone_from is None:from hermes_constants import get_hermes_homesource_dir = get_hermes_home()diff --git a/tests/hermes_cli/test_config_backend.py b/tests/hermes_cli/test_config_backend.pyindex 4e74c99d2c1..1692d1de0ce 100644--- a/tests/hermes_cli/test_config_backend.py+++ b/tests/hermes_cli/test_config_backend.py@@ -74,6 +74,132 @@ class TestFileBackend:assert cb.read_config_doc(path) == {"model": {"default": "c"}}+class _RecordingBackend(cb.FileBackend):+ """The file backend, recording which operations each pipeline asks of it."""++ name = "recording"++ def __init__(self):+ self.calls = []++ def _rec(self, op, home):+ self.calls.append((op, Path(home)))++ def read_user_layer(self, home):+ self._rec("read", home)+ return super().read_user_layer(home)++ def read_user_doc_readonly(self, home):+ self._rec("read", home)+ return super().read_user_doc_readonly(home)++ def version(self, home):+ self._rec("version", home)+ return super().version(home)++ def exists(self, home):+ self._rec("exists", home)+ return super().exists(home)++ def write_changes(self, home, changes):+ self._rec("write", home)+ return super().write_changes(home, changes)++ def ops(self, home):+ return {op for op, h in self.calls if h == Path(home)}+++def recording(monkeypatch, tmp_path):+ """A fresh HERMES_HOME with a config.yaml and every config read/write recorded."""+ from hermes_cli import config as config_mod+ home = tmp_path / ".hermes"+ home.mkdir()+ (home / "config.yaml").write_text(+ "# hand-tuned\nmodel:\n default: my-model\nsecrets:\n sources: []\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.delenv(cb.BACKEND_ENV, raising=False)+ for cache in (config_mod._LOAD_CONFIG_CACHE, config_mod._RAW_CONFIG_CACHE):+ cache.clear()+ backend = _RecordingBackend()+ monkeypatch.setattr(cb, "get_config_backend", lambda: backend)+ return home, backend+++class TestPipelinesConsultTheBackend:+ """Every read pipeline and writer reaches the selected backend, keyed by the hermes home."""++ def test_load_config(self, recording):+ from hermes_cli.config import load_config+ home, backend = recording+ assert load_config()["model"]["default"] == "my-model"+ assert {"version", "read"} <= backend.ops(home)++ def test_raw_primitives(self, recording):+ from hermes_cli.config import read_raw_config, read_user_config_raw+ home, backend = recording+ assert read_raw_config()["model"]["default"] == "my-model"+ assert read_user_config_raw()["model"]["default"] == "my-model"+ assert {"version", "read"} <= backend.ops(home)++ def test_effective_loader(self, recording):+ from hermes_cli import config_effective+ home, backend = recording+ config_effective._EFFECTIVE_CACHE.clear()+ assert config_effective.load_user_config_effective()["model"]["default"] == "my-model"+ assert {"version", "read"} <= backend.ops(home)++ def test_cli_loader(self, recording):+ from hermes_cli.cli_config_load import load_cli_config+ home, backend = recording+ load_cli_config()+ assert {"exists", "read"} <= backend.ops(home)++ def test_gateway_yaml_layers(self, recording):+ from gateway.config_loader import read_yaml_layers+ home, backend = recording+ assert read_yaml_layers(home)["model"]["default"] == "my-model"+ assert "read" in backend.ops(home)++ def test_dotenv_secrets_read(self, recording):+ from hermes_cli.env_loader import _load_secrets_config+ home, backend = recording+ _load_secrets_config(home)+ assert "read" in backend.ops(home)++ def test_writers(self, recording):+ from hermes_cli.config import load_config, save_config+ from hermes_cli.personality import persist_personality+ home, backend = recording+ cfg = load_config()+ cfg["model"]["default"] = "other-model"+ save_config(cfg)+ assert persist_personality("kawaii")+ assert [op for op, h in backend.calls if op == "write" and h == home] == ["write", "write"]+ text = (home / "config.yaml").read_text(encoding="utf-8")+ assert "# hand-tuned" in text and "other-model" in text and "kawaii" in text+++class TestFileTooling:++ def test_file_backend_allows_it(self, home):+ cb.require_file_tooling("x")++ def test_backend_without_a_file_refuses_it(self, home, monkeypatch):+ class NoFile(cb.FileBackend):+ name = "nofile"++ def supports_file_tooling(self):+ return False+ monkeypatch.setattr(cb, "get_config_backend", NoFile)+ from hermes_cli.config_backups import backup_config+ (home / "config.yaml").write_text("a: 1\n", encoding="utf-8")+ assert backup_config(home / "config.yaml", "test") is None+ with pytest.raises(cb.ConfigBackendUnavailable, match="Profile clone"):+ from hermes_cli.profiles import _resolve_clone_source+ _resolve_clone_source(None)++class TestReaderGate:def _guard(self):