The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): ensure() re-records an installed package's env from the current package code, so upgraded stores drop AGENT_BROWSER_EXECUTABLE_PATH
Teknium492482209b88
diff --git a/pm/install.py b/pm/install.pyindex 5c7570b323f..d18af96b341 100644--- a/pm/install.py+++ b/pm/install.py@@ -374,6 +374,22 @@ def _refresh_recorded_env(package, facts, store, entry, previous, target) -> Nondigest=previous.get("digest"))+def _refresh_found_env(package, location, target, operation) -> None:+ """:func:`_refresh_recorded_env` for an entry ``ensure`` found installed: `hermes update` skips+ installed defaults, so no install would re-record it. Only the writable store is re-recorded, under+ its install lock (a sealed store's facts ship with the artifact)."""+ facts, store = location+ entry = store.entry(facts.get(package.name)["entry"])+ if (facts.env_for(package.name, store.root) == package.env(entry, target)+ or store.root != Store(paths.writable_store_root()).root):+ return+ with nullcontext() if operation is not None else store.install_lock():+ facts.reload()+ previous = facts.get(package.name)+ if previous and previous.get("entry") == entry.name:+ _refresh_recorded_env(package, facts, store, entry, previous, target)++def _copy_verified_source(package, lockfile, copy_from, staged, version, target) -> None:source_facts, source_store = copy_fromsource = source_facts.get(package.name)@@ -570,9 +586,11 @@ def ensure(json.dumps(_identity(lockfile, package.name, target), sort_keys=True))if identity in checked:continue- if _installed_location(package, lockfile, target, verify=explicit and verify) is None:+ location = _installed_location(package, lockfile, target, verify=explicit and verify)+ if location is None:missing.append(package)else:+ _refresh_found_env(package, location, target, _operation)checked.add(identity)if missing and not explicit and not lazy_installs_allowed():raise _refuse_lazy(name, ", ".join(p.name for p in missing))diff --git a/tests/pm/test_retired_agent_browser.py b/tests/pm/test_retired_agent_browser.pyindex c14edd5ef2b..d6c65553548 100644--- a/tests/pm/test_retired_agent_browser.py+++ b/tests/pm/test_retired_agent_browser.py@@ -82,6 +82,18 @@ def test_every_reader_skips_the_retired_fact(upgraded_store, monkeypatch):assert str(upgraded_store["retired_bin"]) not in os.environ["PATH"].split(os.pathsep)+def test_ensure_rerecords_the_old_chromium_env_without_installing(upgraded_store, monkeypatch):+ """`hermes update` skips installed defaults, so nothing reinstalls Chromium to re-record its env: an+ ensure() that finds it installed re-derives the env from the package code, without a fetch."""+ import pm.install++ monkeypatch.setattr(pm.install, "_install", lambda *a, **k: pytest.fail("an installed package was installed"))+ pm.install.ensure("chromium")+ assert pm.install.env_for("chromium", base_env={}) == {"PLAYWRIGHT_BROWSERS_PATH": str(upgraded_store["store"])}+ assert "AGENT_BROWSER_EXECUTABLE_PATH" not in Facts(paths.facts_path()).env_for("chromium", paths.store_root())+ assert pm.installed_package("chromium").binary == upgraded_store["binary"]++def test_gc_reclaims_the_retired_entry_and_keeps_chromium(upgraded_store):store = Store(paths.store_root())pm.cli._gc_store(store, Facts(paths.facts_path()))