Add offline unit test suite for chat_backend #12

Merged
westfarn merged 1 commits from issue-5-unit-tests into master 2026-07-26 05:00:17 -07:00
1 Commits
Author SHA1 Message Date
westfarnandCursor bb4176590c Add offline unit test suite for chat_backend (#5)
CI / test (pull_request) Successful in 10s
Unit Tests / test (pull_request) Successful in 9s
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>
2026-07-26 06:48:29 -05:00