|
| 1 | +#!/usr/bin/env bash |
| 2 | +# End-to-end test of the PIP-INSTALL path: build the wheel from source, install |
| 3 | +# it into the latest Hermes image, and drive a turn against a mock LLM + mock |
| 4 | +# Opik — asserting the plugin was discovered via its hermes_agent.plugins ENTRY |
| 5 | +# POINT (no plugin directory copied in) and produced the expected spans. |
| 6 | +# |
| 7 | +# Complements run_e2e.sh (which tests the directory-install path). Both install |
| 8 | +# methods are supported, so CI exercises both. No real keys; the agent has no |
| 9 | +# internet at run time. |
| 10 | +# |
| 11 | +# Run from the repo root: bash e2e/run_e2e_wheel.sh |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 15 | +NET="opik-hermes-e2e-wheel" |
| 16 | +HERMES_IMAGE="${HERMES_IMAGE:-nousresearch/hermes-agent:latest}" |
| 17 | +WORK="$(mktemp -d)" |
| 18 | +JOURNAL_DIR="$WORK/journal" |
| 19 | +HERMES_HOME="$WORK/hermes" |
| 20 | +CTX="$WORK/ctx" |
| 21 | +mkdir -p "$JOURNAL_DIR" "$HERMES_HOME" "$CTX" |
| 22 | + |
| 23 | +cleanup() { |
| 24 | + docker rm -f e2e-w-mock-llm e2e-w-mock-opik e2e-w-hermes >/dev/null 2>&1 || true |
| 25 | + docker network rm "$NET" >/dev/null 2>&1 || true |
| 26 | +} |
| 27 | +trap cleanup EXIT |
| 28 | + |
| 29 | +echo "==> pulling $HERMES_IMAGE" |
| 30 | +docker pull -q "$HERMES_IMAGE" >/dev/null |
| 31 | + |
| 32 | +# --- build the wheel from source into the docker build context --------------- |
| 33 | +echo "==> building opik-hermes wheel from source" |
| 34 | +python3 -m venv "$WORK/.venv" |
| 35 | +"$WORK/.venv/bin/pip" install -q -U build |
| 36 | +"$WORK/.venv/bin/python" -m build --wheel --outdir "$CTX/dist" "$REPO_ROOT" >/dev/null |
| 37 | +cp "$REPO_ROOT/e2e/Dockerfile.wheel" "$CTX/Dockerfile" |
| 38 | +echo "==> wheel: $(ls "$CTX/dist")" |
| 39 | + |
| 40 | +# --- build the Hermes image with the wheel pip-installed (ep assert at build) - |
| 41 | +E2E_IMAGE="opik-hermes-e2e-wheel:local" |
| 42 | +echo "==> building $E2E_IMAGE (opik-hermes pip-installed)" |
| 43 | +docker build -q --build-arg HERMES_IMAGE="$HERMES_IMAGE" \ |
| 44 | + -f "$CTX/Dockerfile" -t "$E2E_IMAGE" "$CTX" >/dev/null |
| 45 | + |
| 46 | +echo "==> private network (no internet; only mocks reachable)" |
| 47 | +docker network create "$NET" >/dev/null |
| 48 | + |
| 49 | +echo "==> mock-opik + mock-llm" |
| 50 | +docker run -d --name e2e-w-mock-opik --network "$NET" \ |
| 51 | + -e MOCK_OPIK_JOURNAL=/journal/opik-journal.jsonl -e MOCK_OPIK_PORT=5173 \ |
| 52 | + -v "$REPO_ROOT/e2e/mock_opik_server.py:/srv/s.py:ro" \ |
| 53 | + -v "$JOURNAL_DIR:/journal" \ |
| 54 | + python:3.12-slim python /srv/s.py >/dev/null |
| 55 | + |
| 56 | +docker run -d --name e2e-w-mock-llm --network "$NET" \ |
| 57 | + -e MOCK_LLM_PORT=18790 \ |
| 58 | + -v "$REPO_ROOT/e2e/mock_llm_server.py:/srv/s.py:ro" \ |
| 59 | + python:3.12-slim python /srv/s.py >/dev/null |
| 60 | + |
| 61 | +# --- Hermes home: config + .env, NO plugin dir (entry-point discovery only) -- |
| 62 | +cat > "$HERMES_HOME/config.yaml" <<YAML |
| 63 | +model: |
| 64 | + default: gpt-5 |
| 65 | + provider: openai-api |
| 66 | + base_url: http://e2e-w-mock-llm:18790/v1 |
| 67 | +providers: {} |
| 68 | +plugins: |
| 69 | + enabled: |
| 70 | + - opik |
| 71 | +agent: |
| 72 | + max_turns: 4 |
| 73 | +terminal: |
| 74 | + backend: local |
| 75 | +YAML |
| 76 | + |
| 77 | +cat > "$HERMES_HOME/.env" <<ENV |
| 78 | +OPENAI_API_KEY=mock-key |
| 79 | +OPENAI_BASE_URL=http://e2e-w-mock-llm:18790/v1 |
| 80 | +OPIK_URL_OVERRIDE=http://e2e-w-mock-opik:5173/api |
| 81 | +OPIK_PROJECT_NAME=hermes-e2e-wheel |
| 82 | +HERMES_OPIK_DEBUG=true |
| 83 | +ENV |
| 84 | +# NOTE: deliberately NO `cp observability/opik` here — the plugin must be found |
| 85 | +# via the pip entry point, which is the whole point of this path. |
| 86 | + |
| 87 | +echo "==> running one Hermes turn (plugin from pip entry point)" |
| 88 | +if command -v timeout >/dev/null 2>&1; then TIMEOUT="timeout 180"; else TIMEOUT=""; fi |
| 89 | +$TIMEOUT docker run --rm --name e2e-w-hermes --network "$NET" \ |
| 90 | + -e HERMES_UID=0 -e HERMES_GID=0 \ |
| 91 | + -v "$HERMES_HOME:/opt/data" \ |
| 92 | + "$E2E_IMAGE" \ |
| 93 | + sh -c ' |
| 94 | + hermes chat -q "Compute 2 to the power 10 and report the number." \ |
| 95 | + --provider openai-api --model gpt-5 2>&1 | tail -20 |
| 96 | + ' < /dev/null || echo "(hermes turn exited non-zero / timed out; assertion judges from the journal)" |
| 97 | + |
| 98 | +sleep 3 |
| 99 | +cp "$JOURNAL_DIR/opik-journal.jsonl" /tmp/opik-e2e-wheel-journal.jsonl 2>/dev/null || true |
| 100 | +echo "==> journal saved ($(wc -l < "$JOURNAL_DIR/opik-journal.jsonl" 2>/dev/null || echo 0) rows)" |
| 101 | + |
| 102 | +echo "==> asserting journal" |
| 103 | +MOCK_OPIK_JOURNAL="$JOURNAL_DIR/opik-journal.jsonl" python3 "$REPO_ROOT/e2e/assert_journal.py" |
0 commit comments