Skip to content

The agent that grows with you

fix(config-remote): hermes config edit exits 1 when the backend has no config file

Ben Barclayfd44f481efeb
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index a321a898915..205557d009e 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -2884,9 +2884,10 @@ def edit_config():
managed_error("edit configuration")
return
if not supports_file_tooling():
- print("`hermes config edit` opens the local config file, and this config backend has none. "
- "Use `hermes config set <key> <value>` instead.", file=sys.stderr)
- return
+ # Exits 1 (unlike the managed refusal above, which every managed_error caller shares):
+ # a script must not read this refusal as a successful edit.
+ _exit_invalid("`hermes config edit` opens the local config file, and this config backend has none. "
+ "Use `hermes config set <key> <value>` instead.")
config_path = get_config_path()
if not config_path.exists(): # config-reader: ok — file tooling, gated on supports_file_tooling()
seed_config_file(config_path)
diff --git a/tests/hermes_cli/test_config_edit_seed.py b/tests/hermes_cli/test_config_edit_seed.py
index eedca6e4175..69217bb77f9 100644
--- a/tests/hermes_cli/test_config_edit_seed.py
+++ b/tests/hermes_cli/test_config_edit_seed.py
@@ -82,3 +82,19 @@ def test_every_seeder_keeps_every_platform_display_default(tmp_path, monkeypatch
config_path = home / "config.yaml"
assert config_path.exists() # the resolution checks below would pass on a missing file
assert_keeps_platform_display_defaults(_load_gateway_config(config_path))
+
+
+def test_config_edit_refusal_without_a_config_file_exits_nonzero(tmp_path, monkeypatch, capsys):
+ """A backend with no local file (Remote Config) refuses `config edit` with rc 1, so a script
+ cannot read the refusal as a successful edit (teknium1 P3 on #122509)."""
+ import hermes_cli.config as cfg
+
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ monkeypatch.setattr(cfg, "is_managed", lambda: False)
+ monkeypatch.setattr(cfg, "supports_file_tooling", lambda: False)
+ monkeypatch.setattr(cfg.subprocess, "run", lambda *a, **k: pytest.fail("no editor may open"))
+ with pytest.raises(SystemExit) as exc:
+ cfg.edit_config()
+ assert exc.value.code == 1
+ assert "hermes config set" in capsys.readouterr().err
+ assert not (tmp_path / "config.yaml").exists()