Use a small contract, a synthetic pagination bug, and executable tests to review AI-suggested changes without rewriting your application.
Give the model a behavior to check
AI for coding is most useful when you give it one small function and describe what a caller should see. “Review my app” asks the model to guess what matters. “Review this pagination helper for skipped items, duplicates and the last partial page” gives it a specific contract. The code is small enough to trace yourself, and a proposed fix has a clear test.
Start with the smallest excerpt and a made-up input. State the runtime and which guarantees callers can rely on. Leave out credentials, customer records and unrelated source code. Check your organization’s rules and the service’s data terms before sharing anything nonpublic. A synthetic case can preserve the behavior without exposing the original.
Worked example: page two skips a plant
Imagine a community garden inventory. The list has already been sorted, pages start at one, and the caller passes a positive page size. The helper should return up to that many plants, retain the order, and return an empty array past the end.
function pageOf(plants, page, size) {
const start = (page - 1) * size;
return plants.slice(start, start + size - 1);
}
With five names and a page size of two, the second page should contain the third and fourth names. The helper calculates a start index of two and an end index of three. JavaScript’s slice excludes the end index, so it returns only the third name. The next page starts at index four. The fourth name never appears. Check that interpretation using the ECMAScript specification and MDN examples.
Try: “Trace page two for five names, with size two. List the indices and literal expected result. Explain the mismatch. Propose the smallest change, leaving validation and sorting out of scope.” If the model sorts again or starts numbering at zero, it changed the contract instead of fixing the issue.
Make the test fail before making it pass
Save this as page-of.test.mjs and put the helper above the test declarations, after the imports. Run node --test page-of.test.mjs. See the Node.js test runner and assertion reference. Compute expected outcomes independently. A test that copies the production formula can repeat the same mistake.
import test from 'node:test';
import assert from 'node:assert/strict';
const plants = ['basil', 'dill', 'mint', 'sage', 'thyme'];
test('middle page in order', () => {
assert.deepEqual(pageOf(plants, 2, 2), ['mint', 'sage']);
});
test('short final page', () => {
assert.deepEqual(pageOf(plants, 3, 2), ['thyme']);
});
test('nothing past the end', () => {
assert.deepEqual(pageOf(plants, 4, 2), []);
});
The original middle-page check fails; the other two pass. Replace start + size - 1 with start + size and all three pass in this example. The final-page case is worth keeping precisely because the mistake did not show up there. It checks that the correction leaves the working behavior alone.
Read the diff like you have to maintain it
Review the smallest change, then check callers. A separate screen that numbers pages from zero needs its own check against the contract. If invalid values can reach the function, agree what should happen before writing tests for them. Do not let the model choose product behavior by adding a new default while fixing an unrelated bug.
Write down the observed failure, expected output, and command you ran. Say which checks passed and which you did not run. A model can help surface an edge case. A patch is ready when a teammate can follow the reasoning, run the test, and see what it proves.
Keep exploring
Browse the other guides or preview SYN. Check the live site for current availability and terms.
PREVIEW SYN BROWSE RESEARCH