mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 09:28:56 +00:00
Keep preparation independent of settings and model imports while preserving root-password persistence and credential masking. Compile checked-hash bytecode during image builds and load MCP/A2A adapters on protocol requests. Reuse the core ASGI builder for desktop routes to preserve socket lifecycle and middleware. Add startup, access-check, and build regression coverage. Validation: three matched Docker boots per version reduced median HTTP readiness from 26.03s to 10.05s. 331 tests and 22 subtests passed, with one skip and two confirmed baseline failures excluded. Browser, offline embeddings, and bytecode invalidation checks passed.
182 lines
7.1 KiB
Python
182 lines
7.1 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_PACKAGES = (
|
|
PROJECT_ROOT / "docker" / "base" / "fs" / "ins" / "install_base_packages.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 sandbox-tools" 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_PACKAGES)
|
|
|
|
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 "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/prepare_assets.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")
|
|
prepare_assets = _read(PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "prepare_assets.sh")
|
|
install_playwright = _read(
|
|
PROJECT_ROOT / "docker" / "run" / "fs" / "ins" / "install_playwright.sh"
|
|
)
|
|
|
|
assert "depfix" not in install_python + requirements + install_a0 + prepare_assets + install_playwright
|
|
assert "uv pip install --no-cache --python /usr/local/bin/python -r /a0/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 "uv pip install" not in prepare_assets
|
|
assert 'bash /ins/install_playwright.sh "$@"' not in prepare_assets
|
|
assert "/usr/local/bin/python preload.py --dockerized=true" in prepare_assets
|
|
assert "pip cache purge" not in prepare_assets
|
|
assert "uv cache" not in prepare_assets
|
|
|
|
|
|
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_proot_replaces_large_engine_sidecars():
|
|
dockerfile = _read(BASE_DOCKERFILE)
|
|
assert 'COPY --from=sandbox-tools /usr/local/bin/a0-proot' in dockerfile
|
|
assert 'runsc' not in dockerfile and 'gvisor' not 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
|
|
|
|
|
|
def test_build_precompiles_with_source_validated_hashes():
|
|
for script in ("install_A0.sh", "prepare_assets.sh"):
|
|
content = _read(PROJECT_ROOT / "docker/run/fs/ins" / script)
|
|
assert "/usr/local/bin/python -m compileall -q --invalidation-mode checked-hash" in content
|