How to Review a Pull Request From an AI

Review an AI’s change in a different order than a human’s (this is the how-to; why ownership of the change is yours is its own essay): files touched first, then new dependencies, then what happened to the tests, then the deleted lines. Read the description last. An AI tool can make a change look finished, and the places it cuts corners are the places it does not show you.
The order, in short:
- The list of changed files, before any content.
- New dependencies: do they exist, and did you want them?
- The test changes: any assertion loosened or removed?
- Old tests on the new code.
- Deleted lines only.
- Break it by hand: typos, empty, negative.
- What was added that nobody asked for?
The rest runs those steps on a small example, with real output.
How do I review a pull request from an AI?
A pull request (PR) is GitHub’s page for comparing a set of changes against your main code before you accept them. A diff is that comparison: lines removed in red, lines added in green. You do not need a team. Lovable, for one, can sync a project to GitHub, where its docs say you can “review changes in pull requests” (Lovable’s docs). With no PR at all, the same steps work on the AI’s last change via git diff HEAD~1. New to git? Start with git for vibe coders.
The example, and what it is
The demo is a tiny shopping cart. The AI was asked to add two discount codes, WELCOME10 (10% off) and SAVE25 (25% off), case-insensitive. Its “pull request” was written by hand to contain common mistakes. It is not a real AI PR and not a measured rate of anything.
The PR passes its own tests, 4 of 4, so CI (the robot that runs your tests on every change) would show a green tick. It still has four problems, one of which makes an order total negative.
Get the files (download the whole folder as a zip, or browse /examples/ai-pr-review/). You need Node 22 and git, on Mac, Linux or Windows.
node make-repo.mjs /tmp/pr-review-democd /tmp/pr-review-demoThat builds a scratch repo with branches main, ai/discount (the PR) and fixed, and leaves you on ai/discount.
Step 1: read the list of files before any content
git diff main --stat cart.js | 14 +++++++++----- package.json | 4 +++- test/cart.test.js | 11 +++++++---- 3 files changed, 19 insertions(+), 10 deletions(-)A task that said “add two codes” touched a package file and deleted ten lines. Every time, before content, read the file names and ask whether each was needed. Pay extra attention to: CI settings (.github/workflows), lockfiles, .env files, anything about login or payments, and test config. Those are the files where a quiet change costs the most.
Step 2: check every new dependency
git diff main -- package.json"dependencies": {}"dependencies": { "example-hallucinated-discount-pkg": "^1.2.0"}The code never uses it. Now ask the registry whether it is real:
npm view example-hallucinated-discount-pkgnpm error code E404npm error 404 Not Found - GET https://registry.npmjs.org/example-hallucinated-discount-pkg - Not foundIt does not exist. (npm view works from any folder, no project needed. The name here is deliberately fake and was unregistered when this was written.) The 404 is the easy case. The dangerous one is a name an attacker has already registered, and npm view on it returns an answer that looks normal. Read the creation date (a package made last week), the version count (one), and the repository line (none). Anything like that for a package an AI just suggested is a reason to stop and ask where the name came from. AI tools invent package names. A USENIX Security 2025 paper generated 576,000 code samples from 16 models and found that, at least 5.2% of the packages suggested by commercial models and 21.7% by open-source models did not exist. That is about package names in generated code, not about pull requests in general (Spracklen et al.). An attacker can register a name an AI keeps inventing, and your install then pulls their code. For any dependency you did not ask for, check how old it is, who publishes it and whether it links to a real repo. Remove it if you cannot say why it is there.
Step 3: read the test diff before the code diff
git diff main -- test/test("adds up price times quantity, in cents", () => { assert.strictEqual(total(items), 2800); assert.ok(total(items) > 0);});
test("a zero or negative quantity is rejected", () => { assert.throws(() => total([{ name: "Mug", priceCents: 1250, quantity: 0 }]), /Bad quantity/); assert.throws(() => total([{ name: "Mug", priceCents: 1250, quantity: -3 }]), /Bad quantity/);test("WELCOME10 takes 10 percent off", () => { assert.strictEqual(total(items, "WELCOME10"), 2520);});An assertion is the line in a test that says what must be true. Two tells: an exact check (2800) became a vague one (> 0), and a whole test vanished, replaced by new ones, so the pass count still looks healthy.
You can catch part of this with a search instead of your eyes:
git diff main -- test/ | grep -nE '^[-+].*(\.skip|\.only|assert\.ok|> 0|\.todo|toBeDefined|toBeTruthy)'git diff main | grep -n 'catch'10:+ assert.ok(total(items) > 0);21:+ } catch (e) {The first flags skipped or loosened tests, the second new catch blocks, where errors go to be swallowed. They are prompts to look, not verdicts: did the requirement change, or did the code stop meeting it? See test behaviors, not code.
Step 4: run the old tests on the new code
This check settles the argument in ten seconds. Commit or stash your work first. Then put main’s tests on the PR’s code:
git checkout main -- testnode --test --test-reporter=spec✔ adds up price times quantity, in cents✔ an empty cart is zero✖ a zero or negative quantity is rejectedℹ pass 2ℹ fail 1The PR’s own suite said 4 of 4. The project’s original promises say one of them is now broken. Put the PR’s tests back and confirm the tree is clean:
git checkout ai/discount -- testgit status --short # prints nothing when you are back to the PR as it wasStep 5: read only the deleted lines
git diff main -- cart.js | grep -E '^-[^-]'-// Prices are whole cents so we never add 0.1 + 0.2 on money.-function total(items) {- if (!Number.isInteger(item.quantity) || item.quantity < 1) {- throw new Error(`Bad quantity for ${item.name}`);- }The AI deleted the guard against zero and negative quantities, and the comment explaining why money is in cents. It looked like tidying. Every deleted line is a decision someone made once. Ask what it protected before accepting it is gone.
Step 6: try to break it by hand
Before reading the new code, poke at it like a customer would. probe.cjs in the demo folder is five lines of Node that do it:
node /path/to/probe.cjstypo code WELCOME1O -> NaNSTAFF -> 0quantity -3 -> -3750no code -> 2800- A typo in a code returns
NaN. The lookup returnsundefined, and the total becomes “not a number”. Depending on the payment code, that is a broken order or a free one. - A quantity of -3 gives a total of -3750. That is the deleted guard from step 5.
STAFFis a 100% discount. See the next step.
One more, from reading the code: a try { ... } catch (e) { } handles “no code was given” by accident, because undefined.toUpperCase() throws. It would swallow any other error there too. When a catch block does the job of an if, use an if.
Step 7: ask what was added that nobody asked for
STAFF was not in the request. AI tools add things “while they are in there”. A code that makes an order free is a lever, and it needs an owner, a limit and a decision. Ask the author why it exists. The fix branch drops it. If staff discounts are wanted, that is a separate change with its own review.
Write the behavior tests, then fix
The fix is small. The tests come first, written against behavior a customer would notice:
test("an unknown code is an error, not a silent full price or a NaN", () => { assert.throws(() => total(items, "WELCOME1O"), /Unknown discount code/);});
test("no code means full price", () => { assert.strictEqual(total(items), 2800);});Run the new test file against the AI’s branch first, to confirm it catches what the AI’s own tests did not:
$ git checkout fixed -- test && node --test --test-reporter=spec # on ai/discount✔ adds up price times quantity, in cents✔ an empty cart is zero✖ a zero or negative quantity is rejected✔ WELCOME10 takes 10 percent off✔ codes work in any letter case✖ an unknown code is an error, not a silent full price or a NaN✔ no code means full price✔ a discount never makes the total negative or fractionalℹ tests 8 ℹ pass 6 ℹ fail 2Then the fixed code on its own branch:
$ git checkout fixed && node --test --test-reporter=spec✔ adds up price times quantity, in cents✔ an empty cart is zero✔ a zero or negative quantity is rejected✔ WELCOME10 takes 10 percent off✔ codes work in any letter case✔ an unknown code is an error, not a silent full price or a NaN✔ no code means full price✔ a discount never makes the total negative or fractionalℹ tests 8 ℹ pass 8 ℹ fail 0The fixed total restores the guard, throws on an unknown code, and drops STAFF and the invented dependency. The PR’s original four tests still pass on it. More on writing the failing test first: TDD with AI.
What these tests do and miss
Each test calls total with inputs a person could cause and checks what comes back, not how total is written, so the next AI rewrite cannot slip past them. They only protect what they cover: nothing here tests huge quantities, two codes at once, or what the payment step does with the total. When you find a new bug, write the test, then fix.
Paste this into a second AI tool
Here is a pull request diff. Do not summarize it. First list every file itchanged that the task did not require. Then every new dependency, with what itis used for. Then every test line that was removed, skipped or weakened, andwhether the requirement changed. Then every deleted line of non-test code andwhat it was protecting. Then any behavior the PR adds that was not in the task.Finally, write behavior tests (inputs a user could give, outputs they wouldsee) for each risk, run them against the PR branch, and show me the failingoutput. Do not modify the PR code.Check each item against the diff yourself, as you would a human who said “looks fine”.
Check by hand
Next time an AI changes your code, run two commands before reading anything else: git diff --stat and git diff main -- test/. If an unexpected file changed, the tests lost lines, or an exact assertion turned vague, stop and ask why.
On who is accountable for an AI-written change: If You Can’t Own the PR, Please Don’t Open One. A longer review: the before and after teardown. After that: stop pasting the error back.
The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.