Skip to main content

Reviewing and testing code

Agent output is draft until you say otherwise — same as code from a fast teammate. This lesson covers two jobs every developer needs with 4RGE:

  1. Review what the agent wrote — skim diffs, catch scope creep, reject bad shortcuts.
  2. Test with intent — name behaviors and commands so "done" is provable, not persuasive.

You can also ask the agent to review your diff as a second pair of eyes. None of that replaces your merge decision or your team's bar.

What this page is for

You want to…This page helps you…
Catch bad diffs earlySkim scope, paths, and intent before accept
Get useful review from the agentAsk for security, edge cases, and regressions on your change
Fill test gapsRequest tests by behavior, not "add tests"
Ship safelyRun the checks you already trust before merge
Use the agent as reviewerFocused second pass on your diff — not vague "is this good?"
Part of 4RGED Learn · Coding agents

Day-to-day review habits — Working with agents. After a fix — Finding and fixing bugs. Prompt templates — Prompting.

Who this page is for

You are…Focus on
New to agent-written codeReview the diff → Before you merge
Author finishing a featureWrite and run tests + Ask for a second pass
Reviewer on a teamSame merge bar as always — agent help is optional, not a substitute
Reviewing cloud or PR outputReview cloud and PR output

Two jobs: review and test

WhenYour jobExample
During the runSkim each diff before accept"Why did you touch middleware.ts?"
Before mergeRun named tests + quick smokepnpm test apps/web -- checkout
After the diff existsOptional agent second pass"Rank security issues in @api/checkout"
On cloud / PR outputRead Diff first, summary secondSame bar as local — you were not watching live

Review catches wrong scope and risky edits. Tests catch wrong behavior. You need both — polished chat text is not proof — Hallucination & limitations.

Agents don't replace your review

4RGE is built for reviewable diffs and approvals — not silent merges.

Agent helps with…You still own…
Spotting edge cases you missedWhether the change matches product intent
Suggesting tests for named behaviorsWhether tests prove the right things
Drafting review follow-upsFinal merge and production risk
Summarizing a large diffSkimming paths and scope creep
Confidence tone ≠ correct code

Polished summaries can hide wrong assumptions — Hallucination & limitations.

Treat the agent like a fast reviewer or test author — not an autopilot. Your CI and team standards still apply — Agent security.

Review the diff

Review as changes land, not only at the end.

CheckWhat to look for
PathsFiles outside the area you asked for
IntentDoes the diff match the spec or bug brief?
ShortcutsCommented-out tests, @ts-ignore, skipped assertions
SecretsNo keys or tokens pasted into source — use env vars
ApprovalsRead shell and integration calls before "allow for session" — Tools
Red flagAction
Unrelated refactors in the same runReject or revert; restate scope — Working with agents
Tests deleted or .skip addedAsk why; require a real fix
"It should work" with no test runName the command and ask the agent to run it

Same habits as reviewing a human PR — the agent is just faster at producing the first draft.

Ask for a second pass

After you have a diff (agent-written or your own), ask for a focused review — not "is this good?"

Review typeExample ask
Security"Review this diff for auth bypass, injection, and unsafe defaults in @api/checkout"
Edge cases"List empty, null, and concurrent cases we don't handle in this change"
Regression"What existing flows could break? Point at callers we should re-test"
Scope"Flag anything outside PR #412's intent"

Attach the diff or @ the changed files. Ask for findings ranked by severity, not a rewrite unless you want one.

For PR comment follow-ups, give a numbered list and file scope — see Prompting (code review follow-up pattern).

Example review prompts

Copy and adapt — attach changed files with @ when you can:

Review the diff in @apps/web/src/app/api/checkout/ for:
- auth bypass or missing checks
- injection or unsafe defaults
- error responses that leak internal details
 
Return findings ranked by severity. Do not rewrite code unless I ask.
List edge cases this PR does not handle: empty input, null, concurrent requests, invalid IDs.
Point at the file/line for each gap.
Address PR #412 review comments only:
1. Use retry helper in lib/http.ts (not inline loops)
2. Add error boundary around ChartPanel
Do not scope outside files already in the branch.

Write and run tests

"Add tests" is too vague. Name behaviors the agent should cover.

Weak askStronger ask
"Add tests""Add cases in checkout.test.ts: empty cart → 400, valid code → lower total, total never below zero"
"Make sure it works""Run pnpm test apps/web -- checkout and fix failures without changing the public API"
"Cover edge cases""Table-driven tests for invalid coupon, expired coupon, and stack overflow on discount percent"
HabitWhy
Test behavior, not implementationSurvives refactors
One command in the briefAgent and CI agree on green
Add tests in the same slice"Done" includes proof — Developing features
Fix failures for realNo skipped tests to green the run — Finding and fixing bugs

If the repo already has patterns (table-driven cases, factory helpers), point at an example file with @.

Example test prompts

Add table-driven cases in checkout.test.ts:
- empty cart → 400 empty_cart
- valid discount code → lower total
- invalid code → inline error, no crash
- total never below zero
 
Run: pnpm test apps/web -- checkout
Fix failures without changing the public API.
Make auth.test.ts pass. JWT refresh must invalidate the old token.
Do not skip or delete existing tests to green the run.

The verify command in the prompt is what makes "done" objective — for you and the agent.

Before you merge

Use the same checklist you would for any PR:

StepInclude
Tests you namedUnit/integration for the change
Lint / typecheckWhatever your package uses
Manual smokeUX paths tests miss
Human reviewTeammate when policy requires it
Sensitive areasAuth, payments, PII — extra scrutiny — Agent security

The agent can run checks you specify; it does not replace your judgment on merge.

What good review looks like

SignalMeaning
You saw every changed fileNo surprise paths after accept
Tests you named are greenBehavior proved, not assumed
No skipped/deleted testsGreen means real fix — Finding and fixing bugs
Second pass had ranked findingsYou chose what to fix — agent did not silently rewrite
You could explain the PRReady for human reviewer or merge
Review as you go

Catching scope creep on diff three is cheaper than reverting twenty files at the end — Working with agents.

Review cloud and PR output

When work finishes in the cloud or on a branch you did not watch live:

SurfaceUse it for
DiffLine-by-line review — same as local
Review tabOutcome summary and notes when the run completes — Cloud agents overview
PR / automationFirst-pass review on open PRs when your team enables it — Automations

You still merge when satisfied — cloud extends reach; it does not bypass your bar.

Habits that work

  1. Review each diff before accept — catch scope creep early.
  2. Ask for ranked findings — security and edge cases on the actual change.
  3. Name behaviors and test files — table-driven when it fits your repo.
  4. One verify command in every feature or fix brief — Developing features.
  5. Reject skipped or deleted tests — same as a human contributor.
  6. Use rules for team conventions — Customizing agents.

Where to go next

Your goalNext step
Build the featureDeveloping features
Fix a defectFinding and fixing bugs
Session disciplineWorking with agents
Prompt templatesPrompting
CI agent reviewCLI headless
End-to-end workflowPutting it all together

Questions about reviewing and testing code?

QuestionAnswer
Can the agent replace code review?No — it assists; you and your team own merge.
Should I review agent code more carefully?Same bar — sometimes more, because scope creep is common.
Can it review my handwritten diff?Yes — @ files or paste the PR scope; ask for focused findings.
Will it always suggest good tests?Only if you name behaviors — vague asks get vague tests.
What about cloud runs I did not watch?Start with Diff, then Review summary — Cloud agents overview.
Does review use more tokens?Long second passes do — Tokens & pricing.
Agent vs human review on my team?Both — agent for speed; humans for judgment and policy when required.
What if tests pass but UX feels wrong?Manual smoke — tests do not replace your product sense.