Skip to content

The agent that grows with you

fix(update): migrate default config.yaml on named-profile update

Adolanium9c02d6868e63
diff --git a/hermes_cli/update_cmd_config.py b/hermes_cli/update_cmd_config.py
index 4b0ae09bc5b..ac11c5739dd 100644
--- a/hermes_cli/update_cmd_config.py
+++ b/hermes_cli/update_cmd_config.py
@@ -37,28 +37,22 @@ def _migrate_sibling_profile_configs() -> list[tuple[str, int, int]]:
91277 Phase 2 (fleet-wide config migration; #20438/#54926/#79048): the shared checkout serves every
profile, but ``hermes update`` historically migrated only the active profile's config — siblings drifted
versions until their gateway hit a config the new code couldn't read.
+
+ Enumeration matches pre-update snapshots (#66140): default lives at
+ ``_get_default_hermes_home()``, not under ``profiles/``, so a named-profile
+ ``hermes update`` still migrates it.
"""
from hermes_cli.config import check_config_version, migrate_config
migrated: list[tuple[str, int, int]] = []
with _best_effort('Sibling profile enumeration failed: %s'):
from hermes_constants import (
get_process_hermes_home, reset_hermes_home_override, set_hermes_home_override)
- from hermes_cli.profiles import _get_profiles_root, _PROFILE_ID_RE
- active_home = get_process_hermes_home()
- root = _get_profiles_root()
- if not root.is_dir():
- return migrated
- for entry in sorted(root.iterdir()):
- if not entry.is_dir() or not _PROFILE_ID_RE.match(entry.name):
- continue
- try:
- if entry.resolve() == Path(active_home).resolve():
- continue
- except OSError:
- continue
- if not (entry / "config.yaml").is_file():
+ from hermes_cli.backup import _sibling_profile_homes
+ active_home = Path(get_process_hermes_home())
+ for name, profile_home in _sibling_profile_homes(active_home):
+ if not (profile_home / "config.yaml").is_file():
continue # profile never configured — nothing to migrate
- token = set_hermes_home_override(entry)
+ token = set_hermes_home_override(profile_home)
try:
current_ver, latest_ver = check_config_version(raise_on_parse_error=True)
if current_ver >= latest_ver:
@@ -66,9 +60,9 @@ def _migrate_sibling_profile_configs() -> list[tuple[str, int, int]]:
migrate_config(interactive=False, quiet=True)
after_ver, _ = check_config_version(raise_on_parse_error=True)
if after_ver > current_ver:
- migrated.append((entry.name, current_ver, after_ver))
+ migrated.append((name, current_ver, after_ver))
except Exception as exc:
- logger.debug("Config migration for profile %s failed: %s", entry.name, exc)
+ logger.debug("Config migration for profile %s failed: %s", name, exc)
finally:
reset_hermes_home_override(token)
return migrated
diff --git a/tests/hermes_cli/test_sibling_config_migration.py b/tests/hermes_cli/test_sibling_config_migration.py
index 8c6d70c89bb..af655a780bb 100644
--- a/tests/hermes_cli/test_sibling_config_migration.py
+++ b/tests/hermes_cli/test_sibling_config_migration.py
@@ -33,10 +33,19 @@ def _latest_version() -> int:
return int(DEFAULT_CONFIG["_config_version"])
-def _setup(monkeypatch, tmp_path, active_home: Path):
+def _setup(monkeypatch, tmp_path, active_home: Path, *, default_home: Path | None = None):
import hermes_cli.profiles as profiles_mod
monkeypatch.setattr(profiles_mod, "_get_profiles_root", lambda: tmp_path / "profiles")
+ # Default lives at the install root, not under profiles/. Absent unless a
+ # test passes default_home, so the original named-profile cases stay
+ # focused on profiles/ and cannot pick up the process HERMES_HOME.
+ missing = tmp_path / "no-such-default-home"
+ monkeypatch.setattr(
+ profiles_mod,
+ "_get_default_hermes_home",
+ lambda: default_home if default_home is not None else missing,
+ )
import hermes_constants
monkeypatch.setattr(
@@ -120,3 +129,50 @@ def test_override_is_reset_after_run(monkeypatch, tmp_path):
before = get_hermes_home_override()
update_cmd._migrate_sibling_profile_configs()
assert get_hermes_home_override() == before
+
+
+def test_named_active_migrates_default_outside_profiles(monkeypatch, tmp_path):
+ """Default lives at the install root, not under profiles/. A named-profile
+ update must still migrate it. Snapshots already treat default as a sibling
+ (#66140). Walking profiles/ only leaves it behind."""
+ default_home = _write_profile(tmp_path, "default-home", 12)
+ active = _write_profile(tmp_path / "profiles", "work", _latest_version())
+ _setup(monkeypatch, tmp_path, active, default_home=default_home)
+
+ migrated = update_cmd._migrate_sibling_profile_configs()
+
+ names = [m[0] for m in migrated]
+ assert "default" in names
+ entry = next(m for m in migrated if m[0] == "default")
+ assert entry[1] == 12 and entry[2] == _latest_version()
+ on_disk = yaml.safe_load((default_home / "config.yaml").read_text())
+ assert on_disk["_config_version"] == _latest_version()
+ assert on_disk["model"]["provider"] == "nous"
+ # named active is the invoking home: its own migrate path handles it
+ assert "work" not in names
+
+
+def test_default_active_still_migrates_named_siblings(monkeypatch, tmp_path):
+ """Invoking from default must still migrate named profiles under profiles/."""
+ default_home = _write_profile(tmp_path, "default-home", _latest_version())
+ sibling = _write_profile(tmp_path / "profiles", "research", 12)
+ _setup(monkeypatch, tmp_path, default_home, default_home=default_home)
+
+ migrated = update_cmd._migrate_sibling_profile_configs()
+
+ names = [m[0] for m in migrated]
+ assert "default" not in names
+ assert "research" in names
+ on_disk = yaml.safe_load((sibling / "config.yaml").read_text())
+ assert on_disk["_config_version"] == _latest_version()
+ assert yaml.safe_load((default_home / "config.yaml").read_text())["_config_version"] == _latest_version()
+
+
+def test_default_without_config_yaml_is_skipped(monkeypatch, tmp_path):
+ default_home = tmp_path / "default-home"
+ default_home.mkdir()
+ active = _write_profile(tmp_path / "profiles", "work", _latest_version())
+ _setup(monkeypatch, tmp_path, active, default_home=default_home)
+
+ assert update_cmd._migrate_sibling_profile_configs() == []
+ assert not (default_home / "config.yaml").exists()