技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
smart-mutation-operator-generator【数据与研究】Analyzes a repository and its test suite to generate customized mutation operators tailored to the project. Use this skill when setting up mutation testing, improving test quality, or generating project-specific mutants. Considers language constructs, business logic patterns, API calls, data types, and code complexity to produce effective mutation op…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Generate customized mutation operators tailored to a specific codebase to maximize mutation testing effectiveness.
Run analysis script:
# Analyze entire repository
python scripts/generate_operators.py /path/to/repo
# Analyze single file
python scripts/generate_operators.py /path/to/file.py
# Save detailed report
python scripts/generate_operators.py /path/to/repo --output operators.json
Script analyzes:
Operator priorities:
🔴 High Priority: Most effective at finding bugs
🟡 Medium Priority: Useful but may generate equivalent mutants
🔵 Low Priority: Often trivial or equivalent
Consider project characteristics:
Financial/calculation-heavy code:
API-heavy code:
Business logic code:
Data processing code:
Example custom operators:
API Timeout Mutation:
# Original
response = api.call(timeout=30)
# Mutant
response = api.call(timeout=1) # Test timeout handling
Retry Logic Mutation:
# Original
@retry(max_attempts=3)
def fetch_data():
pass
# Mutant
@retry(max_attempts=1) # Test with fewer retries
def fetch_data():
pass
Business Rule Mutation:
# Original
if age >= 18 and has_license:
allow_driving()
# Mutants
if age > 18 and has_license: # ROR
if age >= 18 or has_license: # LCR
if age >= 21 and has_license: # CRP (domain-specific)
Skip equivalent mutants:
# Equivalent (don't mutate)
x = a + 0 # → x = a - 0 (still equals a)
x = a * 1 # → x = a / 1 (still equals a)
# Non-equivalent (do mutate)
x = a + 1 # → x = a - 1 (different result)
x = a * 2 # → x = a / 2 (different result)
Skip trivial mutations:
# Trivial (low value)
message = "Hello" # → message = "" (obvious failure)
# Valuable (high value)
if count > 0: # → if count >= 0 (subtle boundary)
Document operator selection:
MUTATION TESTING PLAN
=====================
Project: MyApp
Language: Python
Files Analyzed: 45
SELECTED OPERATORS
------------------
High Priority (Apply to all code):
1. ROR - Relational Operator Replacement
- Target: Comparison operations in business logic
- Expected: 150 mutants
- Rationale: Critical for boundary condition testing
2. LCR - Logical Connector Replacement
- Target: Boolean expressions in validation
- Expected: 80 mutants
- Rationale: Tests logical condition coverage
3. CRP - Constant Replacement
- Target: Numeric thresholds and limits
- Expected: 120 mutants
- Rationale: Tests boundary values
Medium Priority (Apply selectively):
4. AOR - Arithmetic Operator Replacement
- Target: Calculation functions only
- Expected: 60 mutants
- Rationale: Financial calculations need thorough testing
Custom Operators:
5. RETRY - Retry Logic Mutation
- Target: @retry decorators
- Expected: 15 mutants
- Rationale: Test resilience mechanisms
ESTIMATED RESULTS
-----------------
Total Mutants: ~425
Mutation Score Target: >80%
Execution Time: ~25 minutes
Python (mutmut):
mutmut run --paths-to-mutate=src/
mutmut results
JavaScript (Stryker):
// stryker.conf.js
module.exports = {
mutator: {
excludedMutations: ['StringLiteral', 'UnaryOperator']
}
};
See standard_operators.md for complete list.
Most effective:
> → >=, <, ==and → or0 → 1, true → falseif x: → if not x:Mutation Score = (Killed Mutants / Total Mutants) × 100%
Targets:
Start small:
Focus on critical code:
Avoid over-mutation:
Review results:
# Analyze repository
python scripts/generate_operators.py /path/to/repo
# Save detailed report
python scripts/generate_operators.py /path/to/repo --output report.json
Output includes: