tdd-workflows-tdd-refactor

Refactors code incrementally while keeping the full test suite green.

2|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/monang404/lunawave --skill tdd-workflows-tdd-refactor-monang404
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tdd-workflows-tdd-refactor
Source: https://github.com/monang404/lunawave/tree/main/.agent/skills/tdd-workflows-tdd-refactor
Command: npx skills add https://github.com/monang404/lunawave --skill tdd-workflows-tdd-refactor-monang404

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring legacy or messy code is risky because changes can silently break existing behavior. This Skill provides a structured TDD refactor workflow that uses the existing test suite as a safety net, so every code improvement is verified against a green baseline before and after each change. ## Core Features & Use Cases - Code Smell Detection & Remediation: Identifies duplicated code, long methods, large classes, feature envy, and primitive obsession, then applies targeted refactorings like Extract Method and Move Method. - Design Patterns & SOLID Guidance: Applies creational, structural, and behavioral patterns plus SOLID principles only where they add clear value. - Incremental Safe Refactoring: Enforces small atomic changes with test runs after each step, performance measurement before and after, and a rollback recovery protocol if tests fail. - Use Case: You inherit a 300-line OrderProcessor method mixing validation, pricing, payment, and notifications. Use this Skill to decompose it into focused methods with value objects and dependency injection while all tests stay green. ## Quick Start Ask the agent to refactor a specific class or module using the TDD refactor phase, keeping all tests green and reporting before-and-after metrics.

Frequently Asked Questions about tdd-workflows-tdd-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without breaking existing functionality?▼

Establish a green test baseline first, then make small atomic changes and run the full test suite after each modification. If any test fails, immediately revert the last change and retry with a smaller incremental step.

What is the TDD refactor phase in test-driven development?▼

The refactor phase is the third step of the red-green-refactor cycle, where you improve code structure after tests pass. It covers code smell removal, design pattern application, and SOLID principle enforcement without changing external behavior.

Which code smells should I fix first when refactoring?▼

Start with duplicated code and long methods since they cause the most maintenance friction. Then address large classes, long parameter lists, feature envy, and primitive obsession using techniques like Extract Method, Move Method, and value objects.

What should I do when refactoring breaks my tests?▼

Immediately revert the last change to restore the green state, then identify which refactoring caused the failure. Reapply the change in smaller increments and use version control commits after each successful step for safe experimentation.

When should design patterns not be applied during refactoring?▼

Avoid patterns when they add indirection without clear value, such as applying factories to trivial object creation. Patterns should solve an existing smell or complexity problem, not be introduced speculatively for hypothetical future needs.