Chuyển đến nội dung
Skillpedia
Kiểm thử48k · #5937

tdd-workflows-tdd-refactor

Skill này làm gì

Công cụ này giúp cải thiện code lập trình, làm cho code sạch hơn và hiệu quả hơn. Nó áp dụng các kỹ thuật tái cấu trúc và đảm bảo mọi test của code vẫn pass.

Khi nào nên dùng

  • ✓Khi bạn muốn code có tổ chức hơn.
  • ✓Khi bạn muốn cải thiện tốc độ của code.
  • ✓Khi bạn muốn đảm bảo thay đổi code không làm hỏng gì.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflows-tdd-refactor/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflows-tdd-refactor/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tái cấu trúc đoạn code này để sạch hơn và nhanh hơn, nhưng đảm bảo mọi test vẫn pass.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ phân tích code, xác định những chỗ cần cải thiện (như lặp lại hoặc phức tạp) và áp dụng các kỹ thuật đã biết để sửa. Nó chạy test trước và sau khi thay đổi để đảm bảo mọi thứ vẫn hoạt động.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Use this skill when

  • Working on tdd workflows tdd refactor tasks or workflows
  • Needing guidance, best practices, or checklists for tdd workflows tdd refactor

Do not use this skill when

  • The task is unrelated to tdd workflows tdd refactor
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open resources/implementation-playbook.md.

Refactor code with confidence using comprehensive test safety net:

[Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.]

Usage

Use Task tool with subagent_type="tdd-orchestrator" to perform safe refactoring.

Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase:

Core Process

1. Pre-Assessment

  • Run tests to establish green baseline
  • Analyze code smells and test coverage
  • Document current performance metrics
  • Create incremental refactoring plan

2. Code Smell Detection

  • Duplicated code → Extract methods/classes
  • Long methods → Decompose into focused functions
  • Large classes → Split responsibilities
  • Long parameter lists → Parameter objects
  • Feature Envy → Move methods to appropriate classes
  • Primitive Obsession → Value objects
  • Switch statements → Polymorphism
  • Dead code → Remove

3. Design Patterns

  • Apply Creational (Factory, Builder, Singleton)
  • Apply Structural (Adapter, Facade, Decorator)
  • Apply Behavioral (Strategy, Observer, Command)
  • Apply Domain (Repository, Service, Value Objects)
  • Use patterns only where they add clear value

4. SOLID Principles

  • Single Responsibility: One reason to change
  • Open/Closed: Open for extension, closed for modification
  • Liskov Substitution: Subtypes substitutable
  • Interface Segregation: Small, focused interfaces
  • Dependency Inversion: Depend on abstractions

5. Refactoring Techniques

  • Extract Method/Variable/Interface
  • Inline unnecessary indirection
  • Rename for clarity
  • Move Method/Field to appropriate classes
  • Replace Magic Numbers with constants
  • Encapsulate fields
  • Replace Conditional with Polymorphism
  • Introduce Null Object

6. Performance Optimization

  • Profile to identify bottlenecks
  • Optimize algorithms and data structures
  • Implement caching where beneficial
  • Reduce database queries (N+1 elimination)
  • Lazy loading and pagination
  • Always measure before and after

7. Incremental Steps

  • Make small, atomic changes
  • Run tests after each modification
  • Commit after each successful refactoring
  • Keep refactoring separate from behavior changes
  • Use scaffolding when needed

8. Architecture Evolution

  • Layer separation and dependency management
  • Module boundaries and interface definition
  • Event-driven patterns for decoupling
  • Database access pattern optimization

9. Safety Verification

  • Run full test suite after each change
  • Performance regression testing
  • Mutation testing for test effectiveness
  • Rollback plan for major changes

10. Advanced Patterns

  • Strangler Fig: Gradual legacy replacement
  • Branch by Abstraction: Large-scale changes
  • Parallel Change: Expand-contract pattern
  • Mikado Method: Dependency graph navigation

Output Requirements

  • Refactored code with improvements applied
  • Test results (all green)
  • Before/after metrics comparison
  • Applied refactoring techniques list
  • Performance improvement measurements
  • Remaining technical debt assessment

Safety Checklist

Before committing:

  • ✓ All tests pass (100% green)
  • ✓ No functionality regression
  • ✓ Performance metrics acceptable
  • ✓ Code coverage maintained/improved
  • ✓ Documentation updated

Recovery Protocol

If tests fail:

  • Immediately revert last change
  • Identify breaking refactoring
  • Apply smaller incremental changes
  • Use version control for safe experimentation

Example: Extract Method Pattern

Before:

class OrderProcessor {
  processOrder(order: Order): ProcessResult {
    // Validation
    if (!order.customerId || order.items.length === 0) {
      return { success: false, error: "Invalid order" };
    }

    // Calculate totals
    let subtotal = 0;

…
Câu hỏi thường gặp

Tái cấu trúc (refactoring) là gì?

Tái cấu trúc là việc sắp xếp lại code có sẵn mà không thay đổi hành vi bên ngoài của nó. Mục tiêu là làm code rõ ràng hơn, giảm độ phức tạp và dễ bảo trì hơn.

Vì sao cần test luôn pass?

Test luôn pass đảm bảo các thay đổi không đưa lỗi mới vào hoặc làm hỏng chức năng có sẵn. Nó đóng vai trò như một tấm lưới an toàn.

Code có thể được cải thiện ở những mặt nào?

Code có thể dễ đọc hơn, chạy nhanh hơn, có tổ chức tốt hơn và đơn giản hơn để sửa đổi trong tương lai.

Chi tiết

Mô tả gốc của tác giả

Use when working with tdd workflows tdd refactor

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#5937
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự