Remove dispatch after install, install only

Removes post-install extension dispatch to keep the stub focused on
installation. Also removes unused args parameter from the run function.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Kynan Ware 2026-04-16 10:38:33 -06:00
parent b8d504cbd9
commit 32b8af1017
2 changed files with 16 additions and 52 deletions

View file

@ -26,7 +26,7 @@ func NewCmdOfficialExtensionStub(io *iostreams.IOStreams, p prompter.Prompter, e
// cobra validation errors before reaching RunE.
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
return officialExtensionStubRun(io, p, em, ext, args)
return officialExtensionStubRun(io, p, em, ext)
},
}
@ -35,7 +35,7 @@ func NewCmdOfficialExtensionStub(io *iostreams.IOStreams, p prompter.Prompter, e
return cmd
}
func officialExtensionStubRun(io *iostreams.IOStreams, p prompter.Prompter, em extensions.ExtensionManager, ext *extensions.OfficialExtension, args []string) error {
func officialExtensionStubRun(io *iostreams.IOStreams, p prompter.Prompter, em extensions.ExtensionManager, ext *extensions.OfficialExtension) error {
stderr := io.ErrOut
if !io.CanPrompt() {
@ -68,11 +68,5 @@ func officialExtensionStubRun(io *iostreams.IOStreams, p prompter.Prompter, em e
}
fmt.Fprintf(stderr, "Successfully installed %s/%s\n", ext.Owner, ext.Repo)
// Dispatch the newly installed extension with the original arguments.
dispatchArgs := append([]string{ext.Name}, args...)
if _, dispatchErr := em.Dispatch(dispatchArgs, io.In, io.Out, stderr); dispatchErr != nil {
return dispatchErr
}
return nil
}

View file

@ -2,7 +2,6 @@ package root
import (
"fmt"
"io"
"testing"
"github.com/cli/cli/v2/internal/ghrepo"
@ -17,18 +16,14 @@ func TestOfficialExtensionStubRun(t *testing.T) {
ext := &extensions.OfficialExtension{Name: "cool", Owner: "github", Repo: "gh-cool"}
tests := []struct {
name string
isTTY bool
confirmResult bool
confirmErr error
installErr error
dispatchErr error
args []string
wantErr string
wantStderr string
wantInstalled bool
wantDispatched bool
wantDispArgs []string
name string
isTTY bool
confirmResult bool
confirmErr error
installErr error
wantErr string
wantStderr string
wantInstalled bool
}{
{
name: "non-TTY prints install instructions",
@ -36,14 +31,11 @@ func TestOfficialExtensionStubRun(t *testing.T) {
wantStderr: "gh extension install github/gh-cool",
},
{
name: "TTY confirmed installs and dispatches",
isTTY: true,
confirmResult: true,
args: []string{"--help"},
wantStderr: "Successfully installed github/gh-cool",
wantInstalled: true,
wantDispatched: true,
wantDispArgs: []string{"cool", "--help"},
name: "TTY confirmed installs",
isTTY: true,
confirmResult: true,
wantStderr: "Successfully installed github/gh-cool",
wantInstalled: true,
},
{
name: "TTY declined does not install",
@ -64,15 +56,6 @@ func TestOfficialExtensionStubRun(t *testing.T) {
wantErr: "network error",
wantInstalled: true,
},
{
name: "TTY dispatch error is propagated",
isTTY: true,
confirmResult: true,
dispatchErr: fmt.Errorf("dispatch failed"),
wantErr: "dispatch failed",
wantInstalled: true,
wantDispatched: true,
},
}
for _, tt := range tests {
@ -88,12 +71,6 @@ func TestOfficialExtensionStubRun(t *testing.T) {
InstallFunc: func(_ ghrepo.Interface, _ string) error {
return tt.installErr
},
DispatchFunc: func(_ []string, _ io.Reader, _, _ io.Writer) (bool, error) {
if tt.dispatchErr != nil {
return false, tt.dispatchErr
}
return true, nil
},
}
p := &prompter.PrompterMock{
ConfirmFunc: func(_ string, _ bool) (bool, error) {
@ -101,7 +78,7 @@ func TestOfficialExtensionStubRun(t *testing.T) {
},
}
err := officialExtensionStubRun(ios, p, em, ext, tt.args)
err := officialExtensionStubRun(ios, p, em, ext)
if tt.wantErr != "" {
require.Error(t, err)
@ -123,13 +100,6 @@ func TestOfficialExtensionStubRun(t *testing.T) {
} else if tt.isTTY && !tt.confirmResult && tt.confirmErr == nil {
assert.Empty(t, em.InstallCalls())
}
if tt.wantDispatched {
require.NotEmpty(t, em.DispatchCalls())
if tt.wantDispArgs != nil {
assert.Equal(t, tt.wantDispArgs, em.DispatchCalls()[0].Args)
}
}
})
}
}