1
+ import type { Content , IAgentRuntime , Memory , State , TestSuite , UUID } from "@elizaos/core" ;
2
+ import { v4 as uuidv4 } from "uuid" ;
3
+ import { character } from "./index" ;
4
+
5
+ export class StarterTestSuite implements TestSuite {
6
+ name = "starter" ;
7
+ description = "Tests for the starter project" ;
8
+
9
+ tests = [
10
+ {
11
+ name : "Character configuration test" ,
12
+ fn : async ( runtime : IAgentRuntime ) => {
13
+ const requiredFields = [ "name" , "bio" , "plugins" , "system" , "messageExamples" ] ;
14
+ const missingFields = requiredFields . filter ( field => ! ( field in character ) ) ;
15
+
16
+ if ( missingFields . length > 0 ) {
17
+ throw new Error ( `Missing required fields: ${ missingFields . join ( ", " ) } ` ) ;
18
+ }
19
+
20
+ // Additional character property validations
21
+ if ( character . name !== 'Eliza' ) {
22
+ throw new Error ( `Expected character name to be 'Eliza', got '${ character . name } '` ) ;
23
+ }
24
+ if ( ! Array . isArray ( character . plugins ) ) {
25
+ throw new Error ( 'Character plugins should be an array' ) ;
26
+ }
27
+ if ( ! character . system ) {
28
+ throw new Error ( 'Character system prompt is required' ) ;
29
+ }
30
+ if ( ! Array . isArray ( character . bio ) ) {
31
+ throw new Error ( 'Character bio should be an array' ) ;
32
+ }
33
+ if ( ! Array . isArray ( character . messageExamples ) ) {
34
+ throw new Error ( 'Character message examples should be an array' ) ;
35
+ }
36
+ }
37
+ } ,
38
+ {
39
+ name : "Plugin initialization test" ,
40
+ fn : async ( runtime : IAgentRuntime ) => {
41
+ // Test plugin initialization with empty config
42
+ try {
43
+ await runtime . registerPlugin ( {
44
+ name : "starter" ,
45
+ description : "A starter plugin for Eliza" ,
46
+ init : async ( ) => { } ,
47
+ config : { }
48
+ } ) ;
49
+ } catch ( error ) {
50
+ throw new Error ( `Failed to register plugin: ${ error . message } ` ) ;
51
+ }
52
+ }
53
+ } ,
54
+ {
55
+ name : "Hello world action test" ,
56
+ fn : async ( runtime : IAgentRuntime ) => {
57
+ const message : Memory = {
58
+ entityId : uuidv4 ( ) as UUID ,
59
+ roomId : uuidv4 ( ) as UUID ,
60
+ content : {
61
+ text : "Can you say hello?" ,
62
+ source : "test"
63
+ }
64
+ } ;
65
+
66
+ const state : State = {
67
+ values : { } ,
68
+ data : { } ,
69
+ text : ""
70
+ } ;
71
+ let responseReceived = false ;
72
+
73
+ // Test the hello world action
74
+ try {
75
+ await runtime . processActions (
76
+ message ,
77
+ [ ] ,
78
+ state ,
79
+ async ( content : Content ) => {
80
+ if ( content . text === "hello world!" && content . actions ?. includes ( "HELLO_WORLD" ) ) {
81
+ responseReceived = true ;
82
+ }
83
+ return [ ] ;
84
+ }
85
+ ) ;
86
+
87
+ if ( ! responseReceived ) {
88
+ throw new Error ( "Hello world action did not produce expected response" ) ;
89
+ }
90
+ } catch ( error ) {
91
+ throw new Error ( `Hello world action test failed: ${ error . message } ` ) ;
92
+ }
93
+ }
94
+ } ,
95
+ {
96
+ name : "Hello world provider test" ,
97
+ fn : async ( runtime : IAgentRuntime ) => {
98
+ const message : Memory = {
99
+ entityId : uuidv4 ( ) as UUID ,
100
+ roomId : uuidv4 ( ) as UUID ,
101
+ content : {
102
+ text : "What can you provide?" ,
103
+ source : "test"
104
+ }
105
+ } ;
106
+
107
+ const state : State = {
108
+ values : { } ,
109
+ data : { } ,
110
+ text : ""
111
+ } ;
112
+
113
+ // Test the hello world provider
114
+ try {
115
+ const result = await runtime . providers [ 0 ] . get ( runtime , message , state ) ;
116
+
117
+ if ( result . text !== "I am a provider" ) {
118
+ throw new Error ( `Expected provider to return "I am a provider", got "${ result . text } "` ) ;
119
+ }
120
+ } catch ( error ) {
121
+ throw new Error ( `Hello world provider test failed: ${ error . message } ` ) ;
122
+ }
123
+ }
124
+ } ,
125
+ {
126
+ name : "Starter service test" ,
127
+ fn : async ( runtime : IAgentRuntime ) => {
128
+ // Test service registration and lifecycle
129
+ try {
130
+ const service = runtime . getService ( "starter" ) ;
131
+ if ( ! service ) {
132
+ throw new Error ( "Starter service not found" ) ;
133
+ }
134
+
135
+ if ( service . capabilityDescription !== "This is a starter service which is attached to the agent through the starter plugin." ) {
136
+ throw new Error ( "Incorrect service capability description" ) ;
137
+ }
138
+
139
+ await service . stop ( ) ;
140
+ } catch ( error ) {
141
+ throw new Error ( `Starter service test failed: ${ error . message } ` ) ;
142
+ }
143
+ }
144
+ }
145
+ ] ;
146
+ }
147
+
148
+ // Export a default instance
149
+ export default new StarterTestSuite ( ) ;
0 commit comments