Files
hermes-agent/tests/pm/test_plugins_state_remote_config.py
Ben Barclay e4374020bd fix(config-remote): adapt the remote backend to the seam as merged in #134362
puts back what that build deliberately left for the remote backend, on
main's seam shape:

- RemoteBackend implements main's protocol (read_user_doc, probe_readable)
  and is not a FileBackend; _route returns (backend, home) and explicit
  files go through _ExplicitFile, so the is_layer branches are gone.
- One bootstrap: _ensure_bootstrap_env / bootstrap_deployment select the
  backend from the process env, the launch home's .env and the managed .env.
  #134362's _dotenv_backend_override did not survive its file-only refactor,
  so nothing stacks; its rules are now tests (stale shell remote + .env file
  boots file; empty .env value resets to file; .env-only remote selects
  remote; an absent key keeps the shell value).
- The file-tooling gates main removed (backup/import/snapshot restore,
  config edit, migration write-back, config backups, profile clone and
  distribution install, raw config editor, xAI migration, gateway --config).
- profile_serve_signature uses the backend version for config.yaml.
- restore_config_model_settings_if_rewritten is a no-op without file tooling.
- PM's dependency runtime reads a home's selection from the local file it
  publishes to (config_backend.local_file_layer), so a remote deployment
  never needs the plane there or fails PM closed.
- Ratchet: _container_slots/_validate_quoted_containers move to
  config_value_checks, _count_cron_jobs to backup_restore, the gateway
  --config load to gateway/config_loader.
2026-10-27 17:33:48 -07:00

44 lines
1.9 KiB
Python

"""PM's dependency runtime in a Remote Config deployment (#122509): the runtime has no remote
backend client and no plane credential, so reading a home's plugin selection there must neither
fail closed nor reach for the plane. It reads the local file PM publishes to and CAS-checks."""
import sys
import pytest
from pm import plugins_state
@pytest.fixture
def remote_home(tmp_path, monkeypatch):
from hermes_cli import config_backend
from plugins.config_backends import remote
home = tmp_path / "home"
home.mkdir()
(home / "config.yaml").write_text("plugins:\n enabled: [alpha]\n", encoding="utf-8")
monkeypatch.setenv("HERMES_HOME", str(home))
monkeypatch.setenv(config_backend.BACKEND_ENV, "remote")
monkeypatch.delenv("HERMES_CONFIG_INSTANCE_ID", raising=False)
monkeypatch.setattr(config_backend, "_BOOTSTRAPPED", True)
remote._reset_for_tests()
yield home
remote._reset_for_tests()
def test_pm_runtime_reads_the_local_selection_without_the_plane(remote_home, monkeypatch):
import pm.runtime
monkeypatch.setattr(pm.runtime, "is_runtime", lambda: True)
# The runtime cannot import the remote backend at all.
for name in [m for m in sys.modules if m.startswith("plugins.config_backends.remote")]:
monkeypatch.delitem(sys.modules, name)
monkeypatch.setitem(sys.modules, "plugins.config_backends.remote", None)
assert plugins_state.read_home_selection(remote_home)["plugins"]["enabled"] == ["alpha"]
assert plugins_state.read_home_selection(remote_home / "absent") is None
def test_application_process_reads_the_selection_through_the_backend(remote_home):
# Control: outside PM's runtime the selected (unconfigured) remote backend is consulted and
# fails closed rather than serving the local file.
from hermes_cli.config_backend import ConfigBackendUnavailable
with pytest.raises(ConfigBackendUnavailable):
plugins_state.read_home_selection(remote_home)