Skip to content

Add unitconfig to ratecard in domain layer - OM-393 - #4568

Merged
rolosp merged 2 commits into
mainfrom
feat/om-393-implement-unit-config-domain-model
Jun 25, 2026
Merged

rolosp merged 2 commits into
mainfrom
feat/om-393-implement-unit-config-domain-model

Conversation

@rolosp

@rolosp rolosp commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Added UnitConfig to RateCardMeta in preparation for the next phase, persisting it. This change should be pretty low risk as:

  • it is additive only even with the change being on the RateCardMeta
  • no surface moved as persisting it will be the next ticket and there is no api wiring or typespec change
  • no behavior change if the unit config field is nil

Summary by CodeRabbit

  • New Features

    • Added optional per-rate-card unit conversion configuration (multiply/divide) with configurable rounding mode, precision, and display unit.
    • Rate card calculations can now produce both converted and invoiced quantities, applying rounding/precision when configured.
  • Bug Fixes

    • Improved unit conversion handling for cloning, equality comparisons, and validation error reporting (including unit-config field paths).
  • Tests

    • Added coverage for unit conversion apply/validate/equality/clone, plus rate card metadata behavior and deep-copy semantics.

@rolosp
rolosp requested a review from a team as a code owner June 24, 2026 15:25
@coderabbitai

coderabbitai Bot commented Jun 24, 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

Run ID: 08559df2-e878-48bf-8c02-793338e85bf4

📥 Commits

Reviewing files that changed from the base of the PR and between 9846a28 and 1e074b7.

📒 Files selected for processing (4)
  • openmeter/productcatalog/ratecard.go
  • openmeter/productcatalog/ratecard_test.go
  • openmeter/productcatalog/unitconfig.go
  • openmeter/productcatalog/unitconfig_test.go
💤 Files with no reviewable changes (4)
  • openmeter/productcatalog/unitconfig_test.go
  • openmeter/productcatalog/ratecard.go
  • openmeter/productcatalog/unitconfig.go
  • openmeter/productcatalog/ratecard_test.go

📝 Walkthrough

Walkthrough

A new UnitConfig type adds unit conversion and rounding metadata to productcatalog, and RateCardMeta now carries it as an optional field. Clone, equality, validation, and tests were updated to include the new behavior.

Changes

UnitConfig domain type and RateCardMeta integration

Layer / File(s) Summary
UnitConfig contract and validation
openmeter/productcatalog/unitconfig.go
Defines UnitConfigOperation and UnitConfigRoundingMode, then adds UnitConfig with nil-safe validation for operation, conversion factor, rounding mode, and precision.
UnitConfig equality, Apply, and Clone
openmeter/productcatalog/unitconfig.go
Implements Equal, Apply, and Clone for UnitConfig, including empty/default rounding equivalence and deep-copy handling for DisplayUnit.
RateCardMeta UnitConfig wiring and tests
openmeter/productcatalog/ratecard.go, openmeter/productcatalog/ratecard_test.go
Adds optional UnitConfig to RateCardMeta, updates clone/equality/validation to include it, and adds rate card test coverage for the new field alongside formatting updates in existing cases.
UnitConfig tests
openmeter/productcatalog/unitconfig_test.go
Tests Apply, Validate, Equal, and Clone across nil, invalid, rounding, and deep-copy cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • chrisgacsal
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 matches the main change: adding UnitConfig to the ratecard domain model.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/om-393-implement-unit-config-domain-model

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.

@rolosp
rolosp force-pushed the feat/om-393-implement-unit-config-domain-model branch from 68d21f9 to 9846a28 Compare June 24, 2026 15:28
@rolosp rolosp added the release-note/feature Release note: Exciting New Features label Jun 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
openmeter/productcatalog/unitconfig_test.go (1)

12-311: 📐 Maintainability & Code Quality | 🔵 Trivial

Add RateCardMeta coverage for nested UnitConfig
unitconfig_test.go covers UnitConfig itself, but RateCardMeta.Clone / Equal / Validate still need a few cases around the embedded UnitConfig field. A small set should be enough:

  • Clone deep-copies UnitConfig.DisplayUnit
  • Equal flips when only UnitConfig differs, and stays true when both are nil
  • Validate surfaces nested errors under unitConfig
🤖 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/productcatalog/unitconfig_test.go` around lines 12 - 311, Add
RateCardMeta test coverage for the embedded UnitConfig behavior. In the
RateCardMeta test suite, extend Clone, Equal, and Validate cases so they
exercise the nested UnitConfig field: verify Clone deep-copies
UnitConfig.DisplayUnit, verify Equal changes when only RateCardMeta.UnitConfig
differs and still passes when both UnitConfig values are nil, and verify
Validate reports nested UnitConfig failures under the unitConfig path. Use the
existing UnitConfig, RateCardMeta, Clone, Equal, and Validate symbols to place
the new cases alongside the current config tests.

Source: Path instructions

🤖 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/productcatalog/unitconfig.go`:
- Around line 147-158: Update the equality logic in the config comparison method
that checks c.Rounding and c.Precision so Precision is only compared when
rounding is not none. Keep the existing IsNone()/Rounding comparison behavior,
but skip the Precision equality check entirely for none/empty rounding to match
the semantics used by Validate() and Apply(). Verify the change in the equality
path that feeds RateCardMeta.Equal so behaviorally identical configs are no
longer treated as different.

---

Nitpick comments:
In `@openmeter/productcatalog/unitconfig_test.go`:
- Around line 12-311: Add RateCardMeta test coverage for the embedded UnitConfig
behavior. In the RateCardMeta test suite, extend Clone, Equal, and Validate
cases so they exercise the nested UnitConfig field: verify Clone deep-copies
UnitConfig.DisplayUnit, verify Equal changes when only RateCardMeta.UnitConfig
differs and still passes when both UnitConfig values are nil, and verify
Validate reports nested UnitConfig failures under the unitConfig path. Use the
existing UnitConfig, RateCardMeta, Clone, Equal, and Validate symbols to place
the new cases alongside the current config tests.
🪄 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: 22517f44-d7c5-4f97-8dac-851374fe12f4

📥 Commits

Reviewing files that changed from the base of the PR and between 6b60ab6 and 68d21f9.

📒 Files selected for processing (3)
  • openmeter/productcatalog/ratecard.go
  • openmeter/productcatalog/unitconfig.go
  • openmeter/productcatalog/unitconfig_test.go

Comment thread openmeter/productcatalog/unitconfig.go Resolved
@greptile-apps

greptile-apps Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds UnitConfig to RateCardMeta at the domain layer only — no persistence, API wiring, or TypeSpec changes are included. UnitConfig supports multiply/divide conversion with optional ceiling/floor/half_up rounding and a display unit label, and returns separate precise (converted) and rounded (invoiced) quantities from Apply().

  • unitconfig.go introduces the new type with Validate, Equal, Apply, and Clone, all nil-safe; Equal correctly treats empty rounding as equivalent to "none" and skips Precision comparison when rounding is inactive, addressing the pre-existing concern from the previous review thread.
  • ratecard.go wires UnitConfig into RateCardMeta.Clone, Equal, and Validate, with the field path "unit_config" in error messages (documented in tests as the future v3 wire name).
  • Both new files come with thorough unit tests covering all rounding modes, edge cases, nil receivers, and deep-copy semantics.

Confidence Score: 5/5

Purely additive domain-layer change with no persistence, API surface, or behavioral impact when the field is nil; safe to merge.

All new code is nil-guarded, the Equal and Clone implementations are correct, and the previous concern about Precision being compared when rounding is none has been fixed. No existing behavior is altered.

No files require special attention.

Important Files Changed

Filename Overview
openmeter/productcatalog/unitconfig.go New file implementing UnitConfig with Validate, Equal, Apply, and Clone; nil-safe throughout and semantically correct Equal that skips Precision when rounding is none.
openmeter/productcatalog/ratecard.go UnitConfig added to RateCardMeta with proper Clone, Equal, and Validate integration; field selector uses "unit_config" (intentional v3 wire name per test comments).
openmeter/productcatalog/unitconfig_test.go Comprehensive tests for Apply, Validate, Equal, and Clone covering all rounding modes, nil receivers, precision edge cases, and deep-copy semantics.
openmeter/productcatalog/ratecard_test.go Adds TestRateCardMetaUnitConfig covering Clone deep-copy, Equal comparison, and Validate error path; also formatting-only refactors to existing test fixtures.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Raw Metered Quantity] --> B{UnitConfig nil?}
    B -- yes --> C[Return raw, raw]
    B -- no --> D{Operation}
    D -- multiply --> E[converted = raw × ConversionFactor]
    D -- divide --> F[converted = raw ÷ ConversionFactor]
    D -- unknown --> C
    E --> G{Rounding Mode}
    F --> G
    G -- none / empty --> H[invoiced = converted]
    G -- ceiling --> I[invoiced = RoundCeil precision]
    G -- floor --> J[invoiced = RoundFloor precision]
    G -- half_up --> K[invoiced = Round precision]
    H --> L[Return converted, invoiced]
    I --> L
    J --> L
    K --> L
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Raw Metered Quantity] --> B{UnitConfig nil?}
    B -- yes --> C[Return raw, raw]
    B -- no --> D{Operation}
    D -- multiply --> E[converted = raw × ConversionFactor]
    D -- divide --> F[converted = raw ÷ ConversionFactor]
    D -- unknown --> C
    E --> G{Rounding Mode}
    F --> G
    G -- none / empty --> H[invoiced = converted]
    G -- ceiling --> I[invoiced = RoundCeil precision]
    G -- floor --> J[invoiced = RoundFloor precision]
    G -- half_up --> K[invoiced = Round precision]
    H --> L[Return converted, invoiced]
    I --> L
    J --> L
    K --> L
Loading

Reviews (3): Last reviewed commit: "fix: field selector and Equal fix" | Re-trigger Greptile

Comment thread openmeter/productcatalog/unitconfig.go Resolved
Comment thread openmeter/productcatalog/ratecard.go Resolved
@rolosp
rolosp force-pushed the feat/om-393-implement-unit-config-domain-model branch from 9846a28 to 1e074b7 Compare June 25, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants