test-preserving-refactor
/test-preserving-refactor
Use when code needs restructuring and observable behavior must stay unchanged, with existing tests kept green at every step.
- Author
- yeaight7 ↗
- Repository
- agent-powerups ↗
- Licence
- Apache-2.0
- Last repository change
- 27.09.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 27.09.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
What it does and when to use it
Use when code needs restructuring and observable behavior must stay unchanged, with existing tests kept green at every step.
Original author description
Use when code needs restructuring and observable behavior must stay unchanged, with existing tests kept green at every step.
How it works
- Purpose
- When to Use
- Inputs
- Workflow
- Output
- Verification
- Failure Modes
SKILL.md preview
--- name: test-preserving-refactor description: Use when code needs restructuring and observable behavior must stay unchanged, with existing tests kept green at every step. --- ## Purpose Refactoring is only safe if it is backed by tests. Work in a strict loop — green baseline, one structural change, immediate re-run, revert on red — so you are never trapped in an uncompilable state. ## When to Use - Code needs restructuring (extract/inline/move) without behavior change - A previous refactor spiraled into a broken, hard-to-recover state - Tests covering the target area exist or can be run ## Inputs - The target area and the command that runs just its tests ## Workflow 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: ```bash npx jest path/to/target # or: pytest tests/test_target.py -q ``` 2. **Small steps.** Make one structural change at a time (e.g., extract a method). 3. **Run tests immediately** after the single structural change. The per-change loop: ```bash # repeat per structural change: edit -> test -> commit (green) | revert (red) npx jest path/to/target && git commit -am "refactor: extract X" || git checkout -- . ``` 4. **Revert on red.** If the tests fail, you made a mistake. Revert the change (`git checkout -- .` or `git restore .`) and try a different approach. Do not attempt to "fix" the refactor while tests are failing. 5. **Commit on green.** Once the small change is green, consider it a safe checkpoint. This strict loop prevents you from getting trapped in an uncompilable state. ## Output - A chain of small, individually green commits - The final test run output proving unchanged behavior ## Verification - [ ] Baseline test run was green before the first edit - [ ] Exactly one structural change per test cycle - [ ] Every red result handled by revert, not forward-fixing - [ ] Each green step committed as a checkpoint - [ ] No test was modified to make the refactor pass ## Failure Modes - **Refactoring on red** — starting from failing tests means you cannot tell what you broke. - **Step batching** — three changes per test run; when it fails, you don't know which one did it. - **Forward-fixing a broken refactor** — "fixing" while red digs the hole deeper; revert is cheaper. - **Bending the tests** — editing assertions to match new behavior is a behavior change, not a refactor.
Versions
The database has no other skills named test-preserving-refactor.
Identical content appears in 1 other GitHub folders. We show one copy with the highest score.
Database snapshot: 13.11.2026 · package version 87d0d69d78c2 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 2 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100orch-refine-code
Orchestrate a behavior-preserving refactor — confirm tests are green, restructure without changing behavior, keep tests green, review, and gated commit. Use when the structure should improve but behavior must not change. - 96safe-refactor
Use when code needs restructuring without changing observable behavior. - 100orch-refine-code
Orchestrate a behavior-preserving refactor — confirm tests are green, restructure without changing behavior, keep tests green, review, and gated commit. Use when the structure should improve but behavior must not change. - 90refactor
Use when refactoring code while preserving behavior — checkpoint, extract, test, audit - 100refactor
Plans and performs a behaviour-preserving refactor in small steps with the test suite green before, during and after. Use when code is hard to change, duplicated, too large, or when a tech-debt item is scheduled. - 100rescue-refactor
Changes legacy code one small, behaviour-preserving step at a time inside a strict loop: tests green before, one named refactoring, tests green after, commit, repeat. Refuses to start without a safety net, never mixes refactoring with behaviour changes, and stops at the first…