Repository navigation
fix: ent reset list logic - #4406
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 (1)
📝 WalkthroughWalkthroughListActiveEntitlementsWithExpiredUsagePeriod narrows its filters: it evaluates entitlement activity at now, limits results to Metered entitlements, requires a non-nil CurrentUsagePeriodEnd ≤ params.Highwatermark, applies deleted-at checks relative to now, and adds a reset-eligibility predicate (either MeasureUsageFrom is set or HasUsageReset() is true). Tests add a usageResetRepo, persist a reset-anchored metered entitlement, and assert two resettable metered entitlements are returned. ChangesResettable Entitlement Query Filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
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.
🧹 Nitpick comments (1)
openmeter/entitlement/adapter/entitlement_test.go (1)
350-467: ⚡ Quick winAdd a direct assertion for
CurrentUsagePeriodEndNotNilbehavior.Nice coverage overall. One small gap: the test doesn’t explicitly prove that metered entitlements with
CurrentUsagePeriod: nilare excluded. Adding that fixture would lock in the new predicate and prevent regressions.Suggested test addition
+ nilCurrentPeriodEnt, err := repo.entRepo.CreateEntitlement(ctx, entitlement.CreateEntitlementRepoInputs{ + Namespace: ns, + FeatureID: feature.ID, + FeatureKey: featureKey, + UsageAttribution: createCustomerWithSubject(t, repo.subjectRepo, repo.customerRepo, ns, "subject-nil-current").GetUsageAttribution(), + EntitlementType: entitlement.EntitlementTypeMetered, + MeasureUsageFrom: lo.ToPtr(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)), + UsagePeriod: usagePeriod, + CurrentUsagePeriod: nil, + }) + require.NoError(t, err) + require.NotNil(t, nilCurrentPeriodEnt) ... require.Len(t, ents, 2) require.Equal(t, ent1.ID, ents[0].ID) require.Equal(t, resetAnchorEnt.ID, ents[1].ID) + require.NotContains(t, lo.Map(ents, func(e entitlement.Entitlement, _ int) string { return e.ID }), nilCurrentPeriodEnt.ID)As per coding guidelines:
**/*_test.go: Make sure the tests are comprehensive and cover the changes.🤖 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/entitlement/adapter/entitlement_test.go` around lines 350 - 467, The test is missing an explicit fixture proving entitlements with CurrentUsagePeriod == nil are excluded by the CurrentUsagePeriodEndNotNil predicate; add a metered entitlement (use repo.entRepo.CreateEntitlement with EntitlementTypeMetered and without CurrentUsagePeriod set) for a new customer (e.g., custNoPeriod) before calling ListActiveEntitlementsWithExpiredUsagePeriod, then assert the returned ents slice length and contents do NOT include that entitlement (and keep the existing assertions for ent1 and resetAnchorEnt); reference CreateEntitlement, ListActiveEntitlementsWithExpiredUsagePeriod, and the CurrentUsagePeriod field when adding the assertion.
🤖 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.
Nitpick comments:
In `@openmeter/entitlement/adapter/entitlement_test.go`:
- Around line 350-467: The test is missing an explicit fixture proving
entitlements with CurrentUsagePeriod == nil are excluded by the
CurrentUsagePeriodEndNotNil predicate; add a metered entitlement (use
repo.entRepo.CreateEntitlement with EntitlementTypeMetered and without
CurrentUsagePeriod set) for a new customer (e.g., custNoPeriod) before calling
ListActiveEntitlementsWithExpiredUsagePeriod, then assert the returned ents
slice length and contents do NOT include that entitlement (and keep the existing
assertions for ent1 and resetAnchorEnt); reference CreateEntitlement,
ListActiveEntitlementsWithExpiredUsagePeriod, and the CurrentUsagePeriod field
when adding the assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4a7888bb-1aab-47be-847f-461fb2fdb0d7
📒 Files selected for processing (2)
openmeter/entitlement/adapter/entitlement.goopenmeter/entitlement/adapter/entitlement_test.go
Overview
TLDR we were returning more than we should have hence the log storm (the relevant change is only the extra filter, the TS comparison changes are just for semantic correctness)
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit