parseImport cut name= at 80 bytes, which lands mid-character for a name in Chinese (3 bytes each: 80 bytes is 26⅔ characters), so the provider's name ended in U+FFFD. It now steps back to the byte where a character begins (utf8.RuneStart). The MCP tool names namedTools cuts to 64 bytes (with and without the de-dup suffix) had the same cut and use the same helper, cutName. Tests: TestParseImportNameCutKeepsCharactersWhole (30×"鱼"+"-relay" keeps 26 whole characters) and TestToolNameCutKeepsCharactersWhole; each fails with the old byte cut put back by hand. gofmt clean; vet darwin, linux, windows (-tags nogui). Full suite: go test -tags nogui -count=1 -timeout 45m ./internal/provider/ ./internal/gateway/ ok (116.6s, 477.8s); other packages untouched. Co-authored-by: ggbdpq <ggbdpq@gmail.com>
29 lines
803 B
Go
29 lines
803 B
Go
package gateway
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf8"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
)
|
|
|
|
// A tool's name in Chinese is cut to 64 bytes where a character begins,
|
|
// and so is one told apart by a number (#2416).
|
|
func TestToolNameCutKeepsCharactersWhole(t *testing.T) {
|
|
long := strings.Repeat("工", 30)
|
|
pts := []plugin.PluginTools{{Spec: "demo", Tools: []plugin.Tool{{Name: long}, {Name: long + "二"}}}}
|
|
tools := namedTools(pts)
|
|
if len(tools) != 2 {
|
|
t.Fatalf("tools %d", len(tools))
|
|
}
|
|
for _, tl := range tools {
|
|
if !utf8.ValidString(tl.name) || len(tl.name) > 64 {
|
|
t.Fatalf("name %q (%d bytes)", tl.name, len(tl.name))
|
|
}
|
|
}
|
|
if tools[0].name == tools[1].name || !strings.HasSuffix(tools[1].name, "_2") {
|
|
t.Fatalf("names %q %q", tools[0].name, tools[1].name)
|
|
}
|
|
}
|