@@ -135,22 +135,22 @@ func TestMessages(t *testing.T) {
135135 sendMsg := func (c * st.Conversation , msg string ) error {
136136 return c .SendMessage (st.MessagePartText {Content : msg })
137137 }
138- newConversation := func (cfg st.ConversationConfig ) * st.Conversation {
139- if cfg .GetTime == nil {
140- cfg .GetTime = func () time.Time { return now }
138+ newConversation := func (opts ... func (* st.ConversationConfig )) * st.Conversation {
139+ cfg := st.ConversationConfig {
140+ GetTime : func () time.Time { return now },
141+ SnapshotInterval : 1 * time .Second ,
142+ ScreenStabilityLength : 2 * time .Second ,
143+ SkipWritingMessage : true ,
144+ SkipSendMessageStatusCheck : true ,
141145 }
142- if cfg .SnapshotInterval == 0 {
143- cfg .SnapshotInterval = 1 * time .Second
144- }
145- if cfg .ScreenStabilityLength == 0 {
146- cfg .ScreenStabilityLength = 2 * time .Second
146+ for _ , opt := range opts {
147+ opt (& cfg )
147148 }
148- cfg .SkipWritingMessage = true
149149 return st .NewConversation (context .Background (), cfg )
150150 }
151151
152152 t .Run ("messages are copied" , func (t * testing.T ) {
153- c := newConversation (st. ConversationConfig {} )
153+ c := newConversation ()
154154 messages := c .Messages ()
155155 assert .Equal (t , []st.ConversationMessage {
156156 agentMsg (0 , "" ),
@@ -164,11 +164,10 @@ func TestMessages(t *testing.T) {
164164 })
165165
166166 t .Run ("whitespace-padding" , func (t * testing.T ) {
167- c := newConversation (st. ConversationConfig {} )
167+ c := newConversation ()
168168 for _ , msg := range []string {"123 " , " 123" , "123\t \t " , "\n 123" , "123\n \t " , " \t 123\n \t " } {
169169 err := c .SendMessage (st.MessagePartText {Content : msg })
170- assert .Error (t , err )
171- assert .Contains (t , err .Error (), "message must be trimmed of leading and trailing whitespace" )
170+ assert .Error (t , err , st .MessageValidationErrorWhitespace )
172171 }
173172 })
174173
@@ -178,8 +177,8 @@ func TestMessages(t *testing.T) {
178177 }{
179178 Time : now ,
180179 }
181- c := newConversation (st.ConversationConfig {
182- GetTime : func () time.Time { return nowWrapper .Time },
180+ c := newConversation (func ( cfg * st.ConversationConfig ) {
181+ cfg . GetTime = func () time.Time { return nowWrapper .Time }
183182 })
184183
185184 c .AddSnapshot ("1" )
@@ -194,8 +193,8 @@ func TestMessages(t *testing.T) {
194193
195194 t .Run ("tracking messages" , func (t * testing.T ) {
196195 agent := & testAgent {}
197- c := newConversation (st.ConversationConfig {
198- AgentIO : agent ,
196+ c := newConversation (func ( cfg * st.ConversationConfig ) {
197+ cfg . AgentIO = agent
199198 })
200199 // agent message is recorded when the first snapshot is added
201200 c .AddSnapshot ("1" )
@@ -260,8 +259,8 @@ func TestMessages(t *testing.T) {
260259
261260 t .Run ("tracking messages overlap" , func (t * testing.T ) {
262261 agent := & testAgent {}
263- c := newConversation (st.ConversationConfig {
264- AgentIO : agent ,
262+ c := newConversation (func ( cfg * st.ConversationConfig ) {
263+ cfg . AgentIO = agent
265264 })
266265
267266 // common overlap between screens is removed after a user message
@@ -289,11 +288,11 @@ func TestMessages(t *testing.T) {
289288
290289 t .Run ("format-message" , func (t * testing.T ) {
291290 agent := & testAgent {}
292- c := newConversation (st.ConversationConfig {
293- AgentIO : agent ,
294- FormatMessage : func (message string , userInput string ) string {
291+ c := newConversation (func ( cfg * st.ConversationConfig ) {
292+ cfg . AgentIO = agent
293+ cfg . FormatMessage = func (message string , userInput string ) string {
295294 return message + " " + userInput
296- },
295+ }
297296 })
298297 agent .screen = "1"
299298 assert .NoError (t , sendMsg (c , "2" ))
@@ -312,11 +311,11 @@ func TestMessages(t *testing.T) {
312311
313312 t .Run ("format-message" , func (t * testing.T ) {
314313 agent := & testAgent {}
315- c := newConversation (st.ConversationConfig {
316- AgentIO : agent ,
317- FormatMessage : func (message string , userInput string ) string {
314+ c := newConversation (func ( cfg * st.ConversationConfig ) {
315+ cfg . AgentIO = agent
316+ cfg . FormatMessage = func (message string , userInput string ) string {
318317 return "formatted"
319- },
318+ }
320319 })
321320 assert .Equal (t , []st.ConversationMessage {
322321 {
@@ -326,7 +325,27 @@ func TestMessages(t *testing.T) {
326325 Time : now ,
327326 },
328327 }, c .Messages ())
328+ })
329+
330+ t .Run ("send-message-status-check" , func (t * testing.T ) {
331+ c := newConversation (func (cfg * st.ConversationConfig ) {
332+ cfg .SkipSendMessageStatusCheck = false
333+ cfg .SnapshotInterval = 1 * time .Second
334+ cfg .ScreenStabilityLength = 2 * time .Second
335+ cfg .AgentIO = & testAgent {}
336+ })
337+ assert .Error (t , sendMsg (c , "1" ), st .MessageValidationErrorChanging )
338+ for range 3 {
339+ c .AddSnapshot ("1" )
340+ }
341+ assert .NoError (t , sendMsg (c , "4" ))
342+ c .AddSnapshot ("2" )
343+ assert .Error (t , sendMsg (c , "5" ), st .MessageValidationErrorChanging )
344+ })
329345
346+ t .Run ("send-message-empty-message" , func (t * testing.T ) {
347+ c := newConversation ()
348+ assert .Error (t , sendMsg (c , "" ), st .MessageValidationErrorEmpty )
330349 })
331350}
332351
0 commit comments