The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(macos): keep the TCC anchor alive across CVE-repair rotations + sign anchor copies
Teknium9f8cdf89d631
diff --git a/hermes_cli/macos_tcc_anchor.py b/hermes_cli/macos_tcc_anchor.pyindex 24c99b465c3..29ce9fac6b7 100644--- a/hermes_cli/macos_tcc_anchor.py+++ b/hermes_cli/macos_tcc_anchor.py@@ -72,9 +72,18 @@ def _store_bin_names() -> tuple[str, ...]:return (f"python3.{_sys.version_info.minor}", "python3", "python")-# Path fragments that identify a uv-managed macOS CPython store layout:-# ``.../uv/python/cpython-<version>-macos-<arch>/bin/python*``.-_UV_STORE_MARKERS = ("/uv/python/", "cpython-", "-macos-")+# Path fragments that identify a MANAGED macOS CPython store layout — a+# store whose path changes across updates, orphaning path-keyed TCC grants.+# Two roots qualify:+# - uv store patch bumps: .../uv/python/cpython-<ver>-macos-*/bin/...+# - CVE-repair generations: .../.hermes-runtime/python/generation-*/+# cpython-<ver>-macos-*/bin/...+# (repair_vulnerable_runtime() rebuilds the venv against a generation store,+# replacing the anchored bin/python with a fresh symlink — without the second+# root the anchor would read 'not uv-managed' after every SQLite CVE repair+# and never re-anchor, issue #82427.)+_STORE_COMMON_MARKERS = ("cpython-", "-macos-")+_STORE_ROOT_MARKERS = ("/uv/python/", "/.hermes-runtime/python/")def is_macos() -> bool:@@ -83,9 +92,11 @@ def is_macos() -> bool:def _is_uv_macos_store(path: str | Path) -> bool:- """True when *path* lives inside a uv-managed macOS CPython store."""+ """True when *path* lives inside a managed macOS CPython store."""text = str(path).replace("\\", "/")- return all(marker in text for marker in _UV_STORE_MARKERS)+ if not all(marker in text for marker in _STORE_COMMON_MARKERS):+ return False+ return any(root in text for root in _STORE_ROOT_MARKERS)def _venv_dir(project_root: Path | None = None) -> Path | None:@@ -225,6 +236,21 @@ def _install_anchor(venv_dir: Path, source_file: Path) -> None:try:shutil.copy2(source_file, tmp_path)os.chmod(tmp_path, source_file.stat().st_mode | 0o111)+ # Give the anchor copy a stable identifier-pinned signature BEFORE it+ # goes live. copy2 carries over the source build's signature, whose+ # designated requirement is cdhash-based for ad-hoc/linker-signed+ # python-build-standalone binaries — meaning every anchor REFRESH+ # (patch bump, CVE repair) would still change the stored csreq and+ # orphan the grant despite the stable path. Identifier-DR signing+ # (same mechanism as managed_uv's generation signing, #82427) keeps+ # the csreq constant across refreshes. Best-effort: a failed sign+ # leaves the copy usable, just without refresh-stable signing.+ try:+ from hermes_cli.managed_uv import _macos_sign_managed_python++ _macos_sign_managed_python(tmp_path)+ except Exception: # pragma: no cover - never block the anchor+ logger.debug("anchor copy signing skipped", exc_info=True)os.replace(tmp_path, venv_py)_anchor_marker(venv_bin).write_text(str(source_file), encoding="utf-8")_repoint_aliases(venv_bin, venv_py)diff --git a/tests/hermes_cli/test_macos_tcc_anchor.py b/tests/hermes_cli/test_macos_tcc_anchor.pyindex 9b1b56a3443..8f5d12a08c3 100644--- a/tests/hermes_cli/test_macos_tcc_anchor.py+++ b/tests/hermes_cli/test_macos_tcc_anchor.py@@ -89,6 +89,17 @@ class TestUvStoreDetection:)assert tcc._is_uv_macos_store(path)+ def test_matches_hermes_runtime_repair_generation(self):+ # repair_vulnerable_runtime() rebuilds the venv against a generation+ # store under .hermes-runtime/python/ — no /uv/python/ segment. The+ # anchor must recognize it or every SQLite CVE repair silently+ # un-anchors the interpreter (issue #82427 integration).+ path = (+ "/Users/u/hermes-agent/.hermes-runtime/python/"+ "generation-a1b2c3/cpython-3.11.15-macos-aarch64-none/bin/python3.11"+ )+ assert tcc._is_uv_macos_store(path)+def test_rejects_homebrew_interpreter(self):path = ("/opt/homebrew/Cellar/[email protected]/3.14.6/Frameworks/"@@ -116,6 +127,54 @@ class TestEnsureTccAnchor:assert tcc.ensure_tcc_anchor(root) is Noneassert venv_py.is_symlink() # untouched+ def test_install_signs_the_anchor_copy(self, tmp_path, monkeypatch):+ """The anchor copy gets identifier-DR signing before going live —+ without it every refresh changes the stored csreq (cdhash-based for+ ad-hoc source builds) and orphans the grant despite the stable path."""+ _darwin(monkeypatch)+ signed = []+ import hermes_cli.managed_uv as managed_uv++ monkeypatch.setattr(+ managed_uv, "_macos_sign_managed_python", lambda p: signed.append(Path(p)) or True+ )+ store_bin = _build_store(tmp_path)+ root = _build_checkout(tmp_path, store_bin=store_bin)++ anchored = tcc.ensure_tcc_anchor(root)++ assert anchored is not None+ # Signing ran on the temp copy inside the venv bin dir (pre-rename).+ assert len(signed) == 1+ assert signed[0].parent == anchored.parent++ def test_anchors_repair_generation_interpreter(self, tmp_path, monkeypatch):+ """A venv re-created against a .hermes-runtime CVE-repair generation+ store must anchor too (issue #82427 integration)."""+ _darwin(monkeypatch)+ store = (+ tmp_path+ / "checkout"+ / ".hermes-runtime"+ / "python"+ / "generation-a1b2c3"+ / "cpython-3.11.15-macos-aarch64-none"+ )+ store_bin = store / "bin"+ store_bin.mkdir(parents=True)+ store_py = store_bin / "python3.11"+ store_py.write_bytes(b"#!fake generation interpreter")+ store_py.chmod(0o755)+ root = _build_checkout(tmp_path, store_bin=store_bin)+ venv_py = venv_python_path(root / ".venv")+ assert venv_py.is_symlink()++ anchored = tcc.ensure_tcc_anchor(root)++ assert anchored == venv_py+ assert not venv_py.is_symlink()+ assert venv_py.read_bytes() == store_py.read_bytes()+def test_anchors_uv_managed_interpreter(self, tmp_path, monkeypatch):_darwin(monkeypatch)store_bin = _build_store(tmp_path)