11#[ allow( unused_imports) ]
22use q_cli_e2e_tests:: q_chat_helper;
3+ use regex:: Regex ;
34
45#[ test]
56#[ cfg( all( feature = "todos" , feature = "sanity" ) ) ]
67fn test_todos_command ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
78 println ! ( "\n 🔍 Testing /todos command... | Description: Tests the <code> /todos</code> command to view, manage, and resume to-do lists" ) ;
8-
9+
910 let session = q_chat_helper:: get_chat_session ( ) ;
1011 let mut chat = session. lock ( ) . unwrap_or_else ( |poisoned| poisoned. into_inner ( ) ) ;
1112
1213 println ! ( "✅ Q Chat session started" ) ;
13-
14+
1415 let response = chat. execute_command_with_timeout ( "/todos" , Some ( 2000 ) ) ?;
15-
16+
1617 println ! ( "📝 Help response: {} bytes" , response. len( ) ) ;
1718 println ! ( "📝 FULL OUTPUT:" ) ;
1819 println ! ( "{}" , response) ;
1920 println ! ( "📝 END OUTPUT" ) ;
20-
21+
2122 // Verify help content
2223 assert ! ( response. contains( "Commands:" ) , "Missing Commands section" ) ;
2324 println ! ( "✅ Found Commands section with all available commands" ) ;
24-
25+
2526 assert ! ( response. contains( "resume" ) , "Missing resume command" ) ;
2627 assert ! ( response. contains( "view" ) , "Missing view command" ) ;
2728 assert ! ( response. contains( "delete" ) , "Missing delete command" ) ;
2829 assert ! ( response. contains( "help" ) , "Missing help command" ) ;
2930 println ! ( "✅ Found core commands: resume, view, delete, help" ) ;
3031
3132 println ! ( "✅ /todos command test completed successfully" ) ;
32-
33+
3334 drop ( chat) ;
34-
35+
3536 Ok ( ( ) )
3637}
3738
@@ -44,36 +45,36 @@ fn test_todos_help_command() -> Result<(), Box<dyn std::error::Error>> {
4445 let mut chat = session. lock ( ) . unwrap_or_else ( |poisoned| poisoned. into_inner ( ) ) ;
4546
4647 println ! ( "✅ Q Chat session started" ) ;
47-
48+
4849 let response = chat. execute_command_with_timeout ( "/todos help" , Some ( 2000 ) ) ?;
49-
50+
5051 println ! ( "📝 Help response: {} bytes" , response. len( ) ) ;
5152 println ! ( "📝 FULL OUTPUT:" ) ;
5253 println ! ( "{}" , response) ;
5354 println ! ( "📝 END OUTPUT" ) ;
54-
55+
5556 // Verify help content
5657 assert ! ( response. contains( "Commands:" ) , "Missing Commands section" ) ;
5758 println ! ( "✅ Found Commands section with all available commands" ) ;
58-
59+
5960 assert ! ( response. contains( "resume" ) , "Missing resume command" ) ;
6061 assert ! ( response. contains( "view" ) , "Missing view command" ) ;
6162 assert ! ( response. contains( "delete" ) , "Missing delete command" ) ;
6263 assert ! ( response. contains( "help" ) , "Missing help command" ) ;
6364 println ! ( "✅ Found core commands: resume, view, delete, help" ) ;
6465
6566 println ! ( "✅ /todos help command test completed successfully" ) ;
66-
67+
6768 drop ( chat) ;
68-
69+
6970 Ok ( ( ) )
7071}
7172
7273#[ test]
7374#[ cfg( all( feature = "todos" , feature = "sanity" ) ) ]
7475fn test_todos_view_command ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
7576 println ! ( "\n 🔍 Testing /todos view command... | Description: Tests the <code> /todos view</code> command to view to-do lists" ) ;
76-
77+
7778 let session = q_chat_helper:: get_chat_session ( ) ;
7879 let mut chat = session. lock ( ) . unwrap_or_else ( |poisoned| poisoned. into_inner ( ) ) ;
7980
@@ -91,14 +92,14 @@ fn test_todos_view_command() -> Result<(), Box<dyn std::error::Error>> {
9192 println ! ( "✅ Todos feature enabled" ) ;
9293
9394 println ! ( "✅ Q Chat session started" ) ;
94-
95+
9596 let response = chat. execute_command_with_timeout ( "Add task in todos list Review emails" , Some ( 2000 ) ) ?;
96-
97+
9798 println ! ( "📝 Help response: {} bytes" , response. len( ) ) ;
9899 println ! ( "📝 FULL OUTPUT:" ) ;
99100 println ! ( "{}" , response) ;
100101 println ! ( "📝 END OUTPUT" ) ;
101-
102+
102103 // Verify help content
103104 assert ! ( response. contains( "Using tool" ) , "Missing tool usage confirmation" ) ;
104105 assert ! ( response. contains( "todo_list" ) , "Missing todo_list tool usage" ) ;
@@ -118,20 +119,20 @@ fn test_todos_view_command() -> Result<(), Box<dyn std::error::Error>> {
118119
119120 // Send down arrow to select different model
120121 let selection_response = chat. send_key_input ( "\x1b [B" ) ?;
121-
122+
122123 println ! ( "📝 Selection response: {} bytes" , selection_response. len( ) ) ;
123124 println ! ( "📝 SELECTION RESPONSE:" ) ;
124125 println ! ( "{}" , selection_response) ;
125126 println ! ( "📝 END SELECTION RESPONSE" ) ;
126-
127+
127128 // Send Enter to confirm
128129 let confirm_response = chat. send_key_input ( "\r " ) ?;
129-
130+
130131 println ! ( "📝 Confirm response: {} bytes" , confirm_response. len( ) ) ;
131132 println ! ( "📝 CONFIRM RESPONSE:" ) ;
132133 println ! ( "{}" , confirm_response) ;
133134 println ! ( "📝 END CONFIRM RESPONSE" ) ;
134-
135+
135136 assert ! ( confirm_response. contains( "TODO" ) , "Missing TODO message" ) ;
136137 assert ! ( confirm_response. contains( "Review emails" ) , "Missing Review emails to-do item" ) ;
137138 println ! ( "✅ Confirmed viewing of selected to-do list with items" ) ;
@@ -148,36 +149,36 @@ fn test_todos_view_command() -> Result<(), Box<dyn std::error::Error>> {
148149
149150 // Send down arrow to select different model
150151 let selection_response = chat. send_key_input ( "\x1b [B" ) ?;
151-
152+
152153 println ! ( "📝 Selection response: {} bytes" , selection_response. len( ) ) ;
153154 println ! ( "📝 SELECTION RESPONSE:" ) ;
154155 println ! ( "{}" , selection_response) ;
155156 println ! ( "📝 END SELECTION RESPONSE" ) ;
156-
157+
157158 // Send Enter to confirm
158159 let confirm_response = chat. send_key_input ( "\r " ) ?;
159-
160+
160161 println ! ( "📝 Confirm response: {} bytes" , confirm_response. len( ) ) ;
161162 println ! ( "📝 CONFIRM RESPONSE:" ) ;
162163 println ! ( "{}" , confirm_response) ;
163164 println ! ( "📝 END CONFIRM RESPONSE" ) ;
164-
165+
165166 assert ! ( confirm_response. contains( "Deleted" ) , "Missing Deleted message" ) ;
166167 assert ! ( confirm_response. contains( "to-do" ) , "Missing to-do item" ) ;
167168 println ! ( "✅ Confirmed deletion of selected to-do list" ) ;
168169
169170 println ! ( "✅ /todos view command test completed successfully" ) ;
170-
171+
171172 drop ( chat) ;
172-
173+
173174 Ok ( ( ) )
174175}
175176
176177#[ test]
177178#[ cfg( all( feature = "todos" , feature = "sanity" ) ) ]
178179fn test_todos_resume_command ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
179180 println ! ( "\n 🔍 Testing /todos resume command... | Description: Tests the <code> /todos resume</code> command to resume a specific to-do list" ) ;
180-
181+
181182 let session = q_chat_helper:: get_chat_session ( ) ;
182183 let mut chat = session. lock ( ) . unwrap_or_else ( |poisoned| poisoned. into_inner ( ) ) ;
183184
@@ -197,12 +198,12 @@ fn test_todos_resume_command() -> Result<(), Box<dyn std::error::Error>> {
197198 println ! ( "✅ Q Chat session started" ) ;
198199
199200 let response = chat. execute_command_with_timeout ( "Add task in todos list Review emails" , Some ( 2000 ) ) ?;
200-
201+
201202 println ! ( "📝 Help response: {} bytes" , response. len( ) ) ;
202203 println ! ( "📝 FULL OUTPUT:" ) ;
203204 println ! ( "{}" , response) ;
204205 println ! ( "📝 END OUTPUT" ) ;
205-
206+
206207 // Verify help content
207208 assert ! ( response. contains( "Using tool" ) , "Missing tool usage confirmation" ) ;
208209 assert ! ( response. contains( "todo_list" ) , "Missing todo_list tool usage" ) ;
@@ -222,20 +223,20 @@ fn test_todos_resume_command() -> Result<(), Box<dyn std::error::Error>> {
222223
223224 // Send down arrow to select different model
224225 let selection_response = chat. send_key_input ( "\x1b [B" ) ?;
225-
226+
226227 println ! ( "📝 Selection response: {} bytes" , selection_response. len( ) ) ;
227228 println ! ( "📝 SELECTION RESPONSE:" ) ;
228229 println ! ( "{}" , selection_response) ;
229230 println ! ( "📝 END SELECTION RESPONSE" ) ;
230-
231+
231232 // Send Enter to confirm
232233 let confirm_response = chat. send_key_input ( "\r " ) ?;
233-
234+
234235 println ! ( "📝 Confirm response: {} bytes" , confirm_response. len( ) ) ;
235236 println ! ( "📝 CONFIRM RESPONSE:" ) ;
236237 println ! ( "{}" , confirm_response) ;
237238 println ! ( "📝 END CONFIRM RESPONSE" ) ;
238-
239+
239240 assert ! ( confirm_response. contains( "Review emails" ) , "Missing Review emails message" ) ;
240241 assert ! ( confirm_response. contains( "TODO" ) , "Missing TODO item" ) ;
241242 println ! ( "✅ Confirmed resuming of selected to-do list with items" ) ;
@@ -252,36 +253,36 @@ fn test_todos_resume_command() -> Result<(), Box<dyn std::error::Error>> {
252253
253254 // Send down arrow to select different model
254255 let selection_response = chat. send_key_input ( "\x1b [B" ) ?;
255-
256+
256257 println ! ( "📝 Selection response: {} bytes" , selection_response. len( ) ) ;
257258 println ! ( "📝 SELECTION RESPONSE:" ) ;
258259 println ! ( "{}" , selection_response) ;
259260 println ! ( "📝 END SELECTION RESPONSE" ) ;
260-
261+
261262 // Send Enter to confirm
262263 let confirm_response = chat. send_key_input ( "\r " ) ?;
263-
264+
264265 println ! ( "📝 Confirm response: {} bytes" , confirm_response. len( ) ) ;
265266 println ! ( "📝 CONFIRM RESPONSE:" ) ;
266267 println ! ( "{}" , confirm_response) ;
267268 println ! ( "📝 END CONFIRM RESPONSE" ) ;
268-
269+
269270 assert ! ( confirm_response. contains( "Deleted" ) , "Missing Deleted message" ) ;
270271 assert ! ( confirm_response. contains( "to-do" ) , "Missing to-do item" ) ;
271272 println ! ( "✅ Confirmed deletion of selected to-do list" ) ;
272273
273274 println ! ( "✅ /todos resume command test completed successfully" ) ;
274-
275+
275276 drop ( chat) ;
276-
277+
277278 Ok ( ( ) )
278279}
279280
280281#[ test]
281282#[ cfg( all( feature = "todos" , feature = "sanity" ) ) ]
282283fn test_todos_delete_command ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
283284 println ! ( "\n 🔍 Testing /todos delete command... | Description: Tests the <code> /todos delete</code> command to delete a specific to-do list" ) ;
284-
285+
285286 let session = q_chat_helper:: get_chat_session ( ) ;
286287 let mut chat = session. lock ( ) . unwrap_or_else ( |poisoned| poisoned. into_inner ( ) ) ;
287288
@@ -301,12 +302,12 @@ fn test_todos_delete_command() -> Result<(), Box<dyn std::error::Error>> {
301302 println ! ( "✅ Q Chat session started" ) ;
302303
303304 let response = chat. execute_command_with_timeout ( "Add task in todos list Review emails" , Some ( 2000 ) ) ?;
304-
305+
305306 println ! ( "📝 Help response: {} bytes" , response. len( ) ) ;
306307 println ! ( "📝 FULL OUTPUT:" ) ;
307308 println ! ( "{}" , response) ;
308309 println ! ( "📝 END OUTPUT" ) ;
309-
310+
310311 // Verify help content
311312 assert ! ( response. contains( "Using tool" ) , "Missing tool usage confirmation" ) ;
312313 assert ! ( response. contains( "todo_list" ) , "Missing todo_list tool usage" ) ;
@@ -326,20 +327,20 @@ fn test_todos_delete_command() -> Result<(), Box<dyn std::error::Error>> {
326327
327328 // Send down arrow to select different model
328329 let selection_response = chat. send_key_input ( "\x1b [B" ) ?;
329-
330+
330331 println ! ( "📝 Selection response: {} bytes" , selection_response. len( ) ) ;
331332 println ! ( "📝 SELECTION RESPONSE:" ) ;
332333 println ! ( "{}" , selection_response) ;
333334 println ! ( "📝 END SELECTION RESPONSE" ) ;
334-
335+
335336 // Send Enter to confirm
336337 let confirm_response = chat. send_key_input ( "\r " ) ?;
337-
338+
338339 println ! ( "📝 Confirm response: {} bytes" , confirm_response. len( ) ) ;
339340 println ! ( "📝 CONFIRM RESPONSE:" ) ;
340341 println ! ( "{}" , confirm_response) ;
341342 println ! ( "📝 END CONFIRM RESPONSE" ) ;
342-
343+
343344 assert ! ( confirm_response. contains( "TODO" ) , "Missing TODO message" ) ;
344345 assert ! ( confirm_response. contains( "Review emails" ) , "Missing Review emails to-do item" ) ;
345346 println ! ( "✅ Confirmed viewing of selected to-do list with items" ) ;
@@ -357,27 +358,71 @@ fn test_todos_delete_command() -> Result<(), Box<dyn std::error::Error>> {
357358
358359 // Send down arrow to select different model
359360 let selection_response = chat. send_key_input ( "\x1b [B" ) ?;
360-
361+
361362 println ! ( "📝 Selection response: {} bytes" , selection_response. len( ) ) ;
362363 println ! ( "📝 SELECTION RESPONSE:" ) ;
363364 println ! ( "{}" , selection_response) ;
364365 println ! ( "📝 END SELECTION RESPONSE" ) ;
365-
366+
366367 // Send Enter to confirm
367368 let confirm_response = chat. send_key_input ( "\r " ) ?;
368-
369+
369370 println ! ( "📝 Confirm response: {} bytes" , confirm_response. len( ) ) ;
370371 println ! ( "📝 CONFIRM RESPONSE:" ) ;
371372 println ! ( "{}" , confirm_response) ;
372373 println ! ( "📝 END CONFIRM RESPONSE" ) ;
373-
374+
374375 assert ! ( confirm_response. contains( "Deleted" ) , "Missing Deleted message" ) ;
375376 assert ! ( confirm_response. contains( "to-do" ) , "Missing to-do item" ) ;
376377 println ! ( "✅ Confirmed deletion of selected to-do list" ) ;
377378
378379 println ! ( "✅ /todos delete command test completed successfully" ) ;
379-
380+
380381 drop ( chat) ;
381-
382+
382383 Ok ( ( ) )
383384}
385+ #[ test]
386+ #[ cfg( all( feature = "todos" , feature = "sanity" ) ) ]
387+ fn test_todos_clear_finished_command ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
388+ println ! ( "\n 🔍 Testing /todos clear-finished command... | Description: Tests that <code> /todos clear-finished </code> command to validate it clears the todo list." ) ;
389+
390+ let session = q_chat_helper:: get_chat_session ( ) ;
391+ let mut chat = session. lock ( ) . unwrap_or_else ( |poisoned| poisoned. into_inner ( ) ) ;
392+ println ! ( "✅ Global Q Chat session started" ) ;
393+
394+ // Create todo list with 2 tasks
395+ println ! ( "\n 🔍 Creating todo list with 2 tasks..." ) ;
396+ let create_response = chat. execute_command_with_timeout ( "create a todo_list with 2 task in amazon q" , Some ( 2000 ) ) ?;
397+ println ! ( "📝 Create response: {} bytes" , create_response. len( ) ) ;
398+ println ! ( "📝 Create response: {}" , create_response) ;
399+ println ! ( "✅ Found create response." ) ;
400+ println ! ( "✅ Tasks has been created successfully." ) ;
401+
402+ // Extract todo ID
403+ let re = Regex :: new ( r"(\d{10,})" ) ?;
404+ let todo_id = re. find ( & create_response)
405+ . map ( |m| m. as_str ( ) )
406+ . ok_or ( "Could not extract todo list ID" ) ?;
407+ println ! ( "📝 Extracted todo ID: {}" , todo_id) ;
408+
409+ // Mark all tasks as completed
410+ println ! ( "\n 🔍 Marking all tasks as completed..." ) ;
411+ let mark_response = chat. execute_command_with_timeout ( & format ! ( "mark all tasks as completed for todo list {}" , todo_id) , Some ( 2000 ) ) ?;
412+ println ! ( "📝 Mark complete response: {} bytes" , mark_response. len( ) ) ;
413+ println ! ( "📝 Mark complete response: {}" , mark_response) ;
414+ println ! ( "✅ Found Task completion response." ) ;
415+
416+ // Test clear-finished command
417+ println ! ( "\n 🔍 Testing clear-finished command..." ) ;
418+ let clear_response = chat. execute_command_with_timeout ( "/todos clear-finished" , Some ( 2000 ) ) ?;
419+ println ! ( "📝 Clear response: {} bytes" , clear_response. len( ) ) ;
420+ println ! ( "📝 {}" , clear_response) ;
421+
422+ assert ! ( !clear_response. is_empty( ) , "Expected non-empty response from clear-finished command" ) ;
423+ println ! ( "✅ Found todo_list clear response" ) ;
424+ println ! ( "✅ All finished task cleared successfully." ) ;
425+
426+ drop ( chat) ;
427+ Ok ( ( ) )
428+ }
0 commit comments