feat(modfile): add run directive support for custom project runners#126
feat(modfile): add run directive support for custom project runners#126xushiwei merged 2 commits intogoplus:mainfrom
Conversation
Add support for 'run' directive in gop.mod/gox.mod files that allows specifying a custom runner command for projects. This enables projects like SPX to define their own run command: run github.com/goplus/spx/v2/cmd/spxrun Changes: - Add Run struct type to hold the custom runner package path - Add Run field to File struct - Add parsing logic for 'run' directive in parseVerb function
Summary of ChangesHello @xushiwei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #126 +/- ##
==========================================
+ Coverage 93.37% 93.43% +0.06%
==========================================
Files 6 6
Lines 679 701 +22
==========================================
+ Hits 634 655 +21
- Misses 27 28 +1
Partials 18 18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for a runner directive in the modfile, allowing custom project runners to be specified. The changes include updates to the data structures, parsing logic, and associated tests. The implementation is solid, with good test coverage for various error scenarios. I have one suggestion to make the argument parsing for the new runner directive more robust by checking for an excessive number of arguments.
| errorf("repeated runner statement") | ||
| return | ||
| } | ||
| if len(args) < 1 { |
There was a problem hiding this comment.
The current implementation checks for at least one argument but doesn't check for too many arguments. The usage string runner runnerPkgPath [version] implies a maximum of two arguments. Silently ignoring extra arguments could hide user errors. It would be more robust to validate that there are no more than two arguments.
You should also consider adding a test case to TestParseErr to cover this scenario (e.g., runner path version extra).
| if len(args) < 1 { | |
| if len(args) < 1 || len(args) > 2 { |
| require := f.Syntax.Stmt[6].(*modfile.LineBlock) | ||
| if len(require.Token) != 1 || require.Token[0] != "require" { | ||
| t.Fatal("modfile.ParseLax require:", require) | ||
| } |
There was a problem hiding this comment.
Missing test validation for Runner field
While goxmodSpx2 includes a runner directive (line 174), this test doesn't verify that the Runner was parsed correctly. Consider adding assertions:
if f.proj().Runner == nil {
t.Error("project runner expected to be set")
} else {
if f.proj().Runner.Path != "github.com/goplus/spx/v2/cmd/spxrun" {
t.Errorf("runner path expected be github.com/goplus/spx/v2/cmd/spxrun, but %s got", f.proj().Runner.Path)
}
if f.proj().Runner.Version != "v2.0.1" {
t.Errorf("runner version expected be v2.0.1, but %s got", f.proj().Runner.Version)
}
}| Path string // package path of the runner | ||
| Version string // optional version of the runner | ||
| Syntax *Line | ||
| } |
There was a problem hiding this comment.
Incomplete documentation
The example shows only the path syntax, but not the optional version parameter. Consider enhancing:
// A Runner is the runner statement that specifies a custom runner for the project.
// The runner directive must appear after a project statement and only one runner
// per project is allowed.
// Example: runner github.com/goplus/spx/v2/cmd/spxrun
// Example with version: runner github.com/goplus/spx/v2/cmd/spxrun v2.0.1| case "runner": | ||
| proj := f.proj() | ||
| if proj == nil { | ||
| errorf("runner must declare after a project definition") | ||
| return | ||
| } | ||
| if proj.Runner != nil { | ||
| errorf("repeated runner statement") | ||
| return | ||
| } | ||
| if len(args) < 1 { | ||
| errorf("usage: runner runnerPkgPath [version]") | ||
| return | ||
| } | ||
| runnerPath, err := parsePkgPath(&args[0]) |
There was a problem hiding this comment.
Security: Insufficient package path validation
The parsePkgPath() function uses isPkgPath() which only checks that the string doesn't start with . or _. This doesn't prevent:
- Path traversal sequences (e.g.,
../../evil) - Invalid characters for Go module paths
- Windows reserved names
- Cross-platform compatibility issues
Consider using golang.org/x/mod/module.CheckImportPath() for robust validation:
import "golang.org/x/mod/module"
func isPkgPath(s string) bool {
if s == "" {
return false
}
return module.CheckImportPath(s) == nil
}This prevents potential security issues when the runner path is later used in filesystem operations or command execution.
Code Review SummaryGood implementation of the runner directive feature! The code follows existing patterns well and includes comprehensive error test coverage. Key findings:
The implementation is solid and consistent with the codebase. Please review the inline comments for specific recommendations. |
No description provided.