Review a Git diff with Codex CLI
A patch with one changed word can empty a customer’s basket. This drill gives Codex a deliberately broken refactor and gives you a way to judge its review. The chair gets a vote only if it supplies a failing example.
- Before you start
- Git with a commit identity configured, Node.js and Codex CLI installed and signed in. The setup uses a POSIX shell.
- How you’ll know it works
- You can show the wrong output, explain the changed line and verify the correction independently.
Create a known-good baseline
Use a fresh folder. The function removes one item without letting the quantity drop below zero. Commit this version so the reviewer has something to compare against.
git init -b main cart-review
cd cart-review
printf '%s\n' 'export const removeOne = n => Math.max(0, n - 1);' > cart.mjs
git add -- cart.mjs
git commit -m "Keep cart quantities at or above zero"
git switch -c review/quantityIntroduce the one-word regression
Run this only in the cart-review practice repo you just created. It replaces the sample function with a faulty version. Look at the diff before handing it to the assistant.
printf '%s\n' 'export const removeOne = n => Math.min(0, n - 1);' > cart.mjs
git diff HEAD -- cart.mjsThe change replaces an upper/lower bound operation with its opposite. It still returns a number; a test that checks only the return type would approve this with a perfectly straight face.
Ask Codex to review uncommitted changes
Run the review command from the repo. It targets changes that have not been committed. For a normal branch review against main, use the base-branch option instead; choose one target per invocation.
codex review --uncommittedFor a targeted second opinion, launch an interactive session with codex and paste this:
Review the changed cart function without editing it. Our rule is “remove one, with a minimum of zero”. Give the smallest input that violates the rule, its actual and expected results, and the line responsible. Identify anything you have not run.Make the finding earn its merge
Run the same function on zero, one and three items:
node --input-type=module -e "import { removeOne } from './cart.mjs'; console.log([0, 1, 3].map(removeOne))"The broken version yields [-1, 0, 0]. The expected result is [0, 0, 2]. One item hides the defect, three exposes it. Change Math.min back to Math.max and repeat the command. If Codex missed the bug, that counterexample is a better follow-up than “look harder”.