PluginMind Docs

Testing

PluginMind’s backend ships with a comprehensive pytest suite (114 passing tests, 1 skipped). This guide helps you run and extend it.


🚀 Quick Start

Loading code snippet…
  • TESTING=1 enables safe defaults in tests/conftest.py (dummy API keys, SQLite DB).
  • The suite runs in under 3 seconds on most machines.

Need specific tests?

Loading code snippet…

🧱 Test Categories

FileFocus
tests/test_generic_processing.py/process, /analyze, session cookies, registry mocks.
tests/test_ai_service_registry.pyRegistration, metadata, health checks.
tests/test_rate_limit.pyToken bucket, overrides, concurrency.
tests/test_error_handling.pyUnified error envelopes, logging, headers.
tests/test_jwt_security.pySanitised error messages, attack vectors, PII-free logs.
tests/test_http_client.pyHTTP wrapper resilience (timeouts, retries).
tests/test_middleware.pyCORS, security headers, middleware order.

Total coverage: 114 pass / 1 skip (dynamic issuer discovery test).


🔄 Session-friendly Testing

Authentication-sensitive tests now set cookies directly:

Loading code snippet…

This mirrors the production flow (NextAuth proxy + session cookies) and keeps tests realistic.


🧰 Helpful Flags

VariableEffect
TESTING=1Enables testing shortcuts (dummy env vars, logging tweaks).
LOG_LEVEL=DEBUGEmits verbose logs for flaky-test debugging.
PYTEST_ADDOPTS="-k keyword"Run a focused subset.

📦 CI Integration

Add this to GitHub Actions:

Loading code snippet…

Optional: run scripts/smoke_backend.sh after deployment to hit /health, /ready, and /services.


🎯 Best Practices

  • Keep external calls mocked (httpx + dependency overrides) so the suite remains deterministic.
  • Add regression tests alongside new endpoints—use the existing fixtures as references.
  • Update documentation (docs2/operations/testing.md, that’s this file!) whenever you expand coverage areas.

Happy testing! ✅