Refactor Data Store Implementation and Update Tests
- Replaced Badger with Xun as the primary data store across various components, including OAuth, agent memory, and knowledge base stores, enhancing performance and flexibility. - Updated the configuration files to reflect the new Xun store paths and removed obsolete Badger store files. - Refactored test cases to utilize the new Xun store, ensuring compatibility and improved test reliability. - Enhanced test setup functions to initialize the Xun store correctly, streamlining the testing process and ensuring a consistent environment.
This commit is contained in:
parent
5e64c78435
commit
47290d439d
17 changed files with 352 additions and 361 deletions
420
data/bindata.go
420
data/bindata.go
File diff suppressed because it is too large
Load diff
10
go.mod
10
go.mod
|
|
@ -65,18 +65,13 @@ require (
|
|||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgraph-io/badger/v4 v4.7.0 // indirect
|
||||
github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/go-errors/errors v1.5.1 // indirect
|
||||
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.26.0 // indirect
|
||||
|
|
@ -87,7 +82,6 @@ require (
|
|||
github.com/goccy/go-yaml v1.18.0 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/flatbuffers v25.2.10+incompatible // indirect
|
||||
github.com/google/go-github/v30 v30.1.0 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
|
|
@ -125,6 +119,7 @@ require (
|
|||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/qdrant/go-client v1.14.0 // indirect
|
||||
github.com/redis/go-redis/v9 v9.17.2 // indirect
|
||||
github.com/richardlehane/mscfb v1.0.4 // indirect
|
||||
github.com/richardlehane/msoleps v1.0.4 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
|
|
@ -152,10 +147,7 @@ require (
|
|||
github.com/xuri/nfp v0.0.1 // indirect
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel v1.37.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.37.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.37.0 // indirect
|
||||
golang.org/x/arch v0.17.0 // indirect
|
||||
golang.org/x/image v0.29.0 // indirect
|
||||
golang.org/x/mod v0.29.0 // indirect
|
||||
|
|
|
|||
19
go.sum
19
go.sum
|
|
@ -36,6 +36,10 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
|
|||
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=
|
||||
|
|
@ -56,18 +60,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dchest/captcha v1.1.0 h1:2kt47EoYUUkaISobUdTbqwx55xvKOJxyScVfw25xzhQ=
|
||||
github.com/dchest/captcha v1.1.0/go.mod h1:7zoElIawLp7GUMLcj54K9kbw+jEyvz2K0FDdRRYhvWo=
|
||||
github.com/dgraph-io/badger/v4 v4.7.0 h1:Q+J8HApYAY7UMpL8d9owqiB+odzEc0zn/aqOD9jhc6Y=
|
||||
github.com/dgraph-io/badger/v4 v4.7.0/go.mod h1:He7TzG3YBy3j4f5baj5B7Zl2XyfNe5bl4Udl0aPemVA=
|
||||
github.com/dgraph-io/ristretto/v2 v2.2.0 h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM=
|
||||
github.com/dgraph-io/ristretto/v2 v2.2.0/go.mod h1:RZrm63UmcBAaYWC1DotLYBmTvgkrs0+XhBd7Npn7/zI=
|
||||
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
|
||||
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/emersion/go-imap v1.2.1 h1:+s9ZjMEjOB8NzZMVTM3cCenz2JrQIGGo5j1df19WjTA=
|
||||
|
|
@ -79,8 +75,6 @@ github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6/go.mod h1:iL2twTe
|
|||
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
|
||||
github.com/evanw/esbuild v0.25.4 h1:k1bTSim+usBG27w7BfOCorhgx3tO+6bAfMj5pR+6SKg=
|
||||
github.com/evanw/esbuild v0.25.4/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
|
||||
github.com/expr-lang/expr v1.17.3 h1:myeTTuDFz7k6eFe/JPlep/UsiIjVhG61FMHFu63U7j0=
|
||||
github.com/expr-lang/expr v1.17.3/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||
github.com/expr-lang/expr v1.17.7 h1:Q0xY/e/2aCIp8g9s/LGvMDCC5PxYlvHgDZRQ4y16JX8=
|
||||
github.com/expr-lang/expr v1.17.7/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
|
|
@ -101,7 +95,6 @@ github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8b
|
|||
github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e h1:Lf/gRkoycfOBPa42vU2bbgPurFong6zXeFtPoxholzU=
|
||||
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e/go.mod h1:uNVvRXArCGbZ508SxYYTC5v1JWoz2voff5pm25jU1Ok=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
|
|
@ -133,8 +126,6 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
|
|||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q=
|
||||
github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
|
|
@ -264,6 +255,8 @@ github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
|
|||
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||
github.com/qdrant/go-client v1.14.0 h1:cyz9OOooAexudw5w69LRe9vKCQFYJvaFvt9icOciI1U=
|
||||
github.com/qdrant/go-client v1.14.0/go.mod h1:iO8ts78jL4x6LDHFOViyYWELVtIBDTjOykBmiOTHLnQ=
|
||||
github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI=
|
||||
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
|
||||
github.com/rhysd/go-github-selfupdate v1.2.3 h1:iaa+J202f+Nc+A8zi75uccC8Wg3omaM7HDeimXA22Ag=
|
||||
github.com/rhysd/go-github-selfupdate v1.2.3/go.mod h1:mp/N8zj6jFfBQy/XMYoWsmfzxazpPAODuqarmPDe2Rg=
|
||||
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"crypto/rand"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -15,8 +14,8 @@ import (
|
|||
"github.com/yaoapp/gou/connector"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/gou/store"
|
||||
"github.com/yaoapp/gou/store/badger"
|
||||
"github.com/yaoapp/gou/store/lru"
|
||||
"github.com/yaoapp/gou/store/xun"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/openapi/oauth/types"
|
||||
"github.com/yaoapp/yao/test"
|
||||
|
|
@ -357,10 +356,10 @@ func setupOAuthTestEnvironment(t *testing.T) (*Service, store.Store, store.Store
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to Badger if no other store is available
|
||||
// Fallback to Xun if no other store is available
|
||||
if mainStore == nil {
|
||||
mainStore = getBadgerStore(t)
|
||||
storeConfig = StoreConfig{Name: "Badger", GetFunc: getBadgerStore}
|
||||
mainStore = getXunStore(t)
|
||||
storeConfig = StoreConfig{Name: "Xun", GetFunc: getXunStore}
|
||||
}
|
||||
|
||||
// Create cache
|
||||
|
|
@ -656,18 +655,25 @@ func getMongoStore(t *testing.T) store.Store {
|
|||
return mongoStore
|
||||
}
|
||||
|
||||
func getBadgerStore(t *testing.T) store.Store {
|
||||
tempDir := t.TempDir()
|
||||
dbPath := filepath.Join(tempDir, "test_oauth_badger")
|
||||
func getXunStore(t *testing.T) store.Store {
|
||||
// Use test.Prepare to ensure database connection is initialized
|
||||
test.Prepare(t, config.Conf)
|
||||
|
||||
badgerStore, err := badger.New(dbPath)
|
||||
// Create xun store using default database connection
|
||||
xunStore, err := xun.New(xun.Option{
|
||||
Table: "__yao_oauth_test",
|
||||
Connector: "default",
|
||||
CacheSize: 1024,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
badgerStore.Close()
|
||||
xunStore.Clear()
|
||||
xunStore.Close()
|
||||
test.Clean()
|
||||
})
|
||||
|
||||
return badgerStore
|
||||
return xunStore
|
||||
}
|
||||
|
||||
func getLRUCache(t *testing.T) store.Store {
|
||||
|
|
@ -679,7 +685,7 @@ func getLRUCache(t *testing.T) store.Store {
|
|||
func getStoreConfigs() []StoreConfig {
|
||||
return []StoreConfig{
|
||||
{Name: "MongoDB", GetFunc: getMongoStore},
|
||||
{Name: "Badger", GetFunc: getBadgerStore},
|
||||
{Name: "Xun", GetFunc: getXunStore},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -795,7 +801,7 @@ func TestNewService(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("create service with missing issuer URL", func(t *testing.T) {
|
||||
store := getBadgerStore(t)
|
||||
store := getXunStore(t)
|
||||
config := &Config{
|
||||
Store: store,
|
||||
Signing: types.SigningConfig{
|
||||
|
|
@ -836,7 +842,7 @@ func TestServiceGetters(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConfigDefaults(t *testing.T) {
|
||||
store := getBadgerStore(t)
|
||||
store := getXunStore(t)
|
||||
|
||||
t.Run("set default values", func(t *testing.T) {
|
||||
config := &Config{
|
||||
|
|
@ -915,7 +921,7 @@ func TestFeatureFlags(t *testing.T) {
|
|||
|
||||
func TestProviderInitialization(t *testing.T) {
|
||||
t.Run("default providers created when not provided", func(t *testing.T) {
|
||||
store := getBadgerStore(t)
|
||||
store := getXunStore(t)
|
||||
cache := getLRUCache(t)
|
||||
|
||||
config := &Config{
|
||||
|
|
@ -942,7 +948,7 @@ func TestProviderInitialization(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("custom providers used when provided", func(t *testing.T) {
|
||||
store := getBadgerStore(t)
|
||||
store := getXunStore(t)
|
||||
cache := getLRUCache(t)
|
||||
|
||||
// Create a temporary service to get default providers for testing
|
||||
|
|
@ -1026,7 +1032,7 @@ func TestServiceIntegration(t *testing.T) {
|
|||
func TestConfigValidation(t *testing.T) {
|
||||
t.Run("valid configuration", func(t *testing.T) {
|
||||
config := &Config{
|
||||
Store: getBadgerStore(t),
|
||||
Store: getXunStore(t),
|
||||
IssuerURL: "https://test.example.com",
|
||||
Signing: types.SigningConfig{
|
||||
SigningCertPath: testCertPath,
|
||||
|
|
@ -1069,7 +1075,7 @@ func TestConfigValidation(t *testing.T) {
|
|||
|
||||
t.Run("missing issuer URL", func(t *testing.T) {
|
||||
config := &Config{
|
||||
Store: getBadgerStore(t),
|
||||
Store: getXunStore(t),
|
||||
Signing: types.SigningConfig{
|
||||
SigningCertPath: testCertPath,
|
||||
SigningKeyPath: testKeyPath,
|
||||
|
|
@ -1088,7 +1094,7 @@ func TestConfigValidation(t *testing.T) {
|
|||
|
||||
t.Run("partial certificate configuration", func(t *testing.T) {
|
||||
config := &Config{
|
||||
Store: getBadgerStore(t),
|
||||
Store: getXunStore(t),
|
||||
IssuerURL: "https://test.example.com",
|
||||
Signing: types.SigningConfig{
|
||||
SigningCertPath: testCertPath, // Only cert path, missing key path
|
||||
|
|
@ -1108,7 +1114,7 @@ func TestConfigValidation(t *testing.T) {
|
|||
|
||||
t.Run("invalid token lifetime", func(t *testing.T) {
|
||||
config := &Config{
|
||||
Store: getBadgerStore(t),
|
||||
Store: getXunStore(t),
|
||||
IssuerURL: "https://test.example.com",
|
||||
Signing: types.SigningConfig{
|
||||
SigningCertPath: testCertPath,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package client
|
|||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -11,9 +10,11 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"github.com/yaoapp/gou/connector"
|
||||
"github.com/yaoapp/gou/store"
|
||||
"github.com/yaoapp/gou/store/badger"
|
||||
"github.com/yaoapp/gou/store/lru"
|
||||
"github.com/yaoapp/gou/store/xun"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/openapi/oauth/types"
|
||||
"github.com/yaoapp/yao/test"
|
||||
)
|
||||
|
||||
// Store configuration for parameterized tests
|
||||
|
|
@ -52,20 +53,26 @@ func getMongoStore(t *testing.T) store.Store {
|
|||
return mongoStore
|
||||
}
|
||||
|
||||
func getBadgerStore(t *testing.T) store.Store {
|
||||
// Create temporary directory for test database
|
||||
tempDir := t.TempDir()
|
||||
dbPath := filepath.Join(tempDir, "test_oauth_badger")
|
||||
func getXunStore(t *testing.T) store.Store {
|
||||
// Use test.Prepare to initialize the environment (database, etc.)
|
||||
test.Prepare(t, config.Conf)
|
||||
|
||||
badgerStore, err := badger.New(dbPath)
|
||||
// Create xun store using default database connection
|
||||
xunStore, err := xun.New(xun.Option{
|
||||
Table: "__yao_oauth_client_test",
|
||||
Connector: "default",
|
||||
CacheSize: 1024,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Clean up on test completion
|
||||
t.Cleanup(func() {
|
||||
badgerStore.Close()
|
||||
xunStore.Clear()
|
||||
xunStore.Close()
|
||||
test.Clean()
|
||||
})
|
||||
|
||||
return badgerStore
|
||||
return xunStore
|
||||
}
|
||||
|
||||
func getLRUCache(t *testing.T) store.Store {
|
||||
|
|
@ -78,7 +85,7 @@ func getLRUCache(t *testing.T) store.Store {
|
|||
func getStoreConfigs() []StoreConfig {
|
||||
return []StoreConfig{
|
||||
{Name: "MongoDB", GetFunc: getMongoStore},
|
||||
{Name: "Badger", GetFunc: getBadgerStore},
|
||||
{Name: "Xun", GetFunc: getXunStore},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@ import (
|
|||
)
|
||||
|
||||
var systemStores = map[string]string{
|
||||
"__yao.store": "yao/stores/store.badger.yao", // for common data store
|
||||
"__yao.cache": "yao/stores/cache.lru.yao", // for common cache store
|
||||
"__yao.oauth.store": "yao/stores/oauth/store.badger.yao", // for OAuth data store
|
||||
"__yao.oauth.cache": "yao/stores/oauth/cache.lru.yao", // for OAuth cache store
|
||||
"__yao.oauth.client": "yao/stores/oauth/client.badger.yao", // for OAuth client store
|
||||
"__yao.agent.memory": "yao/stores/agent/memory.badger.yao", // for agent memory store (for agent memory)
|
||||
"__yao.agent.cache": "yao/stores/agent/cache.lru.yao", // for agent cache store (for agent cache)
|
||||
"__yao.kb.store": "yao/stores/kb/store.badger.yao", // for knowledge base store
|
||||
"__yao.kb.cache": "yao/stores/kb/cache.lru.yao", // for knowledge base cache store
|
||||
"__yao.store": "yao/stores/store.xun.yao", // for common data store
|
||||
"__yao.cache": "yao/stores/cache.lru.yao", // for common cache store
|
||||
"__yao.oauth.store": "yao/stores/oauth/store.xun.yao", // for OAuth data store
|
||||
"__yao.oauth.cache": "yao/stores/oauth/cache.lru.yao", // for OAuth cache store
|
||||
"__yao.oauth.client": "yao/stores/oauth/client.xun.yao", // for OAuth client store
|
||||
"__yao.agent.memory": "yao/stores/agent/memory.xun.yao", // for agent memory store (for agent memory)
|
||||
"__yao.agent.cache": "yao/stores/agent/cache.lru.yao", // for agent cache store (for agent cache)
|
||||
"__yao.kb.store": "yao/stores/kb/store.xun.yao", // for knowledge base store
|
||||
"__yao.kb.cache": "yao/stores/kb/cache.lru.yao", // for knowledge base cache store
|
||||
}
|
||||
|
||||
// replaceVars replaces template variables in the JSON string
|
||||
|
|
|
|||
|
|
@ -220,14 +220,14 @@ var testSystemModels = map[string]string{
|
|||
}
|
||||
|
||||
var testSystemStores = map[string]string{
|
||||
"__yao.store": "yao/stores/store.badger.yao",
|
||||
"__yao.store": "yao/stores/store.xun.yao",
|
||||
"__yao.cache": "yao/stores/cache.lru.yao",
|
||||
"__yao.oauth.store": "yao/stores/oauth/store.badger.yao",
|
||||
"__yao.oauth.client": "yao/stores/oauth/client.badger.yao",
|
||||
"__yao.oauth.store": "yao/stores/oauth/store.xun.yao",
|
||||
"__yao.oauth.client": "yao/stores/oauth/client.xun.yao",
|
||||
"__yao.oauth.cache": "yao/stores/oauth/cache.lru.yao",
|
||||
"__yao.agent.memory": "yao/stores/agent/memory.badger.yao",
|
||||
"__yao.agent.memory": "yao/stores/agent/memory.xun.yao",
|
||||
"__yao.agent.cache": "yao/stores/agent/cache.lru.yao",
|
||||
"__yao.kb.store": "yao/stores/kb/store.badger.yao",
|
||||
"__yao.kb.store": "yao/stores/kb/store.xun.yao",
|
||||
"__yao.kb.cache": "yao/stores/kb/cache.lru.yao",
|
||||
}
|
||||
|
||||
|
|
@ -253,24 +253,6 @@ func loadSystemStores(t *testing.T, cfg config.Config) error {
|
|||
source = replaceVars(source, vars)
|
||||
}
|
||||
|
||||
// Parse store config to check if we need to create directories (for badger stores)
|
||||
var storeConfig map[string]interface{}
|
||||
if err := application.Parse(path, []byte(source), &storeConfig); err == nil {
|
||||
// Check if this is a badger store
|
||||
if storeType, ok := storeConfig["type"].(string); ok && storeType == "badger" {
|
||||
// Extract the path from option.path
|
||||
if option, ok := storeConfig["option"].(map[string]interface{}); ok {
|
||||
if storePath, ok := option["path"].(string); ok {
|
||||
// Create directory for badger store
|
||||
if err := os.MkdirAll(storePath, 0755); err != nil {
|
||||
log.Error("failed to create directory for store %s at %s: %s", id, storePath, err.Error())
|
||||
return fmt.Errorf("failed to create directory for store %s: %w", id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load store with the processed source
|
||||
_, err = store.LoadSource([]byte(source), id, filepath.Join("__system", path))
|
||||
if err != nil {
|
||||
|
|
@ -574,10 +556,8 @@ func dbconnect(t *testing.T, cfg config.Config) {
|
|||
switch cfg.DB.Driver {
|
||||
case "sqlite3":
|
||||
capsule.AddConn("primary", "sqlite3", cfg.DB.Primary[0]).SetAsGlobal()
|
||||
break
|
||||
default:
|
||||
capsule.AddConn("primary", "mysql", cfg.DB.Primary[0]).SetAsGlobal()
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"label": "Agent Memory Store",
|
||||
"description": "Badger-based store for agent memory persistence and long-term storage",
|
||||
"tags": ["agent", "memory", "badger", "ai"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 20,
|
||||
"name": "Agent Memory Store",
|
||||
"type": "badger",
|
||||
"option": {
|
||||
"path": "{{ YAO_DATA_ROOT }}/stores/agent/memory"
|
||||
}
|
||||
}
|
||||
15
yao/stores/agent/memory.xun.yao
Normal file
15
yao/stores/agent/memory.xun.yao
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"label": "Agent Memory Store",
|
||||
"description": "Database-backed store for agent memory persistence and long-term storage",
|
||||
"tags": ["agent", "memory", "xun", "ai"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 20,
|
||||
"name": "Agent Memory Store",
|
||||
"type": "xun",
|
||||
"option": {
|
||||
"type": "xun",
|
||||
"table": "__yao_agent_memory",
|
||||
"connector": "default"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"label": "Knowledge Base Data Store",
|
||||
"description": "Badger-based persistent store for Knowledge Base data",
|
||||
"tags": ["kb", "persistent", "badger", "data"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 10,
|
||||
"name": "Knowledge Base Data Store",
|
||||
"type": "badger",
|
||||
"option": {
|
||||
"path": "{{ YAO_DATA_ROOT }}/stores/kb/store"
|
||||
}
|
||||
}
|
||||
15
yao/stores/kb/store.xun.yao
Normal file
15
yao/stores/kb/store.xun.yao
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"label": "Knowledge Base Data Store",
|
||||
"description": "Database-backed persistent store for Knowledge Base data",
|
||||
"tags": ["kb", "persistent", "xun", "data"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 10,
|
||||
"name": "Knowledge Base Data Store",
|
||||
"type": "xun",
|
||||
"option": {
|
||||
"type": "xun",
|
||||
"table": "__yao_kb_store",
|
||||
"connector": "default"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"label": "OAuth Client Store",
|
||||
"description": "Badger-based store for OAuth client information and credentials",
|
||||
"tags": ["oauth", "client", "badger", "security"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 10,
|
||||
"name": "OAuth Client Store",
|
||||
"type": "badger",
|
||||
"option": {
|
||||
"path": "{{ YAO_DATA_ROOT }}/stores/oauth/client"
|
||||
}
|
||||
}
|
||||
16
yao/stores/oauth/client.xun.yao
Normal file
16
yao/stores/oauth/client.xun.yao
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"label": "OAuth Client Store",
|
||||
"description": "Database-backed store for OAuth client information and credentials",
|
||||
"tags": ["oauth", "client", "xun", "security"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 10,
|
||||
"name": "OAuth Client Store",
|
||||
"type": "xun",
|
||||
"option": {
|
||||
"type": "xun",
|
||||
"table": "__yao_oauth_client",
|
||||
"connector": "default"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"label": "OAuth Data Store",
|
||||
"description": "Badger-based persistent store for OAuth authorization codes, refresh tokens and session data",
|
||||
"tags": ["oauth", "persistent", "badger", "data"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 10,
|
||||
"name": "OAuth Data Store",
|
||||
"type": "badger",
|
||||
"option": {
|
||||
"path": "{{ YAO_DATA_ROOT }}/stores/oauth/store"
|
||||
}
|
||||
}
|
||||
16
yao/stores/oauth/store.xun.yao
Normal file
16
yao/stores/oauth/store.xun.yao
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"label": "OAuth Data Store",
|
||||
"description": "Database-backed persistent store for OAuth authorization codes, refresh tokens and session data",
|
||||
"tags": ["oauth", "persistent", "xun", "data"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 10,
|
||||
"name": "OAuth Data Store",
|
||||
"type": "xun",
|
||||
"option": {
|
||||
"type": "xun",
|
||||
"table": "__yao_oauth_store",
|
||||
"connector": "default"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"label": "System Data Store",
|
||||
"description": "Badger-based key-value store for common data storage in Yao system",
|
||||
"tags": ["system", "storage", "badger", "kv"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 1,
|
||||
"name": "System Data Store",
|
||||
"type": "badger",
|
||||
"option": {
|
||||
"path": "{{ YAO_DATA_ROOT }}/stores/store"
|
||||
}
|
||||
}
|
||||
16
yao/stores/store.xun.yao
Normal file
16
yao/stores/store.xun.yao
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"label": "System Data Store",
|
||||
"description": "Database-backed key-value store for common data storage in Yao system",
|
||||
"tags": ["system", "storage", "xun", "kv"],
|
||||
"readonly": false,
|
||||
"builtin": true,
|
||||
"sort": 1,
|
||||
"name": "System Data Store",
|
||||
"type": "xun",
|
||||
"option": {
|
||||
"type": "xun",
|
||||
"table": "__yao_kv_store",
|
||||
"connector": "default"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Reference in a new issue