Skip to content

Commit b84b5bf

Browse files
committed
docs: add cursor agent instructions and rules for tests and alembic migrations
Generated-by: aiautocommit
1 parent 8ca6f7b commit b84b5bf

4 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description:
3+
globs: migrations/versions/*.py
4+
alwaysApply: false
5+
---
6+
7+
## Alembic Migrations
8+
9+
### Data Migrations
10+
11+
For migrations that include data mutation, and not only schema modifications, use this pattern to setup a session:
12+
13+
```python
14+
from alembic import op
15+
from sqlmodel import Session
16+
from activemodel.session_manager import global_session
17+
from app import log
18+
19+
def run_migration_helper():
20+
pass
21+
22+
def upgrade() -> None:
23+
session = Session(bind=op.get_bind())
24+
25+
with global_session(session):
26+
run_migration_helper()
27+
flip_point_coordinates()
28+
backfill_screening_host_data()
29+
30+
# flush before running any other operations, otherwise not all changes will persist to the transaction
31+
session.flush()
32+
```

.cursor/rules/fix-tests.mdc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
Focus on all unit + command tests. Make sure they pass and fix errors. If you run into anything very odd stop, and let me know. Mutate test code first and let me know if you think you should update application code.
8+
9+
Then, focus on integration tests in tests/integration. If an integration test fails, run it again just to be sure it wasn't a flakey test (integration tests are not deterministic). If it fails because of a visual error, check the 'tmp/test-results/playwright/' directory for a screenshot relating to the failing test that you can inspect.

.cursor/rules/general.mdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ session_id = client_secret_id.split("_secret")[0]
3737

3838
### Agent instructions
3939

40-
- When running python tests, use an already open terminal and the `pytest` binary.
40+
- Run python tests with `pytest` only. If tests fail because of a configuration or system error, do not attempt to fix and let me know. I will fix it.
4141
- If you added models, generate a migration with `just migration {add,delete,update}_model_other_description`

.cursor/rules/pytest-tests.mdc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description:
3+
globs: tests/**/*.py
4+
alwaysApply: false
5+
---
6+
## Pytest Tests
7+
8+
- Look to tests/factories.py to generate any required database state
9+
- Here's an example of how to create + persist a factory `DistributionFactory.build().save()`
10+
- Use the `faker` factory to generate emails, etc.
11+
- Do not mock or patch unless I instruct you to. Test as much of the application stack as possible in each test.

0 commit comments

Comments
 (0)