Repository navigation
fix(ledger): hydrate tax behavior - #4475
Conversation
📝 WalkthroughWalkthroughThis PR patches a bug where the ChangesTaxBehavior Field Hydration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
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 docstrings
🧪 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
🤖 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/ledger/historical/adapter/ledger_test.go`:
- Around line 189-196: The loop over hydratedGroup.Transactions()[0].Entries()
can vacuously pass if Entries() is empty; add an explicit check before the loop
to assert the expected number of entries (e.g., require.Len on
hydratedGroup.Transactions()[0].Entries()) so the test fails when hydration
drops entries; update the test around the existing require.Len(t,
hydratedGroup.Transactions(), 1) and the subsequent for-loop that iterates
Entries() to include this additional assertion referencing
hydratedGroup.Transactions(), Entries(), and the existing entry assertions on
PostingAddress().Route().
🪄 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: 0a651456-9576-4ab3-9f96-e529e72bb245
📒 Files selected for processing (2)
openmeter/ledger/historical/adapter/ledger.goopenmeter/ledger/historical/adapter/ledger_test.go
| require.Len(t, hydratedGroup.Transactions(), 1) | ||
|
|
||
| for _, entry := range hydratedGroup.Transactions()[0].Entries() { | ||
| hydratedRoute := entry.PostingAddress().Route().Route() | ||
| require.NotNil(t, hydratedRoute.TaxBehavior) | ||
| require.Equal(t, taxBehavior, *hydratedRoute.TaxBehavior) | ||
| require.Equal(t, ledger.RoutingKeyVersionV2, entry.PostingAddress().Route().RoutingKey().Version()) | ||
| } |
There was a problem hiding this comment.
Nice test! One small gap: guard against a vacuous pass.
You assert there's exactly one transaction, but the entry assertions live inside the for loop over Entries(). If hydration ever dropped entries and returned an empty slice, the loop body would never run and the test would happily pass without checking anything. A quick require.Len on the entries closes that hole.
💚 Suggested tweak
require.NoError(t, err)
require.Len(t, hydratedGroup.Transactions(), 1)
- for _, entry := range hydratedGroup.Transactions()[0].Entries() {
+ entries := hydratedGroup.Transactions()[0].Entries()
+ require.Len(t, entries, 2)
+ for _, entry := range entries {
hydratedRoute := entry.PostingAddress().Route().Route()
require.NotNil(t, hydratedRoute.TaxBehavior)
require.Equal(t, taxBehavior, *hydratedRoute.TaxBehavior)
require.Equal(t, ledger.RoutingKeyVersionV2, entry.PostingAddress().Route().RoutingKey().Version())
}📝 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.
| require.Len(t, hydratedGroup.Transactions(), 1) | |
| for _, entry := range hydratedGroup.Transactions()[0].Entries() { | |
| hydratedRoute := entry.PostingAddress().Route().Route() | |
| require.NotNil(t, hydratedRoute.TaxBehavior) | |
| require.Equal(t, taxBehavior, *hydratedRoute.TaxBehavior) | |
| require.Equal(t, ledger.RoutingKeyVersionV2, entry.PostingAddress().Route().RoutingKey().Version()) | |
| } | |
| require.Len(t, hydratedGroup.Transactions(), 1) | |
| entries := hydratedGroup.Transactions()[0].Entries() | |
| require.Len(t, entries, 2) | |
| for _, entry := range entries { | |
| hydratedRoute := entry.PostingAddress().Route().Route() | |
| require.NotNil(t, hydratedRoute.TaxBehavior) | |
| require.Equal(t, taxBehavior, *hydratedRoute.TaxBehavior) | |
| require.Equal(t, ledger.RoutingKeyVersionV2, entry.PostingAddress().Route().RoutingKey().Version()) | |
| } |
🤖 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/ledger/historical/adapter/ledger_test.go` around lines 189 - 196,
The loop over hydratedGroup.Transactions()[0].Entries() can vacuously pass if
Entries() is empty; add an explicit check before the loop to assert the expected
number of entries (e.g., require.Len on
hydratedGroup.Transactions()[0].Entries()) so the test fails when hydration
drops entries; update the test around the existing require.Len(t,
hydratedGroup.Transactions(), 1) and the subsequent for-loop that iterates
Entries() to include this additional assertion referencing
hydratedGroup.Transactions(), Entries(), and the existing entry assertions on
PostingAddress().Route().
Summary
Tests
Summary by CodeRabbit
Bug Fixes
Tests