Skip to content

The agent that grows with you

test: git guard tolerates a dead cwd and argv-less spawns; PM seams take project_root

ethernetc01e1ee5de7b
diff --git a/tests/git_safety.py b/tests/git_safety.py
index 9ef2ae670f9..3e8b8102fc1 100644
--- a/tests/git_safety.py
+++ b/tests/git_safety.py
@@ -17,6 +17,9 @@ def _command_name(token):
return str(token).replace("\\", "/").rsplit("/", 1)[-1].lower().removesuffix(".exe")
def _git_argv_tail(cmd):
+ if cmd is None:
+ # Popen(args=None, executable=...) and shell-less spawns without argv: nothing to classify.
+ return None
if isinstance(cmd, (list, tuple)):
tokens = [os.fsdecode(t) for t in cmd]
else:
@@ -43,7 +46,12 @@ def _git_argv_tail(cmd):
return None
def _git_verb_and_targets(tail, kwargs):
- cwd = Path(kwargs.get("cwd") or os.getcwd())
+ try:
+ cwd = Path(kwargs.get("cwd") or os.getcwd())
+ except FileNotFoundError:
+ # The process cwd was deleted (deferred kanban cleanup, #33774); git itself will
+ # resolve relative to whatever it finds, and nothing under a dead dir is protected.
+ cwd = Path("/nonexistent-deleted-cwd")
env = kwargs.get("env")
if env is None:
env = os.environ
diff --git a/tests/hermes_cli/test_plugins_update_sync.py b/tests/hermes_cli/test_plugins_update_sync.py
index a1a650fcb6d..3157b76bc1f 100644
--- a/tests/hermes_cli/test_plugins_update_sync.py
+++ b/tests/hermes_cli/test_plugins_update_sync.py
@@ -67,13 +67,18 @@ def test_enablement_before_lock_acquisition_cannot_skip_validation(installed, mo
enabled = {}
@contextmanager
- def enable_before_acquiring_lock(project):
+ def enable_before_acquiring_lock(project, **kwargs):
+ # The plugin becomes active after the update read its state but before PM's
+ # publication holds the install lock; the enablement itself is a completed PM
+ # transaction (its own lock cycle), so it runs outside this re-entered seam.
if not enabled:
enabled["begun"] = True
+ monkeypatch.setattr(runtime_state, "runtime_lock", lock)
pc._set_plugin_enabled("transactional", enable=True)
+ monkeypatch.setattr(runtime_state, "runtime_lock", enable_before_acquiring_lock)
enabled["config"] = (home / "config.yaml").read_bytes()
enabled["facts"] = paths.runtime_facts_path().read_bytes()
- with lock(project):
+ with lock(project, **kwargs):
yield
monkeypatch.setattr(runtime_state, "runtime_lock", enable_before_acquiring_lock)
diff --git a/tests/pm/test_plugin_survival_contract.py b/tests/pm/test_plugin_survival_contract.py
index 1bbb0c89d65..82108d69094 100644
--- a/tests/pm/test_plugin_survival_contract.py
+++ b/tests/pm/test_plugin_survival_contract.py
@@ -164,8 +164,14 @@ def admission_env(tmp_path, monkeypatch):
monkeypatch.setattr(ensure, "lazy_installs_allowed", lambda: True)
monkeypatch.setenv("HERMES_RUNTIME_DIR", str(tmp_path / "tools"))
# Exercise the real dependency transaction in-process so the local uv
- # fixture owns provisioning; worker transport is covered separately.
- monkeypatch.setattr("pm.client.sync_venv", ensure.sync_venv)
+ # fixture owns provisioning; worker transport is covered separately. The
+ # facade's project_root selects a foreign checkout for the worker; this
+ # fixture's repo_root already IS the core under test.
+ def in_process_sync(*args, project_root=None, **kwargs):
+ assert project_root is None or Path(project_root).resolve() == core.resolve()
+ return ensure.sync_venv(*args, **kwargs)
+
+ monkeypatch.setattr("pm.client.sync_venv", in_process_sync)
monkeypatch.setattr("pm._uv._toolchain", lambda **kwargs: (Path(shutil.which("uv")), Path(sys.executable)))
return tmp_path, home
diff --git a/tests/tui_gateway/test_slash_worker_profile_home.py b/tests/tui_gateway/test_slash_worker_profile_home.py
index c1459bc5bf1..0cd0bcbc3d6 100644
--- a/tests/tui_gateway/test_slash_worker_profile_home.py
+++ b/tests/tui_gateway/test_slash_worker_profile_home.py
@@ -1,38 +1,23 @@
"""Tests for TUI gateway slash_worker profile_home propagation (#40677)."""
-from pathlib import Path
from unittest.mock import MagicMock, patch
-def test_slash_worker_accepts_profile_home():
- """_SlashWorker.__init__ accepts profile_home parameter."""
- # hermes_state evaluates get_hermes_home() / "state.db" at import time, so
- # the mock must return a Path (a bare str raises TypeError under per-file
- # subprocess isolation).
- with patch.dict("sys.modules", {
- "hermes_constants": MagicMock(
- get_hermes_home=MagicMock(return_value=Path("/tmp/hermes_test")),
- ),
- }):
- with patch("subprocess.Popen") as mock_popen:
- mock_popen.return_value.stdout = MagicMock()
- mock_popen.return_value.stderr = MagicMock()
+def test_slash_worker_accepts_profile_home(tmp_path, monkeypatch):
+ """_SlashWorker.__init__ accepts profile_home and pins the child's HERMES_HOME to it."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes_test"))
+ from tui_gateway.server import _SlashWorker
- from tui_gateway.server import _SlashWorker
-
- # Test initialization with profile_home
- worker = _SlashWorker(
- session_key="test_key",
- model="test-model",
- profile_home="/home/luke/.hermes/profiles/work"
- )
-
- # Verify Popen was called
- assert mock_popen.called
-
- # Check that HERMES_HOME was set in the environment
- call_kwargs = mock_popen.call_args[1]
- assert "env" in call_kwargs
- assert call_kwargs["env"]["HERMES_HOME"] == "/home/luke/.hermes/profiles/work"
+ with patch("subprocess.Popen") as mock_popen:
+ mock_popen.return_value.stdout = MagicMock()
+ mock_popen.return_value.stderr = MagicMock()
+ _SlashWorker(
+ session_key="test_key",
+ model="test-model",
+ profile_home="/home/luke/.hermes/profiles/work",
+ )
+ assert mock_popen.called
+ call_kwargs = mock_popen.call_args[1]
+ assert call_kwargs["env"]["HERMES_HOME"] == "/home/luke/.hermes/profiles/work"