From fe435c87b4c0e63c476f7fb789417fbdaaf724c6 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sun, 18 Oct 2026 05:40:36 -0500 Subject: [PATCH 1/2] fix(mcpx): quote zsh completion _describe entries so the script parses (#272) --- pkgs/mcpx/internal/cli/completion.go | 14 +++++- pkgs/mcpx/internal/cli/completion_test.go | 52 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 pkgs/mcpx/internal/cli/completion_test.go diff --git a/pkgs/mcpx/internal/cli/completion.go b/pkgs/mcpx/internal/cli/completion.go index ecb92fc66a..fdf8fbfa08 100644 --- a/pkgs/mcpx/internal/cli/completion.go +++ b/pkgs/mcpx/internal/cli/completion.go @@ -89,7 +89,9 @@ func zshCompletion(cmds []Command, sch *settings.Schema) string { b.WriteString("# Generated by `mcpx completion zsh`.\n\n") b.WriteString("_mcpx() {\n local -a commands\n commands=(\n") for _, c := range cmds { - fmt.Fprintf(&b, " %s:%s\n", c.Name, zshEscape(c.Summary)) + // Quote each entry: summaries carry apostrophes, parens and glob + // brackets (issue #272), none of which survive unquoted. + fmt.Fprintf(&b, " '%s:%s'\n", c.Name, zshDescribe(c.Summary)) } b.WriteString(" )\n\n") b.WriteString(" if (( CURRENT == 2 )); then\n") @@ -152,6 +154,16 @@ func zshEscape(s string) string { return s } +// zshDescribe prepares a _describe entry's description. The whole entry is +// emitted single-quoted, so the shell itself needs no escaping; what remains +// is _describe's own syntax, where a colon in the description must be +// backslash-escaped so it is not read as another name separator. +func zshDescribe(s string) string { + s = strings.ReplaceAll(s, ":", `\:`) + s = strings.ReplaceAll(s, `'`, `'\''`) + return s +} + func fishQuote(s string) string { return "'" + strings.ReplaceAll(s, "'", `\'`) + "'" } diff --git a/pkgs/mcpx/internal/cli/completion_test.go b/pkgs/mcpx/internal/cli/completion_test.go new file mode 100644 index 0000000000..8928e442b8 --- /dev/null +++ b/pkgs/mcpx/internal/cli/completion_test.go @@ -0,0 +1,52 @@ +package cli + +import ( + "strings" + "testing" +) + +// TestZshCompletionCommandsAreQuoted is the regression test for issue #272: +// `mcpx completion zsh | zsh -n` failed with "parse error near `;;'". +// Summaries carry apostrophes, parens and glob brackets, so every entry in +// the _describe commands array must be single-quoted; an unquoted '\'' escape +// is only valid inside quotes. +func TestZshCompletionCommandsAreQuoted(t *testing.T) { + out, err := Completion("zsh") + if err != nil { + t.Fatal(err) + } + start := strings.Index(out, " commands=(\n") + if start < 0 { + t.Fatal("commands array not found in zsh completion") + } + rest := out[start+len(" commands=(\n"):] + end := strings.Index(rest, "\n )\n") + if end < 0 { + t.Fatal("commands array not terminated in zsh completion") + } + lines := strings.Split(rest[:end], "\n") + if len(lines) == 0 { + t.Fatal("commands array is empty") + } + for _, l := range lines { + if !strings.HasPrefix(l, " '") || !strings.HasSuffix(l, "'") { + t.Errorf("unquoted commands entry: %q", l) + } + } + // At least one summary really does contain an apostrophe, so this test + // guards the case that broke, not a vacuous shape. + if !strings.Contains(out, `server'\''s prompts`) { + t.Error("expected an apostrophe-bearing entry (server's prompts) in the commands array") + } +} + +// TestZshDescribeEscapesColonsAndQuotes pins zshDescribe: the entry is +// single-quoted for the shell, and _describe's own colon separator inside the +// description is backslash-escaped. +func TestZshDescribeEscapesColonsAndQuotes(t *testing.T) { + got := zshDescribe("list a server's prompts: verbosely") + want := `list a server'\''s prompts\: verbosely` + if got != want { + t.Errorf("zshDescribe = %q, want %q", got, want) + } +} From ce382c294011b015bc7bcf5157f47be754389403 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sun, 18 Oct 2026 05:44:03 -0500 Subject: [PATCH 2/2] style(mcpx): gofmt completion test doc comment for treefmt --- pkgs/mcpx/internal/cli/completion_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/mcpx/internal/cli/completion_test.go b/pkgs/mcpx/internal/cli/completion_test.go index 8928e442b8..dc3025f9e7 100644 --- a/pkgs/mcpx/internal/cli/completion_test.go +++ b/pkgs/mcpx/internal/cli/completion_test.go @@ -8,7 +8,7 @@ import ( // TestZshCompletionCommandsAreQuoted is the regression test for issue #272: // `mcpx completion zsh | zsh -n` failed with "parse error near `;;'". // Summaries carry apostrophes, parens and glob brackets, so every entry in -// the _describe commands array must be single-quoted; an unquoted '\'' escape +// the _describe commands array must be single-quoted; an unquoted '\” escape // is only valid inside quotes. func TestZshCompletionCommandsAreQuoted(t *testing.T) { out, err := Completion("zsh")