From cd5375ac8beb02828a1bc80ff8697a42e62f0d61 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 16 Oct 2026 10:52:31 +0400 Subject: [PATCH] fix(profile): an unparseable config never fails the post-clone memory notice `_load_config_dict` replaced main's `profiles._load_yaml_dict` (any Exception -> None) but caught only YAMLError/OSError/UnicodeError. The YAML constructors raise a bare ValueError for values such as `2024-02-30` or `!!int abc`, so a clone of such a profile printed a traceback from `hermes profile create` after the profile was already made. Catch ValueError (which also covers UnicodeDecodeError). ConfigBackendUnavailable still propagates: it is a SystemExit. --- hermes_cli/profile_memory_config.py | 4 ++- .../hermes_cli/test_profile_memory_config.py | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/hermes_cli/test_profile_memory_config.py diff --git a/hermes_cli/profile_memory_config.py b/hermes_cli/profile_memory_config.py index c9f87d8a9e..9725cc056d 100644 --- a/hermes_cli/profile_memory_config.py +++ b/hermes_cli/profile_memory_config.py @@ -67,7 +67,9 @@ def _load_config_dict(profile_dir: Path) -> Optional[dict]: from hermes_cli.config_backend import read_config_doc try: data = read_config_doc(profile_dir / "config.yaml") or {} - except (YAMLError, OSError, UnicodeError): # FileNotFoundError included: no config + # FileNotFoundError included (no config). ValueError: the YAML constructors raise it bare for + # values like ``2024-02-30`` / ``!!int abc``; this read is a best-effort notice and never fails a clone. + except (YAMLError, OSError, ValueError): return None return data if isinstance(data, dict) else None diff --git a/tests/hermes_cli/test_profile_memory_config.py b/tests/hermes_cli/test_profile_memory_config.py new file mode 100644 index 0000000000..ba515b6de6 --- /dev/null +++ b/tests/hermes_cli/test_profile_memory_config.py @@ -0,0 +1,30 @@ +"""cloned_memory_provider: a best-effort post-clone notice that never fails ``hermes profile create``.""" + +import pytest + +from hermes_cli.profile_memory_config import cloned_memory_provider + + +@pytest.mark.parametrize("body", [ + "memory:\n provider: honcho\nwhen: 2024-02-30\n", # YAML constructor raises a bare ValueError + "memory: [unclosed\n", # YAMLError + b"memory:\n provider: \xff\n", # UnicodeDecodeError +]) +def test_unreadable_config_means_no_notice(tmp_path, body): + (tmp_path / "honcho").mkdir() + path = tmp_path / "config.yaml" + if isinstance(body, bytes): + path.write_bytes(body) + else: + path.write_text(body, encoding="utf-8") + assert cloned_memory_provider(tmp_path) is None + + +def test_missing_config_means_no_notice(tmp_path): + assert cloned_memory_provider(tmp_path) is None + + +def test_configured_provider_with_copied_state_is_named(tmp_path): + (tmp_path / "honcho").mkdir() + (tmp_path / "config.yaml").write_text("memory:\n provider: honcho\n", encoding="utf-8") + assert cloned_memory_provider(tmp_path) == "honcho"