Add offline unit test suite for chat_backend (#5)
Replaces the three scattered test modules with a `chat_backend/tests/` package covering models, DatabaseStorage, serializers, every REST endpoint, the LLM services, signals and both websocket consumers — 242 deterministic tests that run without Ollama, Chroma, SMTP or network access, plus 6 opt-in live-Ollama checks behind RUN_LIVE_OLLAMA_TESTS. A custom test runner sets SKIP_RAG_INIT and a cheap password hasher so the suite finishes in seconds and can no longer reach a model server by accident. Bugs the new tests surfaced, fixed here: - views.ConversationDetailView.post silently dropped every prompt: `import datetime` shadowed `from datetime import datetime`, so `datetime.now()` raised inside a bare except. - get_conversation_file_async in both consumers always returned None with DatabaseStorage, because `prompt.file.read` opens the blob (a DB query) during attribute access in async context. - DatabaseStorage._save crashed on str-backed ContentFile. - prompt_classifier/__init__.,py was never importable as a package init. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -44,11 +44,24 @@ uv run python manage.py runserver 0.0.0.0:8003
|
||||
|
||||
Without `DATABASE_URL` / `DB_HOST`, settings fall back to SQLite (`llm_be/db.sqlite3`).
|
||||
|
||||
Tests (skip live-Ollama classifier cases):
|
||||
Tests:
|
||||
|
||||
```bash
|
||||
cd llm_be
|
||||
SKIP_RAG_INIT=1 uv run python manage.py test
|
||||
uv run python manage.py test
|
||||
```
|
||||
|
||||
The suite is offline by default — the custom test runner
|
||||
(`llm_be/test_runner.py`) sets `SKIP_RAG_INIT=1` and a cheap password hasher, and
|
||||
LLM chains are faked, so no Ollama, Chroma, SMTP or network access is needed.
|
||||
Tests live in `llm_be/chat_backend/tests/` (models, storage, serializers, views,
|
||||
services, signals, consumers).
|
||||
|
||||
Non-deterministic checks against a real model server are opt-in:
|
||||
|
||||
```bash
|
||||
cd llm_be
|
||||
RUN_LIVE_OLLAMA_TESTS=1 uv run python manage.py test chat_backend.tests.test_live_ollama
|
||||
```
|
||||
|
||||
### Docker (dev, bundled Postgres)
|
||||
|
||||
Reference in New Issue
Block a user