mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
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.
This commit is contained in:
1 parent
2f6ae9a015
commit
cd5375ac8b
2 files changed
+33
-1
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
Reference in new issue
Block a user