From 2d683ccb776999a78fb4e6126fa1a2cd7d5d3d88 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Fri, 13 Nov 2026 08:19:48 -0600 Subject: [PATCH] fix(mcpx): infer integer params only from complete numeric placeholder tokens (#9557) --- pkgs/mcpx/internal/cli/adapter_import.go | 26 ++++++++++++++++++- .../internal/cli/adapter_import_gen2_test.go | 25 ++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/pkgs/mcpx/internal/cli/adapter_import.go b/pkgs/mcpx/internal/cli/adapter_import.go index 1c3f6031b4..6ecdcf8aa6 100644 --- a/pkgs/mcpx/internal/cli/adapter_import.go +++ b/pkgs/mcpx/internal/cli/adapter_import.go @@ -12,6 +12,7 @@ import ( "sort" "strings" "time" + "unicode" "github.com/developing-today/code/pkgs/mcpx/internal/adapter" ) @@ -256,7 +257,7 @@ func flagParams(flags []importFlag) []adapter.Param { if f.TakesValue { p.Type = "string" p.Equals = f.EqualsOnly - if v := strings.ToLower(f.Value); strings.Contains(v, "int") || strings.Contains(v, "num") || strings.Contains(v, "count") { + if placeholderIsInteger(f.Value) { p.Type = "integer" } } else { @@ -271,6 +272,29 @@ func flagParams(flags []importFlag) []adapter.Param { return out } +// numericPlaceholderTokens are the complete placeholder tokens that +// name a numeric type. Integer typing is inferred only when one of +// them appears as a whole token in the placeholder, never as a +// substring: ENDPOINT contains "int" but is a string placeholder +// (#9557), while MAX_COUNT names a count. +var numericPlaceholderTokens = map[string]bool{ + "int": true, "integer": true, "num": true, "number": true, "count": true, +} + +// placeholderIsInteger reports whether a value placeholder names a +// numeric type with a complete token (INT, NUMBER, MAX_COUNT, ...). +// String is the fallback for every other placeholder. +func placeholderIsInteger(v string) bool { + for _, tok := range strings.FieldsFunc(strings.ToLower(v), func(r rune) bool { + return !unicode.IsLetter(r) && !unicode.IsDigit(r) + }) { + if numericPlaceholderTokens[tok] { + return true + } + } + return false +} + // shapeToSpec renders a parsed shape as a declaration. Global flags of a // subcommand-ful binary are deliberately NOT folded into the subcommand // tools: they belong before the subcommand on a real command line diff --git a/pkgs/mcpx/internal/cli/adapter_import_gen2_test.go b/pkgs/mcpx/internal/cli/adapter_import_gen2_test.go index bc1091630a..c78fa3d107 100644 --- a/pkgs/mcpx/internal/cli/adapter_import_gen2_test.go +++ b/pkgs/mcpx/internal/cli/adapter_import_gen2_test.go @@ -201,3 +201,28 @@ func TestRelativeBinaryPathIsStoredAbsolute(t *testing.T) { t.Errorf("command: got %q, want absolute %q", spec.Command, want) } } + +// Oracle: issue #9557, the Codex scenario from PR #9161. Integer +// typing comes only from complete numeric placeholder tokens; +// ENDPOINT (which merely contains "int") must generate a string +// parameter so argument validation accepts a URL value. +func TestFlagParamsIntegerOnlyFromCompleteNumericTokens(t *testing.T) { + cases := []struct{ placeholder, want string }{ + {"ENDPOINT", "string"}, + {"POINT", "string"}, + {"FILENAME", "string"}, + {"INT", "integer"}, + {"INTEGER", "integer"}, + {"NUMBER", "integer"}, + {"NUM", "integer"}, + {"COUNT", "integer"}, + {"MAX_COUNT", "integer"}, + {"RETRY-NUM", "integer"}, + } + for _, c := range cases { + params := flagParams([]importFlag{{Long: "opt", TakesValue: true, Value: c.placeholder}}) + if len(params) != 1 || params[0].Type != c.want { + t.Errorf("placeholder %s: got %+v, want type %s", c.placeholder, params, c.want) + } + } +}