diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml new file mode 100644 index 0000000000..5328944049 --- /dev/null +++ b/.github/workflows/dispatch.yml @@ -0,0 +1,38 @@ +name: Dispatch Trigger as expirement for SamYuan1990/OpenAI_CodeAgent-action + +on: + workflow_dispatch: + +permissions: + contents: read + pull-requests: write + +jobs: + test-action: + name: GitHub Actions Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + + - name: Test Local Action + id: test-action + uses: SamYuan1990/OpenAI_CodeAgent-action@main + with: + baseURL: https://api.deepseek.com + apiKey: ${{ secrets.API_KEY }} + fileOverWrite: true + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.MyPATToken }} # 使用 GitHub 提供的 token + branch: auto-pr-branch # 新分支名称 + base: main # 目标分支 + title: 'Automated PR: Update generated files' + body: 'This is an automated pull request created by GitHub Actions.' + commit-message: 'Auto-generated changes' + sign-commits: true + labels: automated # 可选:为 PR 添加标签 diff --git a/README.md b/README.md index 52c84dad9c..eeb284f9e0 100644 --- a/README.md +++ b/README.md @@ -168,3 +168,5 @@ dual licensed as above, without any additional terms or conditions. ## Star History [![Star History Chart](https://api.star-history.com/svg?repos=sustainable-computing-io/kepler&type=Date)](https://star-history.com/#sustainable-computing-io/kepler&Date) + +just dummy change \ No newline at end of file diff --git a/Tasks.json b/Tasks.json new file mode 100644 index 0000000000..2aa516fa3b --- /dev/null +++ b/Tasks.json @@ -0,0 +1,20 @@ +{ + "tasks": [ + { + "id": "my_example_task_for_golang", + "inputFilePath": "./cmd/exporter/exporter.go", + "inputFileProcessMethod": "by_function", + "prompt": "Please help me create unit test file for this function with ginkgo framework, here is the function:", + "outputProcessMethod": "regex_match", + "outputFilePath": "./cmd/exporter/exporter{{index}}_test.go" + }, + { + "id": "my_example_task_for_golang_test", + "inputFilePath": "./pkg/collector/metric_collector_test.go", + "inputFileProcessMethod": "by_function", + "prompt": "Please help me create benchmark test content for this function, here is the content:", + "outputProcessMethod": "regex_match", + "outputFilePath": "./pkg/collector/metric_collector{{index}}_test.go" + } + ] +} diff --git a/cmd/exporter/exporter_suite_test.go b/cmd/exporter/exporter_suite_test.go new file mode 100644 index 0000000000..6b8b879998 --- /dev/null +++ b/cmd/exporter/exporter_suite_test.go @@ -0,0 +1,13 @@ +package main + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestExporter(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Exporter Suite") +} diff --git a/cmd/exporter/exporter_test.go b/cmd/exporter/exporter_test.go new file mode 100644 index 0000000000..7bf65425b3 --- /dev/null +++ b/cmd/exporter/exporter_test.go @@ -0,0 +1,159 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "net/http/httptest" + "strings" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/sustainable-computing-io/kepler/pkg/config" +) + +var _ = Describe("AppConfig", func() { + var cfg *AppConfig + + BeforeEach(func() { + cfg = newAppConfig() + // Reset the command-line flags before each test + flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError) + }) + + It("should initialize with default values", func() { + Expect(cfg.BaseDir).To(Equal(config.BaseDir)) + Expect(cfg.Address).To(Equal("0.0.0.0:8888")) + Expect(cfg.MetricsPath).To(Equal("/metrics")) + Expect(cfg.EnableGPU).To(BeFalse()) + Expect(cfg.EnableEBPFCgroupID).To(BeTrue()) + Expect(cfg.ExposeHardwareCounterMetrics).To(BeTrue()) + Expect(cfg.EnableMSR).To(BeFalse()) + Expect(cfg.Kubeconfig).To(BeEmpty()) + Expect(cfg.ApiserverEnabled).To(BeTrue()) + Expect(cfg.RedfishCredFilePath).To(BeEmpty()) + Expect(cfg.ExposeEstimatedIdlePower).To(BeFalse()) + Expect(cfg.MachineSpecFilePath).To(BeEmpty()) + Expect(cfg.DisablePowerMeter).To(BeFalse()) + Expect(cfg.TLSFilePath).To(BeEmpty()) + }) + + It("should override default values with command-line flags", func() { + cfg = newAppConfig() + // Set command-line flags + flag.Set("config-dir", "/custom/config/dir") + flag.Set("address", "127.0.0.1:8080") + flag.Set("metrics-path", "/custom/metrics") + flag.Set("enable-gpu", "true") + flag.Set("enable-cgroup-id", "false") + flag.Set("expose-hardware-counter-metrics", "false") + flag.Set("enable-msr", "true") + flag.Set("kubeconfig", "/custom/kubeconfig") + flag.Set("apiserver", "false") + flag.Set("redfish-cred-file-path", "/custom/redfish/cred") + flag.Set("expose-estimated-idle-power", "true") + flag.Set("machine-spec", "/custom/machine/spec") + flag.Set("disable-power-meter", "true") + flag.Set("web.config.file", "/custom/tls/config") + + // Parse the flags + flag.Parse() + + // Verify that the values are overridden + Expect(cfg.BaseDir).To(Equal("/custom/config/dir")) + Expect(cfg.Address).To(Equal("127.0.0.1:8080")) + Expect(cfg.MetricsPath).To(Equal("/custom/metrics")) + Expect(cfg.EnableGPU).To(BeTrue()) + Expect(cfg.EnableEBPFCgroupID).To(BeFalse()) + Expect(cfg.ExposeHardwareCounterMetrics).To(BeFalse()) + Expect(cfg.EnableMSR).To(BeTrue()) + Expect(cfg.Kubeconfig).To(Equal("/custom/kubeconfig")) + Expect(cfg.ApiserverEnabled).To(BeFalse()) + Expect(cfg.RedfishCredFilePath).To(Equal("/custom/redfish/cred")) + Expect(cfg.ExposeEstimatedIdlePower).To(BeTrue()) + Expect(cfg.MachineSpecFilePath).To(Equal("/custom/machine/spec")) + Expect(cfg.DisablePowerMeter).To(BeTrue()) + Expect(cfg.TLSFilePath).To(Equal("/custom/tls/config")) + }) +}) + +var _ = Describe("HealthProbe", func() { + var ( + w *httptest.ResponseRecorder + req *http.Request + ) + + BeforeEach(func() { + // Initialize the response recorder and request before each test + w = httptest.NewRecorder() + req = httptest.NewRequest("GET", "/health", nil) + }) + + Context("when the health probe is called", func() { + It("should return HTTP status OK", func() { + healthProbe(w, req) + + Expect(w.Code).To(Equal(http.StatusOK)) + }) + + It("should return 'ok' in the response body", func() { + healthProbe(w, req) + + Expect(w.Body.String()).To(Equal("ok")) + }) + }) +}) + +var _ = Describe("RootHandler", func() { + var ( + metricPathConfig string + handler http.HandlerFunc + recorder *httptest.ResponseRecorder + request *http.Request + ) + + BeforeEach(func() { + metricPathConfig = "/metrics" + handler = rootHandler(metricPathConfig) + recorder = httptest.NewRecorder() + request = httptest.NewRequest("GET", "/", nil) + }) + + Context("when the root endpoint is accessed", func() { + It("should return a valid HTML response with the correct metric path", func() { + handler.ServeHTTP(recorder, request) + + Expect(recorder.Code).To(Equal(http.StatusOK)) + Expect(recorder.Body.String()).To(ContainSubstring("