Skip to content

The agent that grows with you

test(agent): drive the profile hint through the real resolver chain

Jeff Mettel4691eb5433bc
diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.py
index c0e309b6da9..b881a356dea 100644
--- a/tests/agent/test_system_prompt.py
+++ b/tests/agent/test_system_prompt.py
@@ -116,72 +116,68 @@ class TestCodingContextBlock:
assert "coding agent" not in _stable_prompt(agent)
-class TestNamedProfileHint:
- """The profile hint must point at real paths (#72894).
-
- ``_resolve_active_profile_name()`` only returns a non-default name when
- ``get_hermes_home()`` has already resolved to ``<root>/profiles/<name>``,
- so appending ``/profiles/<name>`` to it doubled the segment, and using it
- for the *default* profile's data pointed those inside the active profile.
+class TestNamedProfileHintIntegration:
+ """The same defect through the REAL resolution chain (#72894).
+
+ ``TestNamedProfileHint`` mocks ``get_hermes_home``,
+ ``get_default_hermes_root`` and ``_resolve_active_profile_name``, so it
+ validates template rendering but not the relationship that causes the bug:
+ ``_resolve_active_profile_name`` returns a named profile *only* when the
+ active home is already ``<root>/profiles/<name>``, which is exactly why
+ appending that suffix again doubled it. Drive it with a real
+ ``HERMES_HOME`` and no resolver mocks.
"""
- @staticmethod
- def _full_prompt(monkeypatch, agent):
- # Pin the prompt shape: with the coding posture off there is no
- # workspace snapshot, so the hint's position doesn't depend on the
- # cwd the suite happens to run from. Join both parts regardless.
- monkeypatch.delenv("TERMINAL_CWD", raising=False)
- with patch("agent.coding_context._coding_mode", return_value="off"):
- return "\n\n".join(_prompt_parts(agent).values())
-
- @classmethod
- def _named_profile_prompt(cls, monkeypatch, name="mac"):
- import agent.system_prompt as system_prompt
+ def test_real_hermes_home_under_profiles_renders_correct_paths(
+ self, tmp_path, monkeypatch
+ ):
+ root = tmp_path / ".hermes"
+ profile_home = root / "profiles" / "coder"
+ profile_home.mkdir(parents=True)
- agent = _make_agent(valid_tool_names=["read_file"])
- monkeypatch.setattr(
- system_prompt, "get_hermes_home", lambda: Path(f"/hermes/profiles/{name}")
- )
- monkeypatch.setattr(
- system_prompt, "get_default_hermes_root", lambda: Path("/hermes")
- )
- monkeypatch.setattr(
- "agent.file_safety._resolve_active_profile_name", lambda: name
- )
- return cls._full_prompt(monkeypatch, agent)
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(profile_home))
+ monkeypatch.delenv("TERMINAL_CWD", raising=False)
- def test_session_home_is_not_doubled(self, monkeypatch):
- prompt = self._named_profile_prompt(monkeypatch)
+ # Sanity-check the real chain before asserting on the prompt.
+ from agent.file_safety import _resolve_active_profile_name
+ from hermes_constants import get_default_hermes_root, get_hermes_home
- assert "This session reads and writes /hermes/profiles/mac/." in prompt
- assert "/hermes/profiles/mac/profiles/mac" not in prompt
+ assert _resolve_active_profile_name() == "coder"
+ assert get_hermes_home() == profile_home
+ assert get_default_hermes_root() == root
- def test_default_profile_data_points_at_the_root(self, monkeypatch):
- prompt = self._named_profile_prompt(monkeypatch)
+ agent = _make_agent(valid_tool_names=["read_file"])
+ with patch("agent.coding_context._coding_mode", return_value="off"):
+ prompt = "\n\n".join(_prompt_parts(agent).values())
+
+ assert "Active Hermes profile: coder." in prompt
+ assert f"reads and writes {profile_home}/." in prompt
+ # The doubled form must not appear anywhere.
+ assert f"{profile_home}/profiles/coder" not in prompt
+ # Default-profile pointers belong at the root, not inside the profile.
+ assert f"The default profile's data lives at {root}/skills/" in prompt
+ assert f"{profile_home}/skills/" not in prompt
+
+ def test_real_default_home_renders_default_branch(self, tmp_path, monkeypatch):
+ """HERMES_HOME at the root resolves to the default profile, unchanged."""
+ root = tmp_path / ".hermes"
+ root.mkdir(parents=True)
+
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(root))
+ monkeypatch.delenv("TERMINAL_CWD", raising=False)
- assert (
- "The default profile's data lives at /hermes/skills/, "
- "/hermes/plugins/, /hermes/cron/, /hermes/memories/"
- ) in prompt
- # Never inside the active profile — that's the cross-profile
- # confusion this hint exists to prevent.
- assert "/hermes/profiles/mac/skills/" not in prompt
- assert "/hermes/profiles/mac/memories/" not in prompt
+ from agent.file_safety import _resolve_active_profile_name
- def test_default_profile_hint_is_unchanged(self, monkeypatch):
- import agent.system_prompt as system_prompt
+ assert _resolve_active_profile_name() == "default"
agent = _make_agent(valid_tool_names=["read_file"])
- monkeypatch.setattr(system_prompt, "get_hermes_home", lambda: Path("/hermes"))
- monkeypatch.setattr(
- "agent.file_safety._resolve_active_profile_name", lambda: "default"
- )
- prompt = self._full_prompt(monkeypatch, agent)
+ with patch("agent.coding_context._coding_mode", return_value="off"):
+ prompt = "\n\n".join(_prompt_parts(agent).values())
- assert (
- "Active Hermes profile: default. Other profiles (if any) live "
- "under /hermes/profiles/<name>/."
- ) in prompt
+ assert "Active Hermes profile: default." in prompt
+ assert f"under {root}/profiles/<name>/." in prompt
def test_build_system_prompt_records_stable_prefix():