Skip to content

feat(modfile): add run directive support for custom project runners#126

Merged
xushiwei merged 2 commits intogoplus:mainfrom
xushiwei:runner
Dec 27, 2025
Merged

feat(modfile): add run directive support for custom project runners#126
xushiwei merged 2 commits intogoplus:mainfrom
xushiwei:runner

Conversation

@xushiwei
Copy link
Member

No description provided.

joeykchen and others added 2 commits December 26, 2025 20:09
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
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 modfile package by introducing a new runner directive. This feature allows projects to specify custom execution runners directly within their module files, providing greater control and flexibility over how projects are built and executed. The changes encompass the necessary data structures, parsing logic, and robust validation to correctly interpret and manage these new runner definitions.

Highlights

  • New runner directive: Introduces a runner directive in modfile to specify custom project runners, allowing for flexible project execution configurations.
  • Data Structure for Runners: Defines a new Runner struct to model the runner's package path and an optional version, providing a structured way to store runner information.
  • Project Integration: Integrates the Runner into the Project structure, enabling projects to declare and associate a custom runner directly within their module definitions.
  • Parsing Logic and Validation: Adds comprehensive parsing and validation for the runner directive, including checks for correct placement (after a project definition), uniqueness (no repeated runners), and proper argument format.
  • Enhanced Test Coverage: Extends existing test cases to cover the new runner directive's parsing behavior and various error handling scenarios, ensuring robustness.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Dec 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.43%. Comparing base (68cd1cc) to head (9b1bda3).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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 {

Choose a reason for hiding this comment

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

medium

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

Suggested change
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)
}
Copy link

Choose a reason for hiding this comment

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

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
}
Copy link

Choose a reason for hiding this comment

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

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

Comment on lines +331 to +345
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])
Copy link

Choose a reason for hiding this comment

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

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.

@xgopilot
Copy link

xgopilot bot commented Dec 27, 2025

Code Review Summary

Good implementation of the runner directive feature! The code follows existing patterns well and includes comprehensive error test coverage.

Key findings:

  • Missing test assertions for Runner field validation in TestParse2
  • Security concern: Package path validation could be strengthened using module.CheckImportPath()
  • Documentation: Examples could show optional version parameter

The implementation is solid and consistent with the codebase. Please review the inline comments for specific recommendations.

@xushiwei xushiwei merged commit 010be86 into goplus:main Dec 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants