-
-
Notifications
You must be signed in to change notification settings - Fork 1k
test(backend): add unit tests for core modules #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Tests added: - test_config.py: Configuration and environment variable tests - test_schemas.py: Pydantic schema validation tests - test_validators.py: Input validation tests - test_db_models.py: SQLAlchemy model tests - test_blocknote_converter.py: BlockNote conversion tests - test_document_converters.py: Document converter tests - test_permissions.py: Permission system tests - test_rbac.py: Role-based access control tests - test_rbac_schemas.py: RBAC schema tests - test_rbac_utils.py: RBAC utility function tests These tests have minimal external dependencies and can run without a database or external services.
|
@ankitpasayat is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive unit tests for backend core modules to improve test coverage and ensure code reliability. The tests are designed to run without external dependencies like databases or services.
- Adds 10 new test files covering validators, schemas, RBAC, permissions, document converters, database models, configuration, and BlockNote conversion
- Tests validate input validation, schema serialization, access control, and utility functions
- Includes security-critical tests for RBAC and permission systems
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test_validators.py | Comprehensive tests for input validation functions including search space IDs, document IDs, connectors, modes, messages, emails, URLs, and UUIDs |
| test_schemas.py | Pydantic schema validation tests for base models, chats, chunks, documents, LLM configs, and search spaces |
| test_rbac_utils.py | Tests for RBAC utility functions including invite code generation, membership retrieval, permission checks, and ownership verification |
| test_rbac_schemas.py | Schema validation tests for RBAC models including roles, memberships, invites, and permissions |
| test_rbac.py | Security-critical tests for role-based access control, verifying permission enforcement and ownership checks |
| test_permissions.py | Tests for permission functions including has_permission, has_any_permission, has_all_permissions, and default role configurations |
| test_document_converters.py | Tests for document conversion utilities including content hashing, markdown conversion, and chunk transformation |
| test_db_models.py | Database model tests validating SQLAlchemy models, enums, and model relationships |
| test_config.py | Configuration module tests verifying environment variable handling and global LLM configurations |
| test_blocknote_converter.py | Tests for BlockNote conversion with focus on error handling, network resilience, and edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VisitedWebPageURL="https://example.com", | ||
| VisitedWebPageTitle="Example Page", | ||
| VisitedWebPageDateWithTimeInISOString="2024-01-01T00:00:00Z", | ||
| VisitedWebPageReffererURL="https://google.com", |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: "Refferer" should be "Referrer". The correct spelling has two 'r's at the end.
| VisitedWebPageURL="https://example.com", | ||
| VisitedWebPageTitle="Example Page", | ||
| VisitedWebPageDateWithTimeInISOString="2024-01-01T00:00:00Z", | ||
| VisitedWebPageReffererURL="https://google.com", |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: "Refferer" should be "Referrer". The correct spelling has two 'r's at the end.
| """ | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_non_member_cannot_access_search_space(self, mock_session, mock_user): |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing pytest fixture definitions. The test methods reference mock_session and mock_user fixtures that are not defined in this file. These fixtures should either be defined here using @pytest.fixture or imported from a conftest.py file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review by RecurseML
🔍 Review performed on 601489b..161c96d
✨ No bugs found, your code is sparkling clean
✅ Files analyzed, no issues (10)
• surfsense_backend/tests/test_blocknote_converter.py
• surfsense_backend/tests/test_config.py
• surfsense_backend/tests/test_db_models.py
• surfsense_backend/tests/test_document_converters.py
• surfsense_backend/tests/test_permissions.py
• surfsense_backend/tests/test_rbac.py
• surfsense_backend/tests/test_rbac_schemas.py
• surfsense_backend/tests/test_rbac_utils.py
• surfsense_backend/tests/test_schemas.py
• surfsense_backend/tests/test_validators.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added:
These tests have minimal external dependencies and can run without a database or external services.
Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR adds comprehensive unit test coverage for core backend modules including configuration, database models, schemas, validators, permissions, RBAC (role-based access control), and document converters. The tests are designed to run independently without requiring a database or external services, focusing on input validation, error handling, security-critical access control, and data transformation logic. All test files include detailed docstrings explaining what is being tested and why certain behaviors are critical.
⏱️ Estimated Review Time: 30-90 minutes
💡 Review Order Suggestion
surfsense_backend/tests/test_config.pysurfsense_backend/tests/test_db_models.pysurfsense_backend/tests/test_schemas.pysurfsense_backend/tests/test_validators.pysurfsense_backend/tests/test_permissions.pysurfsense_backend/tests/test_rbac_schemas.pysurfsense_backend/tests/test_rbac_utils.pysurfsense_backend/tests/test_rbac.pysurfsense_backend/tests/test_document_converters.pysurfsense_backend/tests/test_blocknote_converter.py