跳到正文
cccskills
免费在 GitHub 公开

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 operators that maximize test sensitivity while avoiding trivial or equivalent mutations. Generates prioritized operator sets (high/medium/low value) with impact summaries. Triggers when users ask to generate mutation operators, customize mutation testing, analyze code for mutation opportunities, or create project-specific mutants.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(3)

  • SKILL.md6.5 KB
  • references/standard_operators.md6.9 KB
  • scripts/generate_operators.py10.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Smart Mutation Operator Generator

Generate customized mutation operators tailored to a specific codebase to maximize mutation testing effectiveness.

Workflow

1. Analyze Codebase

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:

  • Arithmetic operations (AOR candidates)
  • Comparison operations (ROR candidates)
  • Logical operations (LCR candidates)
  • Constants and literals (CRP candidates)
  • Function calls (FCR candidates)
  • API interactions
  • Database operations
  • Control flow structures
  • Exception handling

2. Review Generated Operators

Operator priorities:

  • 🔴 High Priority: Most effective at finding bugs

    • ROR (Relational Operator Replacement)
    • LCR (Logical Connector Replacement)
    • CRP (Constant Replacement)
    • COR (Conditional Operator Replacement)
  • 🟡 Medium Priority: Useful but may generate equivalent mutants

    • AOR (Arithmetic Operator Replacement)
    • FCR (Function Call Replacement)
    • RVR (Return Value Replacement)
    • API/DB operation mutations
  • 🔵 Low Priority: Often trivial or equivalent

    • UOI/UOD (Unary Operator Insertion/Deletion)
    • STR (String Replacement)
    • IHI/IHD (Hiding Variable Insertion/Deletion)

3. Customize for Project

Consider project characteristics:

Financial/calculation-heavy code:

  • Prioritize AOR (arithmetic operators)
  • Focus on CRP (numeric constants)
  • Test boundary conditions

API-heavy code:

  • Custom API call mutations
  • Timeout/retry logic mutations
  • Error response mutations

Business logic code:

  • ROR (comparisons in business rules)
  • LCR (logical conditions)
  • COR (conditional branches)

Data processing code:

  • Collection mutations
  • Null/empty value mutations
  • Type conversion mutations

4. Define Custom Operators

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)

5. Avoid Trivial Mutations

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)

6. Generate Mutation Test Plan

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

7. Implement with Mutation Tool

Python (mutmut):

mutmut run --paths-to-mutate=src/
mutmut results

JavaScript (Stryker):

// stryker.conf.js
module.exports = {
  mutator: {
    excludedMutations: ['StringLiteral', 'UnaryOperator']
  }
};

Quick Reference

Standard Operators

See standard_operators.md for complete list.

Most effective:

  • ROR: > → >=, <, ==
  • LCR: and → or
  • CRP: 0 → 1, true → false
  • COR: if x: → if not x:

Mutation Score

Mutation Score = (Killed Mutants / Total Mutants) × 100%

Targets:

  • Excellent: >80%
  • Good: 60-80%
  • Needs improvement: <60%

Best Practices

Start small:

  • Begin with high-priority operators
  • Test on small modules first
  • Gradually expand coverage

Focus on critical code:

  • Business logic
  • Security-sensitive code
  • Complex algorithms
  • Error handling

Avoid over-mutation:

  • Skip trivial mutations
  • Exclude equivalent mutants
  • Focus on meaningful changes

Review results:

  • Killed: Tests are effective
  • Survived: Add tests or improve existing ones
  • Equivalent: Mark and exclude

Helper Script

# 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:

  • Detected code patterns
  • Recommended operators by priority
  • Estimated mutant count
  • Customization suggestions

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2582026年8月21日 更新

查看 ArabelaTso 的全部技能

报告此技能的问题