Repository navigation
feat(charges): add tax code - #4237
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
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 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 |
There was a problem hiding this comment.
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 INDEXhere isn'tCONCURRENTLY, 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-columntax_code_idindex — 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: Unusedcallbacklocals in the credit purchase tests.
callback := newCountedLedgerTransactionCallback[creditpurchase.Charge]()is created and wired intos.CreditPurchaseTestHandler.onPromotionalCreditPurchase, but the localcallbackitself is never asserted on (noWait/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
⛔ Files ignored due to path filters (35)
go.sumis excluded by!**/*.sum,!**/*.sumopenmeter/ent/db/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (15)
api/spec/packages/aip/src/customers/credits/grant.tspopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/settlement.goopenmeter/billing/charges/models/chargemeta/mixin.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/taxcode_test.goopenmeter/billing/creditgrant/service/service.goopenmeter/ent/schema/charges.goopenmeter/ent/schema/chargescreditpurchase.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260427085157_add_tax_codes_to_charges.down.sqltools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sqltools/migrate/views.sql
💤 Files with no reviewable changes (1)
- openmeter/billing/creditgrant/service/service.go
f3eb15f to
348b12a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
openmeter/billing/charges/service/taxcode_test.go (2)
31-37: These overrides aren't pulling their weight.
SetupSuiteandTearDownTesthere just delegate toBaseSuitewithout doing anything else, so they can be dropped — the embeddedBaseSuitemethods 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:callbackis set on the handler but never asserted.In both
s.Run(...)blocks ofTestCreditPurchaseChargePersistsTaxConfigyou build anewCountedLedgerTransactionCallbackand wire it ontos.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 ans.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
⛔ Files ignored due to path filters (36)
api/v3/openapi.yamlis excluded by!**/openapi.yamlgo.sumis excluded by!**/*.sum,!**/*.sumopenmeter/ent/db/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (16)
api/spec/packages/aip/src/customers/credits/grant.tspapi/v3/api.gen.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/settlement.goopenmeter/billing/charges/models/chargemeta/mixin.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/taxcode_test.goopenmeter/billing/creditgrant/service/service.goopenmeter/ent/schema/charges.goopenmeter/ent/schema/chargescreditpurchase.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260427085157_add_tax_codes_to_charges.down.sqltools/migrate/migrations/20260427085157_add_tax_codes_to_charges.up.sqltools/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
50c4361 to
0c97289
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
openmeter/billing/charges/service/taxcode_test.go (2)
31-37: Tiny nit: the emptySetupSuite/TearDownTestoverrides are no-ops.Since
BaseSuiteis 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:callbackis wired up but never asserted.In both credit-purchase subtests you build a
newCountedLedgerTransactionCallbackand assign its handler, but nothing reads fromcallbackafterwards. If the goal is just to satisfy the test handler soCreatedoesn'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
⛔ Files ignored due to path filters (36)
api/v3/openapi.yamlis excluded by!**/openapi.yamlgo.sumis excluded by!**/*.sum,!**/*.sumopenmeter/ent/db/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (16)
api/spec/packages/aip/src/customers/credits/grant.tspapi/v3/api.gen.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/settlement.goopenmeter/billing/charges/models/chargemeta/mixin.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/taxcode_test.goopenmeter/billing/creditgrant/service/service.goopenmeter/ent/schema/charges.goopenmeter/ent/schema/chargescreditpurchase.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sqltools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sqltools/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
0c97289 to
8c4e2bf
Compare
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (37)
.claude/scheduled_tasks.lockis excluded by!**/*.lock,!**/*.lockapi/v3/openapi.yamlis excluded by!**/openapi.yamlgo.sumis excluded by!**/*.sum,!**/*.sumopenmeter/ent/db/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (16)
api/spec/packages/aip/src/customers/credits/grant.tspapi/v3/api.gen.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/settlement.goopenmeter/billing/charges/models/chargemeta/mixin.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/taxcode_test.goopenmeter/billing/creditgrant/service/service.goopenmeter/ent/schema/charges.goopenmeter/ent/schema/chargescreditpurchase.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sqltools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sqltools/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
8c4e2bf to
32bdaa2
Compare
32bdaa2 to
3934790
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
openmeter/billing/charges/service/taxcode_test.go (1)
373-377:⚠️ Potential issue | 🔴 Critical
ListGatheringInvoicesInputfields here still look mismatched (likely compile blocker).On Line 375 and Line 376,
Customers/Currenciesappear 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
⛔ Files ignored due to path filters (37)
.claude/scheduled_tasks.lockis excluded by!**/*.lock,!**/*.lockapi/v3/openapi.yamlis excluded by!**/openapi.yamlgo.sumis excluded by!**/*.sum,!**/*.sumopenmeter/ent/db/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (16)
api/spec/packages/aip/src/customers/credits/grant.tspapi/v3/api.gen.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/settlement.goopenmeter/billing/charges/models/chargemeta/mixin.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/taxcode_test.goopenmeter/billing/creditgrant/service/service.goopenmeter/ent/schema/charges.goopenmeter/ent/schema/chargescreditpurchase.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260427171846_add_tax_codes_to_charges.down.sqltools/migrate/migrations/20260427171846_add_tax_codes_to_charges.up.sqltools/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
3934790 to
ec16f8b
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (3)
openmeter/billing/charges/models/chargemeta/mixin.go (1)
103-111: Make the newtax_code_idindex partial.This mixin lands on every charge table, and
tax_code_idlooks 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.TaxConfigis set. A sibling case withTaxConfig: nilwould 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/SetOrClearTaxBehaviorinchargemeta.Update(). One service-level round-trip that updates and then clearsTaxConfigwould 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
⛔ Files ignored due to path filters (37)
.claude/scheduled_tasks.lockis excluded by!**/*.lock,!**/*.lockapi/v3/openapi.yamlis excluded by!**/openapi.yamlgo.sumis excluded by!**/*.sum,!**/*.sumopenmeter/ent/db/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchase_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/chargeflatfee.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfee_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/chargessearchv1.gois excluded by!**/ent/db/**openmeter/ent/db/chargessearchv1/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/chargeusagebased.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_query.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebased_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/runtime.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (18)
api/spec/packages/aip/src/customers/credits/grant.tspapi/v3/api.gen.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/settlement.goopenmeter/billing/charges/models/chargemeta/mixin.goopenmeter/billing/charges/service/base_test.goopenmeter/billing/charges/service/taxcode_test.goopenmeter/billing/creditgrant/service/service.goopenmeter/ent/schema/charges.goopenmeter/ent/schema/chargescreditpurchase.goopenmeter/ent/schema/chargesflatfee.goopenmeter/ent/schema/chargesusagebased.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260428102826_add_tax_codes_to_charges.down.sqltools/migrate/migrations/20260428102826_add_tax_codes_to_charges.up.sqltools/migrate/migrations/20260428120000_update_charges_search_view_tax_columns.down.sqltools/migrate/migrations/20260428120000_update_charges_search_view_tax_columns.up.sqltools/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
9649491 to
cf1229d
Compare
✅ Actions performedReview triggered.
|
cf1229d to
a038993
Compare
|
Also please validate in |
a038993 to
8831bd7
Compare
8831bd7 to
abea67f
Compare
abea67f to
e0af9ac
Compare
e0af9ac to
1df0d1e
Compare
@coderabbitai
Summary by CodeRabbit
New Features
Documentation
Tests