Execute structural refactoring with test verification before behavioral changes - use when tidying code before features, cleaning up duplication, or improving clarity
Execute structural changes BEFORE behavioral changes, following Kent Beck's Tidy First approach.
Structural changes rearrange code WITHOUT changing behavior:
β Structural (Tidy First):
β NOT Structural (Behavioral):
Before making ANY structural change, run tests to capture baseline:
# Run all tests
npm test
# Verify TypeScript compilation
tsc -b --noEmit
All tests MUST pass before proceeding. If tests fail, fix them first.
Make exactly ONE type of structural change at a time:
Examples of ONE change:
processData to validateUserInput across all filesvalidateInput() functiondomain/repositories/ folderAfter the structural change, run tests again:
# Run all tests
npm test
# Verify TypeScript compilation
tsc -b --noEmit
Tests MUST still pass - this proves you didn't change behavior.
If tests fail:
Commit the structural change with refactor: type:
git commit -m "refactor: rename processData to validateUserInput for clarity"
git commit -m "refactor: extract duplicate validation into validateInput"
git commit -m "refactor: move repository interfaces to domain layer"
refactor: commit type for structural changes# WRONG: Mixed structural + behavioral
git commit -m "Add user validation and rename variables" # β
# RIGHT: Separate commits
git commit -m "refactor: rename userData to userInput for clarity" # β
git commit -m "feat: add user validation logic" # β