Skip to content

Commit

Permalink
feat/User; Session Refactor; Test data; more (#170)
Browse files Browse the repository at this point in the history
* first cut of user + migration

* refactor sessions; add session List; add users

* user tests pass

* rename updatesessionrequest

* updated deps; fix bugs; modify cursors; all tests passing

* merge user metadata

* initial user route tests

* route tests

* route tests

* remove unused decodeRecordedResponse

* update swagger doc, swagger godoc formatting

* user userid for session join

* fix updateUser returning updated record

* update unit tst

* test comments

* DeleteMemoryHandler should return 404

* update swagger

* fix user update test

* create collection, document, user, and session data

* error check
  • Loading branch information
danielchalef authored Aug 28, 2023
1 parent 90cd50d commit 8eb5609
Show file tree
Hide file tree
Showing 51 changed files with 34,930 additions and 764 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ out/
# Go workspace file
go.work
.idea
.vscode
52 changes: 52 additions & 0 deletions cmd/zep/cmd.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/getzep/zep/config"
"github.com/getzep/zep/internal"
"github.com/getzep/zep/pkg/models"
"github.com/getzep/zep/pkg/store/postgres"
"github.com/sirupsen/logrus"

"github.com/spf13/cobra"
Expand All @@ -16,6 +21,7 @@ var (
showVersion bool
dumpConfig bool
generateKey bool
fixturePath string
)

var cmd = &cobra.Command{
Expand All @@ -24,12 +30,58 @@ var cmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { run() },
}

var testCmd = &cobra.Command{
Use: "test",
Short: "Test utilities",
}

var createFixturesCmd = &cobra.Command{
Use: "create-fixtures",
Short: "Create fixtures for testing",
Run: func(cmd *cobra.Command, args []string) {
fixtureCount, _ := cmd.Flags().GetInt("count")
outputDir, _ := cmd.Flags().GetString("outputDir")
postgres.GenerateFixtureData(fixtureCount, outputDir)
fmt.Println("Fixtures created successfully.")
},
}

var loadFixturesCmd = &cobra.Command{
Use: "load-fixtures",
Short: "Load fixtures for testing",
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.LoadConfig(cfgFile)
if err != nil {
log.Fatalf("Error configuring Zep: %s", err)
}
appState := &models.AppState{
Config: cfg,
}
db := postgres.NewPostgresConn(appState)
err = postgres.LoadFixtures(context.Background(), appState, db, fixturePath)
if err != nil {
fmt.Printf("Failed to load fixtures: %v\n", err)
os.Exit(1)
}
fmt.Println("Fixtures loaded successfully.")
},
}

func init() {
testCmd.AddCommand(createFixturesCmd)
testCmd.AddCommand(loadFixturesCmd)
cmd.AddCommand(testCmd)

cmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default config.yaml)")
cmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "print version number")
cmd.PersistentFlags().BoolVarP(&dumpConfig, "dump-config", "d", false, "dump config")
cmd.PersistentFlags().
BoolVarP(&generateKey, "generate-token", "g", false, "generate a new JWT token")

createFixturesCmd.Flags().Int("count", 100, "Number of fixtures to generate per model")
createFixturesCmd.Flags().String("outputDir", "./test_data", "Path to output fixtures")
loadFixturesCmd.Flags().
StringVarP(&fixturePath, "fixturePath", "f", "./test_data", "Path containing fixtures to load")
}

// Execute executes the root cobra command.
Expand Down
11 changes: 8 additions & 3 deletions cmd/zep/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ func NewAppState(cfg *config.Config) *models.AppState {

// handleCLIOptions handles CLI options that don't require the server to run
func handleCLIOptions(cfg *config.Config) {
if showVersion {
switch {
case showVersion:
fmt.Println(config.VersionString)
os.Exit(0)
} else if dumpConfig {
case dumpConfig:
fmt.Println(dumpConfigToJSON(cfg))
os.Exit(0)
} else if generateKey {
case generateKey:
fmt.Println(auth.GenerateJWT(cfg))
os.Exit(0)
}
Expand Down Expand Up @@ -148,8 +149,12 @@ func initializeStores(appState *models.AppState) {
}
log.Debug("embeddingProcessor started")

userStore := postgres.NewUserStoreDAO(db)
log.Debug("userStore created")

appState.MemoryStore = memoryStore
appState.DocumentStore = documentStore
appState.UserStore = userStore
default:
log.Fatal(
fmt.Sprintf(
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"errors"
"strings"

"github.com/getzep/zep/internal"
Expand Down Expand Up @@ -38,7 +39,7 @@ func LoadConfig(configFile string) (*Config, error) {

if err := viper.ReadInConfig(); err != nil {
// Ignore error if config file not found
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
if errors.Is(err, viper.ConfigFileNotFoundError{}) {
return nil, err
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/docs.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/swagger.json

Large diffs are not rendered by default.

Loading

0 comments on commit 8eb5609

Please sign in to comment.