fix(api/history): exclude cancelled executions from KPI aggregation (closes #736) - #737
Conversation
summarizePurchaseHistory had no case for the "cancelled" status in its switch, so cancelled rows fell through to the default path and added their UpfrontCost and EstimatedSavings to TotalUpfront, TotalMonthlySavings, and TotalAnnualSavings -- as if the purchase had been approved. A cancelled purchase represents zero committed spend and zero realized savings, so it must be excluded from all three aggregates (and from TotalCompleted). Fix: add `case "cancelled": continue` to the switch, matching the existing pattern for pending/failed/expired rows. Update the comment on HistorySummary.TotalPurchases and the inline comment in the loop to document the cancelled exclusion. Regression tests (issue #736): - TestSummarizePurchaseHistory_CancelledExcludedFromKPIs: N completed rows + 1 pending + 2 pre-existing cancelled rows; asserts only the completed rows contribute to the dollar totals. - TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs: mirrors the QA reproduction scenario -- baseline KPI totals captured, then a cancelled row added; asserts all three KPIs and TotalCompleted are unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughUpdated ChangesCancelled Purchase Exclusion from KPI Totals
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
…loses #625) (#821) * fix(purchases): cite #625 in cancelled-KPI regression tests summarizePurchaseHistory already excludes cancelled rows from dollar totals (landed in #737 against #736). Issue #625 describes the same bug -- this commit updates the two existing regression-test comments and assertion messages to cite both issues so the PR can formally close #625. Closes #625 * test(purchases): fix misspell/prealloc/govet in handler_history_test - cancelled->canceled, Cancelling->Canceling, cancelling->canceling, synthesised->synthesized, honour->honor in comments/test messages; Status:"cancelled" DB enum values suppressed with //nolint:misspell - prealloc: preallocate baseline slice with cap 4 in TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs - govet fieldalignment: suppress anonymous test-table struct in TestHandler_getHistory_FilterValidation with //nolint:govet * fix(lint): fix govet/misspell nolints in handler_history_test - Remove nolint:govet by reordering test-case struct fields to optimal alignment (map+string+string+int = 40 bytes, down from 48). - Annotate three nolint:misspell directives on "cancelled" with the DB-schema-value exception note referencing migration 000001. - Drop redundant misspell suppress from the append line (nolint:gocritic retained for the appendAssign check added in an earlier pass).
Summary
Fixes #736 (P1). The
summarizePurchaseHistoryaggregator ininternal/api/handler_history.gohad aswitch p.Statuscovering pending/notified/approved/running/paused/failed/expired but no case forcancelled— rows fell through to the default branch which incrementedTotalCompleted,TotalUpfront,TotalMonthlySavings, and (via*12)TotalAnnualSavings. Result: cancelling a pending purchase added its costs and savings to the KPIs as if it had completed.Cancel mutation was correct (transitions to
status='cancelled'); fix is solely in the aggregation switch.analytics_postgres.go'sHistorySummarypath is unaffected — it queriespurchase_historywhich only contains rows written after successful purchase, so cancelled executions never reach it.Test plan
TestSummarizePurchaseHistory_CancelledExcludedFromKPIsand..._CancelPendingDoesNotChangeKPIspassinternal/apisuite: 1233 pass, 0 failgo build ./...cleanSource of finding: QA verification spreadsheet row 278 (Approval queue step 1.6).
Summary by CodeRabbit
Bug Fixes
Documentation