| 1 | <!-- Parent: ../AGENTS.md --> |
| 2 | <!-- Generated: 2026-03-27 | Updated: 2026-03-27 --> |
| 3 | |
| 4 | # tests |
| 5 | |
| 6 | ## Purpose |
| 7 | Pytest test suite with 23 test modules covering all major components. Uses `pytest-asyncio` for async test support. |
| 8 | |
| 9 | ## Key Files |
| 10 | |
| 11 | | File | Description | |
| 12 | |------|-------------| |
| 13 | | `test_api_client.py` | API client request building and response parsing | |
| 14 | | `test_config_loader.py` | Config loading, merging, env overrides, cookie resolution | |
| 15 | | `test_config_validation.py` | Config validation edge cases | |
| 16 | | `test_cookie_fetcher.py` | Browser-based cookie fetching tool | |
| 17 | | `test_cookie_manager.py` | Cookie storage and validation | |
| 18 | | `test_cookie_utils.py` | Cookie parsing and sanitization helpers | |
| 19 | | `test_database.py` | SQLite history operations | |
| 20 | | `test_downloader_factory.py` | Factory URL-type to downloader mapping | |
| 21 | | `test_file_manager.py` | File path construction and writing | |
| 22 | | `test_mix_downloader.py` | Mix/collection download logic | |
| 23 | | `test_ms_token_manager.py` | MS token generation | |
| 24 | | `test_music_downloader.py` | Music download logic | |
| 25 | | `test_progress_display.py` | Rich progress display | |
| 26 | | `test_rate_limiter.py` | Rate limiting behavior | |
| 27 | | `test_retry_handler.py` | Retry with backoff | |
| 28 | | `test_transcript_manager.py` | Whisper transcription management | |
| 29 | | `test_url_parser.py` | URL classification | |
| 30 | | `test_user_downloader.py` | User content download orchestration | |
| 31 | | `test_user_downloader_modes.py` | User downloader mode integration | |
| 32 | | `test_user_mode_registry.py` | Mode strategy auto-discovery | |
| 33 | | `test_user_mode_strategies.py` | Individual strategy behavior | |
| 34 | | `test_video_downloader.py` | Video and gallery downloads | |
| 35 | | `test_xbogus.py` | Anti-bot signature generation | |
| 36 | |
| 37 | ## For AI Agents |
| 38 | |
| 39 | ### Working In This Directory |
| 40 | - Run all: `python -m pytest tests/` |
| 41 | - Run single: `python -m pytest tests/test_<module>.py -v` |
| 42 | - Async mode is `auto` — no need for `@pytest.mark.asyncio` decorators |
| 43 | - Tests use mocking extensively (`unittest.mock`, `AsyncMock`) |
| 44 | - No fixtures file (`conftest.py`) — fixtures are defined per-module |
| 45 | |
| 46 | ### Testing Requirements |
| 47 | - All new code must have corresponding tests |
| 48 | - Mock external HTTP calls (never hit real Douyin API) |
| 49 | - Use `AsyncMock` for async method mocking |
| 50 | |
| 51 | ### Common Patterns |
| 52 | - `@patch` decorators for dependency injection |
| 53 | - `AsyncMock(return_value=...)` for async API responses |
| 54 | - Direct class instantiation with mocked dependencies |
| 55 | |
| 56 | ## Dependencies |
| 57 | |
| 58 | ### External |
| 59 | - `pytest` — test runner |
| 60 | - `pytest-asyncio` — async test support |
| 61 | |
| 62 | <!-- MANUAL: --> |
| 63 |