mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 03:54:08 +00:00
pm.environment strips every ambient UV_* so a caller's uv settings cannot select PM's project, interpreter or cache. That also dropped the knobs mirrored and air-gapped networks depend on (UV_INDEX_URL/UV_DEFAULT_INDEX, UV_NATIVE_TLS, UV_INSECURE_HOST, UV_HTTP_TIMEOUT, index credentials), and uv never reads pip's configuration, so PIP_INDEX_URL / pip.conf mirrors stalled against pypi.org (#88453, #94613, #95608 on main). pm.index_config owns the allowlist and the pip→uv bridge with pip's own precedence (PIP_INDEX_URL over pip.conf; any explicit uv index wins). Only transport/index config crosses; the lockfile stays authoritative. A uv timeout now raises InstallError naming those knobs instead of a raw TimeoutExpired, so `hermes pm install` and the venv_sync status report tell the user what to configure.
54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
"""Ambient uv settings cannot steer PM; project configuration still can."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def test_ambient_uv_config_does_not_affect_pm_venv_sync(tmp_path, monkeypatch):
|
|
from pm.environment import managed_environment
|
|
|
|
uv = shutil.which("uv")
|
|
assert uv, "the isolation contract requires real uv"
|
|
monkeypatch.setattr("pm._uv._toolchain", lambda **kwargs: (Path(uv), Path(sys.executable)))
|
|
project = tmp_path / "project"
|
|
project.mkdir()
|
|
(project / "pyproject.toml").write_text(
|
|
'[project]\nname="venv-sync-regression"\nversion="1"\nrequires-python=">=3.11"\n'
|
|
'[tool.uv]\npackage=false\nexclude-newer="14 days"\n', encoding="utf-8",
|
|
)
|
|
environment = managed_environment(tmp_path / "candidate", offline=True)
|
|
environment.lock(project)
|
|
locked = (project / "uv.lock").read_bytes()
|
|
config = tmp_path / "config"
|
|
(config / "uv").mkdir(parents=True)
|
|
(config / "uv" / "uv.toml").write_text('required-version="<0.0.1"\n')
|
|
for key, value in {
|
|
"UV_NO_CONFIG": "1", "UV_CONFIG_FILE": "/poison/uv.toml",
|
|
"UV_PYTHON": "/poison/python",
|
|
"UV_PROJECT_ENVIRONMENT": str(tmp_path / "unrelated-environment"),
|
|
"UV_CACHE_DIR": str(tmp_path / "hostile-cache"),
|
|
"UV_PROJECT": "/poison/project", "VIRTUAL_ENV": "/poison/venv",
|
|
"PYTHONPATH": "/poison/imports", "XDG_CONFIG_HOME": str(config), "XDG_CONFIG_DIRS": str(config),
|
|
}.items():
|
|
monkeypatch.setenv(key, value)
|
|
before = dict(os.environ)
|
|
raw = subprocess.run([uv, "lock", "--check"], cwd=project,
|
|
capture_output=True, text=True, timeout=30)
|
|
assert raw.returncode != 0, "negative control: raw poisoned environment must fail"
|
|
environment = managed_environment(tmp_path / "candidate", offline=True)
|
|
environment.create()
|
|
environment.sync(project, locked=True)
|
|
environment.check()
|
|
assert environment.executable.is_file()
|
|
assert environment.cache.is_dir()
|
|
assert not (tmp_path / "hostile-cache").exists()
|
|
assert not (tmp_path / "unrelated-environment").exists()
|
|
assert (project / "uv.lock").read_bytes() == locked
|
|
assert dict(os.environ) == before
|