Skip to content

Conversation

jortel
Copy link
Contributor

@jortel jortel commented Aug 2, 2025

The same ruleset.ruleid can report both a violation and an insight. The addon needs to tolerate this: detect the duplicate and add a _ suffix to the rule id making it unique. A trailing _ is minimally invasive and syntax friendly within the filter syntax.

fixes #163

Summary by CodeRabbit

  • New Features
    • Improved handling of rule ID conflicts by ensuring unique identifiers when the same rule ID appears in both violations and insights.
  • Bug Fixes
    • Resolved potential output issues caused by duplicate rule IDs within the same ruleset.
  • Tests
    • Added new tests to verify correct behavior when handling duplicate rule IDs.
  • Chores
    • Expanded test coverage to include additional directories.

Copy link

coderabbitai bot commented Aug 2, 2025

Walkthrough

A new method was added to the Insights type to ensure unique rule IDs between violations and insights within the same ruleset by appending an underscore to duplicates. The Write method now calls this method before output. A corresponding test was added, and the Makefile test target was updated to include the builder directory.

Changes

Cohort / File(s) Change Summary
Insights Uniqueness Logic
builder/insight.go
Added ensureUnique method to resolve rule ID conflicts between violations and insights; updated Write to invoke it.
Insights Uniqueness Test
builder/builder_test.go
Added TestNextId to verify that duplicate rule IDs are made unique after cleaning.
Makefile Test Coverage
Makefile
Expanded test target to also run tests in the ./builder/... directory.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Insights
    participant Output

    User->>Insights: Write()
    Insights->>Insights: ensureUnique()
    Insights->>Output: Encode and write insights
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • dymurray

Poem

A bunny hopped through builder code,
Ensuring rule IDs don't overload.
With underscores it made them neat,
So violations and insights never meet.
Now tests run wide, the coverage grows—
The garden of code, a rabbit well knows! 🐇✨

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 e08c863 and 4c8a522.

📒 Files selected for processing (1)
  • builder/builder_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • builder/builder_test.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). (1)
  • GitHub Check: build-and-upload-for-global-ci
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Support

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

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.

Signed-off-by: Jeff Ortel <[email protected]>
@jortel jortel force-pushed the deduplicate-insights branch from 71b6992 to ca1faf0 Compare August 2, 2025 19:42
jortel added 8 commits August 3, 2025 07:22
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
@jortel jortel marked this pull request as ready for review August 4, 2025 16:05
Copy link

@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: 1

🧹 Nitpick comments (1)
builder/insight.go (1)

169-191: Algorithm correctly handles duplicates but has misleading variable naming.

The logic correctly detects duplicate rule IDs across violations and insights within the same ruleset and consistently modifies insights (the second collection processed) by appending an underscore suffix.

However, the variable name violations is misleading since it processes both violations and insights collections.

Apply this diff to improve variable naming:

-		for _, violations := range collections {
-			for ruleid, v := range violations {
+		for _, collection := range collections {
+			for ruleid, v := range collection {
 				key := ruleset.Name + ruleid
 				if _, found := rules[key]; found {
-					delete(violations, ruleid)
+					delete(collection, ruleid)
 					ruleid += "_"
-					violations[ruleid] = v
+					collection[ruleid] = v
 				}
 				rules[key]++
 			}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d356195 and e08c863.

📒 Files selected for processing (3)
  • Makefile (1 hunks)
  • builder/builder_test.go (1 hunks)
  • builder/insight.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
builder/builder_test.go (1)
builder/insight.go (1)
  • Insights (30-34)
🪛 GitHub Actions: tackle2-addon-analyzer CI
builder/builder_test.go

[error] 28-28: go vet error: 'b.cleanInput' undefined (type Insights has no field or method cleanInput)

🔇 Additional comments (4)
Makefile (2)

8-9: LGTM! Proper inclusion of builder package tests.

The addition of ./builder/... to the PKG variable correctly extends test coverage to include the new tests in the builder package.


35-35: LGTM! Test target properly updated.

The test command now includes ./builder/... which ensures the new TestNextId test will be executed as part of the test suite.

builder/insight.go (1)

46-46: LGTM! Proper integration of uniqueness enforcement.

The call to ensureUnique() before processing output ensures duplicate rule IDs are resolved before writing insights.

builder/builder_test.go (1)

10-45: Test logic is correct and comprehensive.

The test properly validates the duplicate rule ID resolution by:

  1. Setting up a scenario with overlapping rule IDs between violations and insights
  2. Verifying that insights get renamed with underscore suffix while violations remain unchanged
  3. Using appropriate test data that matches the expected behavior

Once the method name is fixed, this test will properly validate the ensureUnique() functionality.

Signed-off-by: Jeff Ortel <[email protected]>
Copy link
Member

@aufi aufi left a comment

Choose a reason for hiding this comment

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

I do think this should fail in analyzer when it loads rules, but no problem with this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Failed to run source + dependencies analysis on book-server app
2 participants