Sub topic 13
Checking the agent's work with tests and review
This chapter assumes you can run your project's tests and build from the terminal, and that you know basic git (diff, branch, commit). It covers how to check what a terminal coding agent changed before you accept it. Everything here applies to Claude Code, Codex CLI, and Copilot CLI alike.
Why agent output needs checking
An agent reports success based on what it observed, and what it observed may be incomplete. A model can say "all tests pass" after running only one test file. It can also edit a test until it passes, or leave out a case you never mentioned. The agent loop has no built-in guarantee that its changes are correct. You provide that guarantee.
Treat the agent like a fast colleague whose pull request you must review. Verification has three layers, from cheapest to most expensive:
- Automated checks: tests, type checker, linter, build.
- Reading the diff yourself.
- Running the changed behavior by hand.
Automated checks first
Run the checks yourself, even if the agent already ran them. Your run is the one you can trust, because you know exactly which command executed.
npm test
npm run lint
npx tsc --noEmit
npm run buildAdapt the commands to your project. Listing them in your instruction file (see the chapter on CLAUDE.md and AGENTS.md) lets the agent run the same commands during its own loop. That way it can fix failures before you see them.
Check that the tests are meaningful
Passing tests only help if they can fail. Look for these common problems:
- Weakened tests. The agent changed an assertion, deleted a test, or added
skipto make a failure go away. - Tests that mirror the code. A new test that recomputes the expected value with the same logic as the implementation proves nothing.
- Missing edge cases. Empty input, boundary values, and error paths are often absent.
- Over-mocking. If every dependency is mocked, the test may pass while real integration is broken.
A quick way to find changed or removed tests is to look at the diff for test files first.
git diff --stat
git diff -- '*test*' '*spec*'A useful technique is to confirm a new test fails without the fix. Stash the source change, run the test, then restore it.
git stash push -- src/
npm test -- date-parsing
git stash popIf the new test passes even with the source change removed, it is not testing the fix.
Reading the diff
Read the full diff, not the agent's summary. Summaries describe intent. The diff shows what happened.
git status
git diffCheck these items:
- Scope. Did the agent touch files unrelated to the task? Formatting churn across many files makes review harder.
- Forbidden paths. Files under
dist/,generated/, lock files, or CI configuration should change only when you expect it. - New dependencies. Look at
package.jsonfor packages you did not ask for. - Secrets and debug leftovers. Search for
console.log,TODO, hardcoded tokens, and.envcontents. - Deleted code. Removed lines deserve as much attention as added ones.
Untracked files do not appear in git diff. Use git status to see them, and git add -N <file> (intent to add) if you want them to show up in the diff.
Staging selectively
Use git add -p to accept changes hunk by hunk. It prompts for each hunk, and you answer y (stage), n (skip), or s (split a large hunk into smaller ones).
git add -p
git diff --staged
git commit -m "Fix date parsing for ISO week dates"Reviewing with git diff --staged before committing confirms that only the hunks you accepted are included. Work on a branch so you can discard unaccepted changes cleanly (see the git safety-net chapter).
Asking the agent to review
You can also use an agent as a second reviewer. This catches different mistakes than your own reading, but it does not replace it. Two practices make it more reliable:
- Use a fresh session. An agent reviewing in the same session shares the assumptions that produced the code. A new session sees only the diff.
- Ask specific questions. "Review for bugs" is vague. "List edge cases in this diff that have no test" gives you something to verify.
Each tool can run a one-shot prompt, so a review can be scripted. Piping the diff gives the agent exactly what to examine.
git diff main...HEAD | claude -p "Review this diff for bugs and missing tests. List findings by file."Feeding failures back
When a check fails, give the agent the real output instead of a paraphrase. Paste the error message, the failing test name, and the command that produced it. Ask for a root-cause fix, and say what you do not want, for example "do not modify the existing assertions."
If two or three rounds of feedback do not converge, the context may be polluted with failed attempts. Start a new session with a clear description of the problem and what has already been ruled out.
Verifying behavior the tests do not cover
Some changes cannot be proven by unit tests: command-line output, UI layout, performance, or integration with a service. Run the program yourself with representative input, including one case that should fail. For risky changes, ask the agent to write a reproduction script first, confirm that it fails on the original code, then confirm that it passes after the change.
Common errors
| Mistake | Consequence | Fix |
|---|---|---|
| Trusting "tests pass" in the agent's summary | Tests may not have run, or only a subset ran | Run the full suite yourself |
| Reviewing only the summary | Unrequested edits go unnoticed | Read `git diff` and `git status` |
| Committing with `git add .` | Stray files and debug code are included | Use `git add -p` |
| Large tasks in one pass | The diff is too big to review well | Split into small, separately verified tasks |
| Same session reviews its own work | Shared blind spots | Review in a fresh session |
Exercise
An agent says it fixed a bug and that all tests pass. You run git diff --stat and see one source file and one test file changed. Name three checks you should do before committing.
Show answer
(1) Run the full test suite yourself rather than relying on the agent's report. (2) Read the test-file diff to confirm no assertion was weakened, removed, or skipped, and confirm the new or changed test fails when the source change is stashed. (3) Read the source diff and git status for out-of-scope edits, new dependencies, untracked files, or debug leftovers, then stage the accepted hunks with git add -p.
Exercise
Why is it better to review a diff in a fresh agent session than in the session that wrote the code?
Show answer
The writing session carries the same assumptions and reasoning that produced the code, so it tends to repeat the same blind spots. A fresh session sees only the diff and can question choices the original session took for granted.