Update unified cody context to only use search when embeddings are disabled (#59360)

* update cody context to use search when embeddings are disabled

* Update internal/codycontext/context.go

Co-authored-by: Camden Cheek <camden@ccheek.com>

* fix test by adding required embeddings config

---------

Co-authored-by: Camden Cheek <camden@ccheek.com>
This commit is contained in:
Chris Warwick 2024-01-05 16:28:14 -05:00 committed by GitHub
parent 320cdcdd4e
commit 7f1df01d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -33,10 +33,20 @@ import (
func TestContextResolver(t *testing.T) {
logger := logtest.Scoped(t)
ctx := context.Background()
db := database.NewDB(logger, dbtest.NewDB(t))
repo1 := types.Repo{Name: "repo1"}
repo2 := types.Repo{Name: "repo2"}
truePtr := true
conf.Mock(&conf.Unified{
SiteConfiguration: schema.SiteConfiguration{
CodyEnabled: &truePtr,
Embeddings: &schema.Embeddings{
Provider: "sourcegraph",
Enabled: &truePtr,
AccessToken: "123",
},
},
})
// Create populates the IDs in the passed in types.Repo
err := db.Repos().Create(ctx, &repo1, &repo2)
require.NoError(t, err)
@ -139,13 +149,6 @@ func TestContextResolver(t *testing.T) {
contextClient,
)
truePtr := true
conf.Mock(&conf.Unified{
SiteConfiguration: schema.SiteConfiguration{
CodyEnabled: &truePtr,
},
})
ctx = actor.WithActor(ctx, actor.FromMockUser(1))
ffs := featureflag.NewMemoryStore(map[string]bool{"cody": true}, nil, nil)
ctx = featureflag.WithFlags(ctx, ffs)

View File

@ -160,6 +160,10 @@ func (c *CodyContextClient) GetCodyContext(ctx context.Context, args GetContextA
// partitionRepos splits a set of repos into repos with embeddings and repos without embeddings
func (c *CodyContextClient) partitionRepos(ctx context.Context, input []types.RepoIDName) (embedded, notEmbedded []types.RepoIDName, err error) {
// if embeddings are disabled , return all repos in the notEmbedded slice
if !conf.EmbeddingsEnabled() {
return nil, input, nil
}
for _, repo := range input {
exists, err := c.db.Repos().RepoEmbeddingExists(ctx, repo.ID)
if err != nil {