mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-25 05:25:41 -04:00
888ad788bc
* refactor: introduce local plugin control panel and cleanup environment setup process * fix: args * refactor: new local runtime * temp: stash work for refactor on RemotePluginServer * refactor: unify local runtime lifetime and sperate init environment process * chore: add missing files * stash * refactor: local plugin lifetime control * refactor: complete installation process of control panel * refactor: adapt service layer to new controlpanel * refactor: pluginManager.Install * fix: add routine wrap to InstallServerless, avoid blocking main thread * feat: reinstall serverless runtime * chore: add comments to Reinstall and update confusing naming * refactor: unify install plugin service * refactor: add labels to debugging runtime * refactor: add getters to plugin manager * refactor: split install service to decode/install_task/install service * ??? * refactor: adapt controllers * refactor: session write * refactor: session runtime * Refine install task orchestration (#501) * refactor: installing task * refactor cluster management, decouple lifetime management and cluster * fix cli test command * fix: cleanup TODO comments and implement GracefulStop for instance * feat: add logger to control panel * fix: multiple nil references * refactor: better lifetime control * refactor: better cycle interval * fix(LocalPluginRuntime): prevent returning err when it's not error * fix: avoid adding empty PipExtraArgs * fix: missing errors in Environment init * fix: add truncateMessage to avoid db explosion * cleanup: better lifecycle management * fix: init status at the beginning of installation * optimize: GracefulStop for pluginInstance * refactor: tests * refactor: centralize routine labels (#504) * cleanup: RoutineKey * fix: init routine pool * fix: correctly handle cluster register error * fix: memory leak * fix: add \n to instance write * fix(installer.go): set success to true after succeed for defer func * refactor * fix: missing cwd in testutils * fix: scaleup default runtime nums to 1 when testing * fix: localruntime appconfig in testing module * Update internal/core/local_runtime/load_balancing.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * fix: more efficiency implement in installer_local.go * fix: returns after failing in onDebuggingRuntimeDisconnected * fix: returns after failing in onDebuggingRuntimeDisconnected * fix: splits tests * refactor: naming * refactor: manifest.VersionX * fix: adapt SetDefault to tests * fix: enforce use constants in DBType * fix: generate * fix: linter * cleanup tests * refactor: change package to * cleanup: useless codes * Update internal/cluster/plugin.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * cleanup * refactor: decouple connection_key management from debugging_time * refactor: confused naming * feat: recycle resources to adapt to https://github.com/langgenius/dify-plugin-daemon/pull/500 * refactor: confusing redirecting * fix: support get serverless runtime * fix: race condition in Launching * fix: avoid ManifestValidate in first step of debugging handshake * fix: adding ReleaseAllLocks to finalizers * wtf: what a beautiful code * refactor: rename Stream.Async to Stream.Process * fix: kill process if daed instance was detected * fix: correctly handle failures * fix: consistence of difference interfaces * fix: add stacktrace to panic * fix: only trigger once event * fix: ensure plugin runtime was shutdown * feat: cleanup install tasks * fix: add scale logs --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
114 lines
2.7 KiB
Go
114 lines
2.7 KiB
Go
package db
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/app"
|
|
"github.com/langgenius/dify-plugin-daemon/internal/types/models"
|
|
"github.com/stretchr/testify/assert"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func TestTransactionOnPg(t *testing.T) {
|
|
testTransaction(t, &app.Config{
|
|
DBType: app.DB_TYPE_POSTGRESQL,
|
|
DBUsername: "postgres",
|
|
DBPassword: "difyai123456",
|
|
DBHost: "0.0.0.0",
|
|
DBPort: 5432,
|
|
DBDatabase: "testing",
|
|
DBSslMode: "disable",
|
|
})
|
|
}
|
|
|
|
func TestTransactionOnMySQL(t *testing.T) {
|
|
testTransaction(t, &app.Config{
|
|
DBType: app.DB_TYPE_MYSQL,
|
|
DBUsername: "root",
|
|
DBPassword: "difyai123456",
|
|
DBHost: "0.0.0.0",
|
|
DBPort: 3306,
|
|
DBDatabase: "testing",
|
|
DBSslMode: "disable",
|
|
})
|
|
}
|
|
|
|
func testTransaction(t *testing.T, config *app.Config) {
|
|
config.SetDefault()
|
|
Init(config)
|
|
defer Close()
|
|
|
|
model := &models.ToolInstallation{
|
|
PluginID: uuid.New().String(),
|
|
PluginUniqueIdentifier: "plugin_xxx",
|
|
TenantID: uuid.New().String(),
|
|
Provider: "provider_xxx",
|
|
}
|
|
|
|
// create
|
|
if err := WithTransaction(func(tx *gorm.DB) error {
|
|
return Create(model, tx)
|
|
}); err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
// check columns with default value
|
|
assert.NotEmpty(t, model.ID)
|
|
assert.NotEmpty(t, model.CreatedAt)
|
|
assert.NotEmpty(t, model.UpdatedAt)
|
|
|
|
// get one
|
|
var record models.ToolInstallation
|
|
if err := WithTransaction(func(tx *gorm.DB) error {
|
|
row, err := GetOne[models.ToolInstallation](
|
|
WithTransactionContext(tx),
|
|
Equal("plugin_unique_identifier", model.PluginUniqueIdentifier),
|
|
Equal("tenant_id", model.TenantID),
|
|
WLock(),
|
|
)
|
|
record = row
|
|
return err
|
|
}); err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
// check all fields
|
|
assert.Equal(t, model.ID, record.ID)
|
|
assert.Equal(t, model.CreatedAt.Second(), record.CreatedAt.Second())
|
|
assert.Equal(t, model.UpdatedAt.Second(), record.UpdatedAt.Second())
|
|
assert.Equal(t, model.TenantID, record.TenantID)
|
|
assert.Equal(t, model.Provider, record.Provider)
|
|
assert.Equal(t, model.PluginUniqueIdentifier, record.PluginUniqueIdentifier)
|
|
assert.Equal(t, model.PluginID, record.PluginID)
|
|
|
|
// update
|
|
newProvider := "provider_yyy"
|
|
model.Provider = newProvider
|
|
if err := WithTransaction(func(tx *gorm.DB) error {
|
|
return Update(model, tx)
|
|
}); err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
// get all
|
|
rows, err := GetAll[models.ToolInstallation](Equal("id", model.ID))
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
if len(rows) != 1 {
|
|
t.Fatal("expected 1 row")
|
|
}
|
|
|
|
// check updated column
|
|
updated := rows[0]
|
|
assert.Equal(t, newProvider, updated.Provider)
|
|
|
|
// delete
|
|
if err = WithTransaction(func(tx *gorm.DB) error {
|
|
return Delete(model, tx)
|
|
}); err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
}
|