mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 17:38:45 +00:00
Move tunnel, browser, document, speech and integration runtimes into plugin-owned sandboxes with lazy dependencies and instance-scoped lifecycle management. Reuse Tuxee display assets and the sandbox image's Python/Node runtimes, enable automatic Desktop login, and show elapsed time for each browser launch. Slim the outer image, use offline ONNX embeddings, and calculate sandbox storage only on demand. Include regression coverage and updated runtime documentation. Exclude local handoff notes and temporary verification artifacts from publication.
177 lines
6.9 KiB
Python
177 lines
6.9 KiB
Python
import ast
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
REQUIREMENTS = PROJECT_ROOT / "requirements.txt"
|
|
BASE_DOCKERFILE = PROJECT_ROOT / "docker" / "base" / "Dockerfile"
|
|
INSTALL_PYTHON = (
|
|
PROJECT_ROOT / "docker" / "base" / "fs" / "ins" / "install_python.sh"
|
|
)
|
|
INSTALL_PACKAGES3 = (
|
|
PROJECT_ROOT / "docker" / "base" / "fs" / "ins" / "install_base_packages3.sh"
|
|
)
|
|
SETUP_VENV = PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "setup_venv.sh"
|
|
SUPERVISOR_CONFIG = (
|
|
PROJECT_ROOT
|
|
/ "docker"
|
|
/ "run"
|
|
/ "fs"
|
|
/ "etc"
|
|
/ "supervisor"
|
|
/ "conf.d"
|
|
/ "supervisord.conf"
|
|
)
|
|
TRIGGER_SELF_UPDATE = (
|
|
PROJECT_ROOT / "docker" / "run" / "fs" / "exe" / "trigger_self_update.sh"
|
|
)
|
|
|
|
|
|
def _read(path: Path) -> str:
|
|
return path.read_text(encoding="utf-8", errors="ignore")
|
|
|
|
|
|
def test_base_image_uses_official_python_trixie_image() -> None:
|
|
dockerfile = _read(BASE_DOCKERFILE)
|
|
|
|
assert dockerfile.count("FROM ") == 3
|
|
assert "FROM debian:trixie-slim AS gvisor-package" in dockerfile
|
|
assert "FROM python:3.12-slim-trixie AS runtime" in dockerfile
|
|
assert "ENV UV_SYSTEM_PYTHON=1" in dockerfile
|
|
assert "PIP_ROOT_USER_ACTION=ignore" in dockerfile
|
|
assert "kalilinux" not in dockerfile.lower()
|
|
|
|
|
|
def test_node_and_bundled_npm_come_from_official_node_stage() -> None:
|
|
dockerfile = _read(BASE_DOCKERFILE)
|
|
install_script = _read(INSTALL_PACKAGES3)
|
|
|
|
assert "FROM node:22-trixie-slim AS node-runtime" in dockerfile
|
|
assert "COPY --from=node-runtime /usr/local/bin/node" in dockerfile
|
|
assert "COPY --from=node-runtime /usr/local/lib/node_modules" in dockerfile
|
|
assert "node --version" in install_script
|
|
assert "npm --version" in install_script
|
|
assert "apt-get install" not in install_script
|
|
assert "nodejs npm" not in install_script
|
|
|
|
|
|
def test_docker_installs_into_global_python_without_virtualenv() -> None:
|
|
install_script = _read(INSTALL_PYTHON)
|
|
assert not SETUP_VENV.exists()
|
|
assert "python -m pip install" in install_script
|
|
assert "pipx==1.16.7" in install_script.split()
|
|
assert "--no-compile" in install_script
|
|
assert "PYTHONDONTWRITEBYTECODE=1" in _read(BASE_DOCKERFILE)
|
|
assert "python3-venv" not in install_script
|
|
assert " -m venv " not in install_script
|
|
assert "bin/activate" not in install_script
|
|
|
|
|
|
def test_outer_runtime_uses_onnx_without_training_dependencies() -> None:
|
|
install_script = _read(INSTALL_PYTHON)
|
|
requirements = _read(REQUIREMENTS)
|
|
assert "torch" not in install_script
|
|
for package in ("sentence-transformers", "torch", "torchvision", "scipy", "scikit-learn", "transformers"):
|
|
assert not any(line.startswith(package + "=") for line in requirements.splitlines())
|
|
assert "onnxruntime==1.23.2" in requirements
|
|
final_pass = _read(PROJECT_ROOT / "docker/run/fs/ins/install_A02.sh")
|
|
assert final_pass.index("-m helpers.local_embeddings") < final_pass.index("preload.py")
|
|
|
|
|
|
def test_python_service_entrypoints_use_their_own_runtime() -> None:
|
|
supervisor = _read(SUPERVISOR_CONFIG)
|
|
trigger = _read(TRIGGER_SELF_UPDATE)
|
|
|
|
assert (
|
|
"command=/usr/bin/python3 /exe/supervisor_event_listener.py"
|
|
in supervisor
|
|
)
|
|
assert 'exec /usr/local/bin/python "$SCRIPT_DIR/self_update_manager.py"' in trigger
|
|
|
|
|
|
@pytest.mark.parametrize("entrypoint", ["prepare.py", "preload.py", "run_ui.py", "run_tunnel.py"])
|
|
def test_entrypoints_use_installed_dependencies_without_bootstrap(entrypoint: str) -> None:
|
|
tree = ast.parse(_read(PROJECT_ROOT / entrypoint))
|
|
imports = set()
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Import):
|
|
imports.update(alias.name.split(".")[0] for alias in node.names)
|
|
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
imports.add(node.module.split(".")[0])
|
|
assert imports.isdisjoint({"requirements", "depfix"})
|
|
assert not (PROJECT_ROOT / "requirements.py").exists()
|
|
|
|
|
|
def test_tracked_outer_docker_setup_has_no_virtualenv_or_legacy_python_runtime() -> None:
|
|
paths = [
|
|
PROJECT_ROOT / "DockerfileLocal",
|
|
*(
|
|
path
|
|
for path in (PROJECT_ROOT / "docker").rglob("*")
|
|
if path.is_file()
|
|
),
|
|
]
|
|
combined = "\n".join(_read(path) for path in paths)
|
|
|
|
for forbidden in (
|
|
"/opt/venv",
|
|
"/opt/venv-a0",
|
|
"/opt/pyenv",
|
|
"python3.13",
|
|
"setup_venv.sh",
|
|
"bin/activate",
|
|
"kalilinux/kali-rolling",
|
|
):
|
|
assert forbidden not in combined
|
|
|
|
|
|
def test_runtime_dependencies_and_playwright_use_global_python() -> None:
|
|
install_python = _read(INSTALL_PYTHON)
|
|
requirements = _read(REQUIREMENTS)
|
|
install_a0 = _read(PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "install_A0.sh")
|
|
install_a02 = _read(PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "install_A02.sh")
|
|
install_playwright = _read(
|
|
PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "install_playwright.sh"
|
|
)
|
|
|
|
assert "depfix" not in install_python + requirements + install_a0 + install_a02 + install_playwright
|
|
assert "uv pip install --no-cache --python /usr/local/bin/python -r /git/agent-zero/requirements.txt" in install_a0
|
|
assert "python -m pip install --no-cache-dir --no-compile" in install_python
|
|
assert "uv pip install" not in install_playwright
|
|
assert "patchright install" not in install_playwright
|
|
assert 'bash /ins/install_A0.sh "$@"' in install_a02
|
|
assert 'bash /ins/install_playwright.sh "$@"' not in install_a02
|
|
assert "/usr/local/bin/python /git/agent-zero/preload.py --dockerized=true" in install_a02
|
|
assert "pip cache purge" not in install_a02
|
|
assert "uv cache" not in install_a02
|
|
|
|
|
|
def test_runtime_python_launchers_use_global_python() -> None:
|
|
run_a0 = _read(PROJECT_ROOT / "docker" / "run" / "fs" / "exe" / "run_A0.sh")
|
|
run_tunnel = _read(
|
|
PROJECT_ROOT / "docker" / "run" / "fs" / "exe" / "run_tunnel_api.sh"
|
|
)
|
|
trigger_update = _read(TRIGGER_SELF_UPDATE)
|
|
|
|
assert "exec /usr/local/bin/python /exe/self_update_manager.py docker-run-ui" in run_a0
|
|
assert "python" not in run_tunnel
|
|
supervisor = _read(PROJECT_ROOT / "docker/run/fs/etc/supervisor/conf.d/supervisord.conf")
|
|
assert "program:run_tunnel_api" not in supervisor
|
|
assert 'exec /usr/local/bin/python "$SCRIPT_DIR/self_update_manager.py"' in trigger_update
|
|
for dockerfile in (PROJECT_ROOT / "DockerfileLocal", PROJECT_ROOT / "docker/run/Dockerfile"):
|
|
assert "ENV PYTHONDONTWRITEBYTECODE=1" in _read(dockerfile)
|
|
|
|
|
|
def test_runsc_process_sidecars_are_shipped():
|
|
dockerfile = _read(BASE_DOCKERFILE)
|
|
for sidecar in ("gvisor_sentry", "gvisor-sentry-prewarmer", "gvisor-proc-umounter", "runsc-fd-parking"):
|
|
assert f"/usr/bin/gvisor-bin/{sidecar} /usr/bin/gvisor-bin/{sidecar}" in dockerfile
|
|
|
|
|
|
def test_shared_numpy_and_filelock_bounds_remain_declared():
|
|
requirements = _read(REQUIREMENTS)
|
|
assert "numpy>=1.26.4,<2" in requirements
|
|
assert "filelock>=3.20.3" in requirements
|