agentleFS
bybren-llcbybren-llc/safe-agentic-workflow/.cursor/rules/13-testing.mdc

safe-agentic-workflow / rules

Cursor rule419 starsChanged 4 months agoMITView on GitHub

Testing rules for pytest, integration tests, and E2E Docker framework.

The file

We split this 13-testing.mdc into the rules it gives an agent

8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Verify RLS context is used (no direct ORM calls)

    line 54
  2. Distinctive:

    Test both success and error paths

    line 55
  3. Distinctive:

    Test input validation errors (422)

    line 58
  4. Very specific:

    Use docker-compose.test.yml for infrastructure

    line 65
  5. Distinctive:

    Test complete user journeys

    line 66
  6. Distinctive:

    Arrange-Act-Assert: Follow the AAA pattern

    line 75
  7. Distinctive:

    RLS isolation: Verify user A cannot access user B's data

    line 77
  8. Distinctive:

    When testing a spec, map each acceptance criterion to at least one test:

    line 88

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
13-testing.mdc
---
description: "Testing rules for pytest, integration tests, and E2E Docker framework."
globs: "tests/**/*.py,tests/**"
alwaysApply: false
---

# Testing Rules

These rules apply when writing or modifying tests.

## Testing Stack

- **Unit/Integration**: pytest with pytest-asyncio
- **E2E**: Docker-based framework (`docker-compose.test.yml`)
- **Coverage**: pytest-cov

## Test Organization

```
tests/
  unit/           # Fast, isolated unit tests
  integration/    # API and database integration tests
  e2e/            # End-to-end tests (Docker required)
```

## Running Tests

```bash
# Unit tests
pytest tests/unit/

# Integration tests
pytest tests/integration/

# E2E tests
pytest tests/e2e/
# or: make test-e2e

# All tests
pytest tests/ -v

# Full CI validation
{{CI_VALIDATE_COMMAND}}
```

## Test Patterns

### API Integration Tests

See `patterns_library/testing/api-integration-test.md` for the full pattern.

Key points:
- Mock authentication for isolated testing
- Verify RLS context is used (no direct ORM calls)
- Test both success and error paths
- Test authentication failures (401)
- Test authorization failures (403)
- Test input validation errors (422)

### E2E Tests

See `patterns_library/testing/e2e-user-flow.md` for the full pattern.

Key points:
- Use `docker-compose.test.yml` for infrastructure
- Test complete user journeys
- Include login/auth setup in fixtures
- Clean up test data after each run

## Writing Good Tests

1. **Independent**: Tests must not depend on execution order
2. **Repeatable**: Same result every time, no flaky tests
3. **Clear naming**: `test_<what>_<condition>_<expected>`
4. **Arrange-Act-Assert**: Follow the AAA pattern
5. **Edge cases**: Cover boundary conditions, empty states, error paths
6. **RLS isolation**: Verify user A cannot access user B's data

## Coverage Requirements

- Business logic: Aim for high coverage
- API endpoints: All routes should have integration tests
- Security paths: Authentication and authorization MUST be tested
- Error handling: All error responses MUST be tested

## Acceptance Criteria Verification

When testing a spec, map each acceptance criterion to at least one test:

```python
# From spec: "User can create new resource"
def test_user_can_create_resource():
    ...

# From spec: "Validation shows errors for invalid input"
def test_create_resource_invalid_input_returns_422():
    ...

# From spec: "Unauthorized access returns 401"
def test_create_resource_unauthenticated_returns_401():
    ...
```

## Key References

- `patterns_library/testing/` -- Test patterns (copy-paste ready)
- `AGENTS.md` -- QAS role definition and validation commands
- `CONTRIBUTING.md` -- CI pipeline test stages

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.