Repository navigation
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e5c70d3. Configure here.
| } | ||
| total += items[i].price * items[i].qty; | ||
| const line = items[i].price * items[i].qty; | ||
| total += line - (items[i].discountCents ?? 0); |
There was a problem hiding this comment.
Discount can make cart total negative
High Severity
discountCents is subtracted from the line in full, so cartTotal can return a negative amount when the discount exceeds price * qty or when quantity is zero. Zero-quantity items previously contributed nothing to the total.
Reviewed by Cursor Bugbot for commit e5c70d3. Configure here.
| } | ||
| total += items[i].price * items[i].qty; | ||
| const line = items[i].price * items[i].qty; | ||
| total += line - (items[i].discountCents ?? 0); |
There was a problem hiding this comment.
Bug: The discountCents value is not validated, which can lead to incorrect cart totals if it's negative or larger than the line item price.
Severity: HIGH
Suggested Fix
Add validation to ensure discountCents is not negative and does not exceed the line item's total price. Throw a RangeError if the value is invalid, similar to the existing validation for qty.
const line = items[i].price * items[i].qty;
if ((items[i].discountCents ?? 0) < 0) {
throw new RangeError(`Negative discount for item ${i}`);
}
if ((items[i].discountCents ?? 0) > line) {
throw new RangeError(`Discount exceeds line total for item ${i}`);
}
total += line - (items[i].discountCents ?? 0);Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: apps/pr-reviewer/fixtures/demo-pr/cart-total.ts#L10
Potential issue: The `cartTotal` function applies a discount from `discountCents`
without proper validation. This allows for two potential issues: 1) If `discountCents`
is a negative number, it will be added to the line item's total, incorrectly inflating
the final price. 2) If `discountCents` is greater than the line item's total price, it
will result in a negative value for that line item, which could lead to a negative
overall cart total, effectively paying a customer to take items.
Did we get this right? 👍 / 👎 to inform future reviews.
|
Verdict: Needs changes — unit mismatch and missing validation around the new Correctness
These are edge cases that could matter in production financial code (even in a fixture/demo file), and the existing codebase pattern (explicit RangeError on bad Style
Tests
|
Co-authored-by: Claude <[email protected]>
e5c70d3 to
ed75ccc
Compare
|
Verdict: Request changes — the discount logic has unvalidated edge cases and a likely unit mismatch that should be addressed before merge. Correctness
Style
Tests
|


Demo pull request for the workshop. Do not merge.
Lets a cart item carry a discount in cents and subtracts it from the line before it is added to the total.
Created with Claude Code