Skip to content

Commit bcd3bdf

Browse files
committed
docs: add testing documentation to CONTRIBUTING.md and backend README
1 parent 94c5fdb commit bcd3bdf

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ For detailed setup instructions, refer to our [Installation Guide](https://www.s
7171
SurfSense consists of three main components:
7272

7373
- **`surfsense_backend/`** - Python/FastAPI backend service
74+
- `app/` - Main application code
75+
- `tests/` - Test suite (pytest)
76+
- `alembic/` - Database migrations
7477
- **`surfsense_web/`** - Next.js web application
78+
- `tests/` - Frontend tests (vitest)
7579
- **`surfsense_browser_extension/`** - Browser extension for data collection
7680

7781
## 🧪 Development Guidelines
@@ -98,9 +102,48 @@ refactor: improve error handling in connectors
98102
```
99103

100104
### Testing
105+
106+
We use Docker Compose to run tests with all dependencies (PostgreSQL, Redis, etc.).
107+
108+
#### Running Backend Tests
109+
110+
```bash
111+
# Start the test dependencies
112+
docker compose up -d db redis
113+
114+
# Build the backend (pytest is included in the Docker image)
115+
docker compose build backend
116+
117+
# Run all tests
118+
docker compose run --rm -e TESTING=true backend pytest tests/ -v --tb=short
119+
120+
# Run tests with coverage
121+
docker compose run --rm -e TESTING=true backend pytest tests/ -v --tb=short --cov=app --cov-report=html
122+
123+
# Run a specific test file
124+
docker compose run --rm -e TESTING=true backend pytest tests/test_celery_tasks.py -v
125+
126+
# Run tests matching a pattern
127+
docker compose run --rm -e TESTING=true backend pytest tests/ -v -k "test_slack"
128+
129+
# Stop services when done
130+
docker compose down -v
131+
```
132+
133+
#### Running Frontend Tests
134+
135+
```bash
136+
cd surfsense_web
137+
pnpm install
138+
pnpm test
139+
```
140+
141+
#### Test Guidelines
101142
- Write tests for new features and bug fixes
102143
- Ensure existing tests pass before submitting
103144
- Include integration tests for API endpoints
145+
- Use `pytest-asyncio` for async tests in the backend
146+
- Mock external services and APIs appropriately
104147

105148
### Branch Naming
106149
Use descriptive branch names:

surfsense_backend/README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# SurfSense Backend
2+
3+
Python/FastAPI backend service for SurfSense.
4+
5+
## Quick Start
6+
7+
### Prerequisites
8+
9+
- Python 3.12+
10+
- PostgreSQL with PGVector extension
11+
- Redis (for Celery task queue)
12+
- Docker & Docker Compose (recommended)
13+
14+
### Development Setup
15+
16+
1. **Clone and navigate to backend**
17+
```bash
18+
cd surfsense_backend
19+
```
20+
21+
2. **Install dependencies with UV**
22+
```bash
23+
uv sync
24+
```
25+
26+
3. **Set up environment variables**
27+
```bash
28+
cp .env.example .env
29+
# Edit .env with your configuration
30+
```
31+
32+
4. **Run database migrations**
33+
```bash
34+
uv run alembic upgrade head
35+
```
36+
37+
5. **Start the development server**
38+
```bash
39+
uv run uvicorn app.app:app --reload
40+
```
41+
42+
## Testing
43+
44+
We use pytest for testing with Docker Compose for dependencies.
45+
46+
### Running Tests
47+
48+
```bash
49+
# Start dependencies
50+
docker compose up -d db redis
51+
52+
# Run all tests
53+
docker compose run --rm -e TESTING=true backend pytest tests/ -v --tb=short
54+
55+
# Run with coverage
56+
docker compose run --rm -e TESTING=true backend pytest tests/ -v --tb=short --cov=app --cov-report=html
57+
58+
# Run specific test file
59+
docker compose run --rm -e TESTING=true backend pytest tests/test_celery_tasks.py -v
60+
61+
# Run tests matching a pattern
62+
docker compose run --rm -e TESTING=true backend pytest tests/ -v -k "test_slack"
63+
64+
# Stop services
65+
docker compose down -v
66+
```
67+
68+
### Test Categories
69+
70+
Tests are organized by markers:
71+
- `@pytest.mark.unit` - Fast, isolated unit tests
72+
- `@pytest.mark.integration` - Tests requiring external services
73+
- `@pytest.mark.slow` - Slow running tests
74+
75+
### Running Locally (without Docker)
76+
77+
```bash
78+
# Ensure PostgreSQL and Redis are running locally
79+
export TESTING=true
80+
uv run pytest tests/ -v --tb=short
81+
```
82+
83+
## Project Structure
84+
85+
```
86+
surfsense_backend/
87+
├── alembic/ # Database migrations
88+
│ ├── versions/ # Migration files
89+
│ └── env.py # Alembic configuration
90+
├── app/
91+
│ ├── __init__.py
92+
│ ├── app.py # FastAPI application
93+
│ ├── celery_app.py # Celery configuration
94+
│ ├── db.py # Database models
95+
│ ├── users.py # User authentication
96+
│ ├── agents/ # LLM agents (researcher, podcaster)
97+
│ ├── config/ # Configuration management
98+
│ ├── connectors/ # External service connectors
99+
│ ├── prompts/ # LLM prompts
100+
│ ├── retriever/ # Search and retrieval logic
101+
│ ├── routes/ # API endpoints
102+
│ ├── schemas/ # Pydantic models
103+
│ ├── services/ # Business logic services
104+
│ ├── tasks/ # Celery tasks
105+
│ └── utils/ # Utility functions
106+
├── tests/ # Test suite
107+
│ ├── conftest.py # Pytest fixtures
108+
│ ├── test_*.py # Test modules
109+
│ └── __init__.py
110+
├── Dockerfile # Container configuration
111+
├── pyproject.toml # Project dependencies
112+
├── pytest.ini # Pytest configuration
113+
└── alembic.ini # Alembic configuration
114+
```
115+
116+
## API Documentation
117+
118+
When running the development server, API documentation is available at:
119+
- Swagger UI: http://localhost:8000/docs
120+
- ReDoc: http://localhost:8000/redoc
121+
122+
## Configuration
123+
124+
Key environment variables:
125+
126+
| Variable | Description | Default |
127+
|----------|-------------|---------|
128+
| `DATABASE_URL` | PostgreSQL connection string | Required |
129+
| `CELERY_BROKER_URL` | Redis URL for Celery | Required |
130+
| `SECRET_KEY` | Application secret key | Required |
131+
| `TESTING` | Enable test mode | `false` |
132+
133+
See `.env.example` for full configuration options.
134+
135+
## Contributing
136+
137+
See [CONTRIBUTING.md](../CONTRIBUTING.md) for development guidelines.

0 commit comments

Comments
 (0)