From 1a450c0817dc84d4a321455ae558077d5475ed33 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 12 Nov 2023 01:27:05 -0800 Subject: [PATCH] Add basic sanity test to confirm that our interactions with the OpenAI API are correct --- .github/workflows/go-test.yml | 1 + shared/ai/ai_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 shared/ai/ai_test.go diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 1437174..35b86fb 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -66,6 +66,7 @@ jobs: - name: Go test env: DD_API_KEY: ${{ secrets.DD_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} run: | # Once https://github.com/gotestyourself/gotestsum/pull/377 is merged, update this to pull from main rather than my fork diff --git a/shared/ai/ai_test.go b/shared/ai/ai_test.go new file mode 100644 index 0000000..a6ca3a8 --- /dev/null +++ b/shared/ai/ai_test.go @@ -0,0 +1,25 @@ +package ai + +import ( + "os" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +// A basic sanity test that our integration with the OpenAI API is correct and is returning reasonable results (at least for a very basic query) +func TestLiveOpenAiApi(t *testing.T) { + if os.Getenv("OPENAI_API_KEY") == "" { + t.Skip("Skipping test since OPENAI_API_KEY is not set") + } + results, _, err := GetAiSuggestionsViaOpenAiApi("list files in the current directory", 3) + require.NoError(t, err) + resultsContainsLs := false + for _, result := range results { + if strings.Contains(result, "ls") { + resultsContainsLs = true + } + } + require.Truef(t, resultsContainsLs, "expected results=%#v to contain ls", results) +}