Review the AI's code
An AI-written function with five planted bugs. Flag the lines you doubt, run the tests, and see which bugs tests catch and which only reading finds.
Read the function first and tap the number of any line you would question. Then run the tests, and only then show the bugs.
Example data. The tests run in your browser on a copy of this Python function that behaves the same way, checked against real Python 3 and sqlite3.
customer_report.py, written by an AI tool
def customer_report(db, email, min_amount=0):
"""Total, average and biggest order for one customer.
Counts orders of at least min_amount."""
rows = db.execute(
f"SELECT id, amount FROM orders WHERE email = '{email}'").fetchall()
print("debug:", email, [r["amount"] for r in rows])kept = [r for r in rows if r["amount"] > min_amount]
total = sum(r["amount"] for r in kept)
average = total / len(kept)
biggest = sorted(kept, key=lambda r: r["amount"])[0]
return {"total": total,
"average": round(average, 2),
"biggest": biggest["id"],
}
Tests passing
Not run
Bugs the tests catch
Not run
Lines you flagged
0
Test results
Pick tests and run them. All green is not the same as no bugs.
The example table the tests use
| id | amount | |
|---|---|---|
| A-101 | [email protected] | 120.00 |
| A-102 | [email protected] | 80.00 |
| A-103 | [email protected] | 40.00 |
| B-201 | [email protected] | 60.00 |
| C-301 | o'[email protected] | 95.00 |
Tests only check what someone thought to test. Reading the diff for secrets, string-built SQL and data that should not leave the function (step 5 of the review routine) finds what they miss.