Skip to content

feat(taxcode): create tax codes on namespace create & set defaults - #4390

Merged
borbelyr-kong merged 5 commits into
mainfrom
feat/add-default-tax-code-provision
May 20, 2026
Merged

borbelyr-kong merged 5 commits into
mainfrom
feat/add-default-tax-code-provision

Conversation

@borbelyr-kong

@borbelyr-kong borbelyr-kong commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Automatic, idempotent tax-code provisioning for new namespaces and org-defaults
    • Configurable organization default tax codes for invoicing and credit grants
    • Per-application tax code mappings (e.g., Stripe)
  • Configuration
    • New taxcode config section with seeds, defaults, app mappings, examples and validation
  • Bug Fixes
    • Exclude soft-deleted tax codes from normal lookups
  • Tests
    • Unit tests for tax-code seeding, namespace handling, and config validation
  • Chores
    • Server wiring and registration of the TaxCode namespace handler

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 19, 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 tax-code configuration and validation, implements a NamespaceHandler that seeds per-namespace tax codes and organization defaults (idempotent, transactional), wires the handler via Wire, registers it at server startup, and adds tests and example config.

Changes

Tax Code Namespace Auto-Provisioning

Layer / File(s) Summary
Configuration types and validation
app/config/taxcode.go, app/config/taxcode_test.go
TaxCodeConfiguration, TaxCodeSeed, and TaxCodeAppMapping with validation (non-empty fields, unique trimmed keys, Stripe tax-code regexp for stripe mappings, exactly-one defaults). ConfigureTaxCode registers Viper defaults and tests exercise validation cases.
Configuration integration into main app config
app/config/config.go, app/config/config_test.go, app/config/testdata/complete.yaml
Adds TaxCode field to main Configuration, extends Configuration.Validate() to validate TaxCode, calls ConfigureTaxCode() in SetViperDefaults, and updates test data/expected config with seed entries.
Dependency injection and Wire setup
app/common/taxcode.go, cmd/server/wire.go
Adds TaxCodeNamespaceHandler Wire provider set and NewTaxCodeNamespaceHandler constructor that maps config seeds into taxcode.SeedEntry. Application gains a TaxCodeNamespaceHandler field.
Server initialization and handler registration
cmd/server/wire_gen.go, cmd/server/main.go
Generated wiring builds taxCodeNamespaceHandler and assigns it into Application; main registers the handler with NamespaceManager at startup and exits on failure.
Namespace handler core implementation
openmeter/taxcode/namespacehandler.go
NamespaceHandler and NewNamespaceHandler added. CreateNamespace runs in a transaction to ensure seed tax codes, captures invoicing/credit IDs, and upserts organization defaults only when missing. ensureTaxCode lists existing codes, creates annotated system-managed codes when absent, and recovers from create conflicts by re-listing. DeleteNamespace is a no-op.
Namespace handler test suite
openmeter/taxcode/namespacehandler_test.go
Tests provisioning for fresh namespaces, partially pre-existing tax codes, pre-existing org defaults, idempotency, and constructor validation errors.
Examples and test utilities
config.example.yaml, openmeter/taxcode/testutils/env.go, openmeter/taxcode/adapter/taxcode.go, openmeter/taxcode/service.go
Adds commented example taxcode config, exposes Adapter in test env for taxcode tests, filters soft-deleted tax codes in GetTaxCode, and adds IncludeDeleted flag to service input for internal use.

Sequence Diagram(s)

sequenceDiagram
  participant NamespaceManager
  participant NamespaceHandler
  participant TaxCodeService
  participant TaxCodeRepository
  NamespaceManager->>NamespaceHandler: CreateNamespace(ns)
  NamespaceHandler->>TaxCodeService: ListTaxCodes(ctx, org)
  NamespaceHandler->>TaxCodeRepository: CreateTaxCode if missing (annotated)
  TaxCodeRepository-->>NamespaceHandler: taxCodeID (existing or created)
  NamespaceHandler->>TaxCodeService: UpsertOrganizationDefaultTaxCodes(ns, invoicingID, creditGrantID)
  NamespaceHandler-->>NamespaceManager: return success/error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

area/product-catalog, area/subscriptions

Suggested reviewers

  • tothandras
  • mark-vass-konghq
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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 accurately captures the main change: adding tax code auto-provisioning on namespace creation and setting default tax codes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-default-tax-code-provision

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.

@borbelyr-kong borbelyr-kong added the release-note/misc Miscellaneous changes label May 19, 2026
@borbelyr-kong
borbelyr-kong force-pushed the feat/add-default-tax-code-provision branch from 7e36927 to 3f45613 Compare May 19, 2026 20:36

@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)
openmeter/taxcode/namespacehandler_test.go (2)

241-248: 💤 Low value

Same isolation issue: missing Logger and TransactionManager.

This test also omits Logger and TransactionManager, so it fails for three reasons instead of just empty seeds.

♻️ Suggested fix
 	t.Run("EmptySeeds", func(t *testing.T) {
 		_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
-			Logger:  env.Logger,
-			Service: env.Service,
-			Seeds:   nil,
+			Logger:             env.Logger,
+			Service:            env.Service,
+			Seeds:              nil,
+			TransactionManager: env.Adapter,
 		})
 		require.Error(t, err)
 	})
🤖 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/taxcode/namespacehandler_test.go` around lines 241 - 248, The test
should only fail due to empty Seeds but currently also omits required
dependencies; update the call to NewNamespaceHandler to provide a valid Logger
and TransactionManager in NamespaceHandlerConfig (e.g., Logger: env.Logger,
TransactionManager: env.TransactionManager) while keeping Seeds: nil so
NewNamespaceHandler/NamespaceHandlerConfig validation fails only for empty
seeds.

225-238: 💤 Low value

Missing TransactionManager makes these tests less isolated.

Both MissingLogger and MissingService tests omit TransactionManager, so they fail validation for two reasons, not just the one being tested. Since validate() collects all errors, the tests still pass, but they don't cleanly isolate the specific validation.

Consider adding TransactionManager: env.Adapter to both tests so each validates exactly one missing field.

♻️ Suggested fix
 	t.Run("MissingLogger", func(t *testing.T) {
 		_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
-			Service: env.Service,
-			Seeds:   validSeeds,
+			Service:            env.Service,
+			Seeds:              validSeeds,
+			TransactionManager: env.Adapter,
 		})
 		require.Error(t, err)
 	})

 	t.Run("MissingService", func(t *testing.T) {
 		_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
-			Logger: env.Logger,
-			Seeds:  validSeeds,
+			Logger:             env.Logger,
+			Seeds:              validSeeds,
+			TransactionManager: env.Adapter,
 		})
 		require.Error(t, err)
 	})
🤖 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/taxcode/namespacehandler_test.go` around lines 225 - 238, The tests
"MissingLogger" and "MissingService" call taxcode.NewNamespaceHandler with
NamespaceHandlerConfig but omit TransactionManager, so validate() reports
multiple missing fields and the tests don't isolate the single-missing-field
case; update both tests to include TransactionManager: env.Adapter in their
NamespaceHandlerConfig (while still omitting the Logger or Service respectively)
so NewNamespaceHandler/validate() fails for only the intended missing field.
app/config/taxcode_test.go (1)

10-103: ⚡ Quick win

Add one focused test for ConfigureTaxCode default wiring.

Nice coverage on Validate(). I’d add a small test that calls ConfigureTaxCode(v), unmarshals into TaxCodeConfiguration, and asserts Validate() passes plus expected default keys/flags. It’ll catch default drift early.

As per coding guidelines: “**/*_test.go: Make sure the tests are comprehensive and cover the changes.”

🤖 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 `@app/config/taxcode_test.go` around lines 10 - 103, Add a new focused test
that calls ConfigureTaxCode(v) to produce the config bytes, unmarshals into a
TaxCodeConfiguration, then assert cfg.Validate() returns no error and that the
expected default seeds/keys and flags (e.g., presence of a "default" seed,
defaultInvoicing=true and defaultCreditGrant where applicable) are present;
specifically reference ConfigureTaxCode, TaxCodeConfiguration, and Validate in
the test and check the default keys and boolean flags to detect any
default-wiring regressions.
🤖 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 `@app/config/taxcode.go`:
- Around line 44-57: The validation currently treats whitespace-only strings as
non-empty; update the checks to use trimmed values (strings.TrimSpace) so that
seed.Key, seed.Name, seed.AppType and seed.TaxCode are treated as empty when
they contain only whitespace. In the loop that builds and checks the keys map,
use a trimmedKey variable for emptiness checks and duplicate detection (so
duplicate detection uses the trimmed value and keys[trimmedKey] is set), and
apply the same trim-and-validate logic to the name, appType and taxCode checks
referenced around the other validation block (lines ~67-74).

---

Nitpick comments:
In `@app/config/taxcode_test.go`:
- Around line 10-103: Add a new focused test that calls ConfigureTaxCode(v) to
produce the config bytes, unmarshals into a TaxCodeConfiguration, then assert
cfg.Validate() returns no error and that the expected default seeds/keys and
flags (e.g., presence of a "default" seed, defaultInvoicing=true and
defaultCreditGrant where applicable) are present; specifically reference
ConfigureTaxCode, TaxCodeConfiguration, and Validate in the test and check the
default keys and boolean flags to detect any default-wiring regressions.

In `@openmeter/taxcode/namespacehandler_test.go`:
- Around line 241-248: The test should only fail due to empty Seeds but
currently also omits required dependencies; update the call to
NewNamespaceHandler to provide a valid Logger and TransactionManager in
NamespaceHandlerConfig (e.g., Logger: env.Logger, TransactionManager:
env.TransactionManager) while keeping Seeds: nil so
NewNamespaceHandler/NamespaceHandlerConfig validation fails only for empty
seeds.
- Around line 225-238: The tests "MissingLogger" and "MissingService" call
taxcode.NewNamespaceHandler with NamespaceHandlerConfig but omit
TransactionManager, so validate() reports multiple missing fields and the tests
don't isolate the single-missing-field case; update both tests to include
TransactionManager: env.Adapter in their NamespaceHandlerConfig (while still
omitting the Logger or Service respectively) so NewNamespaceHandler/validate()
fails for only the intended missing field.
🪄 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: c12a9f12-38ca-49d8-8b24-8c5d2cd85277

📥 Commits

Reviewing files that changed from the base of the PR and between 7fc84c4 and 3f45613.

📒 Files selected for processing (13)
  • app/common/taxcode.go
  • app/config/config.go
  • app/config/config_test.go
  • app/config/taxcode.go
  • app/config/taxcode_test.go
  • app/config/testdata/complete.yaml
  • cmd/server/main.go
  • cmd/server/wire.go
  • cmd/server/wire_gen.go
  • config.example.yaml
  • openmeter/taxcode/namespacehandler.go
  • openmeter/taxcode/namespacehandler_test.go
  • openmeter/taxcode/testutils/env.go

Comment thread app/config/taxcode.go Resolved

@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 (1)
openmeter/taxcode/namespacehandler.go (1)

149-158: ⚡ Quick win

Avoid re-listing the whole namespace once per seed.

Because CreateNamespace() calls ensureTaxCode() for every seed, this turns namespace provisioning into one ListTaxCodes() round-trip per seed plus repeated full scans in memory. I’d fetch once in CreateNamespace(), index by key, and only re-list on the create-conflict path so the common case stays much cheaper.

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/taxcode/namespacehandler.go` around lines 149 - 158, Currently
ensureTaxCode calls h.service.ListTaxCodes for each seed causing O(N^2) work;
instead, modify CreateNamespace to call h.service.ListTaxCodes once, build a map
indexed by TaxCode.Key, and pass that map (or a lookup function) into
ensureTaxCode so ensureTaxCode checks the in-memory index first; only if a
create returns a conflict should ensureTaxCode re-list via
h.service.ListTaxCodes (or refresh the map) to reconcile concurrent changes.
Update signatures accordingly (e.g., CreateNamespace -> ensureTaxCode(ctx, seed,
existingMap) or add a lookup helper) and keep the existing error/creation logic
intact.
🤖 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/taxcode/namespacehandler.go`:
- Around line 149-158: Currently ensureTaxCode calls h.service.ListTaxCodes for
each seed causing O(N^2) work; instead, modify CreateNamespace to call
h.service.ListTaxCodes once, build a map indexed by TaxCode.Key, and pass that
map (or a lookup function) into ensureTaxCode so ensureTaxCode checks the
in-memory index first; only if a create returns a conflict should ensureTaxCode
re-list via h.service.ListTaxCodes (or refresh the map) to reconcile concurrent
changes. Update signatures accordingly (e.g., CreateNamespace ->
ensureTaxCode(ctx, seed, existingMap) or add a lookup helper) and keep the
existing error/creation logic intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 27dc830f-c3f8-4d91-8ead-95dcecd0f44e

📥 Commits

Reviewing files that changed from the base of the PR and between 3f45613 and 07c5512.

📒 Files selected for processing (3)
  • app/config/taxcode.go
  • openmeter/taxcode/adapter/taxcode.go
  • openmeter/taxcode/namespacehandler.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/config/taxcode.go

@borbelyr-kong
borbelyr-kong force-pushed the feat/add-default-tax-code-provision branch from 0bf996c to fcc7cb0 Compare May 20, 2026 08:20

@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

🧹 Nitpick comments (2)
app/config/taxcode_test.go (1)

90-103: ⚡ Quick win

Add test coverage for Stripe format validation path

Could you add a subtest that fails on an invalid Stripe tax code (and ideally one with whitespace-padded appType)? Right now the Stripe regex branch isn’t exercised.

As per coding guidelines "**/*_test.go: Make sure the tests are comprehensive and cover the changes."

🤖 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 `@app/config/taxcode_test.go` around lines 90 - 103, Add a new subtest that
exercises the Stripe regex path by mutating the test fixture returned by
validBase(): set cfg.Seeds[1].AppMappings[0].AppType to a whitespace-padded
Stripe type (e.g. " stripe ") and set cfg.Seeds[1].AppMappings[0].TaxCode to an
invalid Stripe value (e.g. "abc" or otherwise non-matching the Stripe pattern),
then call cfg.Validate() and assert that it returns an error containing the
Stripe-format validation message; use identifiers validBase, cfg.Validate,
cfg.Seeds, AppMappings, AppType and TaxCode to locate and modify the test
fixture.
openmeter/taxcode/namespacehandler.go (1)

49-60: 💤 Low value

Nice validation coverage! The CountBy checks for defaults are clean.

One optional enhancement: you might consider validating that seed keys are unique. If duplicates slip through, ensureTaxCode will handle it (create → conflict → re-list), but catching it here would surface config mistakes earlier.

✨ Optional: add duplicate key validation
 	if len(c.Seeds) == 0 {
 		errs = append(errs, errors.New("at least one seed entry is required"))
 	} else {
+		keys := lo.Map(c.Seeds, func(s SeedEntry, _ int) string { return s.Key })
+		if len(lo.Uniq(keys)) != len(keys) {
+			errs = append(errs, errors.New("seed entries must have unique keys"))
+		}
+
 		invoicingCount := lo.CountBy(c.Seeds, func(s SeedEntry) bool { return s.DefaultInvoicing })
🤖 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/taxcode/namespacehandler.go` around lines 49 - 60, Add a
duplicate-key validation for c.Seeds: iterate over c.Seeds (type SeedEntry)
tracking seen keys in a map[string]int, collect any keys seen more than once and
append a single error to errs (or one per duplicate) indicating which seed keys
are duplicated; place this check alongside the existing
DefaultInvoicing/DefaultCreditGrant checks so ensureTaxCode’s conflict path is
caught earlier and reference the SeedEntry key field when reporting duplicates.
🤖 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 `@app/config/taxcode.go`:
- Around line 71-80: The Stripe validation branch uses untrimmed mapping.AppType
and mapping.TaxCode so values with surrounding whitespace can bypass checks;
update the validation to use the trimmed values (e.g., the local trimmed
variables or call strings.TrimSpace on mapping.AppType and mapping.TaxCode
before comparing/regex matching) inside the loop that iterates seed.AppMappings
(refer to seed.AppMappings, mapping, mapping.AppType, mapping.TaxCode, and
taxcode.TaxCodeStripeRegexp) so that the equality check against "stripe" and the
regex MatchString both operate on trimmed strings.

In `@openmeter/taxcode/namespacehandler_test.go`:
- Around line 225-247: The three constructor validation tests ("MissingLogger",
"MissingService", "EmptySeeds") currently omit TransactionManager as well, so
failures can be caused by the wrong missing field; update each test to supply a
valid TransactionManager in NamespaceHandlerConfig (e.g. use the same
env.TransactionManager or a test stub) except for the single field under test so
NewNamespaceHandler is exercised for only that specific missing field; keep the
test names and only change the configs passed to NewNamespaceHandler to include
a valid TransactionManager.

---

Nitpick comments:
In `@app/config/taxcode_test.go`:
- Around line 90-103: Add a new subtest that exercises the Stripe regex path by
mutating the test fixture returned by validBase(): set
cfg.Seeds[1].AppMappings[0].AppType to a whitespace-padded Stripe type (e.g. "
stripe ") and set cfg.Seeds[1].AppMappings[0].TaxCode to an invalid Stripe value
(e.g. "abc" or otherwise non-matching the Stripe pattern), then call
cfg.Validate() and assert that it returns an error containing the Stripe-format
validation message; use identifiers validBase, cfg.Validate, cfg.Seeds,
AppMappings, AppType and TaxCode to locate and modify the test fixture.

In `@openmeter/taxcode/namespacehandler.go`:
- Around line 49-60: Add a duplicate-key validation for c.Seeds: iterate over
c.Seeds (type SeedEntry) tracking seen keys in a map[string]int, collect any
keys seen more than once and append a single error to errs (or one per
duplicate) indicating which seed keys are duplicated; place this check alongside
the existing DefaultInvoicing/DefaultCreditGrant checks so ensureTaxCode’s
conflict path is caught earlier and reference the SeedEntry key field when
reporting duplicates.
🪄 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: ab497952-b91b-44c5-8589-eddaac5de024

📥 Commits

Reviewing files that changed from the base of the PR and between 81379a1 and fcc7cb0.

📒 Files selected for processing (15)
  • app/common/taxcode.go
  • app/config/config.go
  • app/config/config_test.go
  • app/config/taxcode.go
  • app/config/taxcode_test.go
  • app/config/testdata/complete.yaml
  • cmd/server/main.go
  • cmd/server/wire.go
  • cmd/server/wire_gen.go
  • config.example.yaml
  • openmeter/taxcode/adapter/taxcode.go
  • openmeter/taxcode/namespacehandler.go
  • openmeter/taxcode/namespacehandler_test.go
  • openmeter/taxcode/service.go
  • openmeter/taxcode/testutils/env.go
✅ Files skipped from review due to trivial changes (2)
  • config.example.yaml
  • cmd/server/wire_gen.go

Comment thread app/config/taxcode.go Resolved
Comment on lines +225 to +247
t.Run("MissingLogger", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Service: env.Service,
Seeds: validSeeds,
})
require.Error(t, err)
})

t.Run("MissingService", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Logger: env.Logger,
Seeds: validSeeds,
})
require.Error(t, err)
})

t.Run("EmptySeeds", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Logger: env.Logger,
Service: env.Service,
Seeds: nil,
})
require.Error(t, err)

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Isolate each constructor validation case to one missing field.

Nice coverage overall, but on Line 225, Line 233, and Line 241 the test inputs omit TransactionManager too, so these cases can pass with the wrong validation error depending on check order.

💡 Suggested patch
 t.Run("MissingLogger", func(t *testing.T) {
 	_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
 		Service: env.Service,
 		Seeds:   validSeeds,
+		TransactionManager: env.Adapter,
 	})
 	require.Error(t, err)
 })

 t.Run("MissingService", func(t *testing.T) {
 	_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
 		Logger: env.Logger,
 		Seeds:  validSeeds,
+		TransactionManager: env.Adapter,
 	})
 	require.Error(t, err)
 })

 t.Run("EmptySeeds", func(t *testing.T) {
 	_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
 		Logger:  env.Logger,
 		Service: env.Service,
 		Seeds:   nil,
+		TransactionManager: env.Adapter,
 	})
 	require.Error(t, err)
 })

As per coding guidelines: "Make sure the tests are comprehensive and cover the changes."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.Run("MissingLogger", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Service: env.Service,
Seeds: validSeeds,
})
require.Error(t, err)
})
t.Run("MissingService", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Logger: env.Logger,
Seeds: validSeeds,
})
require.Error(t, err)
})
t.Run("EmptySeeds", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Logger: env.Logger,
Service: env.Service,
Seeds: nil,
})
require.Error(t, err)
t.Run("MissingLogger", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Service: env.Service,
Seeds: validSeeds,
TransactionManager: env.Adapter,
})
require.Error(t, err)
})
t.Run("MissingService", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Logger: env.Logger,
Seeds: validSeeds,
TransactionManager: env.Adapter,
})
require.Error(t, err)
})
t.Run("EmptySeeds", func(t *testing.T) {
_, err := taxcode.NewNamespaceHandler(taxcode.NamespaceHandlerConfig{
Logger: env.Logger,
Service: env.Service,
Seeds: nil,
TransactionManager: env.Adapter,
})
require.Error(t, err)
})
🤖 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/taxcode/namespacehandler_test.go` around lines 225 - 247, The three
constructor validation tests ("MissingLogger", "MissingService", "EmptySeeds")
currently omit TransactionManager as well, so failures can be caused by the
wrong missing field; update each test to supply a valid TransactionManager in
NamespaceHandlerConfig (e.g. use the same env.TransactionManager or a test stub)
except for the single field under test so NewNamespaceHandler is exercised for
only that specific missing field; keep the test names and only change the
configs passed to NewNamespaceHandler to include a valid TransactionManager.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/config/taxcode.go (1)

58-58: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the trimmed key in the error message for consistency.

Right now the duplicate check compares trimmedKey but reports seed.Key, so if two keys differ only by whitespace the error would show what looks like identical values. Line 82 reports trimmedTaxCode in its error, so for consistency this should do the same.

Quick fix
-				errs = append(errs, fmt.Errorf("seed[%d]: duplicate key %q", i, seed.Key))
+				errs = append(errs, fmt.Errorf("seed[%d]: duplicate key %q", i, trimmedKey))
🤖 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 `@app/config/taxcode.go` at line 58, The error message uses seed.Key but the
duplicate check is performed on trimmedKey, causing inconsistent reporting;
update the errs append to include trimmedKey (use the same trimmedTaxCode style
as line 82) so the error reads the trimmed value when reporting duplicates
(reference variables trimmedKey and seed.Key and the errs = append(...) call).
🤖 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.

Outside diff comments:
In `@app/config/taxcode.go`:
- Line 58: The error message uses seed.Key but the duplicate check is performed
on trimmedKey, causing inconsistent reporting; update the errs append to include
trimmedKey (use the same trimmedTaxCode style as line 82) so the error reads the
trimmed value when reporting duplicates (reference variables trimmedKey and
seed.Key and the errs = append(...) call).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dce66ab2-5521-45b2-8c91-ec4b1c1c6e2f

📥 Commits

Reviewing files that changed from the base of the PR and between fcc7cb0 and a3ac6a0.

📒 Files selected for processing (1)
  • app/config/taxcode.go

@borbelyr-kong
borbelyr-kong merged commit f20774b into main May 20, 2026
27 checks passed
@borbelyr-kong
borbelyr-kong deleted the feat/add-default-tax-code-provision branch May 20, 2026 09:09

This branch was previously deployed

1 inactive deployment
dev — a3ac6a08 Deployed May 20, 2026 by borbelyr-kong via Migration Checks #14520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants