Files

82 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VIDEO_ID="jNQXAC9IVRw"
# 1. Auto-detect and configure proxy
PROXY_DETECTED=false
if nc -z 127.0.0.1 7890 >/dev/null 2>&1; then
echo "=== Auto-detected local proxy on port 7890. Enabling SOCKS5 proxy... ==="
export http_proxy=socks5://127.0.0.1:7890
export https_proxy=socks5://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
export HTTP_PROXY=socks5://127.0.0.1:7890
export HTTPS_PROXY=socks5://127.0.0.1:7890
export ALL_PROXY=socks5://127.0.0.1:7890
PROXY_DETECTED=true
elif [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ]; then
echo "=== Using existing HTTP_PROXY env var: ${HTTP_PROXY:-$http_proxy} ==="
PROXY_DETECTED=true
fi
# 2. Set up virtual environment and install requirements if not set up
if [ ! -d "$DIR/backend/.venv" ]; then
echo "=== Initializing Python Virtual Environment ==="
python3 -m venv "$DIR/backend/.venv"
fi
"$DIR/backend/.venv/bin/pip" install -q -r "$DIR/backend/requirements.txt"
echo "=== Step 1: Running Mock Unit Tests ==="
"$DIR/backend/.venv/bin/python3" -m pytest "$DIR/backend/tests/"
# Only run live integration tests if a proxy is available (needed from China)
if [ "$PROXY_DETECTED" = true ]; then
echo ""
echo "=== Step 2: Seeding DB for Live Integration Test ==="
"$DIR/backend/.venv/bin/python3" -c "import asyncio, aiosqlite, sys; sys.path.insert(0, '$DIR/backend'); import db;
async def run():
await db.init_db()
async with aiosqlite.connect(db.DB_PATH) as conn:
await conn.execute(\"INSERT OR IGNORE INTO videos (video_id, title, url, status) VALUES ('$VIDEO_ID', 'Me at the zoo', 'https://www.youtube.com/watch?v=$VIDEO_ID', 'pending')\")
await conn.commit()
asyncio.run(run())"
echo "=== Step 3: Running Live Ingestion & AI Summarization ==="
set +e
"$DIR/backend/.venv/bin/python3" "$DIR/backend/summarizer.py" "$VIDEO_ID"
SUMMARIZER_EXIT=$?
set -e
echo ""
echo "=== Step 4: Verifying SQLite Database Storage ==="
"$DIR/backend/.venv/bin/python3" -c "import asyncio, aiosqlite, sys; sys.path.insert(0, '$DIR/backend'); import db;
async def run():
async with aiosqlite.connect(db.DB_PATH) as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute(\"SELECT summary FROM videos WHERE video_id = '$VIDEO_ID'\")
row = await cursor.fetchone()
if row and row['summary'] and not row['summary'].startswith('Error') and not row['summary'].startswith('Could not'):
print()
print('=============================================')
print('LIVE INTEGRATION TEST VERIFICATION: SUCCESS')
print('=============================================')
else:
print()
print('=============================================')
print('WARNING: LIVE INTEGRATION TEST COULD NOT COMPLETE')
print('YouTube blocked this request or DeepSeek is unreachable.')
print('Please ensure your proxy is active on port 7890 or export')
print('HTTP_PROXY before running.')
print('This warning is expected and did not break the build.')
print('=============================================')
asyncio.run(run())"
else
echo ""
echo "=== Skipping Live Integration Test (no proxy detected) ==="
echo "From China, YouTube API and DeepSeek require a proxy."
echo "Export HTTP_PROXY or SOCKS5 on port 7890 to enable."
echo ""
echo "=== Mock tests passed — live test skipped (OK) ==="
fi