Files
hermes-agent/tests/pm/test_uv_cache.py
ethernet 92686159d1 fix(pm): integrate audited runtime and lifecycle repairs
Prepare dependency generations before selecting them. Keep shipped tool
bytes separate from writable additions, and store facts beside their entries.
Validate proposed plugin sets before config publication. Restore the previous
config if the facts write fails.

Consolidate duplicate updater, backup, setup, and voice helpers. Repair
launcher selection, dependency consumers, download ownership, update feeds,
and native Windows process and file handling.

Verification: 206 changed/prior-failing Python files reported 4630 passed,
one failed, and 330 skipped. Fix the remaining Hindsight fixture boundary.
The final targeted rerun reported 234 passed and two skipped. The store
review regression batch reported 83 passed and one skipped. Desktop
TypeScript checks, 56 selected Electron tests, 24 release tests, and the
removed-import/compatibility guards passed.

This is an integration checkpoint, not full audit acceptance. The complete
Python suite has not run on this fixed tree. Crash-atomic plugin publication,
generation cleanup, receipt correlation, and packaged lifecycle acceptance
remain open in docs/pm-audit-status.md.
2026-09-05 22:36:48 -04:00

78 lines
2.8 KiB
Python

"""PM caches are writable; shipped dependency environments stay immutable."""
from __future__ import annotations
from pathlib import Path
import pytest
import pm.packages as pkgs
def test_uv_env_pins_cache_dir(monkeypatch, tmp_path):
monkeypatch.setattr(pkgs, "uv_cache_dir", lambda: tmp_path / "c")
env = pkgs.uv_env({"UV_CACHE_DIR": "/ambient/user/cache", "PATH": "x"})
assert env["UV_CACHE_DIR"] == str(tmp_path / "c")
# ambient UV_ vars are stripped, not inherited
assert "UV_PROJECT_ENVIRONMENT" not in env
def test_uv_cache_dir_seeds_from_payload(monkeypatch, tmp_path):
home = tmp_path / "home"
home.mkdir()
payload = tmp_path / "payload"
(payload / "uv-cache" / "wheels-v5").mkdir(parents=True)
(payload / "uv-cache" / "wheels-v5" / "some.pkg").write_text("x", encoding="utf-8")
import hermes_constants
monkeypatch.setattr(hermes_constants, "get_default_hermes_root", lambda: home)
import pm.paths as paths_mod
monkeypatch.setattr(paths_mod, "store_root", lambda: payload / "tools")
machine = pkgs.uv_cache_dir()
assert machine == home / "cache" / "uv"
# seed copied out
assert (machine / "wheels-v5" / "some.pkg").read_text(encoding="utf-8") == "x"
# seeded marker written → second call doesn't re-copy
assert (machine / ".seeded").is_file()
(payload / "uv-cache" / "wheels-v5" / "some.pkg").write_text("changed", encoding="utf-8")
pkgs.uv_cache_dir()
assert (machine / "wheels-v5" / "some.pkg").read_text(encoding="utf-8") == "x"
def test_uv_cache_dir_cold_machine_no_payload(monkeypatch, tmp_path):
home = tmp_path / "home"
home.mkdir()
import hermes_constants
monkeypatch.setattr(hermes_constants, "get_default_hermes_root", lambda: home)
import pm.paths as paths_mod
monkeypatch.setattr(paths_mod, "store_root", lambda: tmp_path / "nowhere" / "tools")
machine = pkgs.uv_cache_dir()
assert machine == home / "cache" / "uv"
assert (machine / ".seeded").is_file()
@pytest.mark.parametrize("lazy_allowed", [False, True])
def test_bundle_uses_shipped_environment_until_an_extension_is_committed(monkeypatch, tmp_path, lazy_allowed):
import json
import importlib
import pm.paths as paths
home = tmp_path / "home"
monkeypatch.setenv("HERMES_HOME", str(home))
payload = tmp_path / "payload"
core = payload / "hermes-agent"
core.mkdir(parents=True)
shipped = payload / "venv"
shipped.mkdir()
(payload / "manifest.json").write_text(json.dumps({"repo": "hermes-agent", "venv": "venv"}))
monkeypatch.setattr(paths, "repo_root", lambda: core)
monkeypatch.setattr(importlib.import_module("pm.ensure"), "lazy_installs_allowed", lambda: lazy_allowed)
assert pkgs.Venv().venv_dir() == shipped
assert not home.exists(), "selecting shipped dependencies must not copy or mutate them"