plan-flow-skill 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/create-contract.md +468 -0
- package/.claude/commands/create-plan.md +512 -0
- package/.claude/commands/discovery-plan.md +561 -0
- package/.claude/commands/execute-plan.md +682 -0
- package/.claude/commands/review-code.md +459 -0
- package/.claude/commands/review-pr.md +651 -0
- package/.claude/commands/setup.md +1609 -0
- package/.claude/commands/write-tests.md +543 -0
- package/.claude/rules/core/allowed-patterns.md +175 -0
- package/.claude/rules/core/complexity-scoring.md +225 -0
- package/.claude/rules/core/forbidden-patterns.md +253 -0
- package/.claude/rules/languages/python-patterns.md +6 -0
- package/.claude/rules/languages/typescript-patterns.md +7 -0
- package/.claude/rules/patterns/contract-patterns.md +332 -0
- package/.claude/rules/patterns/discovery-patterns.md +342 -0
- package/.claude/rules/patterns/discovery-templates.md +319 -0
- package/.claude/rules/patterns/jest-patterns.md +482 -0
- package/.claude/rules/patterns/plans-patterns.md +225 -0
- package/.claude/rules/patterns/plans-templates.md +227 -0
- package/.claude/rules/patterns/pytest-patterns.md +457 -0
- package/.claude/rules/patterns/review-code-templates.md +305 -0
- package/.claude/rules/patterns/review-pr-patterns.md +360 -0
- package/.claude/rules/tools/auth-pr-tool.md +30 -0
- package/.claude/rules/tools/interactive-questions-tool.md +235 -0
- package/.claude/rules/tools/jest-testing-tool.md +73 -0
- package/.claude/rules/tools/plan-mode-tool.md +164 -0
- package/.claude/rules/tools/pytest-testing-tool.md +121 -0
- package/.claude/rules/tools/reference-expansion-tool.md +326 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +139 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/handlers/claude.d.ts +9 -0
- package/dist/cli/handlers/claude.d.ts.map +1 -0
- package/dist/cli/handlers/claude.js +119 -0
- package/dist/cli/handlers/claude.js.map +1 -0
- package/dist/cli/handlers/codex.d.ts +9 -0
- package/dist/cli/handlers/codex.d.ts.map +1 -0
- package/dist/cli/handlers/codex.js +100 -0
- package/dist/cli/handlers/codex.js.map +1 -0
- package/dist/cli/handlers/cursor.d.ts +8 -0
- package/dist/cli/handlers/cursor.d.ts.map +1 -0
- package/dist/cli/handlers/cursor.js +34 -0
- package/dist/cli/handlers/cursor.js.map +1 -0
- package/dist/cli/handlers/openclaw.d.ts +8 -0
- package/dist/cli/handlers/openclaw.d.ts.map +1 -0
- package/dist/cli/handlers/openclaw.js +34 -0
- package/dist/cli/handlers/openclaw.js.map +1 -0
- package/dist/cli/handlers/shared.d.ts +9 -0
- package/dist/cli/handlers/shared.d.ts.map +1 -0
- package/dist/cli/handlers/shared.js +44 -0
- package/dist/cli/handlers/shared.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +43 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/types.d.ts +26 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +5 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/utils/files.d.ts +37 -0
- package/dist/cli/utils/files.d.ts.map +1 -0
- package/dist/cli/utils/files.js +122 -0
- package/dist/cli/utils/files.js.map +1 -0
- package/dist/cli/utils/logger.d.ts +11 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +34 -0
- package/dist/cli/utils/logger.js.map +1 -0
- package/dist/cli/utils/prompts.d.ts +10 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +65 -0
- package/dist/cli/utils/prompts.js.map +1 -0
- package/dist/test/setup.d.ts +5 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/setup.js.map +1 -0
- package/package.json +63 -0
- package/rules/core/_index.mdc +89 -0
- package/rules/core/allowed-patterns.mdc +185 -0
- package/rules/core/complexity-scoring.mdc +235 -0
- package/rules/core/forbidden-patterns.mdc +263 -0
- package/rules/languages/_index.mdc +80 -0
- package/rules/languages/python-patterns.mdc +188 -0
- package/rules/languages/typescript-patterns.mdc +128 -0
- package/rules/patterns/_index.mdc +185 -0
- package/rules/patterns/contract-patterns.mdc +344 -0
- package/rules/patterns/discovery-patterns.mdc +354 -0
- package/rules/patterns/discovery-templates.mdc +329 -0
- package/rules/patterns/jest-patterns.mdc +492 -0
- package/rules/patterns/plans-patterns.mdc +237 -0
- package/rules/patterns/plans-templates.mdc +237 -0
- package/rules/patterns/pytest-patterns.mdc +467 -0
- package/rules/patterns/review-code-templates.mdc +315 -0
- package/rules/patterns/review-pr-patterns.mdc +370 -0
- package/rules/skills/_index.mdc +174 -0
- package/rules/skills/create-contract-skill.mdc +239 -0
- package/rules/skills/create-plan-skill.mdc +271 -0
- package/rules/skills/discovery-skill.mdc +295 -0
- package/rules/skills/execute-plan-skill.mdc +388 -0
- package/rules/skills/review-code-skill.mdc +308 -0
- package/rules/skills/review-pr-skill.mdc +496 -0
- package/rules/skills/setup-skill.mdc +923 -0
- package/rules/skills/write-tests-skill.mdc +294 -0
- package/rules/templates/index-template.mdc +126 -0
- package/rules/tools/_index.mdc +114 -0
- package/rules/tools/auth-pr-tool.mdc +362 -0
- package/rules/tools/interactive-questions-tool.mdc +337 -0
- package/rules/tools/jest-testing-tool.mdc +96 -0
- package/rules/tools/plan-mode-tool.mdc +229 -0
- package/rules/tools/pytest-testing-tool.mdc +144 -0
- package/rules/tools/reference-expansion-tool.mdc +338 -0
- package/skills/plan-flow/SKILL.md +109 -0
- package/skills/plan-flow/create-contract/SKILL.md +139 -0
- package/skills/plan-flow/create-plan/SKILL.md +93 -0
- package/skills/plan-flow/discovery/SKILL.md +85 -0
- package/skills/plan-flow/execute-plan/SKILL.md +89 -0
- package/skills/plan-flow/review-code/SKILL.md +100 -0
- package/skills/plan-flow/review-pr/SKILL.md +122 -0
- package/skills/plan-flow/setup/SKILL.md +73 -0
- package/skills/plan-flow/write-tests/SKILL.md +115 -0
- package/templates/shared/AGENTS.md.template +60 -0
- package/templates/shared/CLAUDE.md.template +62 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Include when Jest test commands are needed in JavaScript/TypeScript projects"
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Jest Testing Tool
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides commands and utilities for running Jest tests in JavaScript/TypeScript codebases.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This tool can be used by:
|
|
15
|
+
- Commands that write tests (e.g., `write-tests`)
|
|
16
|
+
- Skills that need to run or verify tests
|
|
17
|
+
- Any process that needs to execute Jest
|
|
18
|
+
|
|
19
|
+
## Related
|
|
20
|
+
|
|
21
|
+
For patterns and conventions on how to write Jest tests, see [`.cursor/rules/patterns/jest-patterns.mdc`](../patterns/jest-patterns.mdc).
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Running Tests
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Run all tests
|
|
29
|
+
npm run test
|
|
30
|
+
|
|
31
|
+
# Run tests in watch mode
|
|
32
|
+
npm run test -- --watch
|
|
33
|
+
|
|
34
|
+
# Run specific test file
|
|
35
|
+
npm run test -- src/commands/streamChatCommand.server.test.ts
|
|
36
|
+
|
|
37
|
+
# Run tests matching pattern
|
|
38
|
+
npm run test -- --testNamePattern="chat validation"
|
|
39
|
+
|
|
40
|
+
# Run with coverage
|
|
41
|
+
npm run test -- --coverage
|
|
42
|
+
|
|
43
|
+
# Run only changed files
|
|
44
|
+
npm run test -- --onlyChanged
|
|
45
|
+
|
|
46
|
+
# Run with verbose output
|
|
47
|
+
npm run test -- --verbose
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Coverage Commands
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Generate coverage report
|
|
56
|
+
npm run test -- --coverage
|
|
57
|
+
|
|
58
|
+
# Generate HTML coverage report
|
|
59
|
+
npm run test -- --coverage --coverageReporters="html"
|
|
60
|
+
|
|
61
|
+
# Check coverage thresholds
|
|
62
|
+
npm run test -- --coverage --coverageThreshold='{"global":{"branches":80,"functions":80,"lines":80}}'
|
|
63
|
+
|
|
64
|
+
# Coverage for specific files
|
|
65
|
+
npm run test -- --coverage --collectCoverageFrom="src/commands/**/*.ts"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Debugging Tests
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Run with Node debugger
|
|
74
|
+
node --inspect-brk node_modules/.bin/jest --runInBand
|
|
75
|
+
|
|
76
|
+
# Run single test for debugging
|
|
77
|
+
npm run test -- --runInBand --testNamePattern="specific test name"
|
|
78
|
+
|
|
79
|
+
# Show why tests are slow
|
|
80
|
+
npm run test -- --detectOpenHandles
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## CI/CD Commands
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Run in CI mode (no watch, fail on console errors)
|
|
89
|
+
npm run test -- --ci
|
|
90
|
+
|
|
91
|
+
# Run with JUnit reporter for CI
|
|
92
|
+
npm run test -- --ci --reporters=default --reporters=jest-junit
|
|
93
|
+
|
|
94
|
+
# Run with max workers for parallel execution
|
|
95
|
+
npm run test -- --maxWorkers=4
|
|
96
|
+
```
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Include when switching to Plan mode is needed for collaborative phase execution"
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Plan Mode Tool
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides a standardized way to automatically switch to Plan mode before executing implementation plan phases. This ensures collaborative design and user approval before implementation begins.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This tool is used by:
|
|
15
|
+
- Commands that execute plans (e.g., `execute-plan`)
|
|
16
|
+
- Skills that need collaborative approval before proceeding
|
|
17
|
+
- Any process that requires switching to Plan mode
|
|
18
|
+
|
|
19
|
+
**Example**: Used by the `execute-plan` command to switch to Plan mode before each phase execution.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## How to Switch to Plan Mode
|
|
24
|
+
|
|
25
|
+
**⚠️ CRITICAL INSTRUCTION**: You must **ACTUALLY CALL** the `SwitchMode` tool using the tool calling mechanism. Do NOT write text describing what you would do. Do NOT say "Switching to Plan mode" or "I will switch". **ACTUALLY INVOKE** the `SwitchMode` tool. If you cannot call the tool, use the fallback instructions provided.
|
|
26
|
+
|
|
27
|
+
**MANDATORY - AUTO-SWITCH**: Before executing **each individual phase**, **IMMEDIATELY CALL** the `SwitchMode` tool to switch to Plan mode. Do not describe switching. Do not say "Switching to Plan mode". **ACTUALLY CALL THE TOOL**. Do not ask the user if they want to switch - just call the tool:
|
|
28
|
+
|
|
29
|
+
**YOU MUST ACTUALLY CALL THIS TOOL - DO NOT JUST DESCRIBE IT**:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
SwitchMode(target_mode_id: "plan", explanation: "Phase X: [Phase Name] - Complexity: Y/10")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**CRITICAL**: You must use the tool calling mechanism to invoke `SwitchMode`. Do not write text saying you're switching. Actually make the tool call.
|
|
36
|
+
|
|
37
|
+
**DO NOT check if tools are available. DO NOT ask permission. DO NOT describe the action. Just call the tool directly.**
|
|
38
|
+
|
|
39
|
+
**Parameters**:
|
|
40
|
+
- `target_mode_id`: Always `"plan"` for Plan mode
|
|
41
|
+
- `explanation`: Brief description of why switching (include phase name and complexity)
|
|
42
|
+
|
|
43
|
+
**Example Usage**:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
// Before executing Phase 1
|
|
47
|
+
SwitchMode(target_mode_id: "plan", explanation: "Phase 1: Types and Schemas - Complexity: 3/10")
|
|
48
|
+
|
|
49
|
+
// Before executing Phase 2
|
|
50
|
+
SwitchMode(target_mode_id: "plan", explanation: "Phase 2: Backend Implementation - Complexity: 7/10")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Fallback (if SwitchMode tool not available)**:
|
|
54
|
+
If the `SwitchMode` tool is not available or the tool call fails, provide clear instructions to the user:
|
|
55
|
+
|
|
56
|
+
```markdown
|
|
57
|
+
## Switching to Plan Mode
|
|
58
|
+
|
|
59
|
+
**Action Required**: Please switch to Plan mode to proceed with this phase.
|
|
60
|
+
|
|
61
|
+
**Phase**: Phase X - [Phase Name]
|
|
62
|
+
**Complexity**: X/10
|
|
63
|
+
**Scope**: [Brief description]
|
|
64
|
+
|
|
65
|
+
Once in Plan mode, I will present the phase details and approach for your approval.
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Plan Mode Workflow
|
|
71
|
+
|
|
72
|
+
### Step 1: Automatically Switch to Plan Mode
|
|
73
|
+
|
|
74
|
+
**MANDATORY - AUTO-SWITCH**: Before each phase, **IMMEDIATELY CALL** the `SwitchMode` tool. Do not describe switching. **ACTUALLY CALL THE TOOL**.
|
|
75
|
+
|
|
76
|
+
**YOU MUST ACTUALLY CALL THIS TOOL - DO NOT JUST DESCRIBE IT**:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
SwitchMode(target_mode_id: "plan", explanation: "[Context] - [Phase/Task Name]")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Step 2: Present Phase Details
|
|
83
|
+
|
|
84
|
+
Once in Plan mode, present the phase to be executed:
|
|
85
|
+
|
|
86
|
+
```markdown
|
|
87
|
+
## Phase Execution: Phase X - [Phase Name]
|
|
88
|
+
|
|
89
|
+
**Complexity**: X/10
|
|
90
|
+
**Scope**: [Phase scope description]
|
|
91
|
+
|
|
92
|
+
### Tasks to Complete:
|
|
93
|
+
- [ ] Task 1
|
|
94
|
+
- [ ] Task 2
|
|
95
|
+
- [ ] Task 3
|
|
96
|
+
|
|
97
|
+
### Implementation Approach:
|
|
98
|
+
[Discuss the approach, patterns to follow, and any decisions needed]
|
|
99
|
+
|
|
100
|
+
### Cursor Rules Checklist:
|
|
101
|
+
- [ ] Using nullish coalescing (`??`) instead of logical OR (`||`)
|
|
102
|
+
- [ ] Using Zod schemas for API validation
|
|
103
|
+
- [ ] Following view/logic separation pattern for components
|
|
104
|
+
- [ ] Using semantic Tailwind color variables
|
|
105
|
+
- [ ] Using shadcn components instead of raw HTML elements
|
|
106
|
+
- [ ] Using `ReturnType` for view props in logic hooks
|
|
107
|
+
- [ ] Removing unused imports
|
|
108
|
+
- [ ] Using command pattern for API routes
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
**Ready to implement this phase?**
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Step 3: Wait for User Approval
|
|
116
|
+
|
|
117
|
+
The user must approve the plan before implementation begins. This is the collaborative aspect of Plan mode.
|
|
118
|
+
|
|
119
|
+
### Step 4: Implement After Approval
|
|
120
|
+
|
|
121
|
+
After user approval, proceed with implementation following the discussed approach.
|
|
122
|
+
|
|
123
|
+
### Step 5: Update Progress
|
|
124
|
+
|
|
125
|
+
Mark completed tasks in the plan file immediately after completing the phase.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## When to Use Plan Mode
|
|
130
|
+
|
|
131
|
+
### Always Switch For:
|
|
132
|
+
|
|
133
|
+
1. **Each Implementation Phase**: Before executing any phase from an implementation plan
|
|
134
|
+
2. **High Complexity Tasks**: Before tasks with complexity ≥ 7
|
|
135
|
+
3. **Critical Decisions**: Before making architectural or design decisions
|
|
136
|
+
4. **User Approval Required**: When user input is needed before proceeding
|
|
137
|
+
|
|
138
|
+
### Don't Switch For:
|
|
139
|
+
|
|
140
|
+
1. **Simple Mechanical Tasks**: Tasks with complexity ≤ 2
|
|
141
|
+
2. **Read-Only Operations**: Reading files, searching codebase
|
|
142
|
+
3. **Information Gathering**: Discovery, analysis, documentation
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Integration with Execute Plan Command
|
|
147
|
+
|
|
148
|
+
The `execute-plan` command uses this tool for each phase:
|
|
149
|
+
|
|
150
|
+
1. **Auto-switch to Plan mode** - Immediately call `SwitchMode` tool for each phase
|
|
151
|
+
2. **Present phase details** - Show scope, tasks, and approach
|
|
152
|
+
3. **Wait for approval** - Get user confirmation before proceeding
|
|
153
|
+
4. **Implement** - Execute the phase following the approved approach
|
|
154
|
+
5. **Update progress** - Mark tasks complete in plan file
|
|
155
|
+
6. **Continue** - Proceed to next phase (NO BUILD between phases)
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Benefits of Plan Mode
|
|
160
|
+
|
|
161
|
+
1. **Collaborative Design**: Discuss approach before implementation
|
|
162
|
+
2. **Risk Mitigation**: Catch issues early
|
|
163
|
+
3. **User Control**: Approve each phase before changes are made
|
|
164
|
+
4. **Better Decisions**: Time to consider alternatives and trade-offs
|
|
165
|
+
5. **Documentation**: Planning discussions serve as decision records
|
|
166
|
+
6. **Granular Progress**: Clear visibility into which phase is being worked on
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Error Handling
|
|
171
|
+
|
|
172
|
+
### If SwitchMode Tool Fails
|
|
173
|
+
|
|
174
|
+
If the `SwitchMode` tool is not available or fails:
|
|
175
|
+
|
|
176
|
+
1. **Inform the user** that manual mode switch is required
|
|
177
|
+
2. **Provide clear instructions** on how to switch
|
|
178
|
+
3. **Wait for confirmation** before proceeding
|
|
179
|
+
4. **Continue with the workflow** once in Plan mode
|
|
180
|
+
|
|
181
|
+
### If User Rejects Plan
|
|
182
|
+
|
|
183
|
+
If the user rejects the plan in Plan mode:
|
|
184
|
+
|
|
185
|
+
1. **Ask for feedback** on what needs to change
|
|
186
|
+
2. **Revise the approach** based on feedback
|
|
187
|
+
3. **Present revised plan** for approval
|
|
188
|
+
4. **Only proceed** after approval
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Example: Complete Workflow
|
|
193
|
+
|
|
194
|
+
```markdown
|
|
195
|
+
## Executing Phase 1: Types and Schemas
|
|
196
|
+
|
|
197
|
+
**Step 1**: [SwitchMode tool called - actually invoked, not described]
|
|
198
|
+
|
|
199
|
+
**Step 2**: Presenting phase details in Plan mode...
|
|
200
|
+
|
|
201
|
+
## Phase Execution: Phase 1 - Types and Schemas
|
|
202
|
+
|
|
203
|
+
**Complexity**: 3/10
|
|
204
|
+
**Scope**: Define all TypeScript types and Zod schemas needed for the feature.
|
|
205
|
+
|
|
206
|
+
### Tasks to Complete:
|
|
207
|
+
- [ ] Create type definitions in `/src/types/`
|
|
208
|
+
- [ ] Create Zod validation schemas in `/src/types/rest-inputs.ts`
|
|
209
|
+
|
|
210
|
+
### Implementation Approach:
|
|
211
|
+
- Follow existing type patterns in the codebase
|
|
212
|
+
- Use Zod for all API input validation
|
|
213
|
+
- Ensure types are exported for reuse
|
|
214
|
+
|
|
215
|
+
**Ready to implement this phase?**
|
|
216
|
+
|
|
217
|
+
**Step 3**: Waiting for user approval...
|
|
218
|
+
|
|
219
|
+
**Step 4**: User approved. Implementing...
|
|
220
|
+
|
|
221
|
+
**Step 5**: Phase complete. Updating plan file...
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Related Rules
|
|
227
|
+
|
|
228
|
+
- Plan execution patterns: `.cursor/rules/patterns/plans-patterns.mdc`
|
|
229
|
+
- Execute plan command: `.cursor/commands/execute-plan.md`
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Include when pytest commands are needed in Python projects"
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Pytest Testing Tool
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides commands and utilities for running pytest tests in Python codebases.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This tool can be used by:
|
|
15
|
+
- Commands that write tests (e.g., `write-tests`)
|
|
16
|
+
- Skills that need to run or verify tests
|
|
17
|
+
- Any process that needs to execute pytest
|
|
18
|
+
|
|
19
|
+
## Related
|
|
20
|
+
|
|
21
|
+
For patterns and conventions on how to write pytest tests, see [`.cursor/rules/patterns/pytest-patterns.mdc`](../patterns/pytest-patterns.mdc).
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Running Tests
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Run all tests
|
|
29
|
+
pytest
|
|
30
|
+
|
|
31
|
+
# Run with verbose output
|
|
32
|
+
pytest -v
|
|
33
|
+
|
|
34
|
+
# Run specific test file
|
|
35
|
+
pytest tests/test_service.py
|
|
36
|
+
|
|
37
|
+
# Run specific test class
|
|
38
|
+
pytest tests/test_service.py::TestUserService
|
|
39
|
+
|
|
40
|
+
# Run specific test
|
|
41
|
+
pytest tests/test_service.py::TestUserService::test_get_user_returns_user
|
|
42
|
+
|
|
43
|
+
# Run with coverage
|
|
44
|
+
pytest --cov=src --cov-report=html
|
|
45
|
+
|
|
46
|
+
# Run only marked tests
|
|
47
|
+
pytest -m "integration"
|
|
48
|
+
|
|
49
|
+
# Run with parallel execution
|
|
50
|
+
pytest -n auto
|
|
51
|
+
|
|
52
|
+
# Stop on first failure
|
|
53
|
+
pytest -x
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Coverage Commands
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Generate coverage report
|
|
62
|
+
pytest --cov=src
|
|
63
|
+
|
|
64
|
+
# Generate HTML coverage report
|
|
65
|
+
pytest --cov=src --cov-report=html
|
|
66
|
+
|
|
67
|
+
# Generate XML coverage report (for CI)
|
|
68
|
+
pytest --cov=src --cov-report=xml
|
|
69
|
+
|
|
70
|
+
# Check coverage thresholds
|
|
71
|
+
pytest --cov=src --cov-fail-under=80
|
|
72
|
+
|
|
73
|
+
# Coverage for specific modules
|
|
74
|
+
pytest --cov=src/mymodule --cov-report=term-missing
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Debugging Tests
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Drop into debugger on failure
|
|
83
|
+
pytest --pdb
|
|
84
|
+
|
|
85
|
+
# Drop into debugger at start of each test
|
|
86
|
+
pytest --pdb-first
|
|
87
|
+
|
|
88
|
+
# Show local variables in tracebacks
|
|
89
|
+
pytest -l
|
|
90
|
+
|
|
91
|
+
# Verbose output with full diff
|
|
92
|
+
pytest -vv
|
|
93
|
+
|
|
94
|
+
# Show print statements
|
|
95
|
+
pytest -s
|
|
96
|
+
|
|
97
|
+
# Capture no output (show all print statements)
|
|
98
|
+
pytest --capture=no
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## CI/CD Commands
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Run with JUnit XML output for CI
|
|
107
|
+
pytest --junitxml=results.xml
|
|
108
|
+
|
|
109
|
+
# Run with coverage and XML output
|
|
110
|
+
pytest --cov=src --cov-report=xml --junitxml=results.xml
|
|
111
|
+
|
|
112
|
+
# Fail if coverage drops below threshold
|
|
113
|
+
pytest --cov=src --cov-fail-under=80
|
|
114
|
+
|
|
115
|
+
# Run in parallel (requires pytest-xdist)
|
|
116
|
+
pytest -n auto
|
|
117
|
+
|
|
118
|
+
# Rerun only failed tests
|
|
119
|
+
pytest --lf
|
|
120
|
+
|
|
121
|
+
# Rerun failed tests first, then rest
|
|
122
|
+
pytest --ff
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Test Selection
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Run tests matching a keyword expression
|
|
131
|
+
pytest -k "user and not integration"
|
|
132
|
+
|
|
133
|
+
# Run tests matching a marker
|
|
134
|
+
pytest -m "slow"
|
|
135
|
+
|
|
136
|
+
# Run tests in a specific directory
|
|
137
|
+
pytest tests/unit/
|
|
138
|
+
|
|
139
|
+
# Run tests that failed in the last run
|
|
140
|
+
pytest --lf
|
|
141
|
+
|
|
142
|
+
# Run tests in random order (requires pytest-random-order)
|
|
143
|
+
pytest --random-order
|
|
144
|
+
```
|