-
Notifications
You must be signed in to change notification settings - Fork 135
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 unnecessary home directory creation issues #1073
Conversation
WalkthroughThe modifications primarily involve enhancing the setup for testing and configuration within the dYdX Protocol's command-line interface. By integrating a test utilities package and refining the application initialization process, the changes aim to streamline development workflows. Specifically, improvements include the use of a dedicated temporary directory for testing, adjustments in configuration reading mechanisms, and the simplification of command initialization by directly utilizing default node home paths. Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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: 1
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
protocol/go.mod
is excluded by:!**/*.mod
protocol/go.sum
is excluded by:!**/*.sum
Files selected for processing (2)
- protocol/cmd/dydxprotocold/cmd/root.go (5 hunks)
- protocol/cmd/dydxprotocold/main.go (2 hunks)
Additional comments: 5
protocol/cmd/dydxprotocold/main.go (1)
- 17-17: Change aligns with PR objectives to streamline directory management.
protocol/cmd/dydxprotocold/cmd/root.go (4)
- 31-31: Added import for
simtestutil
aligns with the use of simulation test utilities.- 42-42: Added import for
app
is necessary for accessingDefaultNodeHome
.- 94-94: Modification to use
simtestutil.NewAppOptionsWithFlagHome(tempDir())
is appropriate for using a temporary directory during initialization.- 165-165: Change to
config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
is correct for using default client configuration values.
var tempDir = func() string { | ||
dir, err := os.MkdirTemp("", "dydxprotocol") | ||
if err != nil { | ||
dir = app.DefaultNodeHome | ||
} | ||
defer os.RemoveAll(dir) | ||
|
||
return dir | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tempDir
function correctly creates a temporary directory but does not handle the temporary directory's lifecycle properly. defer os.RemoveAll(dir)
will remove the directory as soon as tempDir
returns, which is likely not the intended behavior.
- defer os.RemoveAll(dir)
+ // Note: The caller should ensure to clean up the temporary directory when it's no longer needed.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
var tempDir = func() string { | |
dir, err := os.MkdirTemp("", "dydxprotocol") | |
if err != nil { | |
dir = app.DefaultNodeHome | |
} | |
defer os.RemoveAll(dir) | |
return dir | |
} | |
var tempDir = func() string { | |
dir, err := os.MkdirTemp("", "dydxprotocol") | |
if err != nil { | |
dir = app.DefaultNodeHome | |
} | |
// Note: The caller should ensure to clean up the temporary directory when it's no longer needed. | |
return dir | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an existing ticket about get command line tests for coverage of these edge cases since it is difficult to know what the initial client context and config should be since the Cosmos SDK documentation is lacking as to how those values are needed for Auto CLI opts. Is the additional tests you can add in a follow-up?
@@ -90,7 +91,7 @@ func NewRootCmdWithInterceptors( | |||
dbm.NewMemDB(), | |||
nil, | |||
true, | |||
viper.New(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be replaced with:
initAppOptions := viper.New()
initAppOptions.Set(flags.FlagHome, tempDir())
tempApp(..., initAppOptions)
Was hoping to keep away from test utilities in Cosmos SDK as part of the production code.
There was a problem hiding this 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
Files selected for processing (1)
- protocol/cmd/dydxprotocold/cmd/root.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- protocol/cmd/dydxprotocold/cmd/root.go
There was a problem hiding this 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
Files ignored due to path filters (2)
protocol/go.mod
is excluded by:!**/*.mod
protocol/go.sum
is excluded by:!**/*.sum
Files selected for processing (2)
- protocol/cmd/dydxprotocold/cmd/root.go (4 hunks)
- protocol/cmd/dydxprotocold/main.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- protocol/cmd/dydxprotocold/cmd/root.go
- protocol/cmd/dydxprotocold/main.go
There is a lint issue with an import of the same statement twice and tests are failing (one seems to be due to a flake) |
There was a problem hiding this 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
Files ignored due to path filters (2)
protocol/go.mod
is excluded by:!**/*.mod
protocol/go.sum
is excluded by:!**/*.sum
Files selected for processing (2)
- protocol/cmd/dydxprotocold/cmd/root.go (3 hunks)
- protocol/cmd/dydxprotocold/main.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- protocol/cmd/dydxprotocold/cmd/root.go
- protocol/cmd/dydxprotocold/main.go
@Mergifyio backport release/protocol/v4.x |
* Fix unnecessary home directory creation issues * Address comment * New fork commit with new cherry-picks (cherry picked from commit 71ce2c6) # Conflicts: # protocol/go.mod # protocol/go.sum
✅ Backports have been created
|
* Fix unnecessary home directory creation issues (#1073) * Fix unnecessary home directory creation issues * Address comment * New fork commit with new cherry-picks (cherry picked from commit 71ce2c6) # Conflicts: # protocol/go.mod # protocol/go.sum * fix conflict --------- Co-authored-by: roy-dydx <[email protected]> Co-authored-by: Roy Li <[email protected]>
Changelist
data
directory in the cwdTest Plan
/dydxprotocol/
.Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.