Skip to content

The agent that grows with you

refactor(pm): remove adopt() — redundant re-verification of a signed bundle

ethernet5e7a88fee196
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.py
index 02891201f5f..ba949b510ff 100644
--- a/hermes_cli/venv_sync.py
+++ b/hermes_cli/venv_sync.py
@@ -54,7 +54,6 @@ def check_runtime(project_root: Path) -> str | None:
import pm
from hermes_cli.steward import sealed_steward
- pm.adopt()
problems = pm.activate()
if not problems:
return None
diff --git a/pm/__init__.py b/pm/__init__.py
index 05b9eb09c0f..2103a39dcdb 100644
--- a/pm/__init__.py
+++ b/pm/__init__.py
@@ -13,7 +13,6 @@ packages' env without installing anything.
from pm.ensure import (
activate,
- adopt,
check,
drift,
enabled_extras,
@@ -39,7 +38,6 @@ __all__ = [
"env_for",
"is_installed",
"installed_package",
- "adopt",
"check",
"drift",
"activate",
diff --git a/pm/ensure.py b/pm/ensure.py
index 71616a9fc56..79013ec402b 100644
--- a/pm/ensure.py
+++ b/pm/ensure.py
@@ -166,9 +166,8 @@ def is_installed(name: str) -> bool:
def sealed() -> bool:
- """A bundled payload is read-only: its store sits beside the bundle
- manifest. Asking a sealed install for MORE than it shipped is a
- Sealed = bundled LAYOUT only; adoption verification is adopt()'s job."""
+ """Sealed = bundled LAYOUT only: the store sits beside the bundle
+ manifest and is read-only as shipped."""
return (paths.store_root().parent / "manifest.json").is_file()
@@ -664,75 +663,6 @@ def sync_venv(extras: Optional[list[str]] = None, *, explicit: bool = False, plu
receipt.finalize(outcome, 0 if outcome == "ok" else 1, token=token)
-def adopt() -> bool:
- """First boot of a bundled install: verify the shipped payload, then
- make it THIS machine's installed state. The payload's own shipped
- ``pm/lock.json`` (inside the repo snapshot) is the offline authority:
- for every package it pins, the shipped fact must record the shipped
- identity, package.verify() must pass, and the recorded realized digest
- must match a fresh tree_digest() over the actual bytes. Any failure:
- log the offending package, do NOT write `.adopted`, return False —
- adopt() refuses to vouch for bytes it could not prove.
-
- Idempotent and cheap-ish: returns False when there is nothing to
- adopt (no shipped facts, or already adopted)."""
- store = _store()
- facts = _facts()
- if not paths.facts_path().is_file():
- return False
-
- from hermes_cli.runtime_paths import install_state_dir
- marker = install_state_dir(paths.repo_root()) / ".adopted"
- if marker.is_file():
- return False
-
- shipped_lock = paths.repo_root() / "pm" / "lock.json"
- if shipped_lock.is_file():
- lockfile = Lockfile(shipped_lock)
- target = current_target()
- for name in lockfile.names():
- try:
- package = get_package(name)
- except KeyError:
- continue
- if isinstance(package, StatePackage):
- continue
- fact = facts.get(name)
- if not facts.installed(
- name, lockfile.version(name), store.root, _identity(lockfile, name, target)
- ):
- LOG.warning(
- "pm adopt: refusing %s: fact missing, legacy (no recorded "
- "identity), or does not match the shipped lock",
- name,
- )
- return False
- entry = store.entry(fact["entry"])
- reason = package.verify(entry, target)
- if reason:
- LOG.warning(
- "pm adopt: refusing %s: staged entry failed verification: %s",
- name, reason,
- )
- return False
- if fact.get("digest") != tree_digest(entry):
- LOG.warning(
- "pm adopt: refusing %s: realized bytes do not match the "
- "recorded digest",
- name,
- )
- return False
-
- try:
- marker.parent.mkdir(parents=True, exist_ok=True)
- marker.write_text("", encoding="utf-8")
- except OSError:
- LOG.warning("could not record payload verification", exc_info=True)
- return False
-
- return True
-
-
def drift() -> dict[str, str]:
"""Cheap stamp comparisons of the installed state
against the lockfile. Maps package names to reasons; empty means healthy. Never
diff --git a/tests/gateway/test_pm_activation.py b/tests/gateway/test_pm_activation.py
index ca7c56c3022..342ebf73429 100644
--- a/tests/gateway/test_pm_activation.py
+++ b/tests/gateway/test_pm_activation.py
@@ -7,18 +7,16 @@ from unittest.mock import AsyncMock
import pytest
[email protected]("boundary", ["adopt", "activate"])
-def test_gateway_main_survives_pm_failure(monkeypatch, boundary):
+def test_gateway_main_survives_pm_failure(monkeypatch):
import pm
import gateway.run as gateway
failed = []
def broken():
- failed.append(boundary)
+ failed.append("activate")
raise RuntimeError("PM unavailable")
- monkeypatch.setattr(pm, "adopt", lambda: None)
- monkeypatch.setattr(pm, boundary, broken)
+ monkeypatch.setattr(pm, "activate", broken)
started = AsyncMock(return_value=True)
exited = []
monkeypatch.setattr(gateway, "start_gateway", started)
@@ -28,4 +26,4 @@ def test_gateway_main_survives_pm_failure(monkeypatch, boundary):
gateway.main()
started.assert_awaited_once()
assert exited == [0]
- assert failed == [boundary]
+ assert failed == ["activate"]
diff --git a/tests/pm/test_pm_authority.py b/tests/pm/test_pm_authority.py
index 07bf3f9f6d9..43dee5d599e 100644
--- a/tests/pm/test_pm_authority.py
+++ b/tests/pm/test_pm_authority.py
@@ -1,5 +1,5 @@
"""pm authority spine: digest-bound facts, tree_digest + doctor re-hash,
-adopt() verification gate, repair logging.
+repair logging.
Same conventions as test_pm_core: real loopback server, real archives,
real store — no mocked stores. Assertions are relationships (identity
@@ -417,65 +417,6 @@ def test_doctor_flags_tampered_entry_bytes(pm_env, capsys):
assert cmd_doctor(None) == 0
-def _bundle_payload(env) -> Path:
- """Build a shipped payload the way cmd_bundle lays it out: a repo
- snapshot carrying pm/lock.json, and a store whose facts.json holds
- the installed state. adopt()'s paths point here via repo_root."""
- from pm.ensure import ensure
-
- monkeypatch = env["monkeypatch"]
- tmp_path = env["tmp_path"]
- shipped_repo = tmp_path / "shipped-repo"
- (shipped_repo / "pm").mkdir(parents=True)
- shutil.copy(env["lockfile_path"], shipped_repo / "pm" / "lock.json")
- monkeypatch.setattr(paths, "repo_root", lambda: shipped_repo)
- ensure("faketool", base_env={})
- return shipped_repo
-
-
-def test_adopt_refuses_on_missing_staged_binary(pm_env):
- from pm.ensure import adopt
-
- _bundle_payload(pm_env)
- fact = Facts(paths.facts_path()).get("faketool")
- binary = paths.store_root() / fact["entry"] / "bin" / "faketool"
- binary.unlink()
-
- marker = paths.runtime_facts_path().parent / ".adopted"
- assert adopt() is False
- assert not marker.is_file()
-
-
-def test_adopt_refuses_on_tampered_staged_binary(pm_env):
- """The adversarial witness: bytes substituted AFTER install fail even
- though facts + lock still agree — the digest is computed over the
- actual bytes, not read from the manifest."""
- from pm.ensure import adopt
-
- _bundle_payload(pm_env)
- fact = Facts(paths.facts_path()).get("faketool")
- binary = paths.store_root() / fact["entry"] / "bin" / "faketool"
- binary.write_bytes(b"#!substituted")
-
- marker = paths.runtime_facts_path().parent / ".adopted"
- assert adopt() is False
- assert not marker.is_file()
-
-
-def test_adopt_refuses_when_fact_lacks_identity(pm_env):
- from pm.ensure import adopt
-
- _bundle_payload(pm_env)
- facts_path = paths.facts_path()
- data = json.loads(facts_path.read_text(encoding="utf-8"))
- for key in ("target", "artifacts", "digest"):
- data["packages"]["faketool"].pop(key, None)
- facts_path.write_text(json.dumps(data), encoding="utf-8")
-
- assert adopt() is False
- assert not (paths.store_root().parent / ".adopted").is_file()
-
-
def test_tree_digest_ignores_pycache(pm_env, monkeypatch):
"""Bytecode caches are runtime state, not package bytes: the staged
python entry runs (uv venv/uv sync in a bundle build, first boot of a
diff --git a/tests/pm/test_pm_core.py b/tests/pm/test_pm_core.py
index b0400936809..bae19abfa9e 100644
--- a/tests/pm/test_pm_core.py
+++ b/tests/pm/test_pm_core.py
@@ -538,15 +538,6 @@ def test_machine_matches_binary_elf(tmp_path):
assert machine_matches_binary(b, "linux-x64") is False
-def test_adopt_noop_without_facts(pm_env, monkeypatch):
- import pm
- from pm import paths
-
- monkeypatch.setenv("HERMES_RUNTIME_DIR", str(paths.store_root() / "nowhere"))
- assert pm.adopt() is False
-
-
-
def test_bundle_closure_uv_stays_internal_node_npm_ship(monkeypatch, tmp_path):
"""Locks the semantics split: uv is pm's install machinery and never
ships by closure, node/npm are runtime tools and always do."""
diff --git a/tests/pm/test_store_extensions.py b/tests/pm/test_store_extensions.py
index 3b53c0b5f66..8505073d8a5 100644
--- a/tests/pm/test_store_extensions.py
+++ b/tests/pm/test_store_extensions.py
@@ -35,21 +35,6 @@ def test_missing_bundle_tool_is_installed_in_writable_store(pm_env, tmp_path, mo
assert env_for("faketool", base_env={}) == runner.env
-def test_adoption_records_verification_outside_shipped_payload(pm_env, monkeypatch):
- from pm.ensure import adopt
- from tests.pm.test_pm_authority import _bundle_payload
-
- _bundle_payload(pm_env)
- shipped_roots = (paths.store_root(), paths.repo_root())
- def snapshot():
- return {p: p.read_bytes() for root in shipped_roots for p in root.rglob("*") if p.is_file()}
- before = snapshot()
- assert adopt() is True
- assert snapshot() == before
- assert not (paths.store_root().parent / ".adopted").exists()
- assert adopt() is False
-
-
def test_corrupt_shipped_facts_are_only_read(tmp_path, monkeypatch):
store = tmp_path / "payload" / "tools"
store.mkdir(parents=True)