Skip to main content

Implementation Katas

Four focused drills that exercise the habits from this module. Each targets a specific skill. Repeat each until the technique is automatic.

Kata 1: Write a Regression Test for a Fictional Bug

Time limit: 20 minutes Skill: Regression-first fixing (Concept 11)

Setup: you maintain the fictional task-manager capstone. The following triage entry arrived this morning:

id:       BUG-2026-04-21-07
title: DELETE /tasks/{id} returns 204 for tasks the caller does not own
sev: Sev-1
impact: cross-tenant data deletion; security
root-cause suspected: authorization

Instructions:

  1. Write the smallest test that reproduces the bug. Pick the cheapest level (unit, integration, or E2E) that can reliably show it.
  2. Confirm the test fails for the right reason, not just any reason.
  3. Describe in one sentence the smallest fix that would make the test pass.
  4. Explain why a test written after the fix would be less valuable here.

Repeat until: you can go from triage entry -> failing test in under 10 minutes, and you can name which test level you picked and why.


Kata 2: Refactor a Smelly Function Using a Named Fowler Move

Time limit: 20 minutes Skill: Refactoring cadence with named moves (Concept 13)

Setup: you are given this function in the task-manager service:

def notify(task, user, settings):
if settings.email_enabled:
if user.email and user.verified:
if task.priority in ("high", "urgent"):
send_email(user.email, f"Urgent: {task.title}")
else:
send_email(user.email, f"Update: {task.title}")
if settings.sms_enabled:
if user.phone and user.phone_verified:
if task.priority in ("high", "urgent"):
send_sms(user.phone, f"Urgent: {task.title}")
else:
send_sms(user.phone, f"Update: {task.title}")

Instructions:

  1. Name the smells present in one sentence each.
  2. Pick a Fowler refactor from the catalog (e.g., Decompose Conditional, Extract Function, Replace Conditional with Polymorphism, Introduce Parameter Object). Name it explicitly.
  3. Describe the characterization tests you would add before refactoring.
  4. Sketch the refactored shape in ~15 lines.
  5. Defend the move in one sentence: what specific pressure is it absorbing?

Repeat until: you can name the smell, the move, and the target shape inside 5 minutes.


Kata 3: Diagnose a Flaky Test Given Its Trace

Time limit: 15 minutes Skill: Flaky-test diagnosis (Concept 12)

Setup: an E2E test fails about once every 15 runs with:

AssertionError: expected Task.status == "done", got "in_progress"
traceback:
test_task_finalize.py:44: client.post("/tasks/{id}/finalize")
task_svc.py:88: enqueue_status_update(task_id)
test_task_finalize.py:48: client.get("/tasks/{id}") # assertion here

Instructions:

  1. Walk the five common causes in order. For each, state whether it is likely or unlikely here, with reasoning.
  2. Pick the most likely cause.
  3. Name the diagnostic step that would confirm it.
  4. Name the fix that addresses the cause, not the symptom.
  5. Explain why auto-retry would be the wrong response here.

Repeat until: you can walk the five-cause checklist from memory and assign a diagnostic step to each.


Kata 4: Write a Technical-Debt Ledger Entry

Time limit: 15 minutes Skill: Debt accounting (Concept 15)

Setup: during a 24-hour read-through you noticed this:

The auth_middleware.py in the capstone has three places where it constructs an error response inline instead of using a shared helper. The strings drift. One place returns {"error": "unauthorized"}, another returns {"message": "auth failed"}, and a third returns a plain string "nope". You do not have time to fix it this week -- sync feature takes priority.

Instructions:

Write a ledger entry containing, at minimum:

  • a unique id and short title
  • precise location (file and approximate line range)
  • severity on the Sev-1..Sev-4 scale with rationale
  • impact in one or two sentences
  • why-deferred (specific, not generic)
  • a trigger that would cause you to act on it
  • owner
  • date and source (e.g., "24-hour read-through on 2026-04-21")

Repeat until: you can write a defensible entry in under 10 minutes and defend each field if challenged.


Completion Standard

  • Each kata completed within its time limit at least twice
  • You can explain the technique practiced in each kata in one sentence
  • You do not need to look up the five flaky-test causes, the Fowler catalog names, or the triage Sev rubric mid-kata
  • The artifacts (regression test idea, refactor sketch, diagnosis, ledger entry) are written down somewhere you can reuse them in the capstone