rgoussu@goussu: ~/library/applicative-architecture/exercises
~/library/applicative-architecture/exercises cat gilded-rose-legacy-rescue.md

Gilded Rose — legacy rescue

# The Gilded Rose kata run as a full legacy-rescue project — pin behavior with characterization tests, refactor in small steps, then ship a new feature on the clean design.

Exercisesaved 2026-08-08source #exercise#refactoring#legacy-code#testing#clean-code

Goal

Rescue a small piece of untested, unreadable legacy code without breaking it: build a safety net around the Gilded Rose inventory logic, refactor it into a design that welcomes change, and prove the rescue by shipping the "Conjured items" feature cheaply. This is the whole legacy-code discipline in an afternoon-sized package.

Subject: full brief & instructions

Practices

  • Refactoring techniques — small behavior-preserving steps, smells → named refactorings.
  • Testing strategies — characterization/golden-master tests, mutation testing as the honesty check.
  • Clean code — naming and structure as the target state.
  • TDD — the new feature is written test-first on the cleaned design.
  • Design patterns — polymorphism/Strategy emerging from a refactoring, not installed up front.

Milestones

  1. Read, don't touch. Clone the kata in your language of choice; read the requirements doc and the code. List the smells you see and the trap the goblin sets (the Item class may not be modified).
  2. Pin the behavior. Write characterization tests: a golden-master run over ~30 simulated days covering every item type and the edges (sell-in at 0, quality at 0 and 50). Check branch coverage — untested branches are refactoring landmines.
  3. Mechanical cleanup. Under a green bar only: rename, extract function/variable, flatten the nested conditionals. No behavior change, commits every few minutes.
  4. Structural refactor. Replace the item-type conditional with polymorphism (one update strategy per item kind), still without touching Item.
  5. Ship the feature. TDD "Conjured" items on the new structure. Notice what it costs now versus what it would have cost on day one — that difference is the point.
  6. Audit the net. Mutation-test the suite (PIT/Stryker); every surviving mutant is a hole in the characterization tests. Kill them.

Stretch goals

  • Re-run the kata in a second language from the same repo; compare which refactorings the language makes easy or hard.
  • Redo milestone 2 with an approval-testing tool (TextTest, Approvals) and compare effort.
  • Time-box a from-scratch second attempt and see how differently you sequence the moves.

Related