LichessStatTgWeb/run_tests.sh
vrubelroman a7571f13c1
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 16s
v1.5.1: not-found players paused, tests in repo + CI, log-based daily summary, docs pruned
- players absent from two consecutive bulk answers (deleted/renamed on Lichess) are paused
  like closed accounts with their own notice; ❓ mark; stats service answers 404 instead
  of "0 games" for unknown users
- /getgamers table stays unmarked, a legend line under it lists closed / not-found players
- daily SUMMARY is computed from events.log (survives restarts); lichess_429 comes from the
  stats service /health, which now exposes lichess_429_24h / lichess_429_total
- admin /status reads its numbers through Database.get_admin_stats
- tests/: 36 bot + 15 service unittest cases, run_tests.sh runs them inside the real images,
  CI runs them after the build and before pushing/deploying
- docs: USER_GUIDE/about/API_DOCUMENTATION rewritten for the current code, ARCHITECTURE.md and
  two sub-READMEs removed, 7 obsolete helper scripts removed, CURRENT_STATE updated
- .claude/agents/designer.md: Telegram-aware designer role

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-21 02:48:00 +00:00

68 lines
2.8 KiB
Bash
Executable file

#!/bin/sh
# Runs the unit tests (tests/, stdlib unittest) inside the real images, with no
# network: tests/bot in the bot image, tests/service in the api image. Exit code
# is non-zero when either suite fails.
#
# Two ways to get the code under test into the container:
# default the working tree (LichessClientTG_bot/, LichessWebServices/)
# is bind-mounted read-only over /app, so local edits are
# tested without rebuilding the image;
# RUN_TESTS_FROM_IMAGE=1
# the code baked into the image is tested and only tests/ is
# copied in (docker cp). Used by the CI workflow, where the
# images were just built from the same commit and bind
# mounts from the runner are not reliable.
# tests/ lives at /tests in the container (not /app/tests: a mount point cannot
# be created inside the read-only /app mount) and is discovered with the
# top-level directory "/", so test modules import as tests.bot.* / tests.service.*
# while PYTHONPATH=/app keeps the application modules importable.
#
# BOT_IMAGE / API_IMAGE override the image names (defaults: docker-compose.yml).
set -u
cd "$(dirname "$0")" || exit 2
BOT_IMAGE="${BOT_IMAGE:-192.168.8.174:3000/vrubel/lichess-bot:latest}"
API_IMAGE="${API_IMAGE:-192.168.8.174:3000/vrubel/lichess-api:latest}"
TEST_DB_DIR=/tmp/lichess-tests
# run_suite <image> <code dir> <tests subdir> [extra docker env args...]
run_suite() {
image="$1"; code_dir="$2"; suite="$3"; shift 3
cmd="mkdir -p $TEST_DB_DIR && cd /app && python -m unittest discover -s /tests/$suite -t /"
if [ "${RUN_TESTS_FROM_IMAGE:-0}" = "1" ]; then
cid=$(docker create --network none -w /app \
-e PYTHONDONTWRITEBYTECODE=1 -e PYTHONPATH=/app "$@" \
"$image" sh -c "$cmd") || return 1
docker cp tests "$cid":/tests || { docker rm -f "$cid" >/dev/null; return 1; }
docker start -a "$cid"
rc=$?
docker rm -f "$cid" >/dev/null 2>&1
return $rc
fi
docker run --rm --network none -w /app \
-v "$PWD/$code_dir":/app:ro -v "$PWD/tests":/tests:ro \
-e PYTHONDONTWRITEBYTECODE=1 -e PYTHONPATH=/app "$@" \
"$image" sh -c "$cmd"
}
status=0
echo "=== bot tests (tests/bot) in $BOT_IMAGE"
run_suite "$BOT_IMAGE" LichessClientTG_bot bot \
-e TELEGRAM_BOT_TOKEN=123456:ABCDEF -e ADMINPANEL_TELEGRAM_BOT_TOKEN=123456:ABCDEF \
-e DATABASE_PATH=$TEST_DB_DIR/lichess_bot.db -e LOG_LEVEL=WARNING \
|| status=1
echo
echo "=== stats service tests (tests/service) in $API_IMAGE"
run_suite "$API_IMAGE" LichessWebServices service \
-e LOG_LEVEL=WARNING \
|| status=1
echo
if [ "$status" -eq 0 ]; then
echo "=== ALL TEST SUITES PASSED"
else
echo "=== TESTS FAILED (see above)" >&2
fi
exit $status