Skip to content

refactor(productcatalog): separate plan validation - #4909

Open
GAlexIHU wants to merge 3 commits into
mainfrom
codex/refactor-plan-validation
Open

refactor(productcatalog): separate plan validation#4909
GAlexIHU wants to merge 3 commits into
mainfrom
codex/refactor-plan-validation

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What changed

  • add a canonical structural validator for plans
  • keep catalog versioning validation separate from structural validation
  • validate inline subscription plans without temporarily injecting a fake key and version
  • add coverage for structural, catalog, and inline-plan validation boundaries

Why

Inline subscription plans intentionally have no catalog identity, but the shared plan validator required a key. The conversion path worked around that by mutating the plan with fake identity fields before validation. Separating structural validation from catalog versioning removes that mutation and keeps the full validator list in one place.

This preserves the existing versioning rules: a catalog plan requires a key, while its numeric version is assigned later and is not newly validated here.

Validation

  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/productcatalog/... -count=1
  • go vet -tags=dynamic ./openmeter/productcatalog/...
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Improved plan validation by separating structural checks from version and key requirements.
    • Plan creation now supports unassigned versions while still requiring valid plan keys.
    • Subscription plan conversion now validates names and structure without relying on placeholder values.
    • Validation errors remain clearly associated with their relevant fields.
  • Tests

    • Added coverage for layered plan validation and plan creation scenarios.

Greptile Summary

The PR separates structural plan validation from catalog identity validation, allowing inline subscription plans to remain keyless while catalog plans still require a key.

  • Adds dedicated structural and versioning validators for plans.
  • Removes temporary key and version mutation from inline-plan conversion.
  • Adds tests for catalog, structural, and inline validation boundaries.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
openmeter/productcatalog/plan.go Separates structural and catalog versioning validation while ensuring the outer validation boundary applies only one generic validation wrapper.
openmeter/productcatalog/plan/service.go Explicitly applies both versioning and structural validation when creating catalog plans.
openmeter/productcatalog/subscription/service/plan.go Validates inline plans structurally without injecting temporary catalog identity fields.
openmeter/productcatalog/plan_test.go Covers keyless structural validation, catalog key enforcement, unassigned versions, and single-wrapper diagnostics.
openmeter/productcatalog/subscription/service/plan_test.go Verifies inline-plan conversion preserves empty identity fields and rejects structural errors.

Reviews (3): Last reviewed commit: "refactor(productcatalog): move plan meta..." | Re-trigger Greptile

Context used:

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 899b3772-0b1c-4b8d-a84a-506ed5989f01

📥 Commits

Reviewing files that changed from the base of the PR and between 62b56cc and 0dd2c2c.

📒 Files selected for processing (1)
  • openmeter/productcatalog/plan.go

📝 Walkthrough

Walkthrough

Plan validation now separates structural checks from versioning checks. Create-plan validation applies both layers, while subscription plan conversion applies structural validation without temporary key or version values.

Changes

Plan validation

Layer / File(s) Summary
Plan validation layers
openmeter/productcatalog/plan.go, openmeter/productcatalog/plan_test.go
The plan model exposes separate structural and versioning validators. Structural validation checks metadata, phases, currency, cadence, and alignment. Versioning validation checks the plan key. Tests cover combined validation and error wrapping.
Create-plan validation
openmeter/productcatalog/plan/service.go, openmeter/productcatalog/plan_test.go
CreatePlanInput.Validate applies both validators. Version zero remains valid, while an empty key returns the resource-key error.
Subscription plan conversion
openmeter/productcatalog/subscription/service/plan.go, openmeter/productcatalog/subscription/service/plan_test.go
PlanFromPlanInput validates structure without temporary key or version assignments. Empty key and zero version are preserved, and empty plan names return productcatalog.ErrResourceNameEmpty.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CreatePlanInput
  participant Plan
  participant ValidatePlanVersioning
  participant ValidatePlanStructure
  participant PlanFromPlanInput

  CreatePlanInput->>Plan: ValidateWith(versioning, structure)
  Plan->>ValidatePlanVersioning: Validate plan key
  Plan->>ValidatePlanStructure: Validate plan structure
  Plan-->>CreatePlanInput: Aggregated validation result

  PlanFromPlanInput->>Plan: ValidateWith(structure)
  Plan->>ValidatePlanStructure: Validate plan structure
  Plan-->>PlanFromPlanInput: Structural validation result
Loading

Suggested labels: area/product-catalog

Suggested reviewers: turip, chrisgacsal

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: separating plan validation into distinct validation layers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/refactor-plan-validation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@GAlexIHU GAlexIHU added the release-note/misc Miscellaneous changes label Aug 11, 2026
Comment thread openmeter/productcatalog/plan.go
@GAlexIHU
GAlexIHU marked this pull request as ready for review August 11, 2026 11:20
@GAlexIHU
GAlexIHU requested a review from a team as a code owner August 11, 2026 11:20

@chrisgacsal chrisgacsal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants