Add test for assistant creation and script execution

- 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.
This commit is contained in:
Max 2025-11-13 15:23:30 +08:00
parent 73f6fae626
commit baf90d374c

View file

@ -1,8 +1,11 @@
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"
)
@ -10,4 +13,22 @@ import (
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?"}})
}