Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client/v2/autocli): prevent duplicate addition of customCommands #22576

Merged
merged 3 commits into from
Nov 21, 2024

Conversation

fastfadingviolets
Copy link
Contributor

@fastfadingviolets fastfadingviolets commented Nov 20, 2024

Description

Closes cosmos/gaia#3412

Not every module's custom commands are prefixed by the name of the module. Because of how Gaia bootstraps its tx command, autocli can end up adding duplicate commands if it's only checking whether there's already a command with the module's name added to the CLI. This PR fixes this by adding a second check to autocli's enhanceCommandCommon.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Support for off-chain signing and verification of files.
    • Introduction of governance proposals.
    • Launch of a transaction factory.
    • Extended keyring interface with new types.
    • Custom broadcast logic added.
  • Improvements

    • Enhanced error messaging with possible enum values displayed.
    • Keyring flags added in query commands.
  • Bug Fixes

    • Resolved issues with unmarshalling in transactions.
    • Fixed duplicate command additions in the command interface.
  • Breaking Changes

    • Removed address codecs from specific options, shifting to context-based codecs.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes updates to the client/v2 module's changelog, documenting new features, improvements, breaking changes, and bug fixes. Key new features are off-chain signing and verification, governance proposals, and a transaction factory. Improvements include enhanced error messaging and keyring flags in query commands. The changelog also notes the removal of address codecs and fixes for unmarshalling issues and duplicate command entries. Additionally, modifications to the enhanceCommandCommon function in the autocli package improve command handling and prevent unnecessary command creation.

Changes

File Change Summary
client/v2/CHANGELOG.md Updated to include new features (off-chain signing, governance proposals, transaction factory), improvements (keyring flags, error messaging), breaking changes (removal of address codecs), and bug fixes (unmarshalling, duplicate commands).
client/v2/autocli/common.go Modified enhanceCommandCommon to check for existing sub-commands before enhancing custom commands and adjusted logic for module options.

Assessment against linked issues

Objective Addressed Explanation
Fix duplicate lines in help menu for gaiad tx (#3412)

Possibly related PRs

Suggested reviewers

  • JulianToledano
  • akhilkumarpilli
  • kocubinski

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

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.

@github-actions github-actions bot added the C:CLI label Nov 20, 2024
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

🧹 Outside diff range and nitpick comments (2)
client/v2/CHANGELOG.md (1)

61-61: Consider adding more context to the changelog entry.

While the entry correctly references the issue, it would be more helpful for users to understand the specific problem that was fixed. Consider expanding it to:

-* [cosmos/gaia#3412](https://github.com/cosmos/gaia/issues/3412) Fix duplicate command addition in `autocli`
+* [cosmos/gaia#3412](https://github.com/cosmos/gaia/issues/3412) Fix duplicate command addition in `autocli` where certain module commands appeared multiple times in the CLI help menu
client/v2/autocli/common.go (1)

143-151: LGTM! Consider enhancing error handling consistency.

The additional check for custom commands with names different from their modules effectively prevents duplicate command creation, addressing the core issue. This is a solid fix for the duplicate entries problem reported in issue #3412.

Consider wrapping the error returns in a more descriptive error using fmt.Errorf for consistency with other error handling in the codebase:

 if hasModuleOptions { // check if we need to enhance the existing command
-  if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil {
-    return err
-  }
+  if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil {
+    return fmt.Errorf("failed to enhance existing custom command %s: %w", custom.Name(), err)
+  }
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between efc05e8 and f2b0f2e.

📒 Files selected for processing (2)
  • client/v2/CHANGELOG.md (1 hunks)
  • client/v2/autocli/common.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
client/v2/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

client/v2/autocli/common.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (1)
client/v2/autocli/common.go (1)

143-151: Verify impact on existing custom commands.

Let's ensure this change doesn't affect existing command structures.

✅ Verification successful

Let me gather more specific information about the command registration and custom command handling.


Changes to custom command handling are safe and well-implemented

The code changes implement a safe enhancement to custom command handling in the CLI. The implementation:

  • Properly checks for existing commands using findSubCommand before adding or enhancing them
  • Maintains backward compatibility by preserving existing command structures
  • Has proper fallback mechanisms when commands don't exist
  • Correctly handles both module-named and custom-named commands through separate checks

The changes ensure that:

  1. Custom commands are not duplicated
  2. Existing command hierarchies are preserved
  3. Command enhancement is optional and controlled via module options
  4. Command name conflicts are properly handled
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing custom commands and their structure

# Look for custom command registrations
echo "Checking for custom command registrations..."
rg -A 5 "AddCommand\(.*custom.*\)" --type go

# Look for module command definitions
echo "Checking for module command definitions..."
rg "type.*Command.*struct" --type go

# Look for potential command name conflicts
echo "Checking for potential command name conflicts..."
rg "Use:.*\".*\"" --type go

Length of output: 25112


Script:

#!/bin/bash
# Check for custom command handling and registration patterns
echo "Checking custom command handling..."
rg -B 5 -A 5 "findSubCommand" --type go

echo "Checking command registration patterns..."
rg -B 5 -A 5 "Name\(\)" --type go | grep -A 5 -B 5 "custom"

echo "Checking for potential command conflicts..."
rg -B 3 -A 3 "enhanceCustomCmd" --type go

Length of output: 15246

@fastfadingviolets fastfadingviolets force-pushed the fix/duplicate-autocli-commands branch from f2b0f2e to f17e361 Compare November 20, 2024 16:10
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

🧹 Outside diff range and nitpick comments (1)
client/v2/CHANGELOG.md (1)

61-61: Enhance the changelog entry description

While the entry correctly references the issue, consider making it more descriptive to better explain the fix:

-* [cosmos/gaia#3412](https://github.com/cosmos/gaia/issues/3412) Fix duplicate command addition in `autocli`
+* [cosmos/gaia#3412](https://github.com/cosmos/gaia/issues/3412) Fix duplicate command addition in `autocli` by improving command existence checks for non-prefixed module commands

This provides more context about the nature of the fix and aligns with the level of detail in other changelog entries.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f2b0f2e and f17e361.

📒 Files selected for processing (2)
  • client/v2/CHANGELOG.md (1 hunks)
  • client/v2/autocli/common.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/v2/autocli/common.go
🧰 Additional context used
📓 Path-based instructions (1)
client/v2/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

🔇 Additional comments (1)
client/v2/CHANGELOG.md (1)

Line range hint 1-24: LGTM! Changelog structure follows best practices

The changelog follows the Keep a Changelog format and properly organizes entries into appropriate sections with clear version headers and dates.

client/v2/CHANGELOG.md Outdated Show resolved Hide resolved
@julienrbrt julienrbrt changed the title fix: prevent duplicate addition of customCommands by autocli fix(client/v2/autocli): prevent duplicate addition of customCommands Nov 20, 2024
@fastfadingviolets fastfadingviolets force-pushed the fix/duplicate-autocli-commands branch from f17e361 to 78db252 Compare November 20, 2024 22:15
@julienrbrt julienrbrt added backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release labels Nov 21, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

That makes sense, thank you!

client/v2/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@akhilkumarpilli akhilkumarpilli left a comment

Choose a reason for hiding this comment

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

utACK

@julienrbrt julienrbrt added this pull request to the merge queue Nov 21, 2024
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

🧹 Outside diff range and nitpick comments (1)
client/v2/CHANGELOG.md (1)

61-61: Enhance the changelog entry with more details.

The current entry could be more descriptive about the root cause, impact, and solution.

Consider this more detailed entry:

-* [#22576](https://github.com/cosmos/cosmos-sdk/pull/22576) Fix duplicate command addition in `autocli` when custom enhanced command has a different name than module name
+* [#22576](https://github.com/cosmos/cosmos-sdk/pull/22576) Fix duplicate command entries in `autocli` help menu caused by custom enhanced commands having different names than their module names. The fix improves command name checking in `enhanceCommandCommon` to prevent unintended command duplication.
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 78db252 and 5a039d2.

📒 Files selected for processing (1)
  • client/v2/CHANGELOG.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
client/v2/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Merged via the queue into cosmos:main with commit 685218e Nov 21, 2024
69 of 71 checks passed
mergify bot pushed a commit that referenced this pull request Nov 21, 2024
mergify bot pushed a commit that referenced this pull request Nov 21, 2024
…22576)

Co-authored-by: Julien Robert <[email protected]>
(cherry picked from commit 685218e)

# Conflicts:
#	client/v2/CHANGELOG.md
julienrbrt pushed a commit that referenced this pull request Nov 21, 2024
julienrbrt added a commit that referenced this pull request Nov 21, 2024
alpe added a commit that referenced this pull request Nov 22, 2024
* main:
  feat(serverv2): add benchmarks of (old) cacheKV vs branch (#22497)
  fix: match comets bls implmentation (#22613)
  feat(math): Upstream GDA based decimal type (#21982)
  fix(client/v2/autocli): prevent duplicate addition of customCommands (#22576)
  build(deps): Bump cosmossdk.io/math from 1.3.0 to 1.4.0 (#22580)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Duplicate lines in help menu for gaiad tx
4 participants