Skip to content

Commit 598c9f8

Browse files
committed
update docs
1 parent eee450f commit 598c9f8

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

.cursor

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,60 @@ python manage.py migrate # Apply migrations
4646
python manage.py collectstatic # Static files
4747
```
4848

49+
### Search Index Management
50+
The search system uses three indexes: SQLite FTS5, Whoosh (Haystack), and spaCy vector embeddings.
51+
52+
```bash
53+
# Rebuild all search indexes (2-3 minutes, use for CI/deployment)
54+
pipenv run python manage.py quickindex
55+
56+
# Lower-level commands:
57+
pipenv run python manage.py buildindex --v1 --v2 # Build indexes from scratch
58+
pipenv run python manage.py indexctl pack # Pack indexes for distribution
59+
pipenv run python manage.py indexctl unpack # Unpack indexes after clone
60+
```
61+
62+
- **quickindex**: Convenience command that runs `buildindex --v1 --v2` then `indexctl pack`
63+
- Packed indexes stored in `search/indexes/` (committed to repo)
64+
- After running `quickindex`, commit `search/indexes/` and `search/index_manifest.json`
65+
- GitHub Action `rebuild_search_index.yml` can trigger index rebuilds
66+
4967
### Fixture Data Loading
5068
- Fixtures are automatically loaded by quicksetup
5169
- Data format: JSON files with Django fixture format
5270
- v2 fixtures in `data/v2/publisher/document/` structure
71+
- Each document folder contains model-specific JSON files (e.g., `Spell.json`, `SpellCastingOption.json`)
5372

54-
## Testing System (APPROVAL TESTS)
73+
### Spell Data Structure
74+
- `Spell.json` - Core spell definitions with `higher_level` text field
75+
- `SpellCastingOption.json` - Structured casting options (slot levels, damage scaling, etc.)
76+
- **Rule**: Every spell with `higher_level` text must have corresponding entries in `SpellCastingOption.json`
77+
- Casting option types: `default`, `slot_level_1` through `slot_level_9`, `player_level_5/11/17` for cantrips
5578

56-
### How Approval Tests Work
57-
The project uses **approval testing** - tests compare actual API responses against pre-approved JSON files.
79+
## Testing System
5880

59-
#### Test Structure
81+
### Test Types
82+
1. **Approval Tests** - Compare API responses against pre-approved JSON files
83+
2. **Data Integrity Tests** - Validate relationships and completeness of fixture data
84+
85+
### Test Structure
6086
- Tests in: `api_v2/tests/test_objects.py`
6187
- Approved responses: `api_v2/tests/responses/*.approved.json`
6288
- Failed test responses: `api_v2/tests/responses/*.received.json`
6389

64-
#### Running Tests
90+
### Running Tests
6591
```bash
6692
# Requires running server for integration tests
67-
python manage.py runserver 8000 &
68-
python -m pytest api_v2/tests/test_objects.py -v
93+
pipenv run python manage.py runserver 8000 &
94+
pipenv run pytest api_v2/tests/ -v
6995
pkill -f "python manage.py runserver" # Stop server
7096
```
7197

98+
### Data Integrity Tests (`TestSpellCastingOptions`)
99+
- `test_all_spells_with_higher_level_have_casting_options` - Validates every spell with `higher_level` text has casting options
100+
- `test_no_duplicate_casting_option_types` - Ensures no spell has duplicate casting option types
101+
- **When adding new spells**: If the spell has `higher_level` text, you must also add entries to `SpellCastingOption.json`
102+
72103
#### Updating Test Expectations (IMPORTANT PATTERN)
73104
When API responses change (like adding new fields):
74105

@@ -160,10 +191,13 @@ pkill -f "python manage.py runserver"
160191

161192
```bash
162193
# Full development reset
163-
python manage.py quicksetup --clean --noindex
194+
pipenv run python manage.py quicksetup --clean --noindex
195+
196+
# Run all tests
197+
pipenv run pytest api_v2/tests/ -v
164198

165199
# Run specific test
166-
python -m pytest api_v2/tests/test_objects.py::TestObjects::test_document_example -v
200+
pipenv run pytest api_v2/tests/test_objects.py::TestObjects::test_document_example -v
167201

168202
# Find fixture files
169203
find data/v2/ -name "*.json" | grep -i document
@@ -173,6 +207,7 @@ curl -s "http://localhost:8000/v2/documents/srd-2024/" | python -m json.tool
173207

174208
# Update all failing tests at once
175209
cd api_v2/tests/responses/ && for file in *.received.json; do mv "$file" "${file%.received.json}.approved.json"; done
210+
176211
```
177212

178213
## Project Conventions

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,21 @@ pipenv run python manage.py spectacular --color --file openapi-schema.yml` to bu
124124
```
125125

126126
# Contributing
127-
See [contribution guide](CONTRIBUTING.md).
127+
128+
We welcome contributions! Please join our [Discord](https://discord.gg/9RNE2rY) to coordinate with the team, or check out the [issue board](https://github.com/open5e/open5e-api/issues) to see what's being worked on.
128129
# Tests
129130
130-
Tests are located in the `api/tests` directory. These should be run before pushing new changes to the main repository. These tests require that the api is [running](##run) at `http://localhost:8000`.
131+
Tests are located in `api/tests` and `api_v2/tests`. Run them before pushing new changes. Tests require the API to be [running](##run) at `http://localhost:8000`.
131132
132133
```bash
133134
pipenv run pytest
134135
```
135136
136137
## Approval tests
137-
Approval tests are run against the approved files in `api/tests/approved_files` as `*.approved.*` . If a test fails then the recieved input will be stored in a `*.recieved.*` file. If you wish to approve the changes, replace the old approved file with the recieved file.
138+
Approval tests compare API responses against pre-approved JSON files in `api_v2/tests/responses/*.approved.json`. If a test fails, the received response is saved as `*.received.json`. To approve changes, rename the received file to replace the approved file.
139+
140+
Received files should not be committed to git.
138141
139-
Recieved files shall not be included in the git repo.
140142
141143
# Deployment
142144

0 commit comments

Comments
 (0)