Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(e2e): add Docker-based end-to-end testing infrastructure

cyh19181f794726
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 000000000..f2caa52a9
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,39 @@
+# Git
+.git
+.gitignore
+
+# Python
+__pycache__/
+*.py[cod]
+*.egg-info/
+dist/
+build/
+.eggs/
+*.egg
+.venv/
+venv/
+.env
+
+# IDE
+.idea/
+.vscode/
+.DS_Store
+
+# Tests & CI
+.pytest_cache/
+htmlcov/
+.coverage
+.tox/
+.nox/
+
+# Project
+_tmp/
+tmp/
+logs/
+.vibe_remote/
+.worktrees/
+docs/
+
+# UI (built separately or not needed for API-only testing)
+ui/node_modules/
+ui/.vite/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..c9d6584d2
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,32 @@
+# --- Build stage: install dependencies + build UI if needed ---
+FROM python:3.12-slim AS base
+
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ git \
+ && rm -rf /var/lib/apt/lists/*
+
+WORKDIR /app
+
+# Copy project files
+COPY . .
+
+# Create a minimal UI dist placeholder (pyproject.toml force-includes ui/dist)
+RUN mkdir -p ui/dist && \
+ echo '<html><body>E2E Test</body></html>' > ui/dist/index.html
+
+# hatch-vcs needs git to determine version; .git is excluded by .dockerignore.
+# Use SETUPTOOLS_SCM_PRETEND_VERSION to provide a fake version for the build.
+ARG SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0.dev0
+RUN SETUPTOOLS_SCM_PRETEND_VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION} \
+ pip install --no-cache-dir -e .
+
+# Runtime config
+ENV VIBE_REMOTE_HOME=/data/vibe_remote
+ENV PYTHONUNBUFFERED=1
+
+EXPOSE 5123
+
+COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh
+RUN chmod +x /docker-entrypoint.sh
+
+ENTRYPOINT ["/docker-entrypoint.sh"]
diff --git a/config/paths.py b/config/paths.py
index 2610a42f6..c9d912dc5 100644
--- a/config/paths.py
+++ b/config/paths.py
@@ -1,7 +1,11 @@
+import os
from pathlib import Path
def get_vibe_remote_dir() -> Path:
+ custom = os.environ.get("VIBE_REMOTE_HOME")
+ if custom:
+ return Path(custom)
return Path.home() / ".vibe_remote"
diff --git a/docker-compose.e2e.yml b/docker-compose.e2e.yml
new file mode 100644
index 000000000..ea8365c10
--- /dev/null
+++ b/docker-compose.e2e.yml
@@ -0,0 +1,19 @@
+services:
+ vibe:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ ports:
+ - "${VIBE_E2E_PORT:-15123}:5123"
+ environment:
+ - VIBE_REMOTE_HOME=/data/vibe_remote
+ - VIBE_UI_PORT=5123
+ healthcheck:
+ test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5123/health')"]
+ interval: 3s
+ timeout: 5s
+ retries: 10
+ start_period: 10s
+ # Default: UI server only (sufficient for most API tests)
+ # Override with: command: ["full"] to also start the service process
+ command: ["ui"]
diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh
new file mode 100755
index 000000000..8bd9a67c5
--- /dev/null
+++ b/scripts/docker-entrypoint.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+set -e
+
+# Ensure runtime directories exist
+python -c "from config.paths import ensure_data_dirs; ensure_data_dirs()"
+
+MODE="${1:-ui}"
+
+case "$MODE" in
+ ui)
+ # Start only the UI server (foreground) - for API E2E testing
+ echo "Starting UI server on 0.0.0.0:${VIBE_UI_PORT:-5123}..."
+ exec python -c "
+from vibe.ui_server import run_ui_server
+run_ui_server('0.0.0.0', ${VIBE_UI_PORT:-5123})
+"
+ ;;
+ full)
+ # Start service in background + UI server in foreground
+ echo "Starting service..."
+ python main.py &
+ SERVICE_PID=$!
+
+ # Write PID for runtime tracking
+ RUNTIME_DIR="${VIBE_REMOTE_HOME:-$HOME/.vibe_remote}/runtime"
+ mkdir -p "$RUNTIME_DIR"
+ echo "$SERVICE_PID" > "$RUNTIME_DIR/vibe.pid"
+
+ echo "Starting UI server on 0.0.0.0:${VIBE_UI_PORT:-5123}..."
+ python -c "
+from vibe.ui_server import run_ui_server
+run_ui_server('0.0.0.0', ${VIBE_UI_PORT:-5123})
+" &
+ UI_PID=$!
+ echo "$UI_PID" > "$RUNTIME_DIR/vibe-ui.pid"
+
+ # Wait for either process to exit
+ wait -n "$SERVICE_PID" "$UI_PID" 2>/dev/null || true
+ ;;
+ cli)
+ # Run a vibe CLI command (e.g., docker run ... cli doctor)
+ shift
+ exec vibe "$@"
+ ;;
+ exec)
+ # Run arbitrary command (for debugging)
+ shift
+ exec "$@"
+ ;;
+ *)
+ echo "Usage: docker-entrypoint.sh {ui|full|cli|exec}"
+ echo " ui - Start UI server only (default)"
+ echo " full - Start service + UI server"
+ echo " cli - Run vibe CLI command"
+ echo " exec - Run arbitrary command"
+ exit 1
+ ;;
+esac
diff --git a/scripts/run_e2e.sh b/scripts/run_e2e.sh
new file mode 100755
index 000000000..24e22d6c6
--- /dev/null
+++ b/scripts/run_e2e.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+# Run E2E tests against a Docker container.
+#
+# Usage:
+# ./scripts/run_e2e.sh # build + test + teardown
+# ./scripts/run_e2e.sh --keep # keep container running after tests (for debugging)
+# ./scripts/run_e2e.sh --down # just teardown
+
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
+COMPOSE_FILE="$REPO_ROOT/docker-compose.e2e.yml"
+
+export VIBE_E2E_PORT="${VIBE_E2E_PORT:-15123}"
+
+KEEP=false
+DOWN_ONLY=false
+
+for arg in "$@"; do
+ case "$arg" in
+ --keep) KEEP=true ;;
+ --down) DOWN_ONLY=true ;;
+ esac
+done
+
+cleanup() {
+ if [ "$KEEP" = false ]; then
+ echo "Tearing down containers..."
+ docker compose -f "$COMPOSE_FILE" down -v 2>/dev/null || true
+ else
+ echo "Keeping containers running (use --down to stop)"
+ fi
+}
+
+if [ "$DOWN_ONLY" = true ]; then
+ docker compose -f "$COMPOSE_FILE" down -v
+ exit 0
+fi
+
+# Build
+echo "Building Docker image..."
+docker compose -f "$COMPOSE_FILE" build
+
+# Start
+echo "Starting container (port $VIBE_E2E_PORT)..."
+docker compose -f "$COMPOSE_FILE" up -d
+
+# Wait for health
+echo "Waiting for container to be healthy..."
+for i in $(seq 1 30); do
+ if curl -sf "http://127.0.0.1:$VIBE_E2E_PORT/health" > /dev/null 2>&1; then
+ echo "Container is healthy!"
+ break
+ fi
+ if [ "$i" -eq 30 ]; then
+ echo "ERROR: Container did not become healthy in 30s"
+ docker compose -f "$COMPOSE_FILE" logs
+ cleanup
+ exit 1
+ fi
+ sleep 1
+done
+
+# Run tests
+echo "Running E2E tests..."
+trap cleanup EXIT
+
+pytest tests/e2e/ -v --tb=short "$@" 2>&1 | grep -v "^--keep$\|^--down$" || true
+TEST_EXIT=${PIPESTATUS[0]}
+
+exit ${TEST_EXIT:-0}
diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py
new file mode 100644
index 000000000..4d3b3f523
--- /dev/null
+++ b/tests/e2e/conftest.py
@@ -0,0 +1,85 @@
+"""E2E test fixtures: manage Docker container lifecycle."""
+
+import os
+import subprocess
+import time
+
+import pytest
+import urllib.request
+import urllib.error
+
+# E2E tests connect to the Vibe container on this port
+E2E_PORT = int(os.environ.get("VIBE_E2E_PORT", "15123"))
+E2E_BASE_URL = f"http://127.0.0.1:{E2E_PORT}"
+
+# Compose file path (relative to repo root)
+COMPOSE_FILE = os.path.join(os.path.dirname(__file__), "..", "..", "docker-compose.e2e.yml")
+
+
+def _url(path: str) -> str:
+ return f"{E2E_BASE_URL}{path}"
+
+
+def _wait_for_healthy(timeout: int = 60) -> bool:
+ """Poll /health until it responds or timeout."""
+ deadline = time.monotonic() + timeout
+ while time.monotonic() < deadline:
+ try:
+ resp = urllib.request.urlopen(_url("/health"), timeout=3)
+ if resp.status == 200:
+ return True
+ except (urllib.error.URLError, OSError):
+ pass
+ time.sleep(1)
+ return False
+
+
[email protected](scope="session")
+def vibe_container():
+ """Start Vibe container for the entire test session, tear down after."""
+ compose_file = os.path.abspath(COMPOSE_FILE)
+
+ # Build and start
+ env = os.environ.copy()
+ env["VIBE_E2E_PORT"] = str(E2E_PORT)
+
+ subprocess.run(
+ ["docker", "compose", "-f", compose_file, "build"],
+ check=True,
+ env=env,
+ capture_output=True,
+ )
+ subprocess.run(
+ ["docker", "compose", "-f", compose_file, "up", "-d"],
+ check=True,
+ env=env,
+ capture_output=True,
+ )
+
+ # Wait for healthy
+ if not _wait_for_healthy(timeout=60):
+ # Dump logs for debugging
+ logs = subprocess.run(
+ ["docker", "compose", "-f", compose_file, "logs"],
+ capture_output=True,
+ text=True,
+ env=env,
+ )
+ pytest.fail(
+ f"Vibe container did not become healthy within 60s.\nSTDOUT:\n{logs.stdout}\nSTDERR:\n{logs.stderr}"
+ )
+
+ yield E2E_BASE_URL
+
+ # Teardown
+ subprocess.run(
+ ["docker", "compose", "-f", compose_file, "down", "-v"],
+ env=env,
+ capture_output=True,
+ )
+
+
[email protected](scope="session")
+def api_url(vibe_container):
+ """Convenience: returns the base URL string."""
+ return vibe_container
diff --git a/tests/e2e/test_api.py b/tests/e2e/test_api.py
new file mode 100644
index 000000000..c59f0b445
--- /dev/null
+++ b/tests/e2e/test_api.py
@@ -0,0 +1,123 @@
+"""E2E tests: API endpoints."""
+
+import json
+import urllib.request
+
+
+def _get(url, timeout=5):
+ resp = urllib.request.urlopen(url, timeout=timeout)
+ return resp.status, json.loads(resp.read())
+
+
+def _post(url, body=None, timeout=5):
+ data = json.dumps(body or {}).encode()
+ req = urllib.request.Request(url, data=data, headers={"Content-Type": "application/json"})
+ resp = urllib.request.urlopen(req, timeout=timeout)
+ return resp.status, json.loads(resp.read())
+
+
+# Minimal valid config payload for POST /config
+_VALID_CONFIG = {
+ "mode": "self_host",
+ "runtime": {"default_cwd": "/tmp/test"},
+ "agents": {
+ "default_backend": "opencode",
+ "opencode": {"enabled": True, "cli_path": "opencode"},
+ "claude": {"enabled": False, "cli_path": "claude"},
+ "codex": {"enabled": False, "cli_path": "codex"},
+ },
+}
+
+
+class TestConfigAPI:
+ """Config CRUD via API."""
+
+ def test_post_config_creates(self, api_url):
+ """POST /config with valid payload should save and return config."""
+ status, data = _post(f"{api_url}/config", _VALID_CONFIG)
+ assert status == 200
+ assert data["mode"] == "self_host"
+ assert data["runtime"]["default_cwd"] == "/tmp/test"
+
+ def test_post_then_get_config(self, api_url):
+ """GET /config should return config after it's been created via POST."""
+ _post(f"{api_url}/config", _VALID_CONFIG)
+ status, data = _get(f"{api_url}/config")
+ assert status == 200
+ assert "mode" in data
+ assert "version" in data
+
+ def test_post_config_updates_cwd(self, api_url):
+ """POST /config should update specific fields."""
+ payload = {**_VALID_CONFIG, "runtime": {"default_cwd": "/tmp/e2e_updated"}}
+ status, data = _post(f"{api_url}/config", payload)
+ assert status == 200
+ assert data["runtime"]["default_cwd"] == "/tmp/e2e_updated"
+
+
+class TestStatusAPI:
+ """Service status endpoint."""
+
+ def test_status_returns_json(self, api_url):
+ status, data = _get(f"{api_url}/status")
+ assert status == 200
+ assert "running" in data
+
+ def test_status_shows_not_running(self, api_url):
+ """In UI-only mode, service should not be running."""
+ status, data = _get(f"{api_url}/status")
+ assert status == 200
+ # In UI-only Docker mode, the service process is not started
+ assert data["running"] is False
+
+
+class TestDoctorAPI:
+ """Doctor diagnostic endpoint."""
+
+ def test_doctor_post(self, api_url):
+ status, data = _post(f"{api_url}/doctor")
+ assert status == 200
+ assert "groups" in data
+ assert "summary" in data
+ assert "ok" in data
+
+ def test_doctor_get_after_post(self, api_url):
+ """GET /doctor should return cached results after POST /doctor."""
+ # First run doctor
+ _post(f"{api_url}/doctor")
+ # Then fetch cached result
+ status, data = _get(f"{api_url}/doctor")
+ assert status == 200
+ # Should have groups from the last run
+ assert "groups" in data
+
+
+class TestSlackManifest:
+ """Slack manifest endpoint."""
+
+ def test_get_manifest(self, api_url):
+ status, data = _get(f"{api_url}/slack/manifest")
+ assert status == 200
+ # Manifest is returned wrapped: {"manifest": "...", "ok": True}
+ assert data.get("ok") is True
+ assert "manifest" in data
+
+
+class TestBrowseAPI:
+ """Directory browsing endpoint."""
+
+ def test_browse_root(self, api_url):
+ status, data = _post(f"{api_url}/browse", {"path": "/"})
+ assert status == 200
+ # Should return directory listing info
+ assert "path" in data or "entries" in data or "dirs" in data
+
+
+class TestCLIDetect:
+ """CLI binary detection endpoint."""
+
+ def test_detect_python(self, api_url):
+ """Python should be detectable inside the container."""
+ status, data = _get(f"{api_url}/cli/detect?binary=python3")
+ assert status == 200
+ assert "found" in data or "path" in data
diff --git a/tests/e2e/test_cli.py b/tests/e2e/test_cli.py
new file mode 100644
index 000000000..6a26d6bc4
--- /dev/null
+++ b/tests/e2e/test_cli.py
@@ -0,0 +1,66 @@
+"""E2E tests: CLI commands executed inside the Docker container."""
+
+import os
+import subprocess
+
+import pytest
+
+COMPOSE_FILE = os.path.join(os.path.dirname(__file__), "..", "..", "docker-compose.e2e.yml")
+
+
+def _docker_exec(cmd: str, timeout: int = 30) -> subprocess.CompletedProcess:
+ """Run a command inside the running vibe container."""
+ compose_file = os.path.abspath(COMPOSE_FILE)
+ env = os.environ.copy()
+ env["VIBE_E2E_PORT"] = os.environ.get("VIBE_E2E_PORT", "15123")
+ return subprocess.run(
+ ["docker", "compose", "-f", compose_file, "exec", "-T", "vibe", "bash", "-c", cmd],
+ capture_output=True,
+ text=True,
+ timeout=timeout,
+ env=env,
+ )
+
+
+class TestCLIVersion:
+ """vibe version command."""
+
+ def test_version_output(self, vibe_container):
+ result = _docker_exec("vibe version")
+ assert result.returncode == 0
+ assert "vibe-remote" in result.stdout
+
+
+class TestCLIDoctor:
+ """vibe doctor command."""
+
+ def test_doctor_runs(self, vibe_container):
+ result = _docker_exec("vibe doctor")
+ # Doctor may exit 0 (all ok) or 1 (some failures) - both are valid
+ assert result.returncode in (0, 1)
+ assert "Diagnostics" in result.stdout
+
+
+class TestCLIStatus:
+ """vibe status command."""
+
+ def test_status_runs(self, vibe_container):
+ result = _docker_exec("vibe status")
+ assert result.returncode == 0
+ # Should output JSON status
+ assert "{" in result.stdout
+
+
+class TestCLIPackageInstalled:
+ """Verify the package is properly installed."""
+
+ def test_vibe_importable(self, vibe_container):
+ result = _docker_exec("python -c 'import vibe; print(vibe.__version__)'")
+ assert result.returncode == 0
+ assert result.stdout.strip() # Should print a version string
+
+ def test_config_paths_uses_env(self, vibe_container):
+ """VIBE_REMOTE_HOME env var should control the base directory."""
+ result = _docker_exec("python -c 'from config.paths import get_vibe_remote_dir; print(get_vibe_remote_dir())'")
+ assert result.returncode == 0
+ assert "/data/vibe_remote" in result.stdout
diff --git a/tests/e2e/test_health.py b/tests/e2e/test_health.py
new file mode 100644
index 000000000..eb0120928
--- /dev/null
+++ b/tests/e2e/test_health.py
@@ -0,0 +1,21 @@
+"""E2E tests: health and basic startup verification."""
+
+import json
+import urllib.request
+
+
+class TestHealth:
+ """Verify the container starts and responds."""
+
+ def test_health_endpoint(self, api_url):
+ resp = urllib.request.urlopen(f"{api_url}/health", timeout=5)
+ assert resp.status == 200
+ data = json.loads(resp.read())
+ assert data["status"] == "ok"
+
+ def test_version_endpoint(self, api_url):
+ resp = urllib.request.urlopen(f"{api_url}/version", timeout=5)
+ assert resp.status == 200
+ data = json.loads(resp.read())
+ # Version should be present (may be "0.0.0" in dev/editable mode)
+ assert "version" in data or "current" in data