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.

refactor(httpapi): use slices.Contains in sharedAgentReferences (#531) (#533)

fx-kurumi5ffdba29c811
diff --git a/internal/httpapi/catalog.go b/internal/httpapi/catalog.go
index 5bc5641c..a88bfff3 100644
--- a/internal/httpapi/catalog.go
+++ b/internal/httpapi/catalog.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
+ "slices"
"strconv"
"strings"
"time"
@@ -700,10 +701,8 @@ func (h *catalogHandlers) sharedAgentReferences(kind, id string) bool {
if kind == "skill" {
refs = agent.Skills
}
- for _, ref := range refs {
- if ref == id {
- return true
- }
+ if slices.Contains(refs, id) {
+ return true
}
}
return false
diff --git a/internal/httpapi/catalog_shared_refs_test.go b/internal/httpapi/catalog_shared_refs_test.go
new file mode 100644
index 00000000..ba48e5cf
--- /dev/null
+++ b/internal/httpapi/catalog_shared_refs_test.go
@@ -0,0 +1,44 @@
+package httpapi
+
+import (
+ "testing"
+
+ "agentflow/internal/domain"
+ "agentflow/internal/repo"
+)
+
+func TestSharedAgentReferences(t *testing.T) {
+ s, err := repo.OpenTest()
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { s.Close() })
+ agents := []domain.AgentDefinition{
+ {ID: "sar-shared", Name: "Shared", Version: 1, Shared: true, Rules: []string{"sar-rule-a", "sar-rule-b"}, Skills: []string{"sar-skill-a"}},
+ {ID: "sar-private", Name: "Private", Version: 1, ProjectID: "sar-p", Rules: []string{"sar-rule-private"}, Skills: []string{"sar-skill-private"}},
+ }
+ for _, a := range agents {
+ if err := s.PutAgent(a); err != nil {
+ t.Fatal(err)
+ }
+ }
+ h := &catalogHandlers{deps: &deps{repo: s}}
+ cases := []struct {
+ kind, id string
+ want bool
+ }{
+ {"rule", "sar-rule-a", true},
+ {"rule", "sar-rule-b", true},
+ {"skill", "sar-skill-a", true},
+ {"rule", "sar-skill-a", false},
+ {"skill", "sar-rule-a", false},
+ {"rule", "sar-rule-private", false},
+ {"skill", "sar-skill-private", false},
+ {"rule", "sar-missing", false},
+ }
+ for _, c := range cases {
+ if got := h.sharedAgentReferences(c.kind, c.id); got != c.want {
+ t.Errorf("sharedAgentReferences(%q, %q) = %v, want %v", c.kind, c.id, got, c.want)
+ }
+ }
+}