Repository navigation
Enable unit_config authoring on BillingRateCard behind config flag - OM-392 - #4560
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)
📝 WalkthroughWalkthroughAdds a ChangesUnitConfig Feature Flag Gate
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 |
Greptile SummaryThis PR adds infrastructure for feature-gating
Confidence Score: 4/5Safe to merge with the flag kept at its default of false; enabling the flag before the domain-model persistence work lands will cause silent data loss. The flag gate is correctly wired end-to-end and the default is off, so no existing production behaviour changes. However, FromAPIBillingRateCard does not map rc.UnitConfig to any field in the domain model — the productcatalog package has no UnitConfig field — so any environment that enables the flag before the persistence implementation lands will accept unit_config writes and return 200 OK while silently discarding the value. api/v3/handlers/plans/convert.go — the unit_config field from the request is accepted when the flag is enabled but never forwarded to the domain model. Important Files Changed
|
| }) | ||
| } | ||
|
|
||
| // TestV3PlanRejectsUnitConfigWhenFlagDisabled verifies that, while the UnitConfig | ||
| // feature flag is off (the default in the e2e environment), authoring a plan whose | ||
| // rate card carries a unit_config is rejected on create. unit_config stays | ||
| // read-only — synthesized from v1 dynamic/package prices on the response path only | ||
| // — until the flag is enabled per environment. The reject guard fires before price | ||
| // validation, so a flat rate card is enough to exercise it (no feature needed). | ||
| func TestV3PlanRejectsUnitConfigWhenFlagDisabled(t *testing.T) { | ||
| c := newV3Client(t) | ||
|
|
||
| body := validPlanRequest("unit_config_rejected") | ||
| body.Phases[0].RateCards[0].UnitConfig = &apiv3.BillingUnitConfig{ | ||
| Operation: apiv3.BillingUnitConfigOperationMultiply, | ||
| ConversionFactor: apiv3.Numeric("1.2"), | ||
| } | ||
|
|
||
| status, plan, problem := c.CreatePlan(body) | ||
| require.Equal(t, http.StatusBadRequest, status, "problem: %+v", problem) | ||
| require.Nil(t, plan) | ||
| assertProblemDetail(t, problem, "unit_config") | ||
| } |
There was a problem hiding this comment.
E2E gate test covers create only; update path is untested
TestV3PlanRejectsUnitConfigWhenFlagDisabled verifies that the flag gate fires on create. The update handler (update.go) contains an identical gate, but there is no corresponding test that exercises the update path with unit_config when the flag is disabled. A plan can be created first (without unit_config) and then updated with unit_config in its rate card — if the gate in UpdatePlan regresses, only the create test would pass.
There was a problem hiding this comment.
That's fine. Prefer unit tests (integration level service test) over e2e tests as much as possible.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
e2e/plans_v3_test.go (1)
606-626: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNice test coverage for the CREATE rejection path!
The test correctly validates that
unit_configis rejected when the flag is disabled. Since the handler comment (lines 32 and 35 in create.go/update.go) explicitly states the guard "is applied for both create and update," consider adding a parallel test case for the UPDATE path to ensure both endpoints remain consistently guarded.Something like:
t.Run("rejects on update", func(t *testing.T) { // Create a plan without unit_config first // Then attempt to update it with unit_config set // Assert same 400 + "unit_config" rejection })🤖 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 `@e2e/plans_v3_test.go` around lines 606 - 626, The test TestV3PlanRejectsUnitConfigWhenFlagDisabled currently only covers the CREATE path for rejecting unit_config when the flag is disabled, but the handler guard is applied to both create and update operations. Add a parallel test case (either as a nested t.Run subtest or as a separate test function) that follows the same pattern: first create a valid plan without unit_config using validPlanRequest, then attempt to update that plan by adding unit_config to its rate card, and assert that the update call (via c.UpdatePlan or similar) returns http.StatusBadRequest with a problem detail containing "unit_config". This ensures both the CreatePlan and UpdatePlan endpoints are consistently guarded.
🤖 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 `@e2e/plans_v3_test.go`:
- Around line 606-626: The test TestV3PlanRejectsUnitConfigWhenFlagDisabled
currently only covers the CREATE path for rejecting unit_config when the flag is
disabled, but the handler guard is applied to both create and update operations.
Add a parallel test case (either as a nested t.Run subtest or as a separate test
function) that follows the same pattern: first create a valid plan without
unit_config using validPlanRequest, then attempt to update that plan by adding
unit_config to its rate card, and assert that the update call (via c.UpdatePlan
or similar) returns http.StatusBadRequest with a problem detail containing
"unit_config". This ensures both the CreatePlan and UpdatePlan endpoints are
consistently guarded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c392ab57-2afe-4a44-88da-f892af220411
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (17)
api/spec/packages/aip-client-javascript/src/models/types.tsapi/spec/packages/aip/src/productcatalog/ratecard.tspapi/v3/api.gen.goapi/v3/handlers/plans/convert.goapi/v3/handlers/plans/convert_test.goapi/v3/handlers/plans/create.goapi/v3/handlers/plans/handler.goapi/v3/handlers/plans/update.goapi/v3/server/server.goapp/config/config.goapp/config/config_test.goapp/config/unit_config.gocmd/server/main.goconfig.example.yamle2e/plans_v3_test.goopenmeter/server/router/router.goopenmeter/server/server.go
💤 Files with no reviewable changes (2)
- api/v3/handlers/plans/convert.go
- api/v3/handlers/plans/convert_test.go
| } | ||
|
|
||
| func ConfigureUnitConfig(v *viper.Viper, prefixes ...string) { | ||
| prefixer := NewViperKeyPrefixer(prefixes...) |
| }) | ||
| } | ||
|
|
||
| // TestV3PlanRejectsUnitConfigWhenFlagDisabled verifies that, while the UnitConfig | ||
| // feature flag is off (the default in the e2e environment), authoring a plan whose | ||
| // rate card carries a unit_config is rejected on create. unit_config stays | ||
| // read-only — synthesized from v1 dynamic/package prices on the response path only | ||
| // — until the flag is enabled per environment. The reject guard fires before price | ||
| // validation, so a flat rate card is enough to exercise it (no feature needed). | ||
| func TestV3PlanRejectsUnitConfigWhenFlagDisabled(t *testing.T) { | ||
| c := newV3Client(t) | ||
|
|
||
| body := validPlanRequest("unit_config_rejected") | ||
| body.Phases[0].RateCards[0].UnitConfig = &apiv3.BillingUnitConfig{ | ||
| Operation: apiv3.BillingUnitConfigOperationMultiply, | ||
| ConversionFactor: apiv3.Numeric("1.2"), | ||
| } | ||
|
|
||
| status, plan, problem := c.CreatePlan(body) | ||
| require.Equal(t, http.StatusBadRequest, status, "problem: %+v", problem) | ||
| require.Nil(t, plan) | ||
| assertProblemDetail(t, problem, "unit_config") | ||
| } |
There was a problem hiding this comment.
That's fine. Prefer unit tests (integration level service test) over e2e tests as much as possible.
| func (c UnitConfigConfiguration) Validate() error { | ||
| var errs []error | ||
|
|
||
| return errors.Join(errs...) |
There was a problem hiding this comment.
Please, just return nil here.
Overview
This PR is the ground work for enabling
unit_configonBillingRateCardfor authoring. With this in place we don't need to ship it in one go, but in smaller PRs.Summary by CodeRabbit
unit_configcan now be provided on create and update when the feature flag is enabled.unit_configdocumentation to reflect feature-gated create/update behavior.unitConfig.enabledto the example configuration.unit_configis sent while the flag is disabled.