Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/cart-total.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function cartTotal(items: { price: number; qty: number }[]): number {
let total = 0;
for (let i = 0; i <= items.length; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The loop condition i <= items.length is an off-by-one error and should be i < items.length. This will cause an error when accessing an out-of-bounds index.
Severity: CRITICAL

Suggested Fix

Change the loop condition from i <= items.length to i < items.length to correctly iterate over the array indices without going out of bounds.

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#L3

Potential issue: The `for` loop iterates one time too many due to the condition `i <=
items.length`. On the final iteration, `i` will be equal to `items.length`, making
`items[i]` `undefined`. Attempting to access the `.price` property on this `undefined`
value will throw a `TypeError`, causing the function to crash for any cart that is not
empty.

Did we get this right? 👍 / 👎 to inform future reviews.

total += items[i].price * items[i].qty;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cart total loop overflows

High Severity

The loop condition uses <= against items.length, so the last iteration reads past the end of the array and throws when it dereferences undefined. cartTotal therefore crashes for every cart, including an empty one.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e17dc4d. Configure here.

}
return total;
}
3 changes: 3 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/currency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function formatUsd(cents: number): string {
return "$" + cents / 100;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currency drops trailing zeros

Medium Severity

formatUsd concatenates cents / 100 without forcing two decimal places, so whole-dollar and single-digit-cent amounts lose trailing zeros. Checkout, receipts, and confirmation emails would show incomplete money values.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e17dc4d. Configure here.

}
3 changes: 3 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/discount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function applyDiscount(total: number, percent: number): number {
return total - total * percent;
}
3 changes: 3 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isEmail(value: string): boolean {
return value.includes("@");
}
3 changes: 3 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/loyalty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function pointsFor(totalCents: number): number {
return Math.round(totalCents / 100) * 1.5;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The loyalty point calculation can result in fractional points because the final result of ... * 1.5 is not rounded to an integer.
Severity: MEDIUM

Suggested Fix

Wrap the entire calculation in Math.round() to ensure the final result is always an integer. The expression should be Math.round(Math.round(totalCents / 100) * 1.5).

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/loyalty.ts#L2

Potential issue: The loyalty point calculation `Math.round(totalCents / 100) * 1.5` can
produce fractional numbers. Since loyalty point systems typically use integers, this may
lead to unexpected behavior, such as data truncation if stored in an integer database
column or display issues in the UI. For example, a purchase of $2.50 (`totalCents =
250`) would result in 4.5 points.

Did we get this right? 👍 / 👎 to inform future reviews.

}
3 changes: 3 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/order-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function nextOrderId(last: string): string {
return String(parseInt(last) + 1);
}
4 changes: 4 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/refund-window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function canRefund(deliveredAt: Date, now = new Date()): boolean {
const days = (now.getTime() - deliveredAt.getTime()) / 86400;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The millisecond timestamp difference is divided by the number of seconds in a day (86400) instead of milliseconds, making the refund window 1000x shorter than intended.
Severity: HIGH

Suggested Fix

To correctly convert the millisecond difference to days, divide by 86_400_000 (or 1000 * 60 * 60 * 24) instead of 86400.

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/refund-window.ts#L2

Potential issue: The calculation for the number of days since delivery divides a
millisecond timestamp difference by `86400` (the number of seconds in a day) instead of
`86_400_000` (the number of milliseconds in a day). This results in the calculated
`days` value being 1000 times larger than the actual value. Consequently, an intended
30-day refund window is effectively reduced to approximately 43 minutes, causing valid
refund requests to be incorrectly denied.

Did we get this right? 👍 / 👎 to inform future reviews.

return days <= 30;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refund window uses wrong units

High Severity

canRefund divides a millisecond timestamp delta by 86400 (seconds in a day) instead of milliseconds in a day. The days &lt;= 30 check then treats the refund window as about 43 minutes, so nearly every eligible return is rejected.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e17dc4d. Configure here.

}
4 changes: 4 additions & 0 deletions apps/pr-reviewer/fixtures/demo-pr/shipping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function shippingCost(weightKg: number, express = false): number {
const base = weightKg > 5 ? 12 : 6;
return express ? base * 2 : base;
}
Loading