unit-testing

A set of Python testing rules covering unit tests, API tests, command-line tests, and workflow tests. Unit tests check small pieces of code; integration tests check how pieces work together.

In plain words
What is it for?
Use it when writing or running pytest tests for agents, FastAPI endpoints, command-line commands, and CLI integration.
Why use it?
It helps choose the right test setup and avoid known problems with event loops, mocked clients, databases, and the test server.

Cursor rule for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/eliornl/rolemule/unit-testing
Clone the repo
git clone --depth 1 https://github.com/eliornl/rolemule

Made for: Claude Code.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,389 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02389
Opus 5 $0.00000 $0.01195
Sonnet 5 $0.00000 $0.00478
Haiku 4.5 $0.00000 $0.00239

Measured yesterday against content hash 1c1dadba848d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unit-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/rules/unit-testing.mdc · 223 lines

How it starts

The opening of the file, as written. The whole thing — 223 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Testing

Approximate counts (CI suites): ~300 agent unit tests in tests/test_agents/, ~1,050 API integration tests in tests/test_api/, 364 mocked CLI tests in tests/test_cli/, 6 ASGI CLI integration tests in tests/test_cli_integration/ (run with --override-ini="addopts=").

Test Suites

CLI Tests (tests/test_cli/)

Typer CliRunner + mocked RoleMuleClient — no running server required.

make cli-test
# or:
pip install -e ".[cli]" && pytest tests/test_cli/ -v --override-ini="addopts="

CLI ASGI Integration (tests/test_cli_integration/)

Real FastAPI app + Postgres (same stack as test_api/). Run locally with DATABASE_URL set, or in CI python-tests job.

Event loop: patch_httpx_asgi in tests/test_cli_integration/conftest.py must route sync httpx.Client through httpx.ASGITransport + AsyncClient on the pytest-asyncio session loop. Do not use Starlette TestClient — after tests/test_api has run, TestClient’s private loop causes “Event loop is closed” / “Future attached to a different loop” and auth failures (AUTH_1003).

pytest tests/test_cli_integration/ -v --override-ini="addopts="

Unit Tests (tests/test_agents/)

Pure pytest, fully mocked LLM clients, no network required.

pytest tests/test_agents/ -v
pytest tests/test_agents/test_cv_optimizer_loop.py -v  # CV optimizer orchestrator + agents
pytest tests/test_agents/test_mock_interview.py -v     # practice interview agent
pytest tests/test_agents/test_hiring_outreach.py -v  # hiring outreach agent

API Integration Tests (tests/test_api/)

Uses ASGITransport (no running server). Real test DB, mocked rate limits + LLM agents.

# Strip the coverage addopts that require the pytest-cov plugin:
pytest tests/test_api/ -v --override-ini="addopts="
pytest tests/test_api/test_auth.py -v           # auth endpoints
pytest tests/test_api/test_career_tools.py -v   # 6 career tools
pytest tests/test_api/test_extension_autofill.py -v  # extension POST /extension/autofill/map
pytest tests/test_api/test_interview_prep.py     # interview prep
pytest tests/test_api/test_mock_interview.py     # practice / mock interview
pytest tests/test_api/test_hiring_outreach.py    # hiring outreach
pytest tests/test_api/test_cv_optimizer.py       # CV optimizer (ownership-before-cache, cache unwrap)
pytest tests/test_api/test_workflow.py           # workflow trigger/status; duplicate start → RES_3002 (409); duplicate start → RES_3002 (409)
pytest tests/test_api/test_profile.py            # profile/settings
pytest tests/test_api/test_applications.py       # applications list (search/sort/filter/pagination)

Read the full file on GitHub · 223 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 223 lines · 0 tokens per session scan A 1c1dadba848d

Subscribe to this mod's changes

unit-testing is a cursor rule published in the GitHub repository eliornl/rolemule (37 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,389 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other cursor rules, from other repositories

cursorrules

Agent2 is a framework for building production AI agents with typed HTTP APIs. PydanticAI handles the agent loop. Agent2 handles everything else: API, auth, pause/resume, approvals, provider routing, knowledge search.

Artesiana/agent2 · 399 tokens

product-manager

Holistic product leader who owns the full product lifecycle — from discovery and strategy through roadmap, stakeholder alignment, go-to-market, and outcome measurement. Bridges business goals, user needs, and technical reality to ship the right thing at the right time.

Treevu-ai/cli-market-world · 5,350 tokens

api-tester

Expert API testing specialist focused on comprehensive API validation, performance testing, and quality assurance across all systems and third-party integrations.

Treevu-ai/cli-market-world · 23 tokens

developer-advocate

Expert developer advocate specializing in building developer communities, creating compelling technical content, optimizing developer experience (DX), and driving platform adoption through authentic engineering engagement. Bridges product and engineering teams with external developers.

Treevu-ai/cli-market-world · 38 tokens

architectural-and-structural-rules

The project follows a layered architecture with clear separation of concerns.

mrharishkumar/fastapi-cursor-boilerplate · 559 tokens

angular-20

This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.

angular/angular · 0 tokens