`_install_dependencies` (hermes memory setup) hard-aborted with "uv not found — cannot install dependencies" whenever `uv` was not on PATH, even when a perfectly good `pip` was available. Slim container images and some CI environments don't ship uv, so memory-provider dependency installation dead-ended there for no good reason. Now: use `uv pip install` when uv is present, otherwise fall back to `<python> -m pip install` when pip3/pip is available, and only abort (with the uv install hint) when neither is found. The "Run manually:" hints reflect whichever installer was selected. Salvages #5954 by @MustafaKara7. Their patch added redundant local `import subprocess` / `import sys` (both are already in scope — module -level `sys`, function-top `subprocess`); this salvage drops those and adds a regression test (TestInstallDependenciesRunner) covering all three paths (uv / pip-fallback / abort). Verified adversarially: the pip-fallback test fails against origin/main's unfixed code with the exact dead-end symptom and passes with the fix. Closes #5954. Co-authored-by: MustafaKara7 <186085093+MustafaKara7@users.noreply.github.com>
This commit is contained in:
co-authored by
MustafaKara7
parent
03ba06ebfb
commit
30c7b787d1
@@ -48,3 +48,50 @@ class TestMemorySetupProviderRouting:
|
||||
out = capsys.readouterr().out
|
||||
assert "not found" in out
|
||||
assert "hermes memory setup" in out
|
||||
|
||||
|
||||
class TestInstallDependenciesRunner:
|
||||
"""`_install_dependencies` must install via `uv` when present and fall back
|
||||
to standard `pip` when `uv` is unavailable (e.g. slim containers / CI images
|
||||
that don't ship uv) instead of dead-ending with "cannot install"."""
|
||||
|
||||
def _run_with_missing_dep(self, tmp_path, which_side_effect):
|
||||
"""Drive _install_dependencies for a plugin that declares one missing
|
||||
pip dep, capturing the subprocess.run argv (or None if never called)."""
|
||||
import sys
|
||||
|
||||
(tmp_path / "plugin.yaml").write_text(
|
||||
"pip_dependencies:\n - definitely-not-installed-xyz\n", encoding="utf-8"
|
||||
)
|
||||
captured = {}
|
||||
|
||||
def fake_run(cmd, **kw):
|
||||
captured["cmd"] = cmd
|
||||
return SimpleNamespace()
|
||||
|
||||
with patch("plugins.memory.find_provider_dir", return_value=tmp_path), \
|
||||
patch("shutil.which", side_effect=which_side_effect), \
|
||||
patch("subprocess.run", fake_run):
|
||||
memory_setup._install_dependencies("x")
|
||||
return captured.get("cmd"), sys.executable
|
||||
|
||||
def test_uses_uv_when_available(self, tmp_path):
|
||||
cmd, _ = self._run_with_missing_dep(
|
||||
tmp_path, lambda b: "/usr/bin/uv" if b == "uv" else None
|
||||
)
|
||||
assert cmd is not None
|
||||
assert cmd[:3] == ["/usr/bin/uv", "pip", "install"]
|
||||
|
||||
def test_falls_back_to_pip_when_uv_missing(self, tmp_path, capsys):
|
||||
"""The salvaged behavior (#5954): no uv but pip present -> python -m pip."""
|
||||
cmd, py = self._run_with_missing_dep(
|
||||
tmp_path, lambda b: "/usr/bin/pip3" if b == "pip3" else None
|
||||
)
|
||||
assert cmd is not None
|
||||
assert cmd[:4] == [py, "-m", "pip", "install"]
|
||||
assert "Falling back to standard pip" in capsys.readouterr().out
|
||||
|
||||
def test_aborts_when_neither_uv_nor_pip(self, tmp_path, capsys):
|
||||
cmd, _ = self._run_with_missing_dep(tmp_path, lambda b: None)
|
||||
assert cmd is None # no install attempted
|
||||
assert "cannot install dependencies" in capsys.readouterr().out
|
||||
|
||||
Reference in New Issue
Block a user