From e70fe2f543233a88689c52f0c02a2cbbcc759948 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Sat, 14 Nov 2026 00:38:12 -0600 Subject: [PATCH] fix(mcpx): keep dotted program name for completion parsing and spec command (#9796) buildCompletionFileImport normalised the program name (dots to dashes) before parsing, so every fish -c line of a dotted program (toolbox.v2.fish) was filtered out and the import failed as empty; for bash/zsh the generated spec also stored the normalised name as its command. Keep the original program name for parseCompletion and for shapeToSpec's command; sanitise only the adapter namespace name. Regression test imports a toolbox.v2.fish fixture and asserts a non-empty declaration with Name toolbox-v2 and Command toolbox.v2. --- pkgs/mcpx/internal/cli/adapter_import.go | 19 +++++++++----- .../internal/cli/adapter_import_gen_test.go | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/pkgs/mcpx/internal/cli/adapter_import.go b/pkgs/mcpx/internal/cli/adapter_import.go index 4b092799d7..baeb59eea6 100644 --- a/pkgs/mcpx/internal/cli/adapter_import.go +++ b/pkgs/mcpx/internal/cli/adapter_import.go @@ -533,14 +533,21 @@ func buildCompletionFileImport(o importOptions) (adapter.Spec, []string, error) return adapter.Spec{}, nil, fmt.Errorf("%s does not look like a bash, zsh or fish completion script; say which with --shell", o.completion) } base := filepath.Base(o.completion) - name := o.name - if name == "" { - name = adapterName(completionName(base, shell)) - } + // The program name is kept exactly as written for parsing and + // for the spec's command: parsers match completion lines against + // it (a fish file's -c value is the real program name), so + // normalising it first would filter out every line of a dotted + // program's file (toolbox.v2.fish) and store a command that does + // not exist. Only the adapter namespace name is sanitised (#9796). + program := o.name + if program == "" { + program = completionName(base, shell) + } + name := adapterName(program) if name == "" || name == "-" { return adapter.Spec{}, nil, fmt.Errorf("cannot tell which program %s completes; name it with --name", o.completion) } - shape := parseCompletion(string(b), shell, name) + shape := parseCompletion(string(b), shell, program) if shape.empty() { return adapter.Spec{}, nil, fmt.Errorf("%s yielded no subcommands or flags as a %s completion; nothing to declare", o.completion, shell) } @@ -550,7 +557,7 @@ func buildCompletionFileImport(o importOptions) (adapter.Spec, []string, error) GeneratedAt: time.Now().UTC().Format(time.RFC3339), Generator: "mcpx adapter import", } - spec, notes, err := shapeToSpec(name, name, shape, prov) + spec, notes, err := shapeToSpec(name, program, shape, prov) if err != nil { return adapter.Spec{}, nil, err } diff --git a/pkgs/mcpx/internal/cli/adapter_import_gen_test.go b/pkgs/mcpx/internal/cli/adapter_import_gen_test.go index 7137a7a864..fbec6b8a33 100644 --- a/pkgs/mcpx/internal/cli/adapter_import_gen_test.go +++ b/pkgs/mcpx/internal/cli/adapter_import_gen_test.go @@ -475,6 +475,32 @@ func TestBuildCompletionFileImport(t *testing.T) { } } +func TestBuildCompletionFileImportDottedProgramName(t *testing.T) { + // Issue #9796: a dotted program name must survive for parsing + // and for the spec's command; only the adapter namespace name + // is sanitised (dots to dashes). Before the fix the import of + // this fixture failed as empty, because every `complete` line + // is for -c toolbox.v2 while the parser was handed toolbox-v2. + dotted := strings.ReplaceAll(fishFixture, "-c toolbox", "-c toolbox.v2") + path := filepath.Join(t.TempDir(), "toolbox.v2.fish") + if err := os.WriteFile(path, []byte(dotted), 0o644); err != nil { + t.Fatal(err) + } + spec, _, err := buildCompletionFileImport(importOptions{completion: path}) + if err != nil { + t.Fatal(err) + } + if spec.Name != "toolbox-v2" { + t.Errorf("adapter namespace name should be sanitised: %q", spec.Name) + } + if spec.Command != "toolbox.v2" { + t.Errorf("spec command should keep the original program name: %q", spec.Command) + } + if len(spec.Tools) != 2 { + t.Errorf("declaration should be non-empty with both subcommand tools: %+v", spec.Tools) + } +} + func TestParseImportArgsGenerationFlags(t *testing.T) { o, err := parseImportArgs([]string{"--source", "help", "git", "--out=x.json", "--name", "g"}) if err != nil {