|
| 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