Skip to content

Commit 08eb7c2

Browse files
authored
Directory agent listing tests (#46)
* test(integrations): add list agent test to taskfile Signed-off-by: Árpád Csepi <csepi.arpad@outlook.com> * test(integrations): add test case for agent listing Signed-off-by: Árpád Csepi <csepi.arpad@outlook.com> * fix(integrations): run top level ginkgo test Signed-off-by: Árpád Csepi <csepi.arpad@outlook.com> --------- Signed-off-by: Árpád Csepi <csepi.arpad@outlook.com>
1 parent cb3a7cc commit 08eb7c2

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

integrations/Taskfile.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ tasks:
135135
- defer: { task: manifests:cleanup }
136136
- REMOVE_CONTAINERS={{.REMOVE_CONTAINERS}} IMAGE_REPO={{.IMAGE_REPO}} DIRECTORY_IMAGE_TAG={{.DIRECTORY_IMAGE_TAG}} go test ./agntcy-dir/tests -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 30m -timeout 30m -ginkgo.v -ginkgo.focus "agent push and pull"
137137

138+
test:directory:list:
139+
desc: Directory agent list test
140+
cmds:
141+
- task: k8s:port-forward:setup:directory
142+
- defer: { task: k8s:port-forward:teardown:directory }
143+
- defer: { task: manifests:cleanup }
144+
- REMOVE_CONTAINERS={{.REMOVE_CONTAINERS}} IMAGE_REPO={{.IMAGE_REPO}} DIRECTORY_IMAGE_TAG={{.DIRECTORY_IMAGE_TAG}} go test ./agntcy-dir/tests -v -failfast -test.v -test.paniconexit0 -ginkgo.timeout 30m -timeout 30m -ginkgo.v -ginkgo.focus "Agntcy agent list tests"
145+
138146
test:autogen-agent:run:
139147
internal: true
140148
cmds:
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright AGNTCY Contributors (https://github.com/agntcy)
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package tests
5+
6+
import (
7+
"fmt"
8+
"os"
9+
"path/filepath"
10+
"runtime"
11+
"strings"
12+
13+
ginkgo "github.com/onsi/ginkgo/v2"
14+
"github.com/onsi/gomega"
15+
16+
"github.com/agntcy/csit/integrations/testutils"
17+
)
18+
19+
var _ = ginkgo.Describe("Agntcy agent list tests", func() {
20+
type agent struct {
21+
modelFile string
22+
digest string
23+
}
24+
25+
var (
26+
dockerImage string
27+
mountDest string
28+
mountString string
29+
agents []*agent
30+
)
31+
32+
ginkgo.Context("agents push for listing", func() {
33+
ginkgo.It("should push and publish agents", func() {
34+
examplesDir := "../examples/"
35+
testDataPath, err := filepath.Abs(filepath.Join(examplesDir, "dir/e2e/testdata/examples/"))
36+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
37+
38+
dockerImage = fmt.Sprintf("%s/dir-ctl:%s", os.Getenv("IMAGE_REPO"), os.Getenv("DIRECTORY_IMAGE_TAG"))
39+
mountDest = "/testdata"
40+
mountString = fmt.Sprintf("%s:%s", testDataPath, mountDest)
41+
42+
agents = append(agents, &agent{modelFile: filepath.Join(mountDest, "crewai.agent.json")})
43+
agents = append(agents, &agent{modelFile: filepath.Join(mountDest, "langgraph.agent.json")})
44+
agents = append(agents, &agent{modelFile: filepath.Join(mountDest, "llama-index.agent.json")})
45+
46+
for _, agent := range agents {
47+
dirctlArgs := []string{
48+
"push",
49+
agent.modelFile,
50+
}
51+
52+
if runtime.GOOS != "linux" {
53+
dirctlArgs = append(dirctlArgs,
54+
"--server-addr",
55+
"host.docker.internal:8888",
56+
)
57+
}
58+
59+
runner := testutils.NewDockerRunner(dockerImage, mountString, nil)
60+
outputBuffer, err := runner.Run(dirctlArgs...)
61+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), outputBuffer.String())
62+
63+
agent.digest = strings.Trim(outputBuffer.String(), "\n")
64+
_, err = fmt.Fprintf(ginkgo.GinkgoWriter, "DIGEST: %v\n", agent.digest)
65+
66+
dirctlArgs = []string{
67+
"publish",
68+
agent.digest,
69+
}
70+
71+
if runtime.GOOS != "linux" {
72+
dirctlArgs = append(dirctlArgs,
73+
"--server-addr",
74+
"host.docker.internal:8888",
75+
)
76+
}
77+
78+
runner = testutils.NewDockerRunner(dockerImage, mountString, nil)
79+
outputBuffer, err = runner.Run(dirctlArgs...)
80+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), outputBuffer.String())
81+
}
82+
})
83+
84+
ginkgo.DescribeTable("list agents using categories",
85+
func(categories []string, expectFound bool) {
86+
87+
labels := []string{}
88+
for _, category := range categories {
89+
labels = append(labels, "/skills/"+category)
90+
}
91+
92+
dirctlArgs := []string{
93+
"list",
94+
}
95+
96+
dirctlArgs = append(dirctlArgs, labels...)
97+
98+
if runtime.GOOS != "linux" {
99+
dirctlArgs = append(dirctlArgs,
100+
"--server-addr",
101+
"host.docker.internal:8888",
102+
)
103+
}
104+
105+
_, err := fmt.Fprintf(ginkgo.GinkgoWriter, "dirctl args: %v\n", dirctlArgs)
106+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
107+
108+
runner := testutils.NewDockerRunner(dockerImage, mountString, nil)
109+
outputBuffer, err := runner.Run(dirctlArgs...)
110+
gomega.Expect(err).NotTo(gomega.HaveOccurred(), outputBuffer.String())
111+
112+
if expectFound {
113+
for _, agent := range agents {
114+
gomega.Expect(outputBuffer.String()).To(gomega.ContainSubstring(agent.digest))
115+
}
116+
} else {
117+
gomega.Expect(outputBuffer.String()).To(gomega.BeEmpty())
118+
}
119+
120+
},
121+
ginkgo.Entry("list with one label", []string{"Natural Language Understanding"}, true),
122+
ginkgo.Entry("list with two labes", []string{"Natural Language Understanding", "Fact Extraction"}, true),
123+
ginkgo.Entry("list with non-existing label", []string{"Lorem ipsum dolor sit amet"}, false),
124+
)
125+
})
126+
})

0 commit comments

Comments
 (0)