WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package chatpipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
// Define a test Plugin implementation
|
||||
type testPlugin struct {
|
||||
name string
|
||||
events []types.EventType
|
||||
shouldError bool
|
||||
errorToReturn *PluginError
|
||||
}
|
||||
|
||||
func (p *testPlugin) OnEvent(ctx context.Context,
|
||||
eventType types.EventType, chatManage *types.ChatManage, next func() *PluginError,
|
||||
) *PluginError {
|
||||
if p.shouldError {
|
||||
return p.errorToReturn
|
||||
}
|
||||
fmt.Printf("Plugin %s triggered\n", p.name)
|
||||
err := next()
|
||||
fmt.Printf("Plugin %s finished\n", p.name)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *testPlugin) ActivationEvents() []types.EventType {
|
||||
return p.events
|
||||
}
|
||||
|
||||
func TestTrigger(t *testing.T) {
|
||||
// Prepare test data
|
||||
ctx := context.Background()
|
||||
chatManage := &types.ChatManage{}
|
||||
testEvent := types.EventType("test_event")
|
||||
|
||||
// Test scenario 1: No plugins registered
|
||||
t.Run("NoPluginsRegistered", func(t *testing.T) {
|
||||
manager := &EventManager{}
|
||||
err := manager.Trigger(ctx, testEvent, chatManage)
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil error, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
// Test scenario 2: Register a normally working plugin
|
||||
t.Run("SinglePluginSuccess", func(t *testing.T) {
|
||||
manager := &EventManager{}
|
||||
plugin := &testPlugin{
|
||||
name: "test_plugin",
|
||||
events: []types.EventType{testEvent},
|
||||
}
|
||||
manager.Register(plugin)
|
||||
|
||||
err := manager.Trigger(ctx, testEvent, chatManage)
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil error, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
// Test scenario 3: Plugin chain call
|
||||
t.Run("PluginChain", func(t *testing.T) {
|
||||
manager := &EventManager{}
|
||||
plugin1 := &testPlugin{
|
||||
name: "plugin1",
|
||||
events: []types.EventType{testEvent},
|
||||
}
|
||||
plugin2 := &testPlugin{
|
||||
name: "plugin2",
|
||||
events: []types.EventType{testEvent},
|
||||
}
|
||||
manager.Register(plugin1)
|
||||
manager.Register(plugin2)
|
||||
|
||||
err := manager.Trigger(ctx, testEvent, chatManage)
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil error, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
// Test scenario 4: Plugin returns error
|
||||
t.Run("PluginReturnsError", func(t *testing.T) {
|
||||
manager := &EventManager{}
|
||||
expectedErr := &PluginError{Description: "test error"}
|
||||
plugin := &testPlugin{
|
||||
name: "error_plugin",
|
||||
events: []types.EventType{testEvent},
|
||||
shouldError: true,
|
||||
errorToReturn: expectedErr,
|
||||
}
|
||||
manager.Register(plugin)
|
||||
|
||||
err := manager.Trigger(ctx, testEvent, chatManage)
|
||||
if err != expectedErr {
|
||||
t.Errorf("Expected error %v, got %v", expectedErr, err)
|
||||
}
|
||||
})
|
||||
|
||||
// Test scenario 5: A plugin in the chain returns error
|
||||
t.Run("ErrorInPluginChain", func(t *testing.T) {
|
||||
manager := &EventManager{}
|
||||
expectedErr := &PluginError{Description: "test error"}
|
||||
plugin1 := &testPlugin{
|
||||
name: "plugin1",
|
||||
events: []types.EventType{testEvent},
|
||||
}
|
||||
plugin2 := &testPlugin{
|
||||
name: "plugin2",
|
||||
events: []types.EventType{testEvent},
|
||||
shouldError: true,
|
||||
errorToReturn: expectedErr,
|
||||
}
|
||||
manager.Register(plugin1)
|
||||
manager.Register(plugin2)
|
||||
|
||||
err := manager.Trigger(ctx, testEvent, chatManage)
|
||||
if err != expectedErr {
|
||||
t.Errorf("Expected error %v, got %v", expectedErr, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user