Skip to content
Back to skills

Test Preserving Refactor

ASecurity

Use to restructure code while guaranteeing that all existing tests continue to pass.

  • 6 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 29, 2026
ai-agentsrefactoringgit

Security analysis

A100/100

Scanned May 29, 2026

npx -y skills add yeaight7/agent-powerups --skill test-preserving-refactor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Test Preserving Refactor?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Test Preserving Refactor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/yeaight7-test-preserving-refactor/badge)](https://www.skillsdirectory.com/skills/yeaight7-test-preserving-refactor)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: test-preserving-refactor
description: "Use to restructure code while guaranteeing that all existing tests continue to pass."
---

# Test-Preserving Refactor

Refactoring is only safe if it is backed by tests.

## The Protocol

1. **Run Tests First**: Before touching any code, run the tests covering the target area. They MUST be green. If they are red, stop and fix the tests (or the code) first.
2. **Small Steps**: Make one structural change at a time (e.g., extract a method). 
3. **Run Tests Immediately**: Run the tests immediately after the single structural change.
4. **Revert on Red**: If the tests fail, you made a mistake. Revert the change (`git checkout` or `ctrl+z`) and try a different approach. Do not attempt to "fix" the refactor while tests are failing.
5. **Commit**: Once the small change is green, consider it a safe checkpoint.

This strict Red/Green/Refactor cycle prevents you from getting trapped in an uncompilable state.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…