diff --git a/.github/workflows/metrics-collector.lock.yml b/.github/workflows/metrics-collector.lock.yml index 73a229a1f72..f1713c33de1 100644 --- a/.github/workflows/metrics-collector.lock.yml +++ b/.github/workflows/metrics-collector.lock.yml @@ -1196,6 +1196,7 @@ jobs: env: GH_AW_SETUP_WORKFLOW_NAME: "Metrics Collector - Infrastructure Agent" GH_AW_CURRENT_WORKFLOW_REF: ${{ github.repository }}/.github/workflows/metrics-collector.lock.yml@${{ github.ref }} + GH_AW_INFO_VERSION: "1.0.40" - name: Download agent output artifact id: download-agent-output continue-on-error: true diff --git a/pkg/cli/mcp_list_tools.go b/pkg/cli/mcp_list_tools.go index dafc6978cc0..efd093a09b7 100644 --- a/pkg/cli/mcp_list_tools.go +++ b/pkg/cli/mcp_list_tools.go @@ -203,7 +203,12 @@ The command will: return ListToolsForMCP(workflowFile, serverFilter, verbose) }, - ValidArgsFunction: CompleteWorkflowNames, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) > 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + return CompleteWorkflowNames(cmd, args, toComplete) + }, } cmd.Flags().StringVar(&serverFilter, "server", "", "MCP server name to list tools for") diff --git a/pkg/cli/mcp_list_tools_test.go b/pkg/cli/mcp_list_tools_test.go index 2c91d4f4839..a681bad5ede 100644 --- a/pkg/cli/mcp_list_tools_test.go +++ b/pkg/cli/mcp_list_tools_test.go @@ -15,6 +15,7 @@ import ( "github.com/github/gh-aw/pkg/constants" "github.com/github/gh-aw/pkg/parser" "github.com/modelcontextprotocol/go-sdk/mcp" + "github.com/spf13/cobra" ) func TestListToolsForMCP(t *testing.T) { @@ -336,3 +337,43 @@ func TestNewMCPListToolsSubcommand(t *testing.T) { t.Error("Expected 'server' flag to be marked as required") } } + +func TestMCPListToolsValidArgsFunction(t *testing.T) { + cmd := NewMCPListToolsSubcommand() + + t.Run("no_completions_when_first_arg_already_provided", func(t *testing.T) { + completions, directive := cmd.ValidArgsFunction(cmd, []string{"my-workflow"}, "") + if len(completions) != 0 { + t.Errorf("Expected no completions when first arg is already provided, got: %v", completions) + } + if directive != cobra.ShellCompDirectiveNoFileComp { + t.Errorf("Expected ShellCompDirectiveNoFileComp, got: %v", directive) + } + }) + + t.Run("completions_offered_for_first_arg", func(t *testing.T) { + // Set up a temporary workflow directory so CompleteWorkflowNames finds files. + tmpDir := testutil.TempDir(t, "test-*") + workflowsDir := filepath.Join(tmpDir, constants.GetWorkflowDir()) + if err := os.MkdirAll(workflowsDir, 0755); err != nil { + t.Fatalf("Failed to create workflows dir: %v", err) + } + content := "---\nengine: copilot\n---\n# Workflow\n" + if err := os.WriteFile(filepath.Join(workflowsDir, "my-workflow.md"), []byte(content), 0644); err != nil { + t.Fatalf("Failed to write workflow file: %v", err) + } + origDir, err := os.Getwd() + if err != nil { + t.Fatalf("Failed to get current directory: %v", err) + } + defer os.Chdir(origDir) + if err := os.Chdir(tmpDir); err != nil { + t.Fatalf("Failed to change to temp directory: %v", err) + } + + completions, _ := cmd.ValidArgsFunction(cmd, []string{}, "") + if len(completions) == 0 { + t.Error("Expected at least one completion for first positional arg when workflows exist") + } + }) +}