mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-25 03:00:23 +00:00
fix: validate WebUI launcher can import agent
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import pathlib
|
||||
|
||||
import bootstrap
|
||||
|
||||
|
||||
def test_ensure_python_prefers_agent_venv_when_launcher_cannot_import_agent(monkeypatch, tmp_path):
|
||||
"""Avoid starting WebUI with a local venv that later cannot import AIAgent."""
|
||||
local_python = tmp_path / "webui" / ".venv" / "bin" / "python"
|
||||
agent_python = tmp_path / "agent" / "venv" / "bin" / "python"
|
||||
agent_python.parent.mkdir(parents=True)
|
||||
agent_python.write_text("", encoding="utf-8")
|
||||
|
||||
probes = []
|
||||
|
||||
def fake_can_run(python_exe: str, agent_dir: pathlib.Path | None = None) -> bool:
|
||||
probes.append(pathlib.Path(python_exe))
|
||||
return pathlib.Path(python_exe) == agent_python
|
||||
|
||||
monkeypatch.setattr(bootstrap, "_python_can_run_webui_and_agent", fake_can_run)
|
||||
|
||||
selected = bootstrap.ensure_python_has_webui_deps(str(local_python), tmp_path / "agent")
|
||||
|
||||
assert selected == str(agent_python)
|
||||
assert probes == [local_python, agent_python]
|
||||
|
||||
|
||||
def test_ensure_python_fails_loudly_when_no_interpreter_can_import_agent(monkeypatch, tmp_path):
|
||||
"""Do not report health OK when chat would fail with missing AIAgent."""
|
||||
local_python = tmp_path / "webui" / ".venv" / "bin" / "python"
|
||||
agent_python = tmp_path / "agent" / "venv" / "bin" / "python"
|
||||
agent_python.parent.mkdir(parents=True)
|
||||
agent_python.write_text("", encoding="utf-8")
|
||||
|
||||
monkeypatch.setattr(bootstrap, "_python_can_run_webui_and_agent", lambda *a, **k: False)
|
||||
monkeypatch.setattr(bootstrap.subprocess, "run", lambda *a, **k: None)
|
||||
|
||||
try:
|
||||
bootstrap.ensure_python_has_webui_deps(str(local_python), tmp_path / "agent")
|
||||
except RuntimeError as exc:
|
||||
assert "cannot import both WebUI dependencies and Hermes Agent" in str(exc)
|
||||
else:
|
||||
raise AssertionError("expected RuntimeError")
|
||||
Reference in New Issue
Block a user