Skip to lesson
Exit
Deep Debugging & Root-Cause1 / 2

1 min lesson

Pin the behavior before you touch it

Use "Identify the current state, write tests for that current state, then make the minimal code change" to describe the practical rule.

Step 1 of 2

Pin the behavior before you touch itguardrail tests for a safe refactor

Once a bug is fixed, the next risk is the fix that quietly changes something else. On a large, idiosyncratic codebase, treat tests as guardrails: identify the current behavior, write tests that pin that exact input/output, then make the minimal change while keeping inputs and outputs identical. This is what makes a big refactor safe - say, migrating a hot path from legacy Java to Go for speed without changing what it returns.

Say it like this

Identify the current state, write tests for that current state, then make the minimal code change - keeping the output of the current state intact.

Repo size isn't the blocker it sounds like. Cursor indexes a brand-new project and a ten-year-old monster the same way: semantic search plus efficient grep inside the agent harness. A repo with tens of thousands of stars, a decade of history and thousands of contributors is still navigable - so "the codebase is too big to test" stops being an excuse.