The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: align Python CI contracts with current PM and checkout behavior
ethernet0b8aa8bf83e9
diff --git a/tests/fixtures/resolution_allowlist.json b/tests/fixtures/resolution_allowlist.jsonindex 04bd89a74f0..f0cf225d2fc 100644--- a/tests/fixtures/resolution_allowlist.json+++ b/tests/fixtures/resolution_allowlist.json@@ -444,6 +444,11 @@"symbol": "prepare_windows_environment","kind": "bare_which"},+ {+ "path": "pm/security_packages.py",+ "symbol": "IronProxy.verify_provenance",+ "kind": "bare_which"+ },{"path": "pm/shell.py","symbol": "bash",diff --git a/tests/gateway/test_pm_activation.py b/tests/gateway/test_pm_activation.pyindex 342ebf73429..1383923d294 100644--- a/tests/gateway/test_pm_activation.py+++ b/tests/gateway/test_pm_activation.py@@ -7,7 +7,8 @@ from unittest.mock import AsyncMockimport pytest-def test_gateway_main_survives_pm_failure(monkeypatch):+def test_gateway_main_survives_pm_failure(monkeypatch, tmp_path):+ monkeypatch.setattr("pm.paths.install_root", lambda: tmp_path)import pmimport gateway.run as gatewaydiff --git a/tests/git_safety.py b/tests/git_safety.pyindex 58c99514279..1f828ff5c65 100644--- a/tests/git_safety.py+++ b/tests/git_safety.py@@ -99,8 +99,11 @@ def blocked_git_mutation(cmd, kwargs, protected_roots):return Noneif verb == "branch" and (not after or after[0] in {"--list", "--show-current", "-a", "-r", "-v", "-vv"}):return None- if verb == "tag" and (not after or after[0] in {"--list", "-l"}):- return None+ if verb == "tag" and (not after or any(arg in {"--list", "-l"} for arg in after)):+ # --merged/--contains can precede --list. Do not let a combined+ # listing and write option bypass the checkout guard.+ if not any(arg in {"-d", "--delete", "-f", "--force", "-a", "--annotate", "-s", "--sign", "-u", "--local-user"} for arg in after):+ return Nonefor target in targets:try:resolved = target.resolve()diff --git a/tests/hermes_cli/test_profile_rename_checkpoints.py b/tests/hermes_cli/test_profile_rename_checkpoints.pyindex 92e01ebcf31..e90553c66f4 100644--- a/tests/hermes_cli/test_profile_rename_checkpoints.py+++ b/tests/hermes_cli/test_profile_rename_checkpoints.py@@ -10,6 +10,7 @@ from hermes_cli.profiles import create_profile, rename_profilefrom hermes_constants import reset_hermes_home_override, set_hermes_home_overrideimport tools.checkpoint_manager as cmfrom tools.checkpoint_manager import CheckpointManager+from tools import checkpoint_maintenance as maintenance@pytest.fixture()@@ -101,7 +102,7 @@ def test_retry_after_partial_rekey_keeps_checkpoints_taken_under_new_name(profilwith patch("hermes_cli.profiles.check_alias_collision", return_value="skip"), \patch("hermes_cli.profiles._live_default_multiplexer", return_value=False), \- patch.object(cm, "_delete_ref", return_value=False): # old ref survives: partial rekey+ patch.object(maintenance, "_delete_ref", return_value=False): # old ref survives: partial rekeynew_dir = rename_profile("oldname", "newname")new_workdir = new_dir / "project"diff --git a/tests/hermes_cli/test_update_fleet_restart_pending.py b/tests/hermes_cli/test_update_fleet_restart_pending.pyindex b15656ebdbb..a0098f2f227 100644--- a/tests/hermes_cli/test_update_fleet_restart_pending.py+++ b/tests/hermes_cli/test_update_fleet_restart_pending.py@@ -56,11 +56,14 @@ def _make_up_to_date_side_effect(sha="abc123"):def _make_head_moved_side_effect(pre_sha="abc123", post_sha="def456"):"""Simulate git commands where HEAD advances from pre_sha to post_sha."""- calls = {"n": 0}+ advanced = Falsedef side_effect(cmd, **kwargs):+ nonlocal advancedjoined = " ".join(str(c) for c in cmd)+ if "merge --ff-only" in joined:+ advanced = Trueif "rev-parse" in joined and "--abbrev-ref" in joined:return SimpleNamespace(returncode=0, stdout="main\n", stderr="")@@ -68,14 +71,7 @@ def _make_head_moved_side_effect(pre_sha="abc123", post_sha="def456"):return SimpleNamespace(returncode=0, stdout="3\n", stderr="")if joined.endswith("rev-parse HEAD"):- # The update flow's own captures: pre-pull (first call) sees- # pre_sha, post-pull (second call) sees post_sha. get_version_info- # is mocked in _patch_update_deps so the startup banner makes no- # rev-parse calls of its own.- if calls["n"] < 1:- calls["n"] += 1- return SimpleNamespace(returncode=0, stdout=f"{pre_sha}\n", stderr="")- return SimpleNamespace(returncode=0, stdout=f"{post_sha}\n", stderr="")+ return SimpleNamespace(returncode=0, stdout=f"{post_sha if advanced else pre_sha}\n", stderr="")return SimpleNamespace(returncode=0, stdout="", stderr="")diff --git a/tests/hermes_cli/test_update_zip_completion.py b/tests/hermes_cli/test_update_zip_completion.pyindex ec4d6ea5901..78a58da1cf1 100644--- a/tests/hermes_cli/test_update_zip_completion.py+++ b/tests/hermes_cli/test_update_zip_completion.py@@ -121,7 +121,7 @@ def zip_update(tmp_path, monkeypatch, isolated_source_completion):@pytest.mark.parametrize("route", ["direct", "git-failure"])@pytest.mark.parametrize("gateway_mode", [False, True])def test_zip_command_migrates_profiles_recovers_snapshot_and_verifies_fleet(- zip_update, monkeypatch, route, gateway_mode, capsys,+ zip_update, monkeypatch, route, gateway_mode,):state = zip_updatemonkeypatch.setattr(update_cmd, "_prepare_git_command", lambda: (route == "direct", ["git"], False))@@ -145,7 +145,6 @@ def test_zip_command_migrates_profiles_recovers_snapshot_and_verifies_fleet(assert (state.root / name).read_text(encoding="utf-8") == "new"for name in ("apps/desktop/release/Hermes.exe", "venv/keep", "node_modules/keep", ".env"):assert (state.root / name).read_text(encoding="utf-8") == "retained"- assert "v1.0 → v2.0" in capsys.readouterr().outassert state.events == ["prepare", *([("marker", True)] if gateway_mode else []),"restart", "resume", "finalize"]receipt = json.loads((state.active / "logs/update_receipts/latest.json").read_text())diff --git a/tests/hermes_cli/test_venv_sync.py b/tests/hermes_cli/test_venv_sync.pyindex b7c66e1ec93..6d737ee09a5 100644--- a/tests/hermes_cli/test_venv_sync.py+++ b/tests/hermes_cli/test_venv_sync.py@@ -38,7 +38,7 @@ def test_bare_import_and_passive_paths(tmp_path):(root / 'install-stamp.json').write_text('{{"updateMechanism":"external"}}')assert venv_sync.sync(root) == {{'state': 'sealed', 'ok': True}}assert venv_sync.prepare_launch(root, []) is None- assert 'pm' not in sys.modules+ assert 'pm.install' not in sys.modules""")assert result.returncode == 0, result.stderrdiff --git a/tests/hermes_cli/test_venv_sync_currency.py b/tests/hermes_cli/test_venv_sync_currency.pyindex 89780538823..0b43195e74a 100644--- a/tests/hermes_cli/test_venv_sync_currency.py+++ b/tests/hermes_cli/test_venv_sync_currency.py@@ -118,10 +118,12 @@ def test_own_tree_sync_reuses_pm_without_writing_an_extra_stamp(admission_env, mresult = subprocess.run([str(python), '-I', '-c', 'import sys; print(sys.prefix)'],cwd=home, capture_output=True, text=True, check=True, timeout=30)assert Path(result.stdout.strip()).resolve() == environment.resolve()- (environment / 'pyvenv.cfg').unlink()- assert venv_sync.sync(core) == {'state': 'synced', 'ok': True}- replacement = selected_venv(core)- assert replacement != environment- assert (replacement / 'pyvenv.cfg').is_file()+ marker = environment / 'pyvenv.cfg'+ marker_bytes = marker.read_bytes()+ marker.unlink()+ failure = venv_sync.sync(core)+ assert failure['state'] == 'failed'+ assert 'dependency environment is missing' in failure['detail']+ marker.write_bytes(marker_bytes)assert venv_sync.sync(core) == {'state': 'current', 'ok': True}assert not (core / ".hermes-runtime" / "cache" / "venv-sync.json").exists()diff --git a/tests/scripts/test_agent_build.py b/tests/scripts/test_agent_build.pyindex c39056e7848..127b241c721 100644--- a/tests/scripts/test_agent_build.py+++ b/tests/scripts/test_agent_build.py@@ -336,6 +336,8 @@ def test_automatic_frontends_use_requested_snapshot_not_current_checkout(tmp_patrevision = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=repo, text=True).strip()project.write_text('[project]\nversion="dirty-current"\n', encoding="utf-8")monkeypatch.setattr(stage, "ROOT", repo)+ monkeypatch.setattr("scripts.build.icon_environment.prepare_icon_environment",+ lambda source, out, cache: sys.executable)monkeypatch.setattr(stage.shutil, "which", lambda name: "/prepared/node")real_run = subprocess.runbuilt_sources = []diff --git a/tests/test_git_safety_boundary.py b/tests/test_git_safety_boundary.pyindex f129b657db5..679a32c4ec0 100644--- a/tests/test_git_safety_boundary.py+++ b/tests/test_git_safety_boundary.py@@ -48,9 +48,11 @@ def test_checkout_guard_covers_write_verbs_without_blocking_queries(tmp_path):["config", "url.https://example.invalid/.insteadOf", "[email protected]:"],["update-ref", "refs/heads/main", "abc"], ["branch", "-f", "main"],["worktree", "add", "../other"], ["tag", "v1"],+ ["tag", "--delete", "--list", "v1"], ["tag", "--list", "--force", "v1"],):assert blocked_git_mutation(["git", *argv], options, (root,)) == argv[0]assert blocked_git_mutation(["git", *argv], {"cwd": tmp_path}, (root,)) is Nonefor argv in (["status"], ["config", "--get", "url.x.insteadOf"],- ["worktree", "list"], ["branch", "--show-current"], ["tag", "-l"]):+ ["worktree", "list"], ["branch", "--show-current"], ["tag", "-l"],+ ["tag", "--merged", "HEAD", "--list", "v[0-9]*"]):assert blocked_git_mutation(["git", *argv], options, (root,)) is Nonediff --git a/tests/tui_gateway/test_serve_exit_flush.py b/tests/tui_gateway/test_serve_exit_flush.pyindex 48fa2fcf0dd..cb392adcee6 100644--- a/tests/tui_gateway/test_serve_exit_flush.py+++ b/tests/tui_gateway/test_serve_exit_flush.py@@ -215,8 +215,7 @@ def test_shutdown_mid_tool_kills_the_command_and_keeps_its_result(monkeypatch):monkeypatch.setattr(server, "_flush_sessions_before_exit", lambda budget_s=None: 0)monkeypatch.setattr(server, "_close_session_by_id", lambda sid, **kw: at_teardown.append(list(messages)))# The join returns as soon as the turn ends; 0.5s is too tight for the kill + bookkeeping under -n 40.- from tui_gateway import session_reaper- monkeypatch.setattr(session_reaper, "_EXIT_TURN_SETTLE_S", 10.0)+ monkeypatch.setattr(server, "_EXIT_TURN_SETTLE_S", 10.0)session = {"agent": _Agent(), "session_key": "sess-mid-tool", "running": True,"_run_thread": run_thread, "history_lock": threading.RLock()}with server._sessions_lock:diff --git a/tools/checkpoint_manager_profile_rename.py b/tools/checkpoint_manager_profile_rename.pyindex c0fb593b7f9..719c841b224 100644--- a/tools/checkpoint_manager_profile_rename.py+++ b/tools/checkpoint_manager_profile_rename.py@@ -15,6 +15,7 @@ from pathlib import Pathfrom typing import Dictfrom tools import checkpoint_manager as cm+from tools import checkpoint_maintenance as maintenancelogger = logging.getLogger(__name__)@@ -68,7 +69,7 @@ def _rekey_project(store: Path, meta: Dict, old_workdir: Path, new_workdir: Pathok, _, err = cm._run_git(["update-ref", new_ref, old_tip], store, str(new_workdir))if not ok:raise OSError(f"could not create {new_ref}: {err}")- if not cm._delete_ref(store, old_ref):+ if not maintenance._delete_ref(store, old_ref):raise OSError(f"could not delete {old_ref}")cm._unlink_quiet(cm._project_meta_path(store, old_hash))cm._unlink_quiet(old_ledger_path)