forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·121 lines (104 loc) · 4.49 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·121 lines (104 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# Hermetic E2E Harness — One-command entry point
#
# Usage:
# bash backend/testing/e2e/run.sh
# cd backend && bash testing/e2e/run.sh -v
# cd backend && bash testing/e2e/run.sh -k test_crud
#
# Exit code:
# 0 — all tests passed
# 1 — one or more tests failed (pytest exit code propagated)
# ---------------------------------------------------------------------------
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
REPO_ROOT="$(cd "$BACKEND_DIR/.." && pwd)"
cd "$BACKEND_DIR"
echo "=== Omi Hermetic E2E Harness ==="
echo "Working dir: $(pwd)"
# ─── Detect / activate virtual environment ──────────────────────────────
for venv_dir in "$REPO_ROOT/.venv" "$BACKEND_DIR/.venv" "$REPO_ROOT/venv" "$BACKEND_DIR/venv"; do
if [ -f "$venv_dir/bin/activate" ]; then
echo "Activating ${venv_dir}..."
# shellcheck disable=SC1090
source "$venv_dir/bin/activate"
break
fi
done
if ! command -v python >/dev/null 2>&1; then
echo "ERROR: python not found on PATH"
exit 1
fi
# ─── Verify fake dependencies are installed ───────────────────────────
python -c "import fake_firestore; import fakeredis; import pytest_httpserver; import aioresponses" 2>/dev/null || {
echo "ERROR: E2E test dependencies are not installed."
echo "Run from backend/: ./scripts/sync-python-deps.sh"
echo "Then retry: bash testing/e2e/run.sh"
exit 1
}
# ─── Verify core backend deps are installed ────────────────────────────
python -c "import fastapi; import firebase_admin; import google.cloud.firestore" 2>/dev/null || {
echo "ERROR: Backend dependencies not installed."
echo "Run from backend/: ./scripts/sync-python-deps.sh"
exit 1
}
# ─── Create temp dirs that main.py expects ─────────────────────────────
for d in _temp _samples _segments _speech_profiles; do
mkdir -p "$d" 2>/dev/null || true
done
# ─── Run pytest ────────────────────────────────────────────────────────
echo ""
echo "Running e2e tests..."
echo "================================"
# The suite exercises normal universal memory CRUD. Production manifests keep
# MEMORY_MODE=off until the operator completes the rollout proof, while this
# hermetic harness must explicitly opt into the enabled mode. Preserve an
# explicit `E2E_MEMORY_MODE=off` override so incident-fence tests can still run
# with intake paused
# without inheriting a production-oriented shell environment accidentally.
export MEMORY_MODE="${E2E_MEMORY_MODE:-read}"
if [ "$#" -eq 0 ]; then
set -- -v --tb=short
fi
# WebSocket/provider-seam regressions should fail instead of hanging forever.
# Override with E2E_PYTEST_TIMEOUT=300s when deliberately debugging a slow run.
PYTEST_TIMEOUT="${E2E_PYTEST_TIMEOUT:-120s}"
TIMEOUT_BIN=""
if command -v timeout >/dev/null 2>&1; then
TIMEOUT_BIN="$(command -v timeout)"
elif command -v gtimeout >/dev/null 2>&1; then
TIMEOUT_BIN="$(command -v gtimeout)"
fi
# tiktoken lazily downloads tokenizer data the first time a clean environment calls
# encoding_for_model(). Do this before pytest imports the hermetic socket guard so
# a cold cache does not fail as an accidental outbound network attempt.
echo "Prewarming tokenizer cache..."
python - <<'PY'
import tiktoken
tiktoken.encoding_for_model('gpt-4')
PY
set +e
if [ -n "$TIMEOUT_BIN" ]; then
"$TIMEOUT_BIN" --preserve-status --kill-after=5s "$PYTEST_TIMEOUT" python -m pytest testing/e2e/ "$@"
PYTEST_EXIT_CODE=$?
if [ $PYTEST_EXIT_CODE -eq 143 ] || [ $PYTEST_EXIT_CODE -eq 124 ]; then
echo "ERROR: e2e pytest exceeded timeout ${PYTEST_TIMEOUT}"
fi
else
echo "ERROR: GNU timeout is required so E2E_PYTEST_TIMEOUT=${PYTEST_TIMEOUT} is enforced"
if [ "$(uname -s)" = "Darwin" ]; then
echo "Install it on macOS with: brew install coreutils"
fi
PYTEST_EXIT_CODE=1
fi
set -e
echo ""
echo "================================"
if [ $PYTEST_EXIT_CODE -eq 0 ]; then
echo "✅ All e2e tests passed!"
else
echo "❌ Some e2e tests failed (exit code ${PYTEST_EXIT_CODE})"
fi
exit $PYTEST_EXIT_CODE