Repository navigation
fix: child unique reference handling - #4385
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaces SnapshotQuantities with a ForceCollect flow (trigger, service API, HTTP handler, and state machine); adds Service.ForceCollectInvoice; removes ChildUniqueReferenceID from gathering-line creation; adds Charge.GetUniqueReferenceID; refactors subscription-sync charge assertion tests and related test doubles; adds a SKILL troubleshooting note. ChangesInvoice Force Collection and Charge Reference Updates
Sequence DiagramsequenceDiagram
participant HTTPHandler as ProgressInvoice handler
participant Service as Service.ForceCollectInvoice
participant Executor as executeTriggerOnInvoice
participant State as stdinvoicestate (TriggerForceCollect)
HTTPHandler->>Service: call ForceCollectInvoice(invoiceID)
Service->>Executor: executeTriggerOnInvoice(invoiceID, TriggerForceCollect)
Executor->>State: fire TriggerForceCollect -> transition DraftWaitingForCollection -> DraftCollecting
State-->>Executor: transition result (StandardInvoice)
Executor-->>Service: return StandardInvoice
Service-->>HTTPHandler: return StandardInvoice response
🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
openmeter/billing/worker/subscriptionsync/service/base_test.go (1)
519-522: ⚡ Quick winUse the repo’s preferred decimal assertion style in tests
Could we align this with the test guideline and compare
InexactFloat64()viarequire.Equalhere?Example adjustment
- s.AssertDecimalEqual(expectedFlatPrice.Amount, flatFeeCharge.Intent.AmountBeforeProration, fmt.Sprintf("%s: amount before proration", childID)) + require.Equal( + s.T(), + expectedFlatPrice.Amount.InexactFloat64(), + flatFeeCharge.Intent.AmountBeforeProration.InexactFloat64(), + "%s: amount before proration", + childID, + )As per coding guidelines: "When asserting
alpacadecimal.Decimalequality in tests, preferrequire.Equal(t, expectedFloat64, actual.InexactFloat64())over boolean assertions, and use simple float64 literals over verbose decimal construction".🤖 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 `@openmeter/billing/worker/subscriptionsync/service/base_test.go` around lines 519 - 522, Replace the custom decimal assertion with the repo preferred style: keep the s.NoError(err) after expectedFlatPrice, then replace s.AssertDecimalEqual(expectedFlatPrice.Amount, flatFeeCharge.Intent.AmountBeforeProration, fmt.Sprintf("%s: amount before proration", childID)) with require.Equal(s.T(), expectedFlatPrice.InexactFloat64(), flatFeeCharge.Intent.AmountBeforeProration.InexactFloat64(), fmt.Sprintf("%s: amount before proration", childID)); reference symbols: expectedFlatPrice, s.NoError, flatFeeCharge.Intent.AmountBeforeProration, childID, and require.Equal.
🤖 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 `@openmeter/billing/worker/subscriptionsync/service/base_test.go`:
- Around line 559-567: The test currently uses lo.Find to match
expectedRealization against actualRealizations which can reuse the same actual
entry for duplicate keys; change the logic to locate the index of the matching
actualRealization (e.g., iterate actualRealizations or use lo.FindIndex with the
same predicate), assert found, then remove that element from the
actualRealizations slice (consume it) so subsequent matches cannot reuse it;
apply the same consume-on-match change in the other loop (the one around lines
612-619) and in assertChargeGatheringLines to ensure duplicates are handled
correctly.
- Around line 430-433: Add a nil guard before accessing expectedCharge.Matcher
in the loop that iterates expectedCharges: assert that expectedCharge.Matcher is
not nil (e.g., with s.Require().NotNil(expectedCharge.Matcher, "expected charge
matcher")) prior to calling expectedCharge.Matcher.ChildIDs(subscriptionID.ID)
so a missing matcher fails with a readable assertion; update the loop in
base_test.go where expectedCharge.Matcher.ChildIDs is invoked to perform this
check (and only call ChildIDs after the nil assertion).
---
Nitpick comments:
In `@openmeter/billing/worker/subscriptionsync/service/base_test.go`:
- Around line 519-522: Replace the custom decimal assertion with the repo
preferred style: keep the s.NoError(err) after expectedFlatPrice, then replace
s.AssertDecimalEqual(expectedFlatPrice.Amount,
flatFeeCharge.Intent.AmountBeforeProration, fmt.Sprintf("%s: amount before
proration", childID)) with require.Equal(s.T(),
expectedFlatPrice.InexactFloat64(),
flatFeeCharge.Intent.AmountBeforeProration.InexactFloat64(), fmt.Sprintf("%s:
amount before proration", childID)); reference symbols: expectedFlatPrice,
s.NoError, flatFeeCharge.Intent.AmountBeforeProration, childID, and
require.Equal.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 900d2f95-98ee-4448-ba7d-37338d05876e
📒 Files selected for processing (3)
.agents/skills/test/SKILL.mdopenmeter/billing/worker/subscriptionsync/service/base_test.goopenmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go
fef7a49 to
3079dda
Compare
Overview
This patch makes sure that for charges based billing we are relying on the ChargeID to identify children instead of ChildUniqueReferenceID.
That was only used when we didn't have a central object. Unfortunately this affected the already converted testcases, so a new assertion method is added with charges focus.
Notes for reviewer
Summary by CodeRabbit
New Features
Changes
Tests
Documentation