Skip to content

Conversation

turip
Copy link
Member

@turip turip commented Jun 30, 2025

Overview

This changes #2990 so that we are not missreporting the start/end of the period in case the hierarchy is not expanded, instead we are making sure that we are returning an error.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation to ensure lines in a split line group have the required split line hierarchy.
    • Adjusted logic for determining first and last lines in a period to be more accurate for split line groups.

Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

📝 Walkthrough

Walkthrough

A validation was added to ensure that any line belonging to a split line group must also have a corresponding split line hierarchy. In addition, logic in the methods determining if a line is the first or last in a period was adjusted to remove early returns based on missing split line hierarchy data.

Changes

Cohort / File(s) Change Summary
Line service validation and period logic
openmeter/billing/service/lineservice/linebase.go
Added validation for split line group and hierarchy consistency; updated period boundary check logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9fa528 and f440848.

📒 Files selected for processing (1)
  • openmeter/billing/service/lineservice/linebase.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • openmeter/billing/service/lineservice/linebase.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: CI
  • GitHub Check: E2E
  • GitHub Check: Quickstart
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: Build
  • GitHub Check: Migration Checks
  • GitHub Check: Test
  • GitHub Check: Lint
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/make-sure-we-validate-line-hierarchy-presence

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@turip turip added release-note/misc Miscellaneous changes area/billing labels Jun 30, 2025
@turip turip marked this pull request as ready for review June 30, 2025 12:38
@turip turip requested a review from a team as a code owner June 30, 2025 12:38
@turip turip requested a review from tothandras June 30, 2025 12:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
openmeter/billing/service/lineservice/linebase.go (1)

109-114: Fix the error message typo and approve the validation logic.

The validation logic correctly enforces that split line groups must have their hierarchy expanded, which aligns with the PR objective. However, there's a grammatical error in the error message.

Apply this diff to fix the error message:

-		return billing.ValidationError{
-			Err: fmt.Errorf("split line group[%s] has no hierarchy expanded hierarchy", *l.line.SplitLineGroupID),
-		}
+		return billing.ValidationError{
+			Err: fmt.Errorf("split line group[%s] has no expanded hierarchy", *l.line.SplitLineGroupID),
+		}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c313c7c and f9fa528.

📒 Files selected for processing (1)
  • openmeter/billing/service/lineservice/linebase.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Quickstart
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: CI
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Test
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
openmeter/billing/service/lineservice/linebase.go (1)

119-141: Ensure lineBase.Validate Guards Before Period Methods

The Validate(ctx, invoice) method on lineBase correctly errors when SplitLineGroupID != nil but SplitLineHierarchy is nil, so IsLastInPeriod/IsFirstInPeriod will only see a non-nil hierarchy if validation has run. You need to confirm the service always invokes Validate on each lineBase before calling these methods.

• Inspect openmeter/billing/service/lineservice/service.go to verify there’s a lineBase.Validate(ctx, invoice) call for every code path that uses IsLastInPeriod() or IsFirstInPeriod().
• If any usage of these methods isn’t protected by Validate, either:
– Add nil checks at the top of each method:
go if l.line.SplitLineHierarchy == nil { // fall back or safe default return true }
– Or ensure Validate is invoked unconditionally before those calls.

@turip turip force-pushed the fix/make-sure-we-validate-line-hierarchy-presence branch from f9fa528 to f440848 Compare August 1, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants