reddit-media-collector/tests
Richard Nixon a2727a9ac4 chore(stability): harden runtime, observability, and test coverage
Pacote de endurecimento focado em rodar 24/7 no NAS sem surpresas.

DB / persistence
- Register a datetime adapter so Python 3.12+ stops warning about the
  deprecated default; emits "YYYY-MM-DD HH:MM:SS[.ffffff]" to preserve
  existing string-based comparisons in get_enhanced_stats.
- PRAGMA journal_mode=WAL on init (concurrency + crash safety on the
  NAS) and synchronous=NORMAL per connection (cheap, WAL-safe).
- Two composite indexes: (author, subreddit) and (media_type,
  downloaded_at) — speed up the gallery and cleanup queries.

API surface
- New /health router with no auth dep, returns booleans for db /
  ffmpeg / downloads_writable / scheduler plus the package version and
  whether Basic Auth is configured. Reachable even when
  RMC_AUTH_USER/PASS are set, so it can be wired into Container
  Manager / external monitors.
- Refactor: move require_auth() from app-level dependency to per-router
  include_router(..., dependencies=[require_auth()]); /health is the
  only route that opts out.
- Rate limit (60/min per IP+path) on every POST/PUT/DELETE in config:
  subreddits, users, blacklist.*, settings.* — protects config.yaml
  from runaway loops or spam.

Observability
- Replace silent `except Exception` in main and scheduler with
  exc_info=True logging and a new collector_status["last_error"] field
  surfaced via /api/collector/status, so a failed 3am scheduled run
  isn't invisible.
- RotatingFileHandler (10 MB × 5 backups) caps collector.log around
  60 MB on the NAS volume.

Quality
- tests/test_router_scheduler.py covers status / config (interval +
  cron) / history / run-now / collector run / individual collect
  validation. scheduler.py coverage 25% → 55%, total 55% → 58%
  (135 → 151 tests).
- Type extractors.gfycat (cast yt-dlp Any to str), removed from the
  mypy ignore list. First module destravado — pattern for the rest.

Verified locally: ruff + mypy + 151 pytest green; docker container
boots healthy in 6s; PRAGMA journal_mode reports `wal`; 70 POSTs to
/api/subreddits returned 60 OK + 10 HTTP 429.
2026-05-17 18:11:45 +01:00
..
__init__.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
conftest.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_auth.py test: cover routers, auth, rate limit, config_manager, imgur extractor 2026-05-17 11:54:40 +01:00
test_config.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_config_manager.py ci: add mypy job + pre-commit hook, tighten type annotations 2026-05-17 11:58:40 +01:00
test_database.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_downloader.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_extractors.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_extractors_imgur.py test: cover routers, auth, rate limit, config_manager, imgur extractor 2026-05-17 11:54:40 +01:00
test_main.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_rate_limit.py test: cover routers, auth, rate limit, config_manager, imgur extractor 2026-05-17 11:54:40 +01:00
test_reddit_client.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_router_config.py test: cover routers, auth, rate limit, config_manager, imgur extractor 2026-05-17 11:54:40 +01:00
test_router_favorites.py ci: add mypy job + pre-commit hook, tighten type annotations 2026-05-17 11:58:40 +01:00
test_router_media.py ci: add mypy job + pre-commit hook, tighten type annotations 2026-05-17 11:58:40 +01:00
test_router_scheduler.py chore(stability): harden runtime, observability, and test coverage 2026-05-17 18:11:45 +01:00
test_router_stats.py test: cover routers, auth, rate limit, config_manager, imgur extractor 2026-05-17 11:54:40 +01:00
test_sidecar.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00
test_web_api.py chore: checkpoint baseline (routers, tests, pyproject) 2026-05-17 11:40:35 +01:00