All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 16s
- 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>
61 lines
2.6 KiB
Python
61 lines
2.6 KiB
Python
"""/today, /yesterday, /week helpers in bot.py: _stats_period_bounds and _stats_skip_reason."""
|
|
from tests.bot import _env # noqa: F401 (environment before bot imports)
|
|
|
|
import unittest
|
|
from datetime import datetime, timedelta
|
|
|
|
from bot import LichessBot
|
|
from periodic import PeriodicMonitor
|
|
|
|
|
|
class PeriodBoundsTests(unittest.TestCase):
|
|
NOW = datetime(2026, 10, 20, 15, 30, 45)
|
|
MIDNIGHT = datetime(2026, 10, 20)
|
|
|
|
def test_today(self):
|
|
self.assertEqual((self.MIDNIGHT, self.NOW, True), LichessBot._stats_period_bounds("today", self.NOW))
|
|
|
|
def test_yesterday(self):
|
|
self.assertEqual((self.MIDNIGHT - timedelta(days=1), self.MIDNIGHT, True),
|
|
LichessBot._stats_period_bounds("yesterday", self.NOW))
|
|
|
|
def test_week(self):
|
|
self.assertEqual((self.MIDNIGHT - timedelta(days=6), self.NOW, False),
|
|
LichessBot._stats_period_bounds("week", self.NOW))
|
|
|
|
def test_unknown(self):
|
|
self.assertIsNone(LichessBot._stats_period_bounds("month", self.NOW))
|
|
|
|
|
|
class SkipReasonTests(unittest.TestCase):
|
|
NOW = 1_800_000_000.0
|
|
PERIOD_START = NOW - 6 * 3600
|
|
|
|
def status(self, **overrides):
|
|
base = {'disabled': False, 'not_found': False, 'seen_at': int((self.NOW - 60) * 1000),
|
|
'games_total': 10, 'checked_at': self.NOW - 60, 'missing_count': 0}
|
|
base.update(overrides)
|
|
return base
|
|
|
|
def test_table(self):
|
|
stale = PeriodicMonitor.STATUS_MAX_AGE_SECONDS + 1
|
|
cases = [
|
|
# (expected, status)
|
|
('closed', self.status(disabled=True)),
|
|
('not_found', self.status(not_found=True)),
|
|
('closed', self.status(disabled=True, not_found=True)), # closed first
|
|
('not_seen_since_period_start', self.status(seen_at=int((self.PERIOD_START - 1) * 1000))),
|
|
(None, self.status(seen_at=int((self.PERIOD_START + 1) * 1000))), # online in period
|
|
(None, None), # no status
|
|
(None, self.status(checked_at=None)),
|
|
(None, self.status(disabled=True, checked_at=self.NOW - stale)), # stale: no skip
|
|
(None, self.status(disabled=True, checked_at=self.PERIOD_START - 1)), # pre-window status
|
|
(None, self.status(seen_at=None)), # null seen_at
|
|
]
|
|
for expected, st in cases:
|
|
with self.subTest(expected=expected, status=st):
|
|
self.assertEqual(expected, LichessBot._stats_skip_reason(st, self.PERIOD_START, self.NOW))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|