Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

【架构优化】用 slices.Contains 简化 marketItem 的别名查找循环 (#538) (#539)

fx-kurumie34585aab9f8
diff --git a/internal/httpapi/mcp_market.go b/internal/httpapi/mcp_market.go
index e6cc4703..0be40dff 100644
--- a/internal/httpapi/mcp_market.go
+++ b/internal/httpapi/mcp_market.go
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"regexp"
+ "slices"
"strings"
"time"
@@ -135,14 +136,9 @@ func marketItem(id string) (mcpMarketItem, bool) {
return mcpMarketItem{}, false
}
for _, item := range mcpMarketItems {
- if item.ID == id {
+ if item.ID == id || slices.Contains(item.Aliases, id) {
return item, true
}
- for _, alias := range item.Aliases {
- if alias == id {
- return item, true
- }
- }
}
return mcpMarketItem{}, false
}
diff --git a/internal/httpapi/mcp_market_item_lookup_test.go b/internal/httpapi/mcp_market_item_lookup_test.go
new file mode 100644
index 00000000..4005b12a
--- /dev/null
+++ b/internal/httpapi/mcp_market_item_lookup_test.go
@@ -0,0 +1,32 @@
+package httpapi
+
+import "testing"
+
+func TestMarketItemMatchesIDOrAlias(t *testing.T) {
+ saved := mcpMarketItems
+ t.Cleanup(func() { mcpMarketItems = saved })
+ mcpMarketItems = []mcpMarketItem{
+ {ID: "github", Aliases: []string{"gh"}},
+ {ID: "docs", Aliases: []string{"wiki", "kb"}},
+ }
+
+ cases := []struct {
+ in string
+ wantID string
+ wantOK bool
+ }{
+ {"github", "github", true},
+ {"gh", "github", true},
+ {"kb", "docs", true},
+ {" wiki ", "docs", true},
+ {"", "", false},
+ {" ", "", false},
+ {"missing", "", false},
+ }
+ for _, tc := range cases {
+ item, ok := marketItem(tc.in)
+ if ok != tc.wantOK || item.ID != tc.wantID {
+ t.Errorf("marketItem(%q) = (%q, %v), want (%q, %v)", tc.in, item.ID, ok, tc.wantID, tc.wantOK)
+ }
+ }
+}