fix(approvals): populate Account/Payment/MonthlyCost on Approval queue rows (refs #704) - #738
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR refines the ChangesAccount ID Filtering with Effective Account Resolution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/api/handler_history_test.go (1)
1117-1249: ⚡ Quick winAdd a regression case for account_ids filtering with rec-level AccountID fallback
This suite is strong, but it misses the account-filter path for web-bulk rows (
exec.CloudAccountID=nil, rec-levelCloudAccountIDset). A targeted sub-test here would lock the behavior and prevent silent drops when account filters are active.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/api/handler_history_test.go` around lines 1117 - 1249, Add a new sub-test inside TestHandler_getHistory_ApprovalQueueColumnsPopulated that verifies account filtering when exec.CloudAccountID is nil but recommendations carry CloudAccountID: create a pending execution with exec.CloudAccountID unset and a RecommendationRecord whose CloudAccountID is set, call handler.getHistory (using MockConfigStore stubs for GetExecutionsByStatuses, GetAllPurchaseHistory and GetGlobalConfig and adminHistoryReq for auth/req), pass an account_id filter in the request map, and assert that the returned row is present and row.AccountID equals the rec.CloudAccountID; this ensures the account filter path uses the rec-level fallback in getHistory.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/api/handler_history.go`:
- Around line 228-237: historyFilters.matchesExecution currently checks
exec.CloudAccountID directly and thus rejects web bulk-purchase executions where
CloudAccountID is nil even though the UI fallback uses
collapseRecommendationAccount(exec.Recommendations) for rendering; update
matchesExecution to use the same fallback: when exec.CloudAccountID is
empty/nil, call collapseRecommendationAccount(exec.Recommendations) and use that
value for account_id comparisons (treat empty string from
collapseRecommendationAccount as a non-match as before). Ensure you reference
and update the logic inside historyFilters.matchesExecution (and any helper it
calls) so filtering behavior matches the display fallback.
---
Nitpick comments:
In `@internal/api/handler_history_test.go`:
- Around line 1117-1249: Add a new sub-test inside
TestHandler_getHistory_ApprovalQueueColumnsPopulated that verifies account
filtering when exec.CloudAccountID is nil but recommendations carry
CloudAccountID: create a pending execution with exec.CloudAccountID unset and a
RecommendationRecord whose CloudAccountID is set, call handler.getHistory (using
MockConfigStore stubs for GetExecutionsByStatuses, GetAllPurchaseHistory and
GetGlobalConfig and adminHistoryReq for auth/req), pass an account_id filter in
the request map, and assert that the returned row is present and row.AccountID
equals the rec.CloudAccountID; this ensures the account filter path uses the
rec-level fallback in getHistory.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 712adc07-03fc-43a6-b6f7-e7fab7907bbb
📒 Files selected for processing (3)
frontend/src/__tests__/history-approval-queue.test.tsinternal/api/handler_history.gointernal/api/handler_history_test.go
, CR #738) matchesExecution previously rejected executions with a nil exec.CloudAccountID even though executionToHistoryRow uses collapseRecommendationAccount as a fallback. Web bulk-purchase flows only populate the per-rec CloudAccountID, so an account-filtered approval queue silently dropped all web-initiated pending rows. Align matchesExecution with the same two-level resolution logic. test(approvals): assert account_ids filter uses rec-level fallback (CR #738) Add a regression sub-test inside TestHandler_getHistory_ApprovalQueueColumnsPopulated that seeds a pending execution with exec.CloudAccountID=nil and a rec carrying the target UUID, then asserts the row survives the account_ids filter and that row.AccountID equals the rec's CloudAccountID.
|
Addressed the nitpick in commit 8704e49 - added a sub-test in @coderabbitai review |
|
✅ Actions performedReview triggered.
|
, CR #738) matchesExecution previously rejected executions with a nil exec.CloudAccountID even though executionToHistoryRow uses collapseRecommendationAccount as a fallback. Web bulk-purchase flows only populate the per-rec CloudAccountID, so an account-filtered approval queue silently dropped all web-initiated pending rows. Align matchesExecution with the same two-level resolution logic. test(approvals): assert account_ids filter uses rec-level fallback (CR #738) Add a regression sub-test inside TestHandler_getHistory_ApprovalQueueColumnsPopulated that seeds a pending execution with exec.CloudAccountID=nil and a rec carrying the target UUID, then asserts the row survives the account_ids filter and that row.AccountID equals the rec's CloudAccountID.
8704e49 to
933fdb2
Compare
|
Rebased onto current base branch (resolved conflicts with #729, #737, #740, #734 merged in). @coderabbitai review |
|
✅ Actions performedReview triggered.
|
Summary
Fixes #704 follow-up (PR #713 added the columns but data wasn't populated; verification on QA row 274 still failed with all cells showing
-).Root cause:
executionToHistoryRowandprojectRecommendationFieldsininternal/api/handler_history.gonever wroteAccountorPaymentonto Approval queue rows for web-initiated bulk purchases.buildPendingExecutionsets account IDs at the per-recommendation level only, never on the execution. Similarly,r.Paymentwas never copied ontorow.Paymentin either the single-rec or multi-rec branch. Frontend accessors were already wired correctly; they just had nothing to read.Changes
executionToHistoryRow: fall back tocollapseRecommendationAccount(exec.Recommendations)whenexec.CloudAccountIDis nil.projectRecommendationFieldssingle-rec branch: copyr.Paymenttorow.Payment.projectRecommendationFieldsmulti-rec branch:row.Payment = collapseRecommendationPayment(recs)androw.MonthlyCost = sumRecommendationMonthlyCost(recs).collapseRecommendationPayment,collapseRecommendationAccount,sumRecommendationMonthlyCost.Test plan
TestHandler_getHistory_ApprovalQueueColumnsPopulatedcovers 3 shapes (single-rec, multi-rec uniform payment, multi-rec heterogeneous payment)TestHandler_getHistory_InProgressRowMapsRecFieldsextended with Payment assertion-internal/api: 1277 passgo vetcleanCloses #733 referenced in commit; verifies QA row 274.
Summary by CodeRabbit
Bug Fixes
Tests