# AGENTS.md - Test Suite

## OVERVIEW
Pytest suite: 18+ test files, 5000+ lines. Auto-marked (unit/integration/asyncio) + manual markers (slow/network).

## STRUCTURE
```
tests/
├── conftest.py              # 301 lines: fixtures, markers, DB isolation, event loop
├── e2e/                     # Playwright end-to-end tests
├── test_api.py              # 627 lines — FastAPI endpoints (auto integration)
├── test_favorites.py        # 564 lines — Favorites CRUD
├── test_sonarr.py           # 513 lines — Sonarr webhook
├── test_metadata_enrichment.py  # 442 lines — Kitsu API
├── test_download_manager.py # 395 lines — Download queue
├── test_downloaders.py      # 341 lines — Provider scrapers
├── test_models.py           # 321 lines — Pydantic models
├── test_utils.py            # 246 lines — sanitize_filename, is_safe_filename
└── test_watchlist.py        # 178 lines — Auto-download watchlist
```

**Root-level tests** (legacy placement, NOT in tests/):
- `test_watchlist_simple.py`, `test_watchlist_e2e.py` — should be moved to tests/

## WHERE TO LOOK

| Need | File |
|------|------|
| All tests | `pytest` |
| Unit only | `pytest -m "unit"` |
| Integration only | `pytest -m "integration"` (test_api.py auto-marked) |
| Skip slow | `pytest -m "not slow"` |
| Download logic | `test_download_manager.py`, `test_downloaders.py` |
| API endpoints | `test_api.py` |
| Provider scrapers | `test_anime_sama_*.py`, `test_french_manga.py` |

## CONVENTIONS

**Markers** (auto-applied unless manual):
- `unit` — Default for non-api tests
- `integration` — test_api.py only
- `asyncio` — Auto-detected from coroutine functions
- `slow` — Manual: `@pytest.mark.slow`
- `network` — Manual: `@pytest.mark.network`

**DB isolation**: `conftest.py` forces `DATABASE_URL=sqlite://` in-memory. Tables auto-drop/recreate per test.

**Naming**: Files `test_*.py`, classes `Test*`, functions `test_*`.

**Config**: `pytest.ini` — asyncio_mode=auto, timeout=300s, coverage on app/.

## ANTI-PATTERNS

- Do NOT add network-dependent tests without `@pytest.mark.network`
- Do NOT add slow tests without `@pytest.mark.slow`
- Empty `except:` in `test_api.py:429,451` and `test_download_manager.py:357` — known tech debt
