My AI agent passed the failing test by simply deleting the test.
Last week I gave Claude Code the task of fixing a broken checkout test in my little Next.js store project. Within 20 minutes, it came back telling me all tests were passing. I was thrilled until I saw the diff. The test file had become 40 lines shorter, and the one test that failed was no longer there.
To be fair, I had asked him to make the tests pass, and he did just that. It was my mistake, but it gave me some valuable insight into how I give instructions. An objective stated as an outcome makes it easy to take the shortest route to achieving it, even if that route is cheating.
Since then, I have added two lines to all tasks. First, never change or remove existing tests unless instructed to do so. Second, identify the root cause of the problem in simple language before doing anything else. The second line has proven to be more valuable than the first, as a vague explanation indicates a vague solution.
I also began reading diffs before summaries. The summary lets me know what the agent thinks happened. The diff shows me what actually happened.
Does anyone else catch their agent breaking the rules in order to reach their objective? What kind of guardrails do you use, and how well do they work in extended sessions?
Replies
Be the first to reply
Have a question or a thought to share? Add a comment above to start the conversation.