Skip to content

Conversation

petersssong
Copy link
Contributor

@petersssong petersssong commented Mar 17, 2025

Description

since go.1.21 support map.Copy
ref: https://pkg.go.dev/maps#Copy


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

  • Refactor

    • Streamlined the map updating process for improved efficiency in handling flag values.
  • Tests

    • Introduced new tests to validate the functionality of the generic map value structure, covering various scenarios for the Set method and change tracking.

Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

📝 Walkthrough

Walkthrough

The changes involve modifications to the Set method in the genericMapValue struct located in client/v2/autocli/flag/maps/generic.go. The method's logic for updating the map has been streamlined by replacing a manual iteration with a call to maps.Copy, which efficiently handles the copying of elements. Additionally, an import statement for the "maps" package has been added. A new test file, generic_test.go, has also been introduced to validate the functionality of the Set method and its change tracking.

Changes

Files Change Summary
client/v2/.../maps/generic.go Modified the Set method in the genericMapValue struct to replace the manual map copy loop with a maps.Copy call; added import for "maps".
client/v2/.../maps/generic_test.go Introduced a new test file with TestGenericMapValue_Set and TestGenericMapValue_Changed functions to validate the Set method and change tracking.

Suggested labels

C:Store

Suggested reviewers

  • JulianToledano
  • aljo242
  • tac0turtle

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0f39b6 and f7b55d2.

📒 Files selected for processing (1)
  • client/v2/autocli/flag/maps/generic_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

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

  • client/v2/autocli/flag/maps/generic_test.go
`**/*_test.go`: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

**/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

  • client/v2/autocli/flag/maps/generic_test.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (5)
client/v2/autocli/flag/maps/generic_test.go (5)

11-98: Comprehensive test cases for Set method - good job!

The test suite thoroughly validates the functionality of the genericMapValue.Set method with a variety of scenarios:

  • Basic key-value parsing
  • Handling invalid inputs
  • Overwriting maps
  • Error conditions
  • Appending to existing maps

This ensures proper behavior of the maps.Copy implementation.


62-68: Test case correctly addresses reviewer's feedback

This test case appropriately addresses the previous review comment by testing that the map is appended to correctly when the changed field is already true. The implementation correctly checks whether new entries are added to the existing map rather than replacing it.


83-83: Good job simplifying the valueParser function

You've correctly implemented the simplification of using strconv.Atoi directly instead of wrapping it in a lambda function, addressing the previous lint warning.


100-123: Proper validation of the Changed tracking behavior

The test correctly validates that:

  1. The changed field is initially false
  2. It becomes true after the first Set operation
  3. Subsequent Set operations correctly merge with the existing map

This is important for ensuring the correct behavior of the map handling logic with maps.Copy.


3-123: Tests provide good coverage of the modified Set method functionality

The tests comprehensively cover the functionality of the Set method that now uses maps.Copy, ensuring it behaves correctly in various scenarios. Both replacement and appending behaviors are tested, along with proper error handling and state tracking.

According to the PR objectives, these tests validate that the refactoring to use maps.Copy works as expected, which supports the overall goal of cleaner map handling.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings 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.

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 Mar 17, 2025
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: 1

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 267b93e and e870d27.

📒 Files selected for processing (1)
  • client/v2/autocli/flag/maps/generic.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • client/v2/autocli/flag/maps/generic.go
🪛 GitHub Actions: Lint
client/v2/autocli/flag/maps/generic.go

[error] 5-5: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (1)
client/v2/autocli/flag/maps/generic.go (1)

48-48: Good use of maps.Copy for cleaner code.

This change effectively uses the maps.Copy function introduced in Go 1.21 to replace what was likely a manual iteration loop. This results in cleaner, more maintainable code and leverages modern Go features as intended in the PR objectives.

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: 2

🧹 Nitpick comments (1)
client/v2/autocli/flag/maps/generic_test.go (1)

59-61: Consider simplifying this lambda function too.

For consistency, you could create a simple helper function for the keyParser too, especially since this same function is used in both test functions.

+// identityParser returns the input string unchanged with no error
+func identityParser(s string) (string, error) {
+	return s, nil
+}

 func TestGenericMapValue_Set(t *testing.T) {
     // ...
     gm.Options = genericMapValueOptions[string, int]{
-        keyParser: func(s string) (string, error) {
-            return s, nil
-        },
+        keyParser: identityParser,
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e870d27 and f0f39b6.

📒 Files selected for processing (2)
  • client/v2/autocli/flag/maps/generic.go (2 hunks)
  • client/v2/autocli/flag/maps/generic_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/v2/autocli/flag/maps/generic.go
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • client/v2/autocli/flag/maps/generic_test.go
`**/*_test.go`: "Assess the unit test code assessing suffici...

**/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

  • client/v2/autocli/flag/maps/generic_test.go
🪛 GitHub Actions: Lint
client/v2/autocli/flag/maps/generic_test.go

[error] 62-62: unlambda: replace `func(s string) (int, error) {

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (3)
client/v2/autocli/flag/maps/generic_test.go (3)

11-79: LGTM! Well-structured table-driven test.

The test covers a good range of scenarios including basic functionality, error handling, and edge cases for the map value's Set method. You've properly used maps.Copy to set up the test data, which aligns with the PR's objective.

🧰 Tools
🪛 GitHub Actions: Lint

[error] 62-62: unlambda: replace `func(s string) (int, error) {


81-106: Good test for tracking map state changes.

This test clearly demonstrates the expected behavior of the genericMapValue's change tracking - first replacing the map entirely, then merging with existing entries on subsequent calls. This validates the refactoring of the Set method using maps.Copy.


55-55: Excellent use of maps.Copy.

Using maps.Copy here is consistent with the PR's objective of leveraging this function for cleaner map handling. This is a good demonstration of the function that's being implemented in the actual code.

Copy link
Contributor

@technicallyty technicallyty left a comment

Choose a reason for hiding this comment

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

great, thanks for the contribution

@aljo242 aljo242 merged commit ef81fc8 into cosmos:main Mar 18, 2025
68 of 71 checks passed
mergify bot pushed a commit that referenced this pull request Mar 18, 2025
(cherry picked from commit ef81fc8)

# Conflicts:
#	client/v2/autocli/flag/maps/generic.go
aljo242 pushed a commit that referenced this pull request Mar 18, 2025
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.

3 participants