Repository navigation
feat(test) Charge tax config carryover - #4287
Conversation
20d98a9 to
9d94088
Compare
|
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 new integration-style tests and an import to verify TaxCode/TaxCodeConfig propagation (Behavior, TaxCodeID) and Stripe.Code backfill across charge invoice/gathering flows and credit-grant flows. All edits are test additions and test imports; no production code changes in the diff. ChangesTaxConfig propagation tests (single cohesive cohort)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 892-1315: The file contains unresolved git conflict markers
(<<<<<<< HEAD, =======, >>>>>>>) surrounding several test functions such as
TestFlatFeeInvoiceSettlementPropagatesTaxConfigToGatheringLine,
TestFlatFeeInvoiceSettlementNilTaxConfigDoesNotPropagateToGatheringLine,
TestUsageBasedCreditThenInvoicePropagatesTaxConfigToGatheringLine, etc.; remove
the three marker lines and keep the intended test bodies (the content between
<<<<<<< HEAD and =======) so the file compiles—ensure no leftover markers remain
and run go vet/go test to verify.
In `@test/credits/creditgrant_test.go`:
- Line 273: The tests create a ctx using context.Background(), which prevents
test cancellation propagation; replace each occurrence of "ctx :=
context.Background()" in the newly added test functions with "ctx :=
s.T().Context()" so the test harness controls cancellation and lifecycle (look
for the ctx binding in the new tests in creditgrant_test.go and update the
assignment to use s.T().Context()).
🪄 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: a8f1b31d-4255-4a4c-b5f7-1d188354baa6
📒 Files selected for processing (2)
openmeter/billing/charges/service/taxcode_test.gotest/credits/creditgrant_test.go
9d94088 to
2c60995
Compare
211d41c to
b7f8ad8
Compare
2c60995 to
c891cbb
Compare
c891cbb to
d2c1156
Compare
d2c1156 to
2ba4722
Compare
2ba4722 to
74be3f7
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/billing/charges/service/taxcode_test.go (1)
450-454: 💤 Low valueConsider adding
Behaviorassertions to standard invoice line checks for consistency
TestUsageBasedInvoiceSettlementPopulatesStripeCodeOnStandardInvoiceassertsline.TaxConfig.Behavioron the standard invoice (line 1185), but the two analogous tests (TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLineat lines 450–454 andTestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoiceat lines 757–761) skip it. A targeted regression onBehaviorpropagation to the standard invoice would slip through unnoticed in those two tests.🔧 Optional additions to bring the assertions in line
For
TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine(after line 451):s.Require().NotNil(line.TaxConfig, "standard invoice line must have TaxConfig") +s.Require().NotNil(line.TaxConfig.Behavior, "TaxBehavior must be on standard invoice line") +s.Equal(productcatalog.ExclusiveTaxBehavior, *line.TaxConfig.Behavior) s.Require().NotNil(line.TaxConfig.TaxCodeID, "TaxCodeID must be on standard invoice line")For
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice(after line 757):s.Require().NotNil(line.TaxConfig, "standard invoice line must have TaxConfig") +s.Require().NotNil(line.TaxConfig.Behavior, "TaxBehavior must be on standard invoice line") +s.Equal(productcatalog.ExclusiveTaxBehavior, *line.TaxConfig.Behavior) s.Require().NotNil(line.TaxConfig.TaxCodeID, "TaxCodeID must be on standard invoice line")Also applies to: 757-761
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/billing/charges/service/taxcode_test.go` around lines 450 - 454, Add an assertion to check TaxConfig.Behavior on the standard invoice line in the two tests that currently omit it: in TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine and TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice, after the existing TaxCode/Stripe assertions (the block referencing line.TaxConfig and stripeCode), add a check asserting line.TaxConfig.Behavior equals the expected behavior (use the test's TaxCode variable, e.g., tc.Behavior or the same expectedBehavior value used in TestUsageBasedInvoiceSettlementPopulatesStripeCodeOnStandardInvoice) to ensure Behavior propagation is verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 450-454: Add an assertion to check TaxConfig.Behavior on the
standard invoice line in the two tests that currently omit it: in
TestCreditPurchaseInvoiceSettlementPropagatesTaxConfigToGatheringLine and
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice, after the
existing TaxCode/Stripe assertions (the block referencing line.TaxConfig and
stripeCode), add a check asserting line.TaxConfig.Behavior equals the expected
behavior (use the test's TaxCode variable, e.g., tc.Behavior or the same
expectedBehavior value used in
TestUsageBasedInvoiceSettlementPopulatesStripeCodeOnStandardInvoice) to ensure
Behavior propagation is verified.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 157aa966-5aeb-4cc5-ba80-977caaa7faf4
📒 Files selected for processing (2)
openmeter/billing/charges/service/taxcode_test.gotest/credits/creditgrant_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- test/credits/creditgrant_test.go
74be3f7 to
d7e9f27
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
openmeter/billing/charges/service/taxcode_test.go (2)
1196-1251: 💤 Low valueBehavior-only tests pull in
SetupCustomInvoicing+ manual approval but never invoice — could simplify.Both
TestFlatFeeBehaviorOnlyTaxConfigPropagatesToGatheringLineandTestUsageBasedBehaviorOnlyTaxConfigPropagatesToGatheringLineonly assert on the gathering line and never advance to invoicing or payment, yet they wire up the custom invoicing app withbillingtest.WithManualApproval(). The nil-tax-config sibling at lines 965–1011 uses the lighterInstallSandboxAppfor the equivalent gathering-only assertion. Switching these two to the same sandbox setup would shave noise and make the intent clearer.♻️ Example diff for the flat-fee variant
- customInvoicing := s.SetupCustomInvoicing(ns) - _ = s.ProvisionBillingProfile(ctx, ns, customInvoicing.App.GetID(), - billingtest.WithManualApproval(), - ) + sandboxApp := s.InstallSandboxApp(s.T(), ns) + _ = s.ProvisionBillingProfile(ctx, ns, sandboxApp.GetID())Also applies to: 1256-1311
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/billing/charges/service/taxcode_test.go` around lines 1196 - 1251, The test TestFlatFeeBehaviorOnlyTaxConfigPropagatesToGatheringLine currently calls SetupCustomInvoicing and ProvisionBillingProfile(..., billingtest.WithManualApproval()) even though it only asserts gathering-line behavior; change the setup to the lighter sandbox flow used by the nil-tax-config sibling: replace SetupCustomInvoicing + ProvisionBillingProfile(...) with InstallSandboxApp (or the equivalent sandbox installer used in the other test) and remove the manual approval provisioning call so the test only installs the sandbox app and proceeds to create the charge and assert gathering line behavior; apply the same change to TestUsageBasedBehaviorOnlyTaxConfigPropagatesToGatheringLine (the other test referenced).
1139-1139: ⚡ Quick winConsider explicit
StoredAtfor the late-arriving usage event.
AddSimpleEventhere injects usage at2026-01-15while the clock is still at2025-12-01, and the event needs to be visible during finalization atservicePeriod.To. Per the repo guideline on usage-based finalization tests, usingMockStreamingConnectorwith explicitStoredAt(orSetSimpleEvents) exercises the real stored-at cutoff logic instead of relying on the implicit default. Worth adopting here so the test stays robust if cutoff handling tightens.The flat-fee
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoicedoesn't have this concern since it doesn't depend on streamed usage, so this is the only spot.As per coding guidelines: "use
MockStreamingConnectorevents with explicitStoredAtvalues (orSetSimpleEvents) to exercise real stored-at cutoff logic in finalization when modeling late-arriving or newly visible usage."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/billing/charges/service/taxcode_test.go` at line 1139, The test injects a late-arriving usage event via MockStreamingConnector.AddSimpleEvent(meterSlug, 5, time.Date(2026, 1, 15...)) while the test clock is at 2025-12-01, but it does not set an explicit StoredAt so the stored-at cutoff logic isn't exercised; update the test TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice (or the surrounding test) to create the streamed event with an explicit StoredAt (or use MockStreamingConnector.SetSimpleEvents) so the event's StoredAt is set to a timestamp that makes it visible at finalization (servicePeriod.To) and thus exercises the real stored-at cutoff logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@openmeter/billing/charges/service/taxcode_test.go`:
- Around line 1196-1251: The test
TestFlatFeeBehaviorOnlyTaxConfigPropagatesToGatheringLine currently calls
SetupCustomInvoicing and ProvisionBillingProfile(...,
billingtest.WithManualApproval()) even though it only asserts gathering-line
behavior; change the setup to the lighter sandbox flow used by the
nil-tax-config sibling: replace SetupCustomInvoicing +
ProvisionBillingProfile(...) with InstallSandboxApp (or the equivalent sandbox
installer used in the other test) and remove the manual approval provisioning
call so the test only installs the sandbox app and proceeds to create the charge
and assert gathering line behavior; apply the same change to
TestUsageBasedBehaviorOnlyTaxConfigPropagatesToGatheringLine (the other test
referenced).
- Line 1139: The test injects a late-arriving usage event via
MockStreamingConnector.AddSimpleEvent(meterSlug, 5, time.Date(2026, 1, 15...))
while the test clock is at 2025-12-01, but it does not set an explicit StoredAt
so the stored-at cutoff logic isn't exercised; update the test
TestFlatFeeInvoiceSettlementPopulatesStripeCodeOnStandardInvoice (or the
surrounding test) to create the streamed event with an explicit StoredAt (or use
MockStreamingConnector.SetSimpleEvents) so the event's StoredAt is set to a
timestamp that makes it visible at finalization (servicePeriod.To) and thus
exercises the real stored-at cutoff logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cf3e3ba9-8ceb-4d52-ac3e-7bf83edb3766
📒 Files selected for processing (2)
openmeter/billing/charges/service/taxcode_test.gotest/credits/creditgrant_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- test/credits/creditgrant_test.go
d7e9f27 to
32eb5f8
Compare
32eb5f8 to
3bef920
Compare
@coderabbitai
Summary by CodeRabbit