- Implemented TestCreate to validate the creation of the 'tests.create' assistant. - Added context handling for the assistant, ensuring proper execution of the script with a sample user message. - Enhanced error handling to check for the presence of the script in the assistant.
34 lines
813 B
Go
34 lines
813 B
Go
package hook_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/yaoapp/yao/agent/assistant"
|
|
agentContext "github.com/yaoapp/yao/agent/context"
|
|
"github.com/yaoapp/yao/agent/testutils"
|
|
)
|
|
|
|
// TestCreate test the create hook
|
|
func TestCreate(t *testing.T) {
|
|
testutils.Prepare(t)
|
|
defer testutils.Clean(t)
|
|
|
|
agent, err := assistant.Get("tests.create")
|
|
if err != nil {
|
|
t.Fatalf("Failed to get the tests.create assistant: %s", err.Error())
|
|
}
|
|
|
|
if agent.Script == nil {
|
|
t.Fatalf("The tests.create assistant has no script")
|
|
}
|
|
|
|
ctx := &agentContext.Context{
|
|
Context: context.Background(),
|
|
ChatID: "chat-test-create-hook",
|
|
AssistantID: "tests.create",
|
|
Sid: "test-session-create-hook",
|
|
}
|
|
|
|
agent.Script.Create(ctx, []agentContext.Message{{Role: "user", Content: "Hello, how are you?"}})
|
|
}
|