forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-preflight.sh
More file actions
executable file
·184 lines (157 loc) · 5.87 KB
/
Copy pathtest-preflight.sh
File metadata and controls
executable file
·184 lines (157 loc) · 5.87 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
# test-preflight.sh — Verify environment is ready before running backend tests.
# Run this before backend/test.sh to catch missing tools, packages, and env vars.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT_DIR"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
pass=0
warn=0
fail=0
ok() { echo -e " ${GREEN}✓${NC} $1"; pass=$((pass + 1)); }
skip() { echo -e " ${YELLOW}⚠${NC} $1"; warn=$((warn + 1)); }
bad() { echo -e " ${RED}✗${NC} $1"; fail=$((fail + 1)); }
EXPECTED_PYTHON_VERSION=""
if [[ -f .python-version ]]; then
EXPECTED_PYTHON_VERSION="$(tr -d '[:space:]' < .python-version)"
fi
# ── Tools ──
echo "Tools:"
PYTHON_BIN=""
FIRST_PYTHON_BIN=""
for candidate in "${PYTHON:-}" python3 python; do
if [[ -n "$candidate" ]] && command -v "$candidate" &>/dev/null && "$candidate" -c "import sys" &>/dev/null; then
if [[ -z "$FIRST_PYTHON_BIN" ]]; then
FIRST_PYTHON_BIN="$candidate"
fi
if "$candidate" -m pytest --version &>/dev/null 2>&1; then
PYTHON_BIN="$candidate"
break
fi
fi
done
PYTHON_BIN="${PYTHON_BIN:-$FIRST_PYTHON_BIN}"
if [[ -n "$PYTHON_BIN" ]]; then
python_version="$("$PYTHON_BIN" --version 2>&1 | awk '{print $2}')"
ok "$PYTHON_BIN $python_version"
if [[ -n "$EXPECTED_PYTHON_VERSION" ]]; then
if [[ "$python_version" == "$EXPECTED_PYTHON_VERSION" ]]; then
ok "Python version matches .python-version ($EXPECTED_PYTHON_VERSION)"
else
bad "Python version mismatch: expected $EXPECTED_PYTHON_VERSION from .python-version, got $python_version from $PYTHON_BIN"
echo -e " ${YELLOW}→${NC} Run: ./scripts/sync-python-deps.sh, then PYTHON=.venv/bin/python bash test-preflight.sh"
fi
fi
else
bad "python not found"
fi
if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" -m pytest --version &>/dev/null 2>&1; then
ok "pytest $("$PYTHON_BIN" -m pytest --version 2>&1 | awk '{print $2}')"
else
bad "pytest not installed (${PYTHON_BIN:-python} -m pip install pytest)"
fi
if [[ -n "$PYTHON_BIN" ]] && PYRIGHT_PYTHON_FORCE_VERSION=1.1.403 "$PYTHON_BIN" -m pyright --version &>/dev/null 2>&1; then
ok "pyright $(PYRIGHT_PYTHON_FORCE_VERSION=1.1.403 "$PYTHON_BIN" -m pyright --version 2>&1 | head -n 1 | awk '{print $2}')"
else
bad "pyright not installed (${PYTHON_BIN:-python} -m pip install pyright)"
fi
if command -v black &>/dev/null; then
ok "black (formatter)"
else
skip "black not installed — pre-commit hook will fail (pip install black)"
fi
# ── Python packages ──
echo ""
echo "Python packages:"
missing_pkgs=()
for pkg in pydantic fastapi firebase_admin google.cloud.firestore redis deepgram_sdk openpipe pytest_asyncio fake_firestore fakeredis; do
if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" -c "import $pkg" &>/dev/null 2>&1; then
ok "$pkg"
else
missing_pkgs+=("$pkg")
skip "$pkg not importable"
fi
done
if [[ ${#missing_pkgs[@]} -gt 0 ]]; then
echo -e " ${YELLOW}→${NC} Run: ${PYTHON_BIN:-python} -m pip install -r requirements.txt"
fi
# ── Environment variables (required for unit tests) ──
echo ""
echo "Env vars (unit tests):"
# ENCRYPTION_SECRET is set by test.sh, but check if it's already in env
if [[ -n "${ENCRYPTION_SECRET:-}" ]]; then
ok "ENCRYPTION_SECRET (set in env)"
else
ok "ENCRYPTION_SECRET (set by test.sh — no action needed)"
fi
# ── Environment variables (integration tests / optional) ──
echo ""
echo "Env vars (integration — optional):"
check_env() {
local var=$1
local desc=$2
if [[ -n "${!var:-}" ]]; then
ok "$var ($desc)"
else
skip "$var not set ($desc)"
fi
}
check_env OPENAI_API_KEY "LLM calls — some integration tests skip without it"
check_env DEEPGRAM_API_KEY "STT streaming and pre-recorded transcription"
check_env ADMIN_KEY "admin endpoint tests"
check_env REDIS_DB_HOST "Redis connection (default: localhost)"
check_env REDIS_DB_PASSWORD "Redis auth"
check_env GOOGLE_APPLICATION_CREDENTIALS "Firebase/Firestore integration tests"
# ── Redis connectivity ──
echo ""
echo "Services:"
redis_host="${REDIS_DB_HOST:-localhost}"
redis_port="${REDIS_DB_PORT:-6379}"
if command -v redis-cli &>/dev/null; then
if redis-cli -h "$redis_host" -p "$redis_port" ${REDIS_DB_PASSWORD:+-a "$REDIS_DB_PASSWORD"} ping &>/dev/null 2>&1; then
ok "Redis ($redis_host:$redis_port) — connected"
else
skip "Redis ($redis_host:$redis_port) — not reachable (integration tests may fail)"
fi
else
skip "redis-cli not installed — cannot check Redis connectivity"
fi
# ── Test file sanity ──
echo ""
echo "Test files:"
test_count=$(find tests/unit -name 'test_*.py' 2>/dev/null | wc -l)
if [[ $test_count -gt 0 ]]; then
ok "$test_count unit test files found"
else
bad "No unit test files found in tests/unit/"
fi
# Check if the discovered full unit suite resolves cleanly.
if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" scripts/select_backend_unit_tests.py --all >/tmp/backend-unit-tests-preflight.txt; then
selected_test_count=$(wc -l </tmp/backend-unit-tests-preflight.txt | tr -d ' ')
ok "$selected_test_count backend unit test files selected"
else
bad "backend unit test selection failed"
fi
if [[ -n "$PYTHON_BIN" ]] && "$PYTHON_BIN" scripts/export_openapi.py --help &>/dev/null 2>&1; then
ok "OpenAPI export script is runnable"
else
bad "OpenAPI export script failed to start"
fi
# ── Summary ──
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
total=$((pass + warn + fail))
echo -e " ${GREEN}$pass passed${NC} ${YELLOW}$warn warnings${NC} ${RED}$fail failed${NC} ($total checks)"
if [[ $fail -gt 0 ]]; then
echo -e " ${RED}Fix failures above before running test.sh${NC}"
exit 1
elif [[ $warn -gt 0 ]]; then
echo -e " ${YELLOW}Warnings are optional — unit tests should still pass${NC}"
exit 0
else
echo -e " ${GREEN}All clear — ready to run test.sh${NC}"
exit 0
fi