Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(cli): render Long on group commands' --help (#11636)

Bohan Jiang08190dc28bf0
diff --git a/server/cmd/multica/cmd_doc_test.go b/server/cmd/multica/cmd_doc_test.go
index c75a00c898..a0bd948ed4 100644
--- a/server/cmd/multica/cmd_doc_test.go
+++ b/server/cmd/multica/cmd_doc_test.go
@@ -70,9 +70,7 @@ func TestDocMergeConflictErrorForbidsResendingTheBody(t *testing.T) {
}
}
-// renderHelp renders cmd's --help the way the CLI prints it. Group commands
-// use subHelpTemplate, which prints only Short, so rules agents need must
-// live on the leaf commands the brief points at.
+// renderHelp renders cmd's --help the way the CLI prints it.
func renderHelp(t *testing.T, cmd *cobra.Command) string {
t.Helper()
var out strings.Builder
diff --git a/server/cmd/multica/cmd_quick_action.go b/server/cmd/multica/cmd_quick_action.go
index 6c737a0a80..8db592729d 100644
--- a/server/cmd/multica/cmd_quick_action.go
+++ b/server/cmd/multica/cmd_quick_action.go
@@ -41,6 +41,14 @@ type quickActionDTO struct {
TargetMissing bool `json:"target_missing"`
}
+// Agents often read a leaf's --help without its group's, so the addressing and
+// human-only rules are repeated on each leaf they apply to.
+const (
+ quickActionRefNote = "<id-or-name> takes a full UUID, a UUID prefix, or an exact name " +
+ "(case-insensitive; an active action wins over an archived one with the same name)."
+ quickActionHumanOnlyNote = "Only a human member can run this; agent credentials are refused (403)."
+)
+
var quickActionCmd = &cobra.Command{
Use: "quick-action",
Short: "Manage and run workspace quick actions",
@@ -66,6 +74,7 @@ var quickActionListCmd = &cobra.Command{
var quickActionGetCmd = &cobra.Command{
Use: "get <id-or-name>",
Short: "Show one quick action",
+ Long: "Show one quick action.\n\n" + quickActionRefNote,
Args: exactArgs(1),
RunE: runQuickActionGet,
}
@@ -81,7 +90,9 @@ var quickActionCreateCmd = &cobra.Command{
Omit --agent and --squad to create a targetless action that posts the prompt
without @mentioning anyone. Visibility defaults to private; pass --visibility public
-to share with the workspace (requires owner/admin and a publicly-invocable target).`,
+to share with the workspace (requires owner/admin and a publicly-invocable target).
+
+` + quickActionHumanOnlyNote,
Args: exactArgs(0),
RunE: runQuickActionCreate,
}
@@ -94,7 +105,9 @@ current values.
multica quick-action update "Review" --squad JSquad
multica quick-action update "Review" --clear-target
- multica quick-action update "Review" --prompt-file ./review.md`,
+ multica quick-action update "Review" --prompt-file ./review.md
+
+` + quickActionRefNote + "\n\n" + quickActionHumanOnlyNote,
Args: exactArgs(1),
RunE: runQuickActionUpdate,
}
@@ -102,6 +115,7 @@ current values.
var quickActionArchiveCmd = &cobra.Command{
Use: "archive <id-or-name>",
Short: "Archive a quick action",
+ Long: "Archive a quick action.\n\n" + quickActionRefNote + "\n\n" + quickActionHumanOnlyNote,
Args: exactArgs(1),
RunE: makeQuickActionStatusRun("archived"),
}
@@ -110,6 +124,7 @@ var quickActionRestoreCmd = &cobra.Command{
Use: "restore <id-or-name>",
Aliases: []string{"unarchive"},
Short: "Restore an archived quick action",
+ Long: "Restore an archived quick action.\n\n" + quickActionRefNote + "\n\n" + quickActionHumanOnlyNote,
Args: exactArgs(1),
RunE: makeQuickActionStatusRun("active"),
}
@@ -117,6 +132,7 @@ var quickActionRestoreCmd = &cobra.Command{
var quickActionDeleteCmd = &cobra.Command{
Use: "delete <id-or-name>",
Short: "Permanently delete a quick action",
+ Long: "Permanently delete a quick action.\n\n" + quickActionRefNote + "\n\n" + quickActionHumanOnlyNote,
Args: exactArgs(1),
RunE: runQuickActionDelete,
}
@@ -127,7 +143,9 @@ var quickActionRunCmd = &cobra.Command{
Long: `Run a saved quick action on an issue, posting its comment (and optional
agent or squad mention) through the normal comment trigger path.
-Pass --dry-run to preview the rendered comment body without posting it.`,
+Pass --dry-run to preview the rendered comment body without posting it.
+
+` + quickActionRefNote,
Args: exactArgs(2),
RunE: runQuickActionRun,
}
diff --git a/server/cmd/multica/cmd_quick_action_test.go b/server/cmd/multica/cmd_quick_action_test.go
index b1b8dd45e3..36a670cfb9 100644
--- a/server/cmd/multica/cmd_quick_action_test.go
+++ b/server/cmd/multica/cmd_quick_action_test.go
@@ -460,3 +460,30 @@ func TestQuickActionRunAndDryRun(t *testing.T) {
t.Errorf("run output unexpected:\n%s", runOut)
}
}
+
+func TestQuickActionLeafHelpCarriesAddressingAndHumanOnlyRules(t *testing.T) {
+ tests := []struct {
+ cmd *cobra.Command
+ ref bool
+ humanOnly bool
+ }{
+ {quickActionGetCmd, true, false},
+ {quickActionCreateCmd, false, true},
+ {quickActionUpdateCmd, true, true},
+ {quickActionArchiveCmd, true, true},
+ {quickActionRestoreCmd, true, true},
+ {quickActionDeleteCmd, true, true},
+ {quickActionRunCmd, true, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.cmd.CommandPath(), func(t *testing.T) {
+ help := renderHelp(t, tt.cmd)
+ if got := strings.Contains(help, quickActionRefNote); got != tt.ref {
+ t.Errorf("addressing note present = %v, want %v; rendered:\n%s", got, tt.ref, help)
+ }
+ if got := strings.Contains(help, quickActionHumanOnlyNote); got != tt.humanOnly {
+ t.Errorf("human-only note present = %v, want %v; rendered:\n%s", got, tt.humanOnly, help)
+ }
+ })
+ }
+}
diff --git a/server/cmd/multica/help.go b/server/cmd/multica/help.go
index 647787186e..9c5f02fc94 100644
--- a/server/cmd/multica/help.go
+++ b/server/cmd/multica/help.go
@@ -148,7 +148,7 @@ LEARN MORE
Use ` + "`multica <command> <subcommand> --help`" + ` for more information about a command.
`
-var subHelpTemplate = `{{.Short}}
+var subHelpTemplate = `{{if .Long}}{{.Long}}{{else}}{{.Short}}{{end}}
USAGE
{{- if .Runnable}}
diff --git a/server/cmd/multica/help_test.go b/server/cmd/multica/help_test.go
new file mode 100644
index 0000000000..d41d83f5b3
--- /dev/null
+++ b/server/cmd/multica/help_test.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/spf13/cobra"
+)
+
+// A group command's Long once went unrendered because subHelpTemplate printed
+// only Short, and rules written there never reached anyone. Every Long set on
+// a listed command must show up in its --help. Unavailable commands (cobra's
+// own help and hidden completion commands) keep cobra's templates.
+func TestHelpRendersLongOnEveryCommand(t *testing.T) {
+ var walk func(cmd *cobra.Command)
+ walk = func(cmd *cobra.Command) {
+ for _, c := range cmd.Commands() {
+ if !c.IsAvailableCommand() {
+ continue
+ }
+ if c.Long != "" {
+ if help := renderHelp(t, c); !strings.Contains(help, c.Long) {
+ t.Errorf("%s --help does not render its Long; rendered:\n%s", c.CommandPath(), help)
+ }
+ }
+ walk(c)
+ }
+ }
+ walk(rootCmd)
+}