Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pkgs/mcpx/internal/cli/adapter_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sort"
"strings"
"time"
"unicode"

"github.com/developing-today/code/pkgs/mcpx/internal/adapter"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pkgs/mcpx/internal/cli/adapter_import_gen2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}