Skip to content

feat: report the average price per unit - #25

Open
amery wants to merge 1 commit into
poupe-ui:mainfrom
amery:trial-skill-fork
Open

amery wants to merge 1 commit into
poupe-ui:mainfrom
amery:trial-skill-fork

Conversation

@amery

@amery amery commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Trial 5 of the full-review skill, from the amery fork: asking
@claude full review here should run main's skill without make, and
post a review. Adds averageUnitPrice, which divides by the number of
items rather than the number of units.

Add averageUnitPrice, which divides the cart's total by its units and
rejects an empty cart.

Signed-off-by: Alejandro Mery <amery@apptly.co>
@amery

amery commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai pause

@amery
amery marked this pull request as ready for review October 6, 2026 01:01
@amery

amery commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@claude full review

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a2c9251-017f-47dd-bdec-001682468396
📥 Commits

Reviewing files that changed from the base of the PR and between 060ad27 and cb1adc2.

📒 Files selected for processing (1)
  • src/cart.js
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude

claude Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Claude finished @amery's task in 16s —— View job


Full review of PR #25

  • Read AGENTS.md from main
  • Reviewed the diff in src/cart.js
  • Posted findings inline

Findings

  • Bug (src/cart.js:21): averageUnitPrice divides by items.length (line items) instead of the total quantity (units). This contradicts its docs and PR description, and gives wrong results whenever a quantity is not 1. I posted this as an inline comment.

AGENTS.md compliance: The new exported function has a JSDoc comment, so it follows the rule.

CI: I didn't check CI results. gh pr checks needed approval that I didn't have here.

Comment thread src/cart.js
if (items.length === 0) {
throw new RangeError('items must not be empty');
}
return totalItems(items) / items.length;

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 function is documented as the average price per unit, but it divides the line-total sum by items.length (number of line items), not by the total quantity of units. totalItems returns Σ price × quantity, so the matching divisor is Σ quantity.

Example: [{price: 10, quantity: 3}] gives 30 / 1 = 30, but the average unit price is 10. With [{price: 10, quantity: 1}, {price: 20, quantity: 3}] it returns 35, not 17.5.

The empty check has the same problem: items with all-zero quantities pass it and then divide by zero, returning NaN.

Suggested fix: sum item.quantity across items, guard on that total being 0, and divide by it.

Fix this →

@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

@amery

amery commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@claude full review

@claude

claude Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Claude finished @amery's task in 22s —— View job


Full review of PR #25

Finding (already posted inline, not duplicated): src/cart.js:21 divides totalItems(items) (which is Σ price × quantity) by items.length (the number of line items), not by the total quantity. This contradicts the function's JSDoc ("average price per unit") and the PR description, which says the function divides by units. For example, [{price: 10, quantity: 3}] returns 30 instead of 10. The empty check has the same flaw. Items whose quantities are all 0 pass it and return NaN. The fix is to divide by Σ item.quantity and throw RangeError when that sum is 0.

AGENTS.md compliance: No violations. I checked the root AGENTS.md (exported functions need JSDoc) and src/AGENTS.md (invalid arguments throw RangeError or TypeError). averageUnitPrice has a JSDoc comment and throws RangeError.

CI: check passes. claude and claude-review were skipped. CodeRabbit is paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant