Repository navigation
fix(api): refuse marketplace pricing for an RI with no purchase timestamp - #448
Conversation
…tamp computeRemainingMonths returned 1 for a zero timestamp, so a row without a timestamp was listed at 1/termMonths of its upfront cost. It now returns an error for a zero timestamp or non-positive term; the separate Term <= 0 check in marketplaceList folds into it.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour. 📝 WalkthroughWalkthroughMarketplace listing now returns an error for a purchase with a zero timestamp or non-positive term. Valid remaining-month calculations retain the one-month minimum. ChangesMarketplace listing validation
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: High Merge Risk: ⚪ Minimal · up to No actionable issue remains before merge under normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Independent adversarial review (Opus 5.5) at 3936b03: MERGE. computeRemainingMonths now errors on a zero purchase timestamp or non-positive term instead of returning 1, which had listed the RI at 1/termMonths of its upfront cost. It fails closed before the price schedule, the EC2 client and reserveAndCreateListing, so no listing row and no marketplace call happen. The valid-timestamp math is unchanged. Pre-fix: TestMarketplaceList_ZeroTimestampReturnsError reaches listing reservation on main (panic) and passes here. go test -race -short ./internal/api 2369 pass, golangci-lint v2.10.1 clean; CI 25/25. Follow-up filed (reject expired RIs, 4xx instead of 500). (branch updated with main; reviewed changes unchanged) |
Summary
Marketplace listing no longer prices an RI whose purchase_history row has no timestamp. It returns an explicit error instead.
Root cause
computeRemainingMonthsreturned 1 for a zeropurchaseTime, so the default schedule becameupfront * 1/termMonths * 0.95(a $36k 3-year RI listed at about $950). The supplied-schedule floor used the same value, so it could not catch it.Fix
computeRemainingMonthsnow returns(int, error)and errors on a zero timestamp or non-positive term.marketplaceListreturns that error. The separateTerm <= 0check folds into the helper (keepsmarketplaceListunder the gocyclo 10 budget; the error still contains "invalid term"). No other code computes remaining term from timestamps (greppedinternal/).Regression test
TestMarketplaceList_ZeroTimestampReturnsErrorasserts an error and zeroCreateMarketplaceListingcalls. Against the pre-fix handler (fix stashed) it fails:--- FAIL: TestMarketplaceList_ZeroTimestampReturnsError.TestComputeRemainingMonthsupdated for the new contract.Verification
GOTOOLCHAIN=go1.26.6 go test -race -short ./internal/api/: okCloses #98
Summary by CodeRabbit