test: add unit tests for rag_service (Fixes #444)#514
Conversation
- Replace raw user_id with SHA256 hash (8-char prefix) in all log statements - Maintains audit trail capability while protecting user identifiers (PII) - Complies with GDPR/CCPA privacy requirements - Hash is deterministic for correlation without exposing PII Resolves CodeRabbit PII logging concern
…backfill Fix tenant ticket orphaning by persisting company_id on save
…ashboard feat: Real-time Support Dashboard Updates Using Supabase Realtime Channels
…y bugs on Ticket Detail page
…bles across UI and config
… with premium header
…link them in landing footer
…and style premium elements
Closes ritesh-1918#444 - Test initialization, model loading, and availability - Test context retrieval and relevance scoring - Test empty query handling - Test degraded mode behavior - Test RPC exception handling
|
@Qiu-Difeng is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughAdds a comprehensive pytest test module for ChangesRagService Unit Test Coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
backend/tests/test_rag_service.py (1)
15-16: ⚡ Quick winConsider using conftest.py for path setup instead of sys.path manipulation.
The
sys.path.insertpattern works but is not the recommended pytest approach. A cleaner solution is to createbackend/tests/conftest.pywith shared path configuration, or ensure the backend package is installable (withpyproject.tomlorsetup.py) and run tests withpip install -e ..♻️ Proposed conftest.py approach
Create
backend/tests/conftest.py:import sys import os # Add backend directory to path once for all test modules sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))Then remove lines 15-16 from this test file.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/tests/test_rag_service.py` around lines 15 - 16, Remove the ad-hoc sys.path manipulation from backend/tests/test_rag_service.py (the sys.path.insert call) and instead add a backend/tests/conftest.py that performs the shared path setup once; specifically, create conftest.py to insert the backend parent directory into sys.path (mirroring the current os.path.join(os.path.dirname(__file__), "..") logic) and then delete the sys.path.insert lines from test_rag_service.py so tests use the centralized conftest configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/tests/test_rag_service.py`:
- Around line 15-16: Remove the ad-hoc sys.path manipulation from
backend/tests/test_rag_service.py (the sys.path.insert call) and instead add a
backend/tests/conftest.py that performs the shared path setup once;
specifically, create conftest.py to insert the backend parent directory into
sys.path (mirroring the current os.path.join(os.path.dirname(__file__), "..")
logic) and then delete the sys.path.insert lines from test_rag_service.py so
tests use the centralized conftest configuration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4d8e5e46-1ed0-4687-95ae-773e6a93b860
📒 Files selected for processing (1)
backend/tests/test_rag_service.py
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 29368972 | Triggered | Supabase Service Role JWT | b460068 | scratch/test_companies.js | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
Hi @ritesh-1918! 👋 I've updated this PR to target the |
Summary
Adds comprehensive unit tests for the RAG (Retrieval-Augmented Generation) service.
Closes #444
Changes
backend/tests/test_rag_service.pywith 20 test casesTest Coverage
Initialization (3 tests)
Model Loading (7 tests)
search_knowledge_base (8 tests)
is_available (2 tests)
How to Run
cd backend python -m pytest tests/test_rag_service.py -vBounty attempt under GSSoC '26.
Summary by CodeRabbit