@codeharbor/agent-playbook 0.1.0 → 0.1.2

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.
Files changed (114) hide show
  1. package/README.md +4 -2
  2. package/package.json +5 -2
  3. package/skills/api-designer/README.md +36 -0
  4. package/skills/api-designer/SKILL.md +232 -0
  5. package/skills/api-designer/references/graphql-patterns.md +12 -0
  6. package/skills/api-designer/references/rest-patterns.md +17 -0
  7. package/skills/api-designer/scripts/generate_api.py +87 -0
  8. package/skills/api-designer/scripts/validate_api.py +48 -0
  9. package/skills/api-documenter/README.md +41 -0
  10. package/skills/api-documenter/SKILL.md +209 -0
  11. package/skills/api-documenter/references/examples/README.md +3 -0
  12. package/skills/api-documenter/references/examples/openapi-example.yaml +10 -0
  13. package/skills/api-documenter/references/openapi-template.yaml +5 -0
  14. package/skills/api-documenter/scripts/generate_openapi.py +84 -0
  15. package/skills/api-documenter/scripts/validate_openapi.py +45 -0
  16. package/skills/architecting-solutions/README.md +22 -0
  17. package/skills/architecting-solutions/SKILL.md +459 -0
  18. package/skills/auto-trigger/README.md +23 -0
  19. package/skills/auto-trigger/SKILL.md +183 -0
  20. package/skills/code-reviewer/README.md +59 -0
  21. package/skills/code-reviewer/SKILL.md +220 -0
  22. package/skills/code-reviewer/references/checklist.md +80 -0
  23. package/skills/code-reviewer/references/patterns.md +226 -0
  24. package/skills/code-reviewer/references/security.md +88 -0
  25. package/skills/code-reviewer/scripts/review_checklist.py +191 -0
  26. package/skills/commit-helper/README.md +58 -0
  27. package/skills/commit-helper/SKILL.md +159 -0
  28. package/skills/commit-helper/references/conventional-commits.md +68 -0
  29. package/skills/commit-helper/references/examples.md +125 -0
  30. package/skills/commit-helper/references/scopes.md +49 -0
  31. package/skills/commit-helper/scripts/validate_commit.py +70 -0
  32. package/skills/create-pr/README.md +182 -0
  33. package/skills/create-pr/SKILL.md +340 -0
  34. package/skills/debugger/README.md +53 -0
  35. package/skills/debugger/SKILL.md +239 -0
  36. package/skills/debugger/references/checklist.md +7 -0
  37. package/skills/debugger/references/errors.md +6 -0
  38. package/skills/debugger/references/patterns.md +5 -0
  39. package/skills/debugger/scripts/debug_report.py +77 -0
  40. package/skills/deployment-engineer/README.md +40 -0
  41. package/skills/deployment-engineer/SKILL.md +242 -0
  42. package/skills/deployment-engineer/references/kubernetes.md +23 -0
  43. package/skills/deployment-engineer/references/monitoring.md +14 -0
  44. package/skills/deployment-engineer/references/pipelines.md +12 -0
  45. package/skills/deployment-engineer/scripts/generate_deploy.py +72 -0
  46. package/skills/deployment-engineer/scripts/validate_deploy.py +46 -0
  47. package/skills/documentation-engineer/README.md +41 -0
  48. package/skills/documentation-engineer/SKILL.md +164 -0
  49. package/skills/documentation-engineer/references/api-template.md +22 -0
  50. package/skills/documentation-engineer/references/readme-template.md +25 -0
  51. package/skills/documentation-engineer/references/style-guide.md +13 -0
  52. package/skills/documentation-engineer/scripts/generate_docs.py +68 -0
  53. package/skills/documentation-engineer/scripts/validate_docs.py +46 -0
  54. package/skills/figma-designer/README.md +222 -0
  55. package/skills/figma-designer/SKILL.md +407 -0
  56. package/skills/figma-designer/references/example-output.md +86 -0
  57. package/skills/performance-engineer/README.md +42 -0
  58. package/skills/performance-engineer/SKILL.md +236 -0
  59. package/skills/performance-engineer/references/checklist.md +6 -0
  60. package/skills/performance-engineer/references/monitoring.md +5 -0
  61. package/skills/performance-engineer/references/optimization.md +7 -0
  62. package/skills/performance-engineer/scripts/perf_report.py +64 -0
  63. package/skills/performance-engineer/scripts/profile.py +63 -0
  64. package/skills/planning-with-files/README.md +27 -0
  65. package/skills/planning-with-files/SKILL.md +103 -0
  66. package/skills/prd-implementation-precheck/README.md +97 -0
  67. package/skills/prd-implementation-precheck/SKILL.md +112 -0
  68. package/skills/prd-planner/README.md +102 -0
  69. package/skills/prd-planner/SKILL.md +449 -0
  70. package/skills/prd-planner/references/edge-case-analysis.md +111 -0
  71. package/skills/qa-expert/README.md +37 -0
  72. package/skills/qa-expert/SKILL.md +225 -0
  73. package/skills/qa-expert/references/gates.md +11 -0
  74. package/skills/qa-expert/references/metrics.md +6 -0
  75. package/skills/qa-expert/references/strategy.md +11 -0
  76. package/skills/qa-expert/scripts/coverage_analysis.py +61 -0
  77. package/skills/qa-expert/scripts/generate_test_plan.py +68 -0
  78. package/skills/refactoring-specialist/README.md +37 -0
  79. package/skills/refactoring-specialist/SKILL.md +283 -0
  80. package/skills/refactoring-specialist/references/checklist.md +6 -0
  81. package/skills/refactoring-specialist/references/smells.md +6 -0
  82. package/skills/refactoring-specialist/references/techniques.md +6 -0
  83. package/skills/security-auditor/README.md +48 -0
  84. package/skills/security-auditor/SKILL.md +256 -0
  85. package/skills/security-auditor/references/checklist.md +7 -0
  86. package/skills/security-auditor/references/owasp.md +12 -0
  87. package/skills/security-auditor/references/remediation.md +7 -0
  88. package/skills/security-auditor/scripts/find_secrets.py +58 -0
  89. package/skills/security-auditor/scripts/security_audit.py +64 -0
  90. package/skills/self-improving-agent/README.md +136 -0
  91. package/skills/self-improving-agent/SKILL.md +407 -0
  92. package/skills/self-improving-agent/hooks/post-bash.sh +10 -0
  93. package/skills/self-improving-agent/hooks/pre-tool.sh +10 -0
  94. package/skills/self-improving-agent/hooks/session-end.sh +4 -0
  95. package/skills/self-improving-agent/memory/semantic-patterns.json +288 -0
  96. package/skills/self-improving-agent/references/appendix.md +131 -0
  97. package/skills/self-improving-agent/templates/correction-template.md +11 -0
  98. package/skills/self-improving-agent/templates/pattern-template.md +15 -0
  99. package/skills/self-improving-agent/templates/validation-template.md +14 -0
  100. package/skills/session-logger/README.md +50 -0
  101. package/skills/session-logger/SKILL.md +156 -0
  102. package/skills/skill-router/README.md +155 -0
  103. package/skills/skill-router/SKILL.md +215 -0
  104. package/skills/test-automator/README.md +41 -0
  105. package/skills/test-automator/SKILL.md +202 -0
  106. package/skills/test-automator/references/best-practices.md +6 -0
  107. package/skills/test-automator/references/examples/README.md +3 -0
  108. package/skills/test-automator/references/examples/unit-test-example.md +8 -0
  109. package/skills/test-automator/references/mocking.md +5 -0
  110. package/skills/test-automator/scripts/coverage_report.py +59 -0
  111. package/skills/test-automator/scripts/generate_test.py +66 -0
  112. package/skills/workflow-orchestrator/README.md +20 -0
  113. package/skills/workflow-orchestrator/SKILL.md +342 -0
  114. package/src/cli.js +107 -20
@@ -0,0 +1,155 @@
1
+ # Skill Router
2
+
3
+ An intelligent routing layer for Claude Code skills that helps users find the right skill for their task.
4
+
5
+ ## Overview
6
+
7
+ The Skill Router analyzes user requests and intelligently recommends the most appropriate skill from the available catalog. It uses intent classification, semantic matching, and interactive clarification to ensure users get the help they need.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ # Create symbolic link to global skills directory
13
+ ln -s ~/Documents/code/GitHub/agent-playbook/skills/skill-router/SKILL.md ~/.claude/skills/skill-router.md
14
+ ```
15
+
16
+ ## How It Works
17
+
18
+ ```
19
+ User Request → Intent Analysis → Skill Matching → Recommendation
20
+
21
+ Interactive Clarification (if needed)
22
+ ```
23
+
24
+ ### Routing Process
25
+
26
+ 1. **Intent Analysis**: Parse user request to identify task type, context, and complexity
27
+ 2. **Skill Matching**: Match intent against available skills using keywords and semantics
28
+ 3. **Interactive Clarification**: Ask targeted questions if request is ambiguous
29
+ 4. **Recommendation**: Present the best matching skill with reasoning
30
+
31
+ ## Usage Examples
32
+
33
+ ### Direct Skill Match
34
+
35
+ ```
36
+ You: "I need to review this pull request"
37
+
38
+ Skill Router: Recommended Skill: code-reviewer
39
+ This skill is designed for reviewing PRs and code changes for quality,
40
+ security, and best practices.
41
+
42
+ Would you like me to activate this skill?
43
+ ```
44
+
45
+ ### Ambiguous Request
46
+
47
+ ```
48
+ You: "Use a skill to help with my project"
49
+
50
+ Skill Router: I'd like to understand your needs better:
51
+ - What type of task are you working on?
52
+ - Are you designing, coding, testing, or documenting?
53
+ - What's the primary goal?
54
+
55
+ [Based on your answers, I'll recommend the right skill]
56
+ ```
57
+
58
+ ### Multi-Skill Workflow
59
+
60
+ ```
61
+ You: "I'm building a new API from scratch"
62
+
63
+ Skill Router: For a complete API project, I recommend using multiple skills:
64
+
65
+ 1. api-designer - Design your API structure and endpoints
66
+ 2. api-documenter - Create OpenAPI/Swagger documentation
67
+ 3. test-automator - Set up automated API testing
68
+ 4. code-reviewer - Review your implementation
69
+
70
+ Shall we start with api-designer?
71
+ ```
72
+
73
+ ## Supported Skills
74
+
75
+ | Category | Skills |
76
+ |----------|--------|
77
+ | **Core Development** | commit-helper, code-reviewer, debugger, refactoring-specialist |
78
+ | **Documentation & Testing** | documentation-engineer, api-documenter, test-automator, qa-expert |
79
+ | **Architecture & DevOps** | api-designer, security-auditor, performance-engineer, deployment-engineer |
80
+ | **Planning & Analysis** | architecting-solutions, planning-with-files, self-improving-agent |
81
+
82
+ ## Features
83
+
84
+ - **Intent Classification**: Understands what the user wants to accomplish
85
+ - **Semantic Matching**: Finds relevant skills even with different wording
86
+ - **Interactive Guidance**: Asks clarifying questions when needed
87
+ - **Multi-Skill Orchestrations**: Suggests skill combinations for complex tasks
88
+ - **Confidence Indicators**: Shows how confident the recommendation is
89
+
90
+ ## Best Practices
91
+
92
+ ### For Users
93
+
94
+ 1. **Be specific**: "I need to write tests for my API" vs "Help with tests"
95
+ 2. **Provide context**: Mention your project type and stage
96
+ 3. **Answer clarification questions**: Helps the router find the best match
97
+ 4. **Request alternatives**: Ask "What are my options?" for multiple choices
98
+
99
+ ### For Maintainers
100
+
101
+ 1. **Update skill catalog**: Add new skills to the catalog table
102
+ 2. **Refine routing logic**: Add new patterns and keywords
103
+ 3. **Track edge cases**: Note requests that don't fit existing skills
104
+ 4. **Improve questions**: Refine clarification templates based on usage
105
+
106
+ ## Routing Patterns
107
+
108
+ | User Says | Routes To |
109
+ |-----------|-----------|
110
+ | "review my code" | code-reviewer |
111
+ | "fix this bug" | debugger |
112
+ | "write tests" | test-automator |
113
+ | "create documentation" | documentation-engineer |
114
+ | "design an API" | api-designer |
115
+ | "deploy to production" | deployment-engineer |
116
+ | "improve performance" | performance-engineer |
117
+ | "check security" | security-auditor |
118
+ | "refactor code" | refactoring-specialist |
119
+ | "commit these changes" | commit-helper |
120
+
121
+ ## Architecture
122
+
123
+ ```
124
+ ┌─────────────────────────────────────────────────────────┐
125
+ │ Skill Router │
126
+ ├─────────────────────────────────────────────────────────┤
127
+ │ │
128
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
129
+ │ │ Intent │ │ Skill │ │ Interactive │ │
130
+ │ │ Analyzer │→ │ Matcher │→ │ Clarifier │ │
131
+ │ └──────────────┘ └──────────────┘ └──────────────┘ │
132
+ │ ↓ │
133
+ │ ┌──────────────┐ │
134
+ │ │ Recommended │ │
135
+ │ │ Skill │ │
136
+ │ └──────────────┘ │
137
+ └─────────────────────────────────────────────────────────┘
138
+
139
+
140
+ ┌──────────────────┼──────────────────┐
141
+ │ │ │
142
+ ┌───▼────┐ ┌─────▼────┐ ┌──────▼───┐
143
+ │ Skill 1│ │ Skill 2 │ │ Skill N │
144
+ └────────┘ └──────────┘ └──────────┘
145
+ ```
146
+
147
+ ## References
148
+
149
+ - [AI Agent Routing: Tutorial & Best Practices](https://www.patronus.ai/ai-agent-development/ai-agent-routing)
150
+ - [Intent Recognition in Multi-Agent Systems](https://gist.github.com/mkbctrl/a35764e99fe0c8e8c00b2358f55cd7fa)
151
+ - [Multi-LLM Routing Strategies - AWS](https://aws.amazon.com/blogs/machine-learning/multi-llm-routing-strategies-for-generative-ai-applications-on-aws/)
152
+
153
+ ## License
154
+
155
+ MIT
@@ -0,0 +1,215 @@
1
+ ---
2
+ name: skill-router
3
+ description: Intelligently routes user requests to the most appropriate Claude Code skill. ALWAYS use this skill FIRST when user asks for help, mentions "skill", "which", "how to", or seems unsure about which approach to take. This is the default entry point for all skill-related requests.
4
+ allowed-tools: Read, AskUserQuestion, WebSearch, Grep
5
+ ---
6
+
7
+ # Skill Router
8
+
9
+ An intelligent router that analyzes user requests and recommends the most appropriate Claude Code skill for the task.
10
+
11
+ ## When This Skill Activates
12
+
13
+ This skill activates when you:
14
+ - Ask "which skill should I use?" or "what skill can help with...?"
15
+ - Say "use a skill" without specifying which one
16
+ - Express a need but aren't sure which skill fits
17
+ - Mention "skill router" or "help me find a skill"
18
+
19
+ ## Available Skills Catalog
20
+
21
+ ### Core Development
22
+
23
+ | Skill | Best For |
24
+ |-------|----------|
25
+ | `commit-helper` | Writing Git commit messages, formatting commits |
26
+ | `code-reviewer` | Reviewing PRs, code changes, quality checks |
27
+ | `debugger` | Diagnosing bugs, errors, unexpected behavior |
28
+ | `refactoring-specialist` | Improving code structure, reducing technical debt |
29
+
30
+ ### Design & UX
31
+
32
+ | Skill | Best For |
33
+ |-------|----------|
34
+ | `figma-designer` | Analyzing Figma designs and producing implementation-ready visual specs/PRDs |
35
+
36
+ ### Documentation & Testing
37
+
38
+ | Skill | Best For |
39
+ |-------|----------|
40
+ | `documentation-engineer` | Writing README, technical docs, code documentation |
41
+ | `api-documenter` | Creating OpenAPI/Swagger specifications |
42
+ | `test-automator` | Writing tests, setting up test frameworks |
43
+ | `qa-expert` | Test strategy, quality gates, QA processes |
44
+
45
+ ### Architecture & DevOps
46
+
47
+ | Skill | Best For |
48
+ |-------|----------|
49
+ | `api-designer` | Designing REST/GraphQL APIs, API architecture |
50
+ | `security-auditor` | Security audits, vulnerability reviews, OWASP Top 10 |
51
+ | `performance-engineer` | Performance optimization, speed analysis |
52
+ | `deployment-engineer` | CI/CD pipelines, deployment automation |
53
+
54
+ ### Planning & Analysis
55
+
56
+ | Skill | Best For |
57
+ |-------|----------|
58
+ | `architecting-solutions` | Creating PRDs, solution design, requirements analysis |
59
+ | `planning-with-files` | Multi-step task planning, persistent file-based organization |
60
+ | `self-improving-agent` | Universal self-improvement that learns from all skill experiences |
61
+
62
+ ## Routing Process
63
+
64
+ ### Step 1: Intent Analysis
65
+
66
+ Analyze the user's request to identify:
67
+ - **Task Type**: What does the user want to accomplish?
68
+ - **Context**: What is the working domain (web, mobile, data, etc.)?
69
+ - **Complexity**: Is this a simple task or complex workflow?
70
+
71
+ ### Step 2: Skill Matching
72
+
73
+ Match the identified intent to the most relevant skill(s) using:
74
+ - **Keyword matching**: Compare request keywords with skill descriptions
75
+ - **Semantic similarity**: Understand the meaning behind the request
76
+ - **Context awareness**: Consider project state and previous actions
77
+
78
+ ### Step 3: Interactive Clarification
79
+
80
+ If the request is ambiguous, guide the user with targeted questions:
81
+ - What is the primary goal?
82
+ - What type of output is expected?
83
+ - Are there specific constraints or preferences?
84
+
85
+ ### Step 4: Recommendation & Execution
86
+
87
+ Present the recommended skill with:
88
+ - Skill name and brief description
89
+ - Why it fits the current request
90
+ - Option to proceed or ask for alternatives
91
+
92
+ ## Routing Examples
93
+
94
+ ### Example 1: Clear Intent
95
+
96
+ **User:** "I need to review this pull request"
97
+
98
+ **Router Analysis:**
99
+ - Keywords: "review", "pull request"
100
+ - Intent: Code review
101
+ - **Recommendation:** `code-reviewer`
102
+
103
+ ### Example 2: Ambiguous Intent
104
+
105
+ **User:** "Use a skill to help with my project"
106
+
107
+ **Router Questions:**
108
+ 1. What type of task are you working on?
109
+ 2. Are you designing, coding, testing, or documenting?
110
+
111
+ Based on answers → Recommend appropriate skill
112
+
113
+ ### Example 3: Multi-Skill Scenario
114
+
115
+ **User:** "I'm building a new API and need help with the full workflow"
116
+
117
+ **Router Recommendation:**
118
+ Consider using multiple skills in sequence:
119
+ 1. `api-designer` - Design the API structure
120
+ 2. `api-documenter` - Document endpoints with OpenAPI
121
+ 3. `test-automator` - Set up API tests
122
+ 4. `code-reviewer` - Review implementation
123
+
124
+ ## Interactive Question Templates
125
+
126
+ When user intent is unclear, use these question patterns:
127
+
128
+ ### Goal Clarification
129
+ - "What are you trying to accomplish with this task?"
130
+ - "What would the ideal outcome look like?"
131
+
132
+ ### Domain Identification
133
+ - "What area does this relate to: development, testing, documentation, or deployment?"
134
+ - "Are you working on code, APIs, infrastructure, or something else?"
135
+
136
+ ### Stage Assessment
137
+ - "What stage are you at: planning, implementing, testing, or maintaining?"
138
+
139
+ ### Preference Confirmation
140
+ - "Do you want a quick solution or a comprehensive approach?"
141
+ - "Are there specific tools or frameworks you're using?"
142
+
143
+ ## Best Practices
144
+
145
+ ### 1. Start Broad, Then Narrow
146
+ - Begin with general category questions
147
+ - Drill down into specifics based on responses
148
+
149
+ ### 2. Explain Your Reasoning
150
+ - Tell the user why a particular skill is recommended
151
+ - Build trust through transparency
152
+
153
+ ### 3. Offer Alternatives
154
+ - Present the top recommendation
155
+ - Mention 1-2 alternatives if applicable
156
+
157
+ ### 4. Handle Edge Cases
158
+ - If no skill fits perfectly, suggest the closest match
159
+ - Offer to help without a specific skill if better
160
+
161
+ ### 5. Learn from Context
162
+ - Consider previous interactions
163
+ - Remember user preferences for future routing
164
+
165
+ ## Advanced Routing Patterns
166
+
167
+ ### Semantic Routing
168
+ Use semantic similarity when keywords don't match directly:
169
+ - "clean up my code" → `refactoring-specialist`
170
+ - "make my app faster" → `performance-engineer`
171
+ - "check for security issues" → `security-auditor`
172
+
173
+ ### Multi-Skill Orchestrations
174
+ Suggest skill combinations for complex workflows:
175
+ - **New Feature**: `architecting-solutions` → `debugger` → `code-reviewer`
176
+ - **API Project**: `api-designer` → `api-documenter` → `test-automator`
177
+ - **Production Readiness**: `security-auditor` → `performance-engineer` → `deployment-engineer`
178
+
179
+ ### Confidence Levels
180
+ Indicate confidence in recommendations:
181
+ - **High**: Direct keyword match, clear intent
182
+ - **Medium**: Semantic similarity, reasonable inference
183
+ - **Low**: Ambiguous request, clarification needed
184
+
185
+ ## Error Recovery
186
+
187
+ If the recommended skill doesn't fit:
188
+ 1. Acknowledge the mismatch
189
+ 2. Ask follow-up questions to refine understanding
190
+ 3. Provide alternative recommendations
191
+ 4. Fall back to general assistance if needed
192
+
193
+ ## Output Format
194
+
195
+ When recommending a skill, use this format:
196
+
197
+ ```markdown
198
+ ## Recommended Skill: {skill-name}
199
+
200
+ {brief description of why this skill fits}
201
+
202
+ **What it does:** {one-sentence skill description}
203
+
204
+ **Best for:** {specific use cases}
205
+
206
+ ---
207
+
208
+ Would you like me to activate this skill, or would you prefer to see other options?
209
+ ```
210
+
211
+ ## References
212
+
213
+ - [AI Agent Routing: Tutorial & Best Practices](https://www.patronus.ai/ai-agent-development/ai-agent-routing)
214
+ - [Intent Recognition and Auto-Routing in Multi-Agent Systems](https://gist.github.com/mkbctrl/a35764e99fe0c8e8c00b2358f55cd7fa)
215
+ - [Multi-LLM Routing Strategies (AWS)](https://aws.amazon.com/blogs/machine-learning/multi-llm-routing-strategies-for-generative-ai-applications-on-aws/)
@@ -0,0 +1,41 @@
1
+ # Test Automator
2
+
3
+ > A Claude Code skill for creating and maintaining automated tests.
4
+
5
+ ## Installation
6
+
7
+ This skill is part of the [agent-playbook](https://github.com/Charon-Fan/agent-playbook) collection.
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ You: Write tests for this function
13
+ You: Create test cases
14
+ You: Improve test coverage
15
+ ```
16
+
17
+ ## Testing Frameworks
18
+
19
+ | Language | Framework |
20
+ |----------|-----------|
21
+ | TypeScript/JS | Jest, Vitest, Mocha |
22
+ | Python | pytest, unittest |
23
+ | Go | testing package |
24
+ | Java | JUnit |
25
+
26
+ ## Scripts
27
+
28
+ Generate test boilerplate:
29
+ ```bash
30
+ python scripts/generate_test.py <filename>
31
+ ```
32
+
33
+ Check test coverage:
34
+ ```bash
35
+ python scripts/coverage_report.py
36
+ ```
37
+
38
+ ## Resources
39
+
40
+ - [Testing Best Practices](https://google.github.io/eng-practices/review/developer/tests.html)
41
+ - [Test Driven Development](https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530)
@@ -0,0 +1,202 @@
1
+ ---
2
+ name: test-automator
3
+ description: Test automation framework expert for creating and maintaining automated tests. Use when user asks to write tests, automate testing, or improve test coverage.
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ ---
6
+
7
+ # Test Automator
8
+
9
+ Expert in creating and maintaining automated tests for various frameworks and languages.
10
+
11
+ ## When This Skill Activates
12
+
13
+ Activates when you:
14
+ - Ask to write tests
15
+ - Mention test automation
16
+ - Request test coverage improvement
17
+ - Need to set up testing framework
18
+
19
+ ## Testing Pyramid
20
+
21
+ ```
22
+ /\
23
+ /E2E\ - Few, expensive, slow
24
+ /------\
25
+ / Integration \ - Moderate number
26
+ /--------------\
27
+ / Unit Tests \ - Many, cheap, fast
28
+ /------------------\
29
+ ```
30
+
31
+ ## Unit Testing
32
+
33
+ ### Principles
34
+ 1. **Test behavior, not implementation**
35
+ 2. **One assertion per test** (generally)
36
+ 3. **Arrange-Act-Assert** pattern
37
+ 4. **Descriptive test names**
38
+
39
+ ### Example (Jest)
40
+
41
+ ```typescript
42
+ describe('UserService', () => {
43
+ describe('createUser', () => {
44
+ it('should create a user with valid data', async () => {
45
+ // Arrange
46
+ const userData = {
47
+ name: 'John Doe',
48
+ email: 'john@example.com'
49
+ };
50
+
51
+ // Act
52
+ const user = await userService.create(userData);
53
+
54
+ // Assert
55
+ expect(user.id).toBeDefined();
56
+ expect(user.email).toBe(userData.email);
57
+ });
58
+
59
+ it('should throw error for invalid email', async () => {
60
+ // Arrange
61
+ const userData = { email: 'invalid' };
62
+
63
+ // Act & Assert
64
+ await expect(userService.create(userData))
65
+ .rejects.toThrow('Invalid email');
66
+ });
67
+ });
68
+ });
69
+ ```
70
+
71
+ ## Integration Testing
72
+
73
+ ### Principles
74
+ 1. **Test component interactions**
75
+ 2. **Use test doubles for external services**
76
+ 3. **Clean up test data**
77
+ 4. **Run in isolation**
78
+
79
+ ### Example (Supertest)
80
+
81
+ ```typescript
82
+ describe('POST /api/users', () => {
83
+ it('should create a user', async () => {
84
+ const response = await request(app)
85
+ .post('/api/users')
86
+ .send({
87
+ name: 'John Doe',
88
+ email: 'john@example.com'
89
+ })
90
+ .expect(201)
91
+ .expect((res) => {
92
+ expect(res.body.id).toBeDefined();
93
+ expect(res.body.email).toBe('john@example.com');
94
+ });
95
+ });
96
+ });
97
+ ```
98
+
99
+ ## E2E Testing
100
+
101
+ ### Principles
102
+ 1. **Test critical user flows**
103
+ 2. **Use realistic test data**
104
+ 3. **Handle async operations properly**
105
+ 4. **Clean up after tests**
106
+
107
+ ### Example (Playwright)
108
+
109
+ ```typescript
110
+ test('user can login', async ({ page }) => {
111
+ await page.goto('/login');
112
+ await page.fill('[name="email"]', 'user@example.com');
113
+ await page.fill('[name="password"]', 'password123');
114
+ await page.click('button[type="submit"]');
115
+
116
+ await expect(page).toHaveURL('/dashboard');
117
+ await expect(page.locator('h1')).toContainText('Welcome');
118
+ });
119
+ ```
120
+
121
+ ## Test Coverage
122
+
123
+ ### Coverage Goals
124
+
125
+ | Type | Target |
126
+ |------|--------|
127
+ | Lines | > 80% |
128
+ | Branches | > 75% |
129
+ | Functions | > 80% |
130
+ | Statements | > 80% |
131
+
132
+ ### Coverage Reports
133
+
134
+ ```bash
135
+ # Jest
136
+ npm test -- --coverage
137
+
138
+ # Python (pytest-cov)
139
+ pytest --cov=src --cov-report=html
140
+
141
+ # Go
142
+ go test -coverprofile=coverage.out
143
+ go tool cover -html=coverage.out
144
+ ```
145
+
146
+ ## Testing Best Practices
147
+
148
+ ### DO's
149
+ - Write tests before fixing bugs (TDD)
150
+ - Test edge cases
151
+ - Keep tests independent
152
+ - Use descriptive test names
153
+ - Mock external dependencies
154
+ - Clean up test data
155
+
156
+ ### DON'Ts
157
+ - Don't test implementation details
158
+ - Don't write brittle tests
159
+ - Don't skip tests without a reason
160
+ - Don't commit commented-out tests
161
+ - Don't test third-party libraries
162
+
163
+ ## Test Naming Conventions
164
+
165
+ ```typescript
166
+ // Good: Describes what is being tested
167
+ it('should reject invalid email addresses')
168
+
169
+ // Good: Describes the scenario and outcome
170
+ it('returns 401 when user provides invalid credentials')
171
+
172
+ // Bad: Vague
173
+ it('works correctly')
174
+ ```
175
+
176
+ ## Common Testing Frameworks
177
+
178
+ | Language | Framework | Command |
179
+ |----------|-----------|---------|
180
+ | TypeScript/JS | Jest, Vitest | `npm test` |
181
+ | Python | pytest | `pytest` |
182
+ | Go | testing | `go test` |
183
+ | Java | JUnit | `mvn test` |
184
+ | Rust | built-in | `cargo test` |
185
+
186
+ ## Scripts
187
+
188
+ Generate test boilerplate:
189
+ ```bash
190
+ python scripts/generate_test.py <filename>
191
+ ```
192
+
193
+ Check test coverage:
194
+ ```bash
195
+ python scripts/coverage_report.py
196
+ ```
197
+
198
+ ## References
199
+
200
+ - `references/best-practices.md` - Testing best practices
201
+ - `references/examples/` - Framework-specific examples
202
+ - `references/mocking.md` - Mocking guidelines
@@ -0,0 +1,6 @@
1
+ # Test Automation Best Practices
2
+
3
+ - Keep tests deterministic
4
+ - Avoid test order dependencies
5
+ - Prefer explicit fixtures
6
+ - Run tests in CI on every change
@@ -0,0 +1,3 @@
1
+ # Examples
2
+
3
+ This directory contains small, focused test automation examples.
@@ -0,0 +1,8 @@
1
+ # Unit Test Example
2
+
3
+ ```python
4
+ from my_module import add
5
+
6
+ def test_add():
7
+ assert add(2, 3) == 5
8
+ ```
@@ -0,0 +1,5 @@
1
+ # Mocking Guide
2
+
3
+ - Mock external services
4
+ - Avoid mocking internal logic
5
+ - Use realistic data shapes
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env python3
2
+ # Template generator for coverage report.
3
+
4
+ from pathlib import Path
5
+ import argparse
6
+ import textwrap
7
+
8
+
9
+ def write_output(path: Path, content: str, force: bool) -> bool:
10
+ if path.exists() and not force:
11
+ print(f"{path} already exists (use --force to overwrite)")
12
+ return False
13
+ path.parent.mkdir(parents=True, exist_ok=True)
14
+ path.write_text(content, encoding="utf-8")
15
+ return True
16
+
17
+
18
+ def main() -> int:
19
+ parser = argparse.ArgumentParser(description="Generate a coverage report.")
20
+ parser.add_argument("--output", default="coverage-report.md", help="Output file path")
21
+ parser.add_argument("--name", default="example", help="Component or repo name")
22
+ parser.add_argument("--owner", default="team", help="Owning team")
23
+ parser.add_argument("--force", action="store_true", help="Overwrite existing file")
24
+ args = parser.parse_args()
25
+
26
+ content = textwrap.dedent(
27
+ f"""\
28
+ # Coverage Report
29
+
30
+ ## Summary
31
+ Coverage for {args.name}
32
+
33
+ ## Ownership
34
+ - Owner: {args.owner}
35
+
36
+ ## Coverage Breakdown
37
+ - Lines:
38
+ - Branches:
39
+ - Functions:
40
+
41
+ ## Low Coverage Areas
42
+ - Module:
43
+ - Module:
44
+
45
+ ## Action Items
46
+ - Add missing tests
47
+ - Track progress
48
+ """
49
+ ).strip() + "\n"
50
+
51
+ output = Path(args.output)
52
+ if not write_output(output, content, args.force):
53
+ return 1
54
+ print(f"Wrote {output}")
55
+ return 0
56
+
57
+
58
+ if __name__ == "__main__":
59
+ raise SystemExit(main())