Repository navigation
fix(api): let domain validation own the metered entitlement usage period - #4981
Conversation
The v3 plan and addon converters hard-rejected a metered entitlement with no usage_period and no billing_cadence to default from, duplicating MeteredEntitlementTemplate.Validate. Map the zero usage period through so the issue surfaces on the draft and blocks publish. Add the missing HTTP 400 attribute to entitlement_template_negative_usage_period so its publish-time mapping no longer depends on the sibling less-than-an-hour issue firing alongside it. Claude-Session: https://claude.ai/code/session_01S93A9RigLLfBnXoauNNt7w
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughMetered entitlement conversion now defers missing usage period validation to the domain when billing cadence is unavailable. End-to-end tests verify HTTP 400 responses for plans and addons. The validation issue now includes HTTP status code 400. ChangesMetered entitlement validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change preserves the existing create-time rejection while returning the structured domain validation error, with focused converter, error-mapping, and end-to-end test updates. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
Replaces the converter unit subtests. The e2e run surfaced the real behavior: the entitlement_template ent field validator runs EntitlementTemplate.Validate severity-blind at insert, so the zero usage period rejects create with a 400 carrying entitlement_template_negative_usage_period rather than being stored as a draft validation issue. Claude-Session: https://claude.ai/code/session_01S93A9RigLLfBnXoauNNt7w
Summary
The v3 plan and addon rate card converters hard-rejected (400 at create) a metered entitlement that has no
usage_periodand nobilling_cadenceto default it from. That duplicates the domain layer:MeteredEntitlementTemplate.Validatealready rejects a non-positive usage period (entitlement_template_negative_usage_period).The converters now keep the defaulting (
usage_period← rate card billing cadence) but map a zero usage period through, so the domain validation reports it.Companion one-liner:
entitlement_template_negative_usage_periodwas missing the HTTP 400 status attribute its sibling..._less_then_an_hourissue carries — added so its 400 mapping is deliberate rather than dependent on the sibling firing alongside.Converters should translate bodies to service types faithfully and leave validation to the owning layer (same principle as #4979, sibling of #4980).
Behavior change
Create with a metered entitlement lacking both
usage_periodandbilling_cadencestill returns 400 at create — but now with the structured domain codeentitlement_template_negative_usage_period(field$.entitlementTemplate.usagePeriod) instead of the converter's free-text message.Writing the e2e tests surfaced why it stays a create-time 400 rather than the draft-with-issues flow used by other rate card warnings: ent auto-runs
Validate()on theentitlement_templatefield's Go type at insert (ent/db/addonratecard_create.gogenerated check), severity-blind. Entitlement warnings therefore block persistence while rate-card-level warnings (e.g.billing_cadence_invalid_value) are stored on the draft. That layering inconsistency predates this PR and is left as a follow-up.Test plan
TestV3PlanMeteredEntitlementWithoutUsagePeriod,TestV3AddonMeteredEntitlementWithoutUsagePeriod) assert both endpoints reject with 400 +entitlement_template_negative_usage_period; run green against a local stack built from this branch.go test ./api/v3/handlers/addons/... ./api/v3/handlers/plans/... ./openmeter/productcatalog/...green.🤖 Generated with Claude Code
https://claude.ai/code/session_01S93A9RigLLfBnXoauNNt7w
Summary by CodeRabbit
Greptile Summary
The PR moves missing metered-entitlement usage-period handling from the v3 plan and add-on converters into product-catalog domain validation.
Confidence Score: 5/5
The PR appears safe to merge because no blocking failure remains within the eligible follow-up-review scope.
No blocking failure remains.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Client participant API as V3 Plan/Add-on API participant Converter participant Domain as Product Catalog Validation Client->>API: Create with metered entitlement API->>Converter: Convert request alt Billing cadence is available Converter->>Converter: Default usage period from cadence else No usage period or cadence Converter->>Domain: Pass zero usage period through Domain-->>API: negative_usage_period validation issue API-->>Client: HTTP 400 endReviews (2): Last reviewed commit: "test(api): cover missing entitlement usa..." | Re-trigger Greptile