CLAUDE CODE AGENTS: FUNDAMENTALS - Chapter 8, Exercise 2 Refactoring a Function With No Existing Tests ==================================================================================== QUESTION: A refactoring agent is asked to simplify a function that has no existing tests at all. Explain what it should do before making any structural change, using this chapter's own guidance. SOLUTION / EXPLANATION: This chapter's own system-prompt guidance is explicit that a refactoring agent should flag missing or inadequate test coverage rather than proceeding as though the absence of failing tests proves nothing broke. With genuinely zero existing tests for this function, there is no "before" baseline to compare against at all - the entire before/after verification method this chapter relies on has nothing to work with. Per this chapter's own tip box, the right move is to check (and if necessary establish) test coverage BEFORE refactoring, not after. Concretely, that means the refactoring agent should flag the missing coverage rather than proceeding immediately, and either the coverage gap gets addressed first - potentially delegating that work to a testing agent (Chapter 7) to write tests capturing the function's current behavior - or the refactor proceeds with an explicit acknowledgment that there is no automated way to confirm behavior was actually preserved, and extra manual review is needed instead. What the agent should NOT do is simplify the function and simply report that no tests failed, since with zero tests to begin with, "no tests failed" is a meaningless, guaranteed-true statement that provides no actual evidence behavior was preserved - it isn't a genuine verification result at all. -------------------------------------------------------------------------- WHY THIS WORKS AS AN ANSWER: It identifies specifically why zero existing tests removes the entire before/after verification method this chapter depends on, and names the concrete correct response (flag the gap, establish coverage first or proceed with explicit manual-review caveats) rather than treating "no tests failed" as meaningful verification when there were no tests to fail in the first place.