Skip to content

The agent that grows with you

test(update): a failed config-format write is owed, not swallowed; children inherit the runner's dependency path

Tekniumfbe441814274
diff --git a/tests/hermes_cli/test_update_config_migration_on_current.py b/tests/hermes_cli/test_update_config_migration_on_current.py
index e511d9920ce..700f9f5bb40 100644
--- a/tests/hermes_cli/test_update_config_migration_on_current.py
+++ b/tests/hermes_cli/test_update_config_migration_on_current.py
@@ -49,7 +49,12 @@ def test_migration_policy(monkeypatch, capsys, case, expected):
monkeypatch.setattr('builtins.input', prompt)
gateway_prompts = []
monkeypatch.setattr(update_cmd, '_gateway_prompt', lambda text, default: gateway_prompts.append((text, default)) or 'y')
- update_cmd._check_and_apply_config_migration(assume_yes=case == 'yes', gateway_mode=case == 'gateway')
+ if case == 'migration-error':
+ # A failed write is owed, not silently completed: the owed-step guard needs the raise.
+ with pytest.raises(RuntimeError, match=r'v2 → v3 was not written: cannot write config'):
+ update_cmd._check_and_apply_config_migration(assume_yes=False, gateway_mode=False)
+ else:
+ update_cmd._check_and_apply_config_migration(assume_yes=case == 'yes', gateway_mode=case == 'gateway')
assert calls == expected
assert bool(prompts) is (case in {'tty-yes', 'tty-decline', 'eof', 'unicode'})
assert bool(gateway_prompts) is (case == 'gateway')
diff --git a/tests/hermes_cli/test_update_post_commit_safety.py b/tests/hermes_cli/test_update_post_commit_safety.py
index 218342a53f7..1729116989f 100644
--- a/tests/hermes_cli/test_update_post_commit_safety.py
+++ b/tests/hermes_cli/test_update_post_commit_safety.py
@@ -19,6 +19,15 @@ import pytest
ROOT = Path(__file__).resolve().parents[2]
+
+def _child_env(**values: str) -> dict[str, str]:
+ """A fresh env for a child of THIS interpreter: same dependency path, no hermes state."""
+ env = {key: value for key, value in os.environ.items() if not key.startswith(("HERMES_", "PYTEST_"))}
+ # The test runner may provide dependencies through sys.path rather than site-packages.
+ env["PYTHONPATH"] = os.pathsep.join(path for path in sys.path if path)
+ env.update(values)
+ return env
+
_CHILD = textwrap.dedent('''
import copy, json, os, subprocess, sys
from pathlib import Path
@@ -93,10 +102,9 @@ def _run_completion(tmp_path: Path, mode: str, *, sqlite: str | None = None) ->
profile = root_home / "profiles" / "probe"
for name in ("logs/update_receipts", "skills", "cache", "profiles/probe"):
(root_home / name).mkdir(parents=True, exist_ok=True)
- env = {key: value for key, value in os.environ.items() if not key.startswith(("HERMES_", "PYTEST_"))}
- env.update(HOME=str(cell / "home"), HERMES_HOME=str(profile), HERMES_DISABLE_LAZY_INSTALLS="1",
- HERMES_RUNTIME_DIR=str(tmp_path / "store"), PYTHONDONTWRITEBYTECODE="1",
- XDG_CONFIG_HOME=str(cell / "home/.config"), XDG_CACHE_HOME=str(cell / "home/.cache"))
+ env = _child_env(HOME=str(cell / "home"), HERMES_HOME=str(profile), HERMES_DISABLE_LAZY_INSTALLS="1",
+ HERMES_RUNTIME_DIR=str(tmp_path / "store"), PYTHONDONTWRITEBYTECODE="1",
+ XDG_CONFIG_HOME=str(cell / "home/.config"), XDG_CACHE_HOME=str(cell / "home/.cache"))
if sqlite is not None:
payload = json.dumps({"base_prefix": sys.base_prefix, "executable": sys.executable,
"python_version": list(sys.version_info[:3]),
@@ -172,8 +180,7 @@ def test_old_schema_handoff_receipt_keeps_the_previous_runs_manual_serve_debt(tm
home.mkdir(parents=True)
# The durable reminder store is obstructed, so the receipt is the only record of the debt.
(home / "serve_restart_pending").write_text("not a directory\n", encoding="utf-8")
- env = {key: value for key, value in os.environ.items() if not key.startswith(("HERMES_", "PYTEST_"))}
- env.update(HOME=str(tmp_path / "home"), HERMES_HOME=str(home), PYTHONDONTWRITEBYTECODE="1")
+ env = _child_env(HOME=str(tmp_path / "home"), HERMES_HOME=str(home), PYTHONDONTWRITEBYTECODE="1")
child = tmp_path / "receipt_child.py"
child.write_text(_RECEIPT_CHILD, encoding="utf-8")
serve = subprocess.Popen([sys.executable, "-I", "-c", "import time; print('ready', flush=True); time.sleep(120)"],