1
+ use std:: io:: { stdout, Stdout } ;
1
2
use crate :: ai_functions:: ai_func_backend:: {
2
3
print_backend_webserver_code, print_fixed_code, print_improved_webserver_code,
3
4
print_rest_api_endpoints,
@@ -8,14 +9,15 @@ use crate::helpers::general::{
8
9
} ;
9
10
10
11
use crate :: helpers:: command_lines:: { PrintCommand , confirm_safe_code} ;
11
- use crate :: helpers:: general:: ai_task_request;
12
+ use crate :: helpers:: general:: { ai_task_request, WEB_SERVER_PROJECT_PATH } ;
12
13
use crate :: models:: agent_basic:: basic_agent:: { AgentState , BasicAgent } ;
13
14
use crate :: models:: agents:: agent_traits:: { FactSheet , RouteObject , SpecialFunctions } ;
14
15
15
16
use async_trait:: async_trait;
16
17
use reqwest:: Client ;
17
18
use std:: process:: { Command , Stdio } ;
18
19
use std:: time:: Duration ;
20
+ use syn:: token:: Comma ;
19
21
use tokio:: time;
20
22
21
23
#[ derive( Debug ) ]
@@ -160,17 +162,52 @@ impl SpecialFunctions for AgentBackendDeveloper {
160
162
}
161
163
162
164
AgentState :: UnitTesting => {
163
- // GUard
165
+ // API SAFETY GUARD
164
166
PrintCommand :: UnitTest . print_agent_message (
165
167
& self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Ensuring Safe Code" ) ;
166
- self . attributes . state = AgentState :: Finished ;
167
168
168
169
let user_confirmation = confirm_safe_code ( ) ;
169
- match user_confirmation {
170
- false => panic ! ( "Better go work on some AI alignment instead..." ) ,
171
- true => { }
170
+
171
+ if !user_confirmation {
172
+ panic ! ( "Better go work on some AI alignment instead..." ) ;
172
173
}
173
174
175
+ // Build and testing code
176
+ PrintCommand :: UnitTest . print_agent_message (
177
+ & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: building web server..." ) ;
178
+
179
+ let build_backend_server: std:: process:: Output = Command :: new ( "cargo" )
180
+ . arg ( "build" )
181
+ . current_dir ( WEB_SERVER_PROJECT_PATH )
182
+ . stdout ( Stdio :: piped ( ) )
183
+ . stderr ( Stdio :: piped ( ) )
184
+ . output ( )
185
+ . expect ( "Failed to run backend application" ) ;
186
+
187
+ // determine errors
188
+ if build_backend_server. status . success ( ) {
189
+ self . bug_count = 0 ;
190
+ PrintCommand :: UnitTest . print_agent_message (
191
+ & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Test server build successful..." ) ;
192
+ } else {
193
+ let error_arr: Vec < u8 > = build_backend_server. stderr ;
194
+ let error_str = String :: from_utf8 ( error_arr) . unwrap ( ) ;
195
+ //update error count
196
+ self . bug_count +=1 ;
197
+ self . bug_errors = Some ( error_str) ;
198
+
199
+ if self . bug_count >2 {
200
+ PrintCommand :: Issue . print_agent_message (
201
+ & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Too many bugs found in code " ) ;
202
+ panic ! ( "ERROR: Too many bugs" ) ;
203
+ }
204
+
205
+ // Pass back to work
206
+ self . attributes . state = AgentState :: Working ;
207
+ continue
208
+ }
209
+
210
+ self . attributes . state = AgentState :: Finished ;
174
211
}
175
212
176
213
_ => { }
0 commit comments