Career BreakHQYOUR NEXT CHAPTER
← AI skills library

Software engineering · ABOUT 30 MINUTES · BASIC JAVASCRIPT READING

Review an AI bug fix with boundary tests

Refresh a familiar engineering habit: turn a bug report into a small, testable change. Ask an AI assistant for a proposal, then use your own contract and checks to decide whether it holds up.

You’ll make: A synthetic bug report, a reviewed one-line fix, six checked cases and a short review note.

STEP 01

Read the contract before the code

This fictional function counts pages of search results. Assume totalItems is a nonnegative safe integer and pageSize is a positive safe integer. A partly filled page counts as one page; zero items needs zero pages. The caller validates inputs. Strings, negatives, zero page size and unsafe integers are outside this exercise, not silently supported.

You need basic JavaScript reading skills. Use only the code here in an AI chat you’re allowed to use. Never paste employer repositories, credentials, customer records or private bug reports. Do not connect a repository or grant an agent access for this exercise. Tool access and prices vary; no paid account is required for the manual path.

For 11 items at 10 per page, sketch one full page and one partial page. The expected count is 2. Read the current implementation:

function pageCount(totalItems, pageSize) {
  return Math.floor(totalItems / pageSize);
}

Math.floor rounds the quotient down: 11 / 10 becomes 1.1, then 1. That loses the last page. Keep this failing example before changing anything.

STEP 02

Ask for a proposal, not a verdict

Copy the prompt below into your approved AI chat, with automatic execution and repository access off. Save its proposed patch and predicted tests. Treat both as unverified.

No AI access? Write your own candidate fix and test predictions, then continue. Describe that version as manual practice rather than AI-assisted work.

Try this prompt
Review this synthetic JavaScript exercise. Contract: totalItems is a nonnegative safe integer, pageSize is a positive safe integer, and pageCount returns the number of pages needed, including a partially filled last page. Zero items means zero pages. The caller validates inputs; invalid inputs are outside this exercise.

function pageCount(totalItems, pageSize) {
  return Math.floor(totalItems / pageSize);
}

For 11 items at 10 per page, the expected result is 2. Explain the bug, suggest the smallest patch and propose tests for empty, exact-multiple and partial-page cases. Do not change the contract, add dependencies or claim tests ran. Label predicted results as predictions. Identify what this small test set does not prove.

Paste into your approved AI tool. This site does not call an AI model.

STEP 03

Check boundaries independently

Write expected results before running the candidate: 0/10 → 0; 1/10 → 1; 10/10 → 1; 11/10 → 2; 20/10 → 2; 21/10 → 3. The two exact multiples help catch a plausible but wrong “add one page” patch.

Optional execution: in an empty local JavaScript file or a blank browser tab’s developer console, copy the original function and the test harness below. Review every line first. It has no packages, files or network calls. Do not run it in a work app’s console or execute unfamiliar AI-generated commands.

const cases = [
  [0, 10, 0], [1, 10, 1], [10, 10, 1],
  [11, 10, 2], [20, 10, 2], [21, 10, 3]
];
let failures = 0;
for (const [total, size, expected] of cases) {
  const actual = pageCount(total, size);
  const ok = actual === expected;
  if (!ok) failures++;
  console.log(
    (ok ? "PASS" : "FAIL") + " " + total + "/" + size +
    ": expected " + expected + ", got " + actual
  );
}
console.log(failures + " failing checks");

The original should report 3 failing checks: 1, 11 and 21 items. Then replace only the function with your reviewed candidate and rerun the same harness. Keep both outputs. If you cannot run code, trace each division and rounding step by hand and label the result “manually checked”, not “tests passed”.

Compare the checked fix and results
function pageCount(totalItems, pageSize) {
  return Math.ceil(totalItems / pageSize);
}

The fixed results are 0, 1, 1, 2, 2, 3 in the listed order: 0 failing checks. Math.ceil rounds up, so it preserves exact multiples and counts partial pages. Reject Math.floor(totalItems / pageSize) + 1: it incorrectly returns 1 for zero items and 2 for 10/10.

STEP 04

Review scope and remaining risk

Compare the patch against the contract line by line. A fix that changes expected values to match the bug, adds a special case only for 11 items, or brings in a dependency has not solved the stated problem cleanly.

These six cases establish their own results, not exhaustive correctness, security or production readiness. We did not test input validation, integration with a UI or large-value behavior. In a real project, confirm who validates inputs and run the relevant project tests and human review before merging.

GitHub’s responsible-use guidance treats AI review as assistance requiring human scrutiny. A confident explanation or “all tests pass” sentence is not an execution log. Separate predictions, manually checked results and results you actually ran.

STEP 05

Save a small review note

Keep the synthetic contract, original bug, AI proposal if used, final patch, expected values and actual or manual results together. Write a short note: what failed, why the patch works for the contract, what you rejected and what remains untested.

Example to adapt only after doing it: “The original rounded partial pages down. I checked empty, exact-multiple and partial-page cases and rejected an unconditional +1 fix. The revised function matched all six expected values. Input validation and application integration remain outside this practice.” Add whether you executed the harness or traced it manually.

PAUSE & CHECK

Does it hold up?

See the explanation

No. It returns 2, but exactly 10 items fit on 1 page. It also returns 1 for zero items instead of 0. Checking only the original 11-item bug would miss these regressions.

ONLY AFTER YOU’VE DONE THE WORK

A truthful way to describe it

In self-directed practice with synthetic JavaScript, I reviewed a pagination bug fix against a written contract and six boundary cases, documented my checks and noted what remained untested. If you used AI, name how it helped; if you traced cases by hand, say so. This was practice, not production engineering work.

Use this only if it accurately describes your completed practice. Adapt it to the tool and checks you actually used. It is not a certificate or a claim of professional experience.

Sources & editorial notes

Feature documentation checked 16 October 2026. The practice brief and teaching checks are original editorial exercises. Interfaces and account availability can change.

No sponsor funded this tutorial. No affiliate links. Our sponsorship policy.

Choose another practice →