Skip to content

feat(charges): add tax code - #4237

Merged
mark-vass-konghq merged 4 commits into
mainfrom
feat/add-tax-code-to-charges
Apr 30, 2026
Merged

mark-vass-konghq merged 4 commits into
mainfrom
feat/add-tax-code-to-charges

Conversation

@mark-vass-konghq

@mark-vass-konghq mark-vass-konghq commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

@coderabbitai

Summary by CodeRabbit

  • New Features

    • Tax configuration is now persisted with individual charges and included in search results, covering flat-fee, usage-based, and credit purchases.
    • Credit-purchase invoice lines now reflect the tax configuration provided on the purchase intent when present.
  • Documentation

    • Clarified API docs for credit grants to update default tax-configuration behavior.
  • Tests

    • Added tests validating tax configuration persistence and propagation across charge flows.

@mark-vass-konghq mark-vass-konghq self-assigned this Apr 27, 2026
@mark-vass-konghq
mark-vass-konghq requested a review from a team as a code owner April 27, 2026 08:53
@mark-vass-konghq mark-vass-konghq added release-note/feature Release note: Exciting New Features area/billing labels Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds persisted tax metadata to charges (tax_code_id, tax_behavior), removes TaxConfig from GenericSettlement, propagates TaxConfig from intent to gathering lines, updates schemas/views/migrations, and adds tests and docs clarifying tax-config fallback behavior.

Changes

Cohort / File(s) Summary
API spec & docs
api/spec/packages/aip/src/customers/credits/grant.tsp, api/v3/api.gen.go
Clarified TaxConfig fallback wording and regenerated embedded OpenAPI swagger payload (doc-only changes).
Charge model persistence & mixins
openmeter/billing/charges/models/chargemeta/mixin.go
Added nullable DB fields tax_code_id and tax_behavior, extended Creator/Updater/Getter interfaces to set/get them, persist on create/update, and reconstruct Intent.TaxConfig on read.
Service logic — charge & credit purchase
openmeter/billing/charges/creditpurchase/service/create.go, openmeter/billing/creditgrant/service/service.go
Gathering lines now take TaxConfig from charge intent; grant->settlement mapping no longer maps intent TaxConfig into GenericSettlement.
Settlement struct & validation
openmeter/billing/charges/creditpurchase/settlement.go
Removed TaxConfig field from GenericSettlement and related validation/error messages.
Ent schema changes
openmeter/ent/schema/chargesflatfee.go, openmeter/ent/schema/chargesusagebased.go, openmeter/ent/schema/chargescreditpurchase.go, openmeter/ent/schema/taxcode.go, openmeter/ent/schema/charges.go
Added nullable tax_code edges on all charge types, set OnDelete(SetNull), and included tax_code_id/tax_behavior in ChargesSearchV1 projection.
Migrations & view SQL
tools/migrate/migrations/*add_tax_codes_to_charges*.up.sql, *.down.sql, *update_charges_search_view_tax_columns*.up.sql, *.down.sql, tools/migrate/migrations/*change_tax_code_id_index_to_partial*.up.sql, *.down.sql, tools/migrate/views.sql
Added tax_code_id and tax_behavior columns, FK constraints (ON DELETE SET NULL), partial indexes, and updated view to project tax columns; included down-migrations to reverse changes.
Tests & test helpers
openmeter/billing/charges/service/taxcode_test.go, openmeter/billing/charges/service/base_test.go
New test suite validating persistence/propagation of TaxConfig across charge types and invoice gathering lines; test builder updated to accept optional taxConfig.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Client
    participant ChargeService as ChargeService
    participant TaxCodeService as TaxCodeService
    participant Database as Database
    participant InvoiceGathering as InvoiceGathering

    Client->>ChargeService: CreateCharge(intent with TaxConfig)
    ChargeService->>TaxCodeService: Resolve/validate TaxCode (if present)
    ChargeService->>Database: Persist charge row (tax_code_id, tax_behavior)
    Database-->>ChargeService: ACK

    Client->>ChargeService: ReadCharge(chargeID)
    ChargeService->>Database: Fetch charge + tax fields
    Database-->>ChargeService: Return tax_code_id, tax_behavior
    ChargeService->>ChargeService: Reconstruct Intent.TaxConfig
    ChargeService-->>Client: Return charge with TaxConfig

    Client->>InvoiceGathering: CreateGatheringLine(creditPurchase, expand lines)
    InvoiceGathering->>Database: Load charge + intent tax fields
    Database-->>InvoiceGathering: Return tax_code_id, tax_behavior
    InvoiceGathering->>InvoiceGathering: Populate GatheringLine.TaxConfig from intent
    InvoiceGathering-->>Client: GatheringLine with TaxConfig
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • borbelyr-kong
  • tothandras
  • GAlexIHU
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'feat(charges): add tax code' is concise and directly summarizes the main change: adding tax code support to the billing charges system.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-tax-code-to-charges

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 and usage tips.

@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 (3)
tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sql (1)

1-12: Migration looks solid; just a small heads-up on index creation under load. ⚠️

Adding nullable columns + NOT VALID-free FK on freshly-added (all-NULL) columns is fine — PG won't rewrite the table and FK validation on all-NULL data is trivial. Per prior learnings, no backfill is needed since tax data flows from the intent.

One operational note (not a blocker): CREATE INDEX here isn't CONCURRENTLY, so on busy production charge tables this will briefly block writes. If these tables are already large in prod, consider running the index creations concurrently in a follow-up. Otherwise it matches the repo's established Atlas-generated style.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sql`
around lines 1 - 12, Summary: non-CONCURRENT CREATE INDEX statements
(chargecreditpurchase_tax_code_id, chargeflatfee_tax_code_id,
chargeusagebased_tax_code_id) will block writes on large production tables;
switch to concurrent index creation or run them outside a transaction. Fix: move
the three CREATE INDEX statements into a follow-up migration (or separate
migration file) that uses CREATE INDEX CONCURRENTLY ... ON
"charge_credit_purchases" ("tax_code_id"), CREATE INDEX CONCURRENTLY ... ON
"charge_flat_fees" ("tax_code_id"), and CREATE INDEX CONCURRENTLY ... ON
"charge_usage_based" ("tax_code_id"); ensure the migration runner does not wrap
the concurrent statements in a transaction (or run them manually in production)
because CREATE INDEX CONCURRENTLY cannot run inside a transaction block.
openmeter/billing/charges/models/chargemeta/mixin.go (1)

110-110: Worth scoping the index by namespace?

Most lookups in this codebase are tenant-scoped, so a composite ("namespace", "tax_code_id") index tends to give better selectivity than a single-column tax_code_id index — and matches the pattern used for the other indexes here. Totally optional, just worth a thought given how hot some of these charge tables get.

♻️ Optional tweak
-		index.Fields("tax_code_id"),
+		index.Fields("namespace", "tax_code_id"),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/models/chargemeta/mixin.go` at line 110, The
single-column index on tax_code_id should be scoped by tenant/namespace for
better selectivity and to match existing indexes; update the index definition
that currently calls index.Fields("tax_code_id") to a composite index including
namespace (e.g. index.Fields("namespace", "tax_code_id")) so lookups are
tenant-scoped and consistent with other indexes in mixin.go.
openmeter/billing/charges/service/taxcode_test.go (1)

240-241: Unused callback locals in the credit purchase tests.

callback := newCountedLedgerTransactionCallback[creditpurchase.Charge]() is created and wired into s.CreditPurchaseTestHandler.onPromotionalCreditPurchase, but the local callback itself is never asserted on (no Wait/count check). If the handler assignment is the actual goal (to satisfy a non-nil hook), feel free to ignore — otherwise it's dead state worth either asserting on (e.g., callback.Wait(...) or expected count) or simplifying to just the handler wiring.

Also applies to: 283-284

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 240 - 241,
The test creates a counted callback via
newCountedLedgerTransactionCallback[creditpurchase.Charge]() and assigns its
Handler to s.CreditPurchaseTestHandler.onPromotionalCreditPurchase but never
asserts against the callback, leaving dead state; either remove the local and
assign a plain handler if you only need a non-nil hook, or add assertions such
as calling callback.Wait(...) or checking the expected count after the operation
to verify the handler was invoked. Locate the creation and wiring
(newCountedLedgerTransactionCallback and
s.CreditPurchaseTestHandler.onPromotionalCreditPurchase) and either replace it
with a simple handler assignment or add a Wait/count assertion (e.g., expected
count) to validate the callback was triggered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/spec/packages/aip/src/customers/credits/grant.tsp`:
- Line 210: The doc guarantees defaulting to the organization's tax
configuration but the service only forwards and validates input.TaxConfig;
update the service path that handles the grant (the handler/function that
accepts input.TaxConfig and performs validation) to apply a fallback: if
input.TaxConfig is missing/null/empty, load the organization's tax configuration
(from the org config service/store) and assign it before validation and
persisting, ensuring the same validation logic runs against the resolved tax
config; alternatively, if you prefer not to change behavior, edit the spec
sentence to remove the guaranteed default and state that tax config is used only
when provided.

---

Nitpick comments:
In `@openmeter/billing/charges/models/chargemeta/mixin.go`:
- Line 110: The single-column index on tax_code_id should be scoped by
tenant/namespace for better selectivity and to match existing indexes; update
the index definition that currently calls index.Fields("tax_code_id") to a
composite index including namespace (e.g. index.Fields("namespace",
"tax_code_id")) so lookups are tenant-scoped and consistent with other indexes
in mixin.go.

In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 240-241: The test creates a counted callback via
newCountedLedgerTransactionCallback[creditpurchase.Charge]() and assigns its
Handler to s.CreditPurchaseTestHandler.onPromotionalCreditPurchase but never
asserts against the callback, leaving dead state; either remove the local and
assign a plain handler if you only need a non-nil hook, or add assertions such
as calling callback.Wait(...) or checking the expected count after the operation
to verify the handler was invoked. Locate the creation and wiring
(newCountedLedgerTransactionCallback and
s.CreditPurchaseTestHandler.onPromotionalCreditPurchase) and either replace it
with a simple handler assignment or add a Wait/count assertion (e.g., expected
count) to validate the callback was triggered.

In `@tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sql`:
- Around line 1-12: Summary: non-CONCURRENT CREATE INDEX statements
(chargecreditpurchase_tax_code_id, chargeflatfee_tax_code_id,
chargeusagebased_tax_code_id) will block writes on large production tables;
switch to concurrent index creation or run them outside a transaction. Fix: move
the three CREATE INDEX statements into a follow-up migration (or separate
migration file) that uses CREATE INDEX CONCURRENTLY ... ON
"charge_credit_purchases" ("tax_code_id"), CREATE INDEX CONCURRENTLY ... ON
"charge_flat_fees" ("tax_code_id"), and CREATE INDEX CONCURRENTLY ... ON
"charge_usage_based" ("tax_code_id"); ensure the migration runner does not wrap
the concurrent statements in a transaction (or run them manually in production)
because CREATE INDEX CONCURRENTLY cannot run inside a transaction block.
🪄 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: 61c04d2f-e2b6-4e8f-b636-8a3de73d4c6b

📥 Commits

Reviewing files that changed from the base of the PR and between acf60a9 and f3eb15f.

⛔ Files ignored due to path filters (35)
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openmeter/ent/db/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (15)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/settlement.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/creditgrant/service/service.go

@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.

🧹 Nitpick comments (2)
openmeter/billing/charges/service/taxcode_test.go (2)

31-37: These overrides aren't pulling their weight.

SetupSuite and TearDownTest here just delegate to BaseSuite without doing anything else, so they can be dropped — the embedded BaseSuite methods are inherited automatically. Saves a few lines and avoids the “did I forget to call super?” trap if these ever grow.

♻️ Suggested cleanup
 type TaxCodePersistenceTestSuite struct {
 	BaseSuite
 }
-
-func (s *TaxCodePersistenceTestSuite) SetupSuite() {
-	s.BaseSuite.SetupSuite()
-}
-
-func (s *TaxCodePersistenceTestSuite) TearDownTest() {
-	s.BaseSuite.TearDownTest()
-}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 31 - 37, The
methods SetupSuite and TearDownTest on TaxCodePersistenceTestSuite are redundant
wrappers that only call the embedded BaseSuite equivalents; remove both methods
(SetupSuite and TearDownTest) from the TaxCodePersistenceTestSuite type so it
inherits BaseSuite behavior directly and avoids unnecessary delegation or future
"forgot to call super" errors.

240-241: callback is set on the handler but never asserted.

In both s.Run(...) blocks of TestCreditPurchaseChargePersistsTaxConfig you build a newCountedLedgerTransactionCallback and wire it onto s.CreditPurchaseTestHandler.onPromotionalCreditPurchase, but never check it (e.g., expected call count). If the handler needs to be set so the create path doesn't panic/no-op, a tiny comment to that effect would help future readers; otherwise an s.Equal(1, callback.Count())-style assertion would make the test stronger and document intent. Not a blocker — just a small clarity nit.

Also applies to: 283-284

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 240 - 241,
The test constructs a newCountedLedgerTransactionCallback and assigns it to
s.CreditPurchaseTestHandler.onPromotionalCreditPurchase but never verifies it;
either assert the expected invocation count after each s.Run in
TestCreditPurchaseChargePersistsTaxConfig (e.g., s.Equal(1, callback.Count()) or
require.Equal) or, if the handler is only set to avoid panics, add a short
comment explaining that the callback is a no-op stub to prevent panics. Update
both s.Run blocks (and the corresponding callbacks created at the other location
mentioned) to include the assertion or the explanatory comment so intent is
clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 31-37: The methods SetupSuite and TearDownTest on
TaxCodePersistenceTestSuite are redundant wrappers that only call the embedded
BaseSuite equivalents; remove both methods (SetupSuite and TearDownTest) from
the TaxCodePersistenceTestSuite type so it inherits BaseSuite behavior directly
and avoids unnecessary delegation or future "forgot to call super" errors.
- Around line 240-241: The test constructs a newCountedLedgerTransactionCallback
and assigns it to s.CreditPurchaseTestHandler.onPromotionalCreditPurchase but
never verifies it; either assert the expected invocation count after each s.Run
in TestCreditPurchaseChargePersistsTaxConfig (e.g., s.Equal(1, callback.Count())
or require.Equal) or, if the handler is only set to avoid panics, add a short
comment explaining that the callback is a no-op stub to prevent panics. Update
both s.Run blocks (and the corresponding callbacks created at the other location
mentioned) to include the assertion or the explanatory comment so intent is
clear.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6527a3fa-b4bd-4122-99e7-9d0f78408740

📥 Commits

Reviewing files that changed from the base of the PR and between f3eb15f and 348b12a.

⛔ Files ignored due to path filters (36)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openmeter/ent/db/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (16)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/settlement.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/creditgrant/service/service.go
✅ Files skipped from review due to trivial changes (1)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
🚧 Files skipped from review as they are similar to previous changes (6)
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sql
  • tools/migrate/migrations/20260427085157_add_tax_codes_to_charges.down.sql
  • openmeter/billing/charges/models/chargemeta/mixin.go

@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.

🧹 Nitpick comments (2)
openmeter/billing/charges/service/taxcode_test.go (2)

31-37: Tiny nit: the empty SetupSuite/TearDownTest overrides are no-ops.

Since BaseSuite is embedded, these forwarders aren't needed — testify will pick up the embedded methods automatically. Safe to delete to reduce noise, but totally fine to leave as-is too.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 31 - 37, The
tests define no-op forwarding methods SetupSuite and TearDownTest on
TaxCodePersistenceTestSuite that simply call the same methods on the embedded
BaseSuite; remove these two methods (SetupSuite and TearDownTest) from
TaxCodePersistenceTestSuite so testify will use the embedded BaseSuite
implementations directly, reducing noise.

240-284: callback is wired up but never asserted.

In both credit-purchase subtests you build a newCountedLedgerTransactionCallback and assign its handler, but nothing reads from callback afterwards. If the goal is just to satisfy the test handler so Create doesn't error out, you can drop the local variable; if you actually want to verify the handler was hit (which would be a nice extra signal for these persistence tests), assert on its count.

♻️ One way to tighten it
-		callback := newCountedLedgerTransactionCallback[creditpurchase.Charge]()
-		s.CreditPurchaseTestHandler.onPromotionalCreditPurchase = callback.Handler(s.T())
+		callback := newCountedLedgerTransactionCallback[creditpurchase.Charge]()
+		s.CreditPurchaseTestHandler.onPromotionalCreditPurchase = callback.Handler(s.T())
+		defer func() { s.Equal(1, callback.Count()) }()

(or just drop the variable and inline .Handler(s.T()) if you don't care about the count.)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 240 - 284,
The local callback created with newCountedLedgerTransactionCallback and wired
via CreditPurchaseTestHandler.onPromotionalCreditPurchase is never asserted;
either remove the unused local and inline the handler assignment (e.g.,
.Handler(s.T())) or add an assertion after Create to verify the callback was
invoked (e.g., use s.Require().Equal(1, callback.Count()) or
s.Require().GreaterThan(callback.Count(), 0) depending on semantics) so the test
verifies the handler was hit; update both credit-purchase subtests that call
newCountedLedgerTransactionCallback and callback.Handler(s.T()) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 31-37: The tests define no-op forwarding methods SetupSuite and
TearDownTest on TaxCodePersistenceTestSuite that simply call the same methods on
the embedded BaseSuite; remove these two methods (SetupSuite and TearDownTest)
from TaxCodePersistenceTestSuite so testify will use the embedded BaseSuite
implementations directly, reducing noise.
- Around line 240-284: The local callback created with
newCountedLedgerTransactionCallback and wired via
CreditPurchaseTestHandler.onPromotionalCreditPurchase is never asserted; either
remove the unused local and inline the handler assignment (e.g.,
.Handler(s.T())) or add an assertion after Create to verify the callback was
invoked (e.g., use s.Require().Equal(1, callback.Count()) or
s.Require().GreaterThan(callback.Count(), 0) depending on semantics) so the test
verifies the handler was hit; update both credit-purchase subtests that call
newCountedLedgerTransactionCallback and callback.Handler(s.T()) accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9859f5ac-2621-4751-adaf-526c4ffabd3d

📥 Commits

Reviewing files that changed from the base of the PR and between 348b12a and 0c97289.

⛔ Files ignored due to path filters (36)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openmeter/ent/db/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (16)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/settlement.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/creditgrant/service/service.go
✅ Files skipped from review due to trivial changes (5)
  • openmeter/ent/schema/taxcode.go
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sql
  • openmeter/billing/charges/creditpurchase/settlement.go
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sql
🚧 Files skipped from review as they are similar to previous changes (4)
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/billing/charges/models/chargemeta/mixin.go

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 19-20: Replace the incorrect struct literal fields on the
ListGatheringInvoicesInput usages: change the Customers field to CustomerIDs and
remove the non-existent Currencies field (or replace it with the correct field
if one exists on billing.ListGatheringInvoicesInput); update both the occurrence
near the top of the test and the other occurrence (the one around lines 373-377)
so the struct matches the actual billing.ListGatheringInvoicesInput type.
🪄 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: 7f54df6f-11e8-4589-8f3c-ff638ce82b23

📥 Commits

Reviewing files that changed from the base of the PR and between 0c97289 and 8c4e2bf.

⛔ Files ignored due to path filters (37)
  • .claude/scheduled_tasks.lock is excluded by !**/*.lock, !**/*.lock
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openmeter/ent/db/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (16)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/settlement.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/creditgrant/service/service.go
✅ Files skipped from review due to trivial changes (2)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • tools/migrate/views.sql
🚧 Files skipped from review as they are similar to previous changes (4)
  • openmeter/ent/schema/charges.go
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sql
  • openmeter/billing/charges/models/chargemeta/mixin.go

@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: 2

♻️ Duplicate comments (1)
openmeter/billing/charges/service/taxcode_test.go (1)

373-377: ⚠️ Potential issue | 🔴 Critical

ListGatheringInvoicesInput fields here still look mismatched (likely compile blocker).

On Line 375 and Line 376, Customers / Currencies appear to be the old field names for this input type. If the API shape is unchanged, this call won’t compile.

💡 Suggested fix
  gatheringInvoices, err := s.BillingService.ListGatheringInvoices(ctx, billing.ListGatheringInvoicesInput{
      Namespaces: []string{ns},
-     Customers:  []string{cust.ID},
-     Currencies: []currencyx.Code{USD},
+     CustomerIDs: []string{cust.ID},
      Expand:     []billing.GatheringInvoiceExpand{billing.GatheringInvoiceExpandLines},
  })
#!/bin/bash
# Verify the current shape of ListGatheringInvoicesInput and call sites.
rg -n -C3 'type\s+ListGatheringInvoicesInput\s+struct|CustomerIDs|Customers|Currencies' --type go
rg -n -C3 'ListGatheringInvoices\(ctx,\s*billing\.ListGatheringInvoicesInput' openmeter/billing/charges/service/taxcode_test.go
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 373 - 377,
ListGatheringInvoicesInput usage in the ListGatheringInvoices call is using
outdated field names (Customers, Currencies); inspect the current
ListGatheringInvoicesInput struct and replace those fields with the correct ones
(e.g., CustomerIDs, CustomerIds, CurrencyCodes, or whatever the current names
are) in the call to s.BillingService.ListGatheringInvoices (keep Expand and
Namespaces as-is); verify by searching for the type definition
(ListGatheringInvoicesInput) and update the fields in taxcode_test.go to match
the struct exactly so the code compiles.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@openmeter/ent/schema/chargesflatfee.go`:
- Around line 125-128: The edge.From("tax_code",
TaxCode.Type).Ref("charge_flat_fees").Field("tax_code_id").Unique() definition
in the ChargesFlatFee schema is missing the explicit "ON DELETE SET NULL"
annotation; update that edge by appending an annotation like
.Annotations(entsql.OnDelete(entsql.SetNull)) (importing the entsql package) so
the generated schema matches the migration, and apply the same change to other
schemas with tax_code edges (e.g., ChargesUsageBased, ChargesCreditPurchase) to
keep behavior consistent.

In `@openmeter/ent/schema/chargesusagebased.go`:
- Around line 121-124: The edge definition for TaxCode on ChargeUsageBased is
missing the Ent SQL on-delete annotation; update the edge chain starting at
edge.From("tax_code",
TaxCode.Type).Ref("charge_usage_based").Field("tax_code_id").Unique() to include
an Ent annotation that sets ON DELETE to SET NULL (use
entsql.OnDelete(entsql.SetNull)) so the schema matches the migration and
generates the correct FK behavior.

---

Duplicate comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 373-377: ListGatheringInvoicesInput usage in the
ListGatheringInvoices call is using outdated field names (Customers,
Currencies); inspect the current ListGatheringInvoicesInput struct and replace
those fields with the correct ones (e.g., CustomerIDs, CustomerIds,
CurrencyCodes, or whatever the current names are) in the call to
s.BillingService.ListGatheringInvoices (keep Expand and Namespaces as-is);
verify by searching for the type definition (ListGatheringInvoicesInput) and
update the fields in taxcode_test.go to match the struct exactly so the code
compiles.
🪄 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: 7747e482-bc53-4e94-ae14-5cd6f84a3b3a

📥 Commits

Reviewing files that changed from the base of the PR and between 8c4e2bf and 32bdaa2.

⛔ Files ignored due to path filters (37)
  • .claude/scheduled_tasks.lock is excluded by !**/*.lock, !**/*.lock
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openmeter/ent/db/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (16)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/settlement.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/creditgrant/service/service.go
✅ Files skipped from review due to trivial changes (3)
  • openmeter/ent/schema/taxcode.go
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • tools/migrate/views.sql
🚧 Files skipped from review as they are similar to previous changes (3)
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • tools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sql

Comment thread openmeter/ent/schema/chargesflatfee.go Resolved
@mark-vass-konghq

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

🧹 Nitpick comments (3)
openmeter/billing/charges/models/chargemeta/mixin.go (1)

103-111: Make the new tax_code_id index partial.

This mixin lands on every charge table, and tax_code_id looks optional everywhere in this PR. A plain Postgres index will still store the null-heavy common case, so you pay extra write/storage cost without helping the FK lookup path.

Suggested tweak
 func (metaMixin) Indexes() []ent.Index {
 	return []ent.Index{
 		index.Fields("namespace", "customer_id", "unique_reference_id").
 			Annotations(
 				entsql.IndexWhere("unique_reference_id IS NOT NULL AND deleted_at IS NULL"),
 			).
 			Unique(),
-		index.Fields("tax_code_id"),
+		index.Fields("tax_code_id").
+			Annotations(
+				entsql.IndexWhere("tax_code_id IS NOT NULL"),
+			),
 	}
 }

As per coding guidelines, "Performance should be a priority in critical code paths. Anything related to event ingestion, message processing, database operations (regardless of database) should be vetted for potential performance bottlenecks."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/models/chargemeta/mixin.go` around lines 103 - 111,
The index on tax_code_id in metaMixin.Indexes() is currently a full index;
change it to a partial index that only indexes non-null, non-deleted rows to
avoid storing null-heavy entries. Update the index.Fields("tax_code_id") entry
to add an Annotations(entsql.IndexWhere("tax_code_id IS NOT NULL AND deleted_at
IS NULL")) (mirroring the unique_reference_id index) so the index only covers
rows where tax_code_id is present and not soft-deleted.
openmeter/billing/charges/service/taxcode_test.go (2)

318-391: Add the nil-tax-config gathering-line case here.

This only locks in the happy path where intent.TaxConfig is set. A sibling case with TaxConfig: nil would also protect the new single-source-of-truth behavior and catch accidental fallback to settlement/profile tax data.

As per coding guidelines, "Make sure the tests are comprehensive and cover the changes. Keep a strong focus on unit tests and in-code integration tests."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 318 - 391,
Add a sibling test to exercise the nil-tax-config case: create a credit-purchase
intent where Intent.TaxConfig is nil but the Settlement (or profile) has a
TaxConfig set, call charges.Create(...) and then
billing.ListGatheringInvoices(...), and assert that the resulting gathering
line's TaxConfig is nil (i.e., gatheringLine.TaxConfig == nil) to ensure we
don't fall back to settlement/profile tax data; reference functions/types to
edit/replicate:
TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine,
charges.Create, creditpurchase.Intent, creditpurchase.InvoiceSettlement,
billing.ListGatheringInvoices, and gatheringInvoices.Items[0].Lines /
gatheringLine.TaxConfig.

41-316: Please cover the update/clear path too.

The new suite proves create→read, but the production change also added SetOrClearTaxCodeID / SetOrClearTaxBehavior in chargemeta.Update(). One service-level round-trip that updates and then clears TaxConfig would keep that branch from drifting untested.

As per coding guidelines, "Make sure the tests are comprehensive and cover the changes. Keep a strong focus on unit tests and in-code integration tests."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openmeter/billing/charges/service/taxcode_test.go` around lines 41 - 316, Add
tests that exercise the update + clear paths for TaxConfig: after the existing
create→read assertions in each TestFlatFeeChargePersistsTaxConfig,
TestUsageBasedChargePersistsTaxConfig, and
TestCreditPurchaseChargePersistsTaxConfig, add a subtest that calls
s.Charges.Update(...) (or the service-level update that eventually calls
chargemeta.Update which uses SetOrClearTaxCodeID / SetOrClearTaxBehavior) to
change the TaxConfig (e.g., flip Behavior or set a different TaxCodeID), read
back with mustGetChargeByID and assert the new values via
AsFlatFeeCharge/AsUsageBasedCharge/AsCreditPurchaseCharge, then call
s.Charges.Update(...) again to clear the TaxConfig (nil it), read back and
assert Intent.TaxConfig is nil; reference the existing helper methods
createMockChargeIntent, mustGetChargeByID and the SetOrClearTaxCodeID /
SetOrClearTaxBehavior behavior so the tests validate both updating and clearing
paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openmeter/billing/charges/models/chargemeta/mixin.go`:
- Around line 103-111: The index on tax_code_id in metaMixin.Indexes() is
currently a full index; change it to a partial index that only indexes non-null,
non-deleted rows to avoid storing null-heavy entries. Update the
index.Fields("tax_code_id") entry to add an
Annotations(entsql.IndexWhere("tax_code_id IS NOT NULL AND deleted_at IS NULL"))
(mirroring the unique_reference_id index) so the index only covers rows where
tax_code_id is present and not soft-deleted.

In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 318-391: Add a sibling test to exercise the nil-tax-config case:
create a credit-purchase intent where Intent.TaxConfig is nil but the Settlement
(or profile) has a TaxConfig set, call charges.Create(...) and then
billing.ListGatheringInvoices(...), and assert that the resulting gathering
line's TaxConfig is nil (i.e., gatheringLine.TaxConfig == nil) to ensure we
don't fall back to settlement/profile tax data; reference functions/types to
edit/replicate:
TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine,
charges.Create, creditpurchase.Intent, creditpurchase.InvoiceSettlement,
billing.ListGatheringInvoices, and gatheringInvoices.Items[0].Lines /
gatheringLine.TaxConfig.
- Around line 41-316: Add tests that exercise the update + clear paths for
TaxConfig: after the existing create→read assertions in each
TestFlatFeeChargePersistsTaxConfig, TestUsageBasedChargePersistsTaxConfig, and
TestCreditPurchaseChargePersistsTaxConfig, add a subtest that calls
s.Charges.Update(...) (or the service-level update that eventually calls
chargemeta.Update which uses SetOrClearTaxCodeID / SetOrClearTaxBehavior) to
change the TaxConfig (e.g., flip Behavior or set a different TaxCodeID), read
back with mustGetChargeByID and assert the new values via
AsFlatFeeCharge/AsUsageBasedCharge/AsCreditPurchaseCharge, then call
s.Charges.Update(...) again to clear the TaxConfig (nil it), read back and
assert Intent.TaxConfig is nil; reference the existing helper methods
createMockChargeIntent, mustGetChargeByID and the SetOrClearTaxCodeID /
SetOrClearTaxBehavior behavior so the tests validate both updating and clearing
paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 682c93b8-3924-45d6-8c21-9c89996f879f

📥 Commits

Reviewing files that changed from the base of the PR and between 8c4e2bf and 9649491.

⛔ Files ignored due to path filters (37)
  • .claude/scheduled_tasks.lock is excluded by !**/*.lock, !**/*.lock
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • openmeter/ent/db/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargecreditpurchase_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/taxcode.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/taxcode_update.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (18)
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/v3/api.gen.go
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/billing/charges/creditpurchase/settlement.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/service/base_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargescreditpurchase.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260428102826_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260428102826_add_tax_codes_to_charges.up.sql
  • tools/migrate/migrations/20260428120000_update_charges_search_view_tax_columns.down.sql
  • tools/migrate/migrations/20260428120000_update_charges_search_view_tax_columns.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/creditgrant/service/service.go
✅ Files skipped from review due to trivial changes (7)
  • openmeter/billing/charges/creditpurchase/service/create.go
  • openmeter/ent/schema/charges.go
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • tools/migrate/migrations/20260428102826_add_tax_codes_to_charges.down.sql
  • tools/migrate/migrations/20260428120000_update_charges_search_view_tax_columns.up.sql
  • openmeter/ent/schema/taxcode.go
  • tools/migrate/migrations/20260428102826_add_tax_codes_to_charges.up.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/migrate/views.sql

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread tools/migrate/views.sql Resolved
@turip

turip commented Apr 29, 2026

Copy link
Copy Markdown
Member

Also please validate in openmeter/billing/worker/subscriptionsync/service/creditsonly_test.go that if there's a subscription that has taxcode_id set, the sync properly propagates that to charges.

@turip turip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Nice job.

@mark-vass-konghq
mark-vass-konghq merged commit 0da1145 into main Apr 30, 2026
27 of 28 checks passed
@mark-vass-konghq
mark-vass-konghq deleted the feat/add-tax-code-to-charges branch April 30, 2026 14:38

This branch was previously deployed

1 inactive deployment
dev — 10b372d6 Deployed Apr 30, 2026 by mark-vass-konghq via Migration Checks #13971
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants