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

refactor(confix): properly update migrate and diff command #18596

Merged
merged 6 commits into from
Nov 30, 2023

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Nov 29, 2023

Description

ref: https://github.com/cosmos/cosmos-sdk/pull/18455/files#r1409559081
Follow-up of #18455 that had some mistakes and a CLI breaking UX.


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

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

    • Introduced a --client flag for migrating and diffing client configuration files.
    • Search functionality now available in the app interface.
  • Bug Fixes

    • Fixed issues with configuration migration and diff commands.
  • Documentation

    • Updated README with new flag usage instructions.
  • Refactor

    • Simplified command function signatures for configuration handling.
    • Enhanced logic for determining configuration paths and types.
  • Style

    • Standardized error message capitalization in math operations.
  • Tests

    • Adjusted test cases to reflect changes in migration and diff commands.

@julienrbrt julienrbrt requested a review from a team as a code owner November 29, 2023 17:18
@github-actions github-actions bot added the C:Confix Issues and PR related to Confix label Nov 29, 2023
Copy link
Contributor

coderabbitai bot commented Nov 29, 2023

Note

Reviews Paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The updates focus on enhancing the confix toolset for Cosmos SDK configuration management. The simd and confix commands now support a --client flag for client configuration migration and diffing. The DiffCommand and MigrateCommand functions have been refactored to simplify their signatures and improve the handling of configuration paths and types. Additionally, error messages have been clarified, and test cases have been adjusted to align with the new command structures. Minor changes include standardizing error strings in math/int.go and updating function signatures in confix to streamline parameter handling.

Changes

File Path Change Summary
tools/confix/README.md Added support for --client flag in simd config migrate and confix migrate commands; updated simd config diff and confix diff to support --client flag.
tools/confix/cmd/.../diff.go
tools/confix/cmd/.../migrate.go
- Removed config-type argument from DiffCommand and MigrateCommand function signatures.
- Updated logic for determining configPath based on arguments and clientCtx.HomeDir.
- Added --client flag for diffing and migrating client.toml instead of app.toml.
tools/confix/cmd/.../migrate_test.go
tools/confix/cmd/.../mutate_test.go
Modified test cases to reflect changes in MigrateCommand and added symbolic link creation in initClientContext.
math/int.go Standardized error strings to lowercase ("integer overflow" and "divide by zero").
tools/confix/file.go
tools/confix/migrations.go
Updated function signatures to accept additional parameters for configuration type handling.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a37f416 and 95f8150.
Files ignored due to filter (1)
  • tools/confix/data/v0.51-app.toml
Files selected for processing (5)
  • tools/confix/README.md (2 hunks)
  • tools/confix/cmd/diff.go (2 hunks)
  • tools/confix/cmd/migrate.go (4 hunks)
  • tools/confix/cmd/migrate_test.go (1 hunks)
  • tools/confix/cmd/mutate_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • tools/confix/README.md
Additional comments: 11
tools/confix/cmd/diff.go (3)
  • 18-18: The Use field in the command still indicates two arguments, which is inconsistent with the summary stating that the function's signature has been changed to accept only one argument.

  • 42-45: The retrieval of targetVersion after the configuration checks is consistent with the summary and the intended refactoring.

  • 71-71: The addition of the flag to diff client.toml instead of app.toml is consistent with the summary and the intended refactoring.

tools/confix/cmd/migrate.go (1)
  • 21-45: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [22-84]

The changes in the MigrateCommand function reflect the updates mentioned in the summary and pull request details. The logic for determining configPath and handling the --client flag has been updated accordingly. The flags are correctly defined, and the error handling for loading the configuration and upgrading it seems appropriate.

tools/confix/cmd/migrate_test.go (6)
  • 19-20: The test case for version v0.0 has been updated to remove the app argument, which aligns with the changes in the command-line interface.

  • 23-24: The test case for version v0.45 has been updated to remove the app argument, which aligns with the changes in the command-line interface.

  • 26-28: The test case for version v0.46 has been updated to use unsupported.toml instead of client.toml, which aligns with the changes in the command-line interface and the summary.

  • 30-33: The test case for version v0.46 with --skip-validate and --verbose flags has been updated to use unsupported.toml instead of client.toml, which aligns with the changes in the command-line interface and the summary.

  • 36-38: The test case for version v0.51 has been updated to include the --client flag, which aligns with the changes in the command-line interface and the summary.

  • 16-39: The summary mentions the introduction of a symbolic link from client.toml to unsupported.toml within the initClientContext function to support the new test scenarios, but this is not visible in the provided hunk. Ensure that the initClientContext function is correctly setting up the test environment as described.

tools/confix/cmd/mutate_test.go (1)
  • 3-8: The addition of the path/filepath import is appropriate for the file operations being performed in the initClientContext function.

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 95f8150 and 241a96f.
Files selected for processing (2)
  • tools/confix/cmd/diff.go (2 hunks)
  • tools/confix/cmd/migrate.go (4 hunks)
Additional comments: 7
tools/confix/cmd/diff.go (5)
  • 16-16: The summary states that the DiffCommand function's signature has changed, but the hunk shows no change in the signature. Please verify this discrepancy.

  • 21-21: The change from cobra.MinimumNArgs(2) to cobra.MinimumNArgs(1) is correctly implemented.

  • 22-45: The restructuring of the logic for determining configPath and configType using a switch statement and conditional checks is correctly implemented.

  • 39-39: The updated error message for an unexpected file type provides clearer guidance to the user.

  • 71-71: The new flag confix.ClientConfigType has been correctly added to the command flags.

tools/confix/cmd/migrate.go (2)
  • 24-24: The Use field in the cobra.Command struct still expects two arguments, but the summary indicates that the config-type argument has been removed. This should be updated to reflect the actual changes.
- Use:   "migrate [target-version] <config-path>",
+ Use:   "migrate [target-version]",
  • 79-82: The flags have been correctly added to the cobra.Command struct.

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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 241a96f and 403241c.
Files selected for processing (5)
  • math/int.go (1 hunks)
  • tools/confix/cmd/diff.go (2 hunks)
  • tools/confix/cmd/migrate.go (4 hunks)
  • tools/confix/file.go (2 hunks)
  • tools/confix/migrations.go (3 hunks)
Files skipped from review due to trivial changes (2)
  • math/int.go
  • tools/confix/file.go
Additional comments: 7
tools/confix/cmd/diff.go (1)
  • 72-72: The addition of the new flag --client to the command is implemented correctly and aligns with the summary.
tools/confix/cmd/migrate.go (5)
  • 6-15: The summary states that the import statement for "github.com/cosmos/cosmos-sdk/client" was removed, but it has actually been moved within the import block.

  • 40-40:

  • 66-66:

  • 69-69:

  • 83-83: The addition of the --client flag is consistent with the summary and the changes in the hunk.

tools/confix/migrations.go (1)
  • 21-25: The summary states that the function signature of MigrationMap has been altered to accept three parameters, but the hunk does not reflect this change. Please verify if the summary is accurate or if the code change was omitted.

Comment on lines +34 to 37
func PlanBuilder(from *tomledit.Document, to, planType string) transform.Plan {
plan := transform.Plan{}
deletedSections := map[string]bool{}

Copy link
Contributor

Choose a reason for hiding this comment

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

The use of panic for error handling within PlanBuilder is not recommended in Go, as it can cause the program to terminate abruptly. Consider returning an error and handling it gracefully.

@julienrbrt
Copy link
Member Author

@coderabbitai resolve

Copy link
Contributor

coderabbitai bot commented Nov 29, 2023

Resolve command requires updated permissions

CodeRabbit does not currently have write access to Content permissions, which is required to resolve conversations.
Please review and grant the necessary permissions to CodeRabbit under GitHub Apps, and then try again.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 403241c and f11e6be.
Files selected for processing (1)
  • tools/confix/cmd/diff.go (2 hunks)
Additional comments: 7
tools/confix/cmd/diff.go (7)
  • 27-28: The summary states that DiffCommand now accepts only one argument, but the code still checks for a second argument. Please verify if the summary or the code needs to be updated.
- case len(args) > 1:
+ case len(args) == 1:
  • 40-40: The error message "app.toml file expected, got client.toml, use --client flag to diff client.toml" could be improved for clarity. It should indicate that the --client flag is required when the client.toml file is being used.

  • 35-41: The changes to handle confix.ClientConfigType using a switch statement and a boolean flag are correctly implemented.

  • 32-32: The error message provided when neither a config path nor a home directory is available is clear and consistent with the improved error handling.

  • 40-40: The error message at line 40 could be improved for clarity based on previous comments.

  • 45-46: The error message for an unknown version is specific and informative, listing the supported versions.

  • 50-50: The error message for failing to load the internal config is consistent with the improved error handling.

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Thank you @julienrbrt! I've sent in the first round of reviews, please take a look but LGTM otherwise after addressing the comments.

@julienrbrt
Copy link
Member Author

@coderabbitai pause

@tac0turtle tac0turtle added this pull request to the merge queue Nov 30, 2023
Merged via the queue into main with commit 519c55c Nov 30, 2023
@tac0turtle tac0turtle deleted the julien/follow-up-confix branch November 30, 2023 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Confix Issues and PR related to Confix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants