Files
hermes-agent/tests/pm/test_uv_cache.py
ethernet a00ca233f8 fix(pm): voice enables audio-io through PM; public plugin-state readers; PM tests isolate the machine home
- voice_mode: `_import_audio` asks `pm.ensure_import("audio-io")` before importing
  sounddevice, so `/voice on` turns the feature on (or reports exactly why PM
  refused: lazy installs off, platform gate, restart needed) instead of printing a
  `python -c "from pm import sync_venv…"` one-liner for the user to run.
- pm.plugins_state: `read_home_selection` and `dependency_homes` are the public
  readers; memory_provider_migration and plugins_cmd stop importing underscored names.
- pm.store: the `sha256_file` shim is gone; the authority test asserts the Store has no
  file hash of its own rather than patching one.
- tests/pm/conftest: `isolated_machine_home` is autouse (Path.home, HOME, USERPROFILE,
  HERMES_HOME all under tmp_path); `@pytest.mark.real_machine_home` opts a module out
  — the four suites that spawn children with a home they build themselves.
- activate / activate.ps1 / Dockerfile followed hermes_cli.runtime_paths to
  pm.environments (the earlier sweep only covered .py).
- pm.registry loads builtins through importlib so a test patching `pm.packages` in
  sys.modules still registers the security packages.
2026-09-19 00:48:11 -04:00

69 lines
2.2 KiB
Python

"""PM caches are writable; shipped dependency environments stay immutable."""
from __future__ import annotations
import pm.packages as pkgs
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()
def test_bundle_uses_shipped_environment_until_an_extension_is_committed(monkeypatch, tmp_path):
import json
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)
assert pkgs.Venv().venv_dir() == shipped
assert not home.exists(), "selecting shipped dependencies must not copy or mutate them"