From f12e5ec126a1285a8deb5b0e31c2ea7ec37e8d60 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Tue, 7 Jul 2026 20:56:16 +1000 Subject: [PATCH] Fix: allow completion commands to run without a client The completion command and cobra's __complete/__completeNoDesc helpers require a client factory, so shell completion fails with exit 3 when the user is not logged in. Add them to commandDoesNotRequireClient since they are purely local and never contact the server. --- cmd/octopus/main.go | 2 +- cmd/octopus/main_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cmd/octopus/main_test.go diff --git a/cmd/octopus/main.go b/cmd/octopus/main.go index d336c3a0..24c133d3 100644 --- a/cmd/octopus/main.go +++ b/cmd/octopus/main.go @@ -96,5 +96,5 @@ func commandDoesNotRequireClient(args []string) bool { return true } cmdToRun := args[0] - return cmdToRun == "config" || cmdToRun == "version" || cmdToRun == "--version" || cmdToRun == "-v" || cmdToRun == "help" || cmdToRun == "login" || cmdToRun == "logout" || (cmdToRun == "package" && util.SliceContains(args, "create")) + return cmdToRun == "config" || cmdToRun == "version" || cmdToRun == "--version" || cmdToRun == "-v" || cmdToRun == "help" || cmdToRun == "login" || cmdToRun == "logout" || cmdToRun == "completion" || cmdToRun == "__complete" || cmdToRun == "__completeNoDesc" || (cmdToRun == "package" && util.SliceContains(args, "create")) } diff --git a/cmd/octopus/main_test.go b/cmd/octopus/main_test.go new file mode 100644 index 00000000..aaa7c938 --- /dev/null +++ b/cmd/octopus/main_test.go @@ -0,0 +1,33 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCommandDoesNotRequireClient_CompletionCommandsDoNotRequireClient(t *testing.T) { + cases := [][]string{ + {"completion"}, + {"completion", "powershell"}, + {"completion", "bash"}, + {"__complete", "completion", "powershell", ""}, + {"__completeNoDesc", "release", "list", ""}, + } + + for _, args := range cases { + assert.True(t, commandDoesNotRequireClient(args), "expected %v to not require a client", args) + } +} + +func TestCommandDoesNotRequireClient_ServerCommandsRequireClient(t *testing.T) { + cases := [][]string{ + {"release", "list"}, + {"deployment", "create"}, + {"package", "list"}, + } + + for _, args := range cases { + assert.False(t, commandDoesNotRequireClient(args), "expected %v to require a client", args) + } +}