TDD Refactor Phase - Improve Quality & Security
TDD Refactor Phase - Improve Quality & Security是一款security方向的AI技能,核心价值是Improve code quality, apply security best practices, and enhance design whilst maintaining green tests and GitHub issue compliance,可用于解决开发者在security领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Improve code quality, apply security best practices, and enhance design whilst maintaining green tests and GitHub issue compliance.
mkdir -p ./skills/tdd-refactor && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/tdd-refactor/SKILL.md -o ./skills/tdd-refactor/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# TDD Refactor Phase - Improve Quality & Security
Clean up code, apply security best practices, and enhance design whilst keeping all tests green and maintaining GitHub issue compliance.
GitHub Issue Integration
Issue Completion Validation
- **Verify all acceptance criteria met** - Cross-check implementation against GitHub issue requirements
- **Update issue status** - Mark issue as completed or identify remaining work
- **Document design decisions** - Comment on issue with architectural choices made during refactor
- **Link related issues** - Identify technical debt or follow-up issues created during refactoring
Quality Gates
- **Definition of Done adherence** - Ensure all issue checklist items are satisfied
- **Security requirements** - Address any security considerations mentioned in issue
- **Performance criteria** - Meet any performance requirements specified in issue
- **Documentation updates** - Update any documentation referenced in issue
Core Principles
Code Quality Improvements
- **Remove duplication** - Extract common code into reusable methods or classes
- **Improve readability** - Use intention-revealing names and clear structure aligned with issue domain
- **Apply SOLID principles** - Single responsibility, dependency inversion, etc.
- **Simplify complexity** - Break down large methods, reduce cyclomatic complexity
Security Hardening
- **Input validation** - Sanitise and validate all external inputs per issue security requirements
- **Authentication/Authorisation** - Implement proper access controls if specified in issue
- **Data protection** - Encrypt sensitive data, use secure connection strings
- **Error handling** - Avoid information disclosure through exception details
- **Dependency scanning** - Check for vulnerable packages (`npm audit`, `pip audit`, `dotnet list package --vulnerable`, etc.)
- **Secrets management** - Use environment variables or a secrets manager; never hard-code credentials
- **OWASP compliance** - Address security concerns mentioned in issue or related security tickets
Design Excellence
- **Design patterns** - Apply appropriate patterns (Repository, Factory, Strategy, etc.)
- **Dependency injection** - Use DI container or constructor injection for loose coupling
- **Configuration management** - Externalise settings using environment variables or config files
- **Logging and monitoring** - Add structured logging appropriate to your stack for issue troubleshooting
- **Performance optimisation** - Use async/await or equivalent concurrency primitives, efficient collections, caching
Language Best Practices (Polyglot)
- **Null safety** - Enable strict null checks (TypeScript), nullable reference types (C#), or Optional types (Java/Kotlin)
- **Modern language features** - Use pattern matching, destructuring, and idiomatic constructs for your language
- **Memory & performance** - Apply language-specific optimisations only when profiling reveals a bottleneck
- **Error handling** - Use specific error/exception types; avoid swallowing errors silently
Security Checklist
- [ ] Input validation on all public methods
- [ ] SQL injection prevention (parameterised queries)
- [ ] XSS protection for web applications
- [ ] Authorisation checks on sensitive operations
- [ ] Secure configuration (no secrets in code)
- [ ] Error handling without information disclosure
- [ ] Dependency vulnerability scanning
- [ ] OWASP Top 10 considerations addressed
Execution Guidelines
1. **Review issue completion** - Ensure GitHub issue acceptance criteria are fully met
2. **Ensure green tests** - All tests must pass before refactoring
3. **Confirm your plan with the user** - Ensure understanding of requirements and edge cases. NEVER start making changes without user confirmation
4. **Small incremental changes** - Refactor in tiny steps, running tests frequently
5. **Apply one improvement at a time** - Focus on single refactoring technique
6. **Run security analysis**
🎯 Best For
- Security auditors
- DevSecOps teams
- Compliance officers
- QA engineers
- Developers writing unit tests
💡 Use Cases
- Auditing dependencies for known CVEs
- Scanning API endpoints for auth gaps
- Generating test cases for edge conditions
- Writing integration test suites
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply TDD Refactor Phase - Improve Quality & Security to Your Work
Provide context for your task — paste source material, describe your audience, or share existing work to guide the AI.
- 4
Review and Refine
Edit the AI output for accuracy, tone, and completeness. Add human insight where the AI lacks context.
❓ Frequently Asked Questions
Can this replace a dedicated SAST tool?
AI-based security review is complementary to SAST tools. Use it as a first-pass filter, not a replacement.
Does this generate test mocks?
Many testing skills include mock generation. Check the install command and skill content for details.
Does this handle breaking changes?
Refactoring skills identify breaking changes but always run your test suite after applying suggestions.
How do I install TDD Refactor Phase - Improve Quality & Security?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/tdd-refactor/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Only scanning surface-level issues
Deep security review requires understanding your app architecture, not just regex patterns.
Not testing edge cases
AI tends to generate happy-path tests. Manually review for boundary conditions.
Refactoring without tests
Never refactor critical paths without a comprehensive test suite to catch regressions.
Not reading the full skill
Skills contain important context and edge cases beyond the quick start.