1
- use std:: io:: { stdout, Stdout } ;
2
1
use crate :: ai_functions:: ai_func_backend:: {
3
2
print_backend_webserver_code, print_fixed_code, print_improved_webserver_code,
4
3
print_rest_api_endpoints,
@@ -7,8 +6,9 @@ use crate::helpers::general::{
7
6
check_status_code, read_code_template_contents, read_exec_main_contents, save_api_endpoints,
8
7
save_backend_code,
9
8
} ;
9
+ use std:: io:: { stdout, Stdout } ;
10
10
11
- use crate :: helpers:: command_lines:: { PrintCommand , confirm_safe_code } ;
11
+ use crate :: helpers:: command_lines:: { confirm_safe_code , PrintCommand } ;
12
12
use crate :: helpers:: general:: { ai_task_request, WEB_SERVER_PROJECT_PATH } ;
13
13
use crate :: models:: agent_basic:: basic_agent:: { AgentState , BasicAgent } ;
14
14
use crate :: models:: agents:: agent_traits:: { FactSheet , RouteObject , SpecialFunctions } ;
@@ -61,7 +61,7 @@ impl AgentBackendDeveloper {
61
61
get_function_string ! ( print_backend_webserver_code) ,
62
62
print_backend_webserver_code,
63
63
)
64
- . await ;
64
+ . await ;
65
65
println ! (
66
66
"* ==============FIRST Backend(AI RESPONSE) code to Save: {:?}" ,
67
67
& ai_response
@@ -86,7 +86,7 @@ impl AgentBackendDeveloper {
86
86
get_function_string ! ( print_improved_webserver_code) ,
87
87
print_improved_webserver_code,
88
88
)
89
- . await ;
89
+ . await ;
90
90
println ! (
91
91
"* ==============SECOND (AI RESPONSE) Backend code to save: {:?}" ,
92
92
& ai_response
@@ -108,7 +108,7 @@ impl AgentBackendDeveloper {
108
108
get_function_string ! ( print_fixed_code) ,
109
109
print_fixed_code,
110
110
)
111
- . await ;
111
+ . await ;
112
112
113
113
save_backend_code ( & ai_response) ;
114
114
factsheet. backend_code = Some ( ai_response) ;
@@ -126,7 +126,7 @@ impl AgentBackendDeveloper {
126
126
get_function_string ! ( print_rest_api_endpoints) ,
127
127
print_rest_api_endpoints,
128
128
)
129
- . await ;
129
+ . await ;
130
130
131
131
ai_response
132
132
}
@@ -138,7 +138,10 @@ impl SpecialFunctions for AgentBackendDeveloper {
138
138
& self . attributes
139
139
}
140
140
141
- async fn execute ( & mut self , fact_sheet : & mut FactSheet ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
141
+ async fn execute (
142
+ & mut self ,
143
+ fact_sheet : & mut FactSheet ,
144
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
142
145
while self . attributes . state != AgentState :: Finished {
143
146
match & self . attributes . state {
144
147
AgentState :: Discovery => {
@@ -160,7 +163,9 @@ impl SpecialFunctions for AgentBackendDeveloper {
160
163
AgentState :: UnitTesting => {
161
164
// API SAFETY GUARD
162
165
PrintCommand :: UnitTest . print_agent_message (
163
- & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Ensuring Safe Code" ) ;
166
+ & self . attributes . position . as_str ( ) ,
167
+ "Backend Code Unit Testing: Ensuring Safe Code" ,
168
+ ) ;
164
169
165
170
let user_confirmation: bool = confirm_safe_code ( ) ;
166
171
@@ -170,7 +175,9 @@ impl SpecialFunctions for AgentBackendDeveloper {
170
175
171
176
// Build and testing code
172
177
PrintCommand :: UnitTest . print_agent_message (
173
- & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Building web server..." ) ;
178
+ & self . attributes . position . as_str ( ) ,
179
+ "Backend Code Unit Testing: Building web server..." ,
180
+ ) ;
174
181
175
182
let build_backend_server: std:: process:: Output = Command :: new ( "cargo" )
176
183
. arg ( "build" )
@@ -184,7 +191,9 @@ impl SpecialFunctions for AgentBackendDeveloper {
184
191
if build_backend_server. status . success ( ) {
185
192
self . bug_count = 0 ;
186
193
PrintCommand :: UnitTest . print_agent_message (
187
- & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Test server build successful..." ) ;
194
+ & self . attributes . position . as_str ( ) ,
195
+ "Backend Code Unit Testing: Test server build successful..." ,
196
+ ) ;
188
197
} else {
189
198
let error_arr: Vec < u8 > = build_backend_server. stderr ;
190
199
let error_str = String :: from_utf8 ( error_arr) . unwrap ( ) ;
@@ -194,7 +203,9 @@ impl SpecialFunctions for AgentBackendDeveloper {
194
203
195
204
if self . bug_count > 2 {
196
205
PrintCommand :: Issue . print_agent_message (
197
- & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Too many bugs found in code " ) ;
206
+ & self . attributes . position . as_str ( ) ,
207
+ "Backend Code Unit Testing: Too many bugs found in code " ,
208
+ ) ;
198
209
panic ! ( "ERROR: Too many bugs" ) ;
199
210
}
200
211
@@ -212,19 +223,27 @@ impl SpecialFunctions for AgentBackendDeveloper {
212
223
let api_endpoints_str: String = self . call_extract_rest_api_endpoints ( ) . await ;
213
224
214
225
// convert API endpoints into value
215
- let api_endpoints: Vec < RouteObject > = serde_json:: from_str ( api_endpoints_str. as_str ( ) ) . expect ( "Failed to parse API endpoints" ) ;
226
+ let api_endpoints: Vec < RouteObject > =
227
+ serde_json:: from_str ( api_endpoints_str. as_str ( ) )
228
+ . expect ( "Failed to parse API endpoints" ) ;
216
229
217
230
// define endpoints checks. Выбрать в итераторе только проверяемые ендпоинты
218
- let check_endpoints: Vec < RouteObject > = api_endpoints. iter ( )
219
- . filter ( |& route_object| { route_object. method == "get" && route_object. is_route_dynamic == "false" } )
220
- . cloned ( ) . collect ( ) ;
231
+ let check_endpoints: Vec < RouteObject > = api_endpoints
232
+ . iter ( )
233
+ . filter ( |& route_object| {
234
+ route_object. method == "get" && route_object. is_route_dynamic == "false"
235
+ } )
236
+ . cloned ( )
237
+ . collect ( ) ;
221
238
222
239
// Store API endpoints
223
240
fact_sheet. api_endpoint_schema = Some ( check_endpoints. clone ( ) ) ;
224
241
225
242
//Run backend application
226
243
PrintCommand :: UnitTest . print_agent_message (
227
- & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Starting Web server..." ) ;
244
+ & self . attributes . position . as_str ( ) ,
245
+ "Backend Code Unit Testing: Starting Web server..." ,
246
+ ) ;
228
247
229
248
let mut run_backend_server: std:: process:: Child = Command :: new ( "cargo" )
230
249
. arg ( "run" )
@@ -236,49 +255,68 @@ impl SpecialFunctions for AgentBackendDeveloper {
236
255
237
256
//Launching testing on the server
238
257
PrintCommand :: UnitTest . print_agent_message (
239
- & self . attributes . position . as_str ( ) , "Backend Code Unit Testing: Launching test on server in 5 sec..." ) ;
258
+ & self . attributes . position . as_str ( ) ,
259
+ "Backend Code Unit Testing: Launching test on server in 5 sec..." ,
260
+ ) ;
240
261
241
262
//Sleep for 5 sec before call webserver
242
263
let seconds_sleep: Duration = Duration :: from_secs ( 5 ) ;
243
264
time:: sleep ( seconds_sleep) . await ;
244
265
245
-
246
266
// check endpoints against server
247
267
for endpoint in check_endpoints {
248
- let test_message: String = format ! ( "Testing endpoint: '{}...'" , endpoint. route) ;
268
+ let test_message: String =
269
+ format ! ( "Testing endpoint: '{}...'" , endpoint. route) ;
249
270
PrintCommand :: UnitTest . print_agent_message (
250
- & self . attributes . position . as_str ( ) , test_message. as_str ( ) ) ;
271
+ & self . attributes . position . as_str ( ) ,
272
+ test_message. as_str ( ) ,
273
+ ) ;
251
274
252
275
//create client to call endpoints api
253
276
let client: Client = Client :: builder ( )
254
277
. timeout ( Duration :: from_secs ( 5 ) )
255
- . build ( ) . unwrap ( ) ;
278
+ . build ( )
279
+ . unwrap ( ) ;
256
280
257
281
// test url
258
282
let url: String = format ! ( "http://127.0.0.1:8080{}" , endpoint. route) ;
259
283
match check_status_code ( & client, & url) . await {
260
284
Ok ( status_code) => {
261
285
if status_code != 200 {
262
- let error_msg: String = format ! ( "WARNING: Failed to call backend endpoint{}" , endpoint. route) ;
286
+ let error_msg: String = format ! (
287
+ "WARNING: Failed to call backend endpoint{}" ,
288
+ endpoint. route
289
+ ) ;
263
290
PrintCommand :: Issue . print_agent_message (
264
- & self . attributes . position . as_str ( ) , error_msg. as_str ( ) ) ;
291
+ & self . attributes . position . as_str ( ) ,
292
+ error_msg. as_str ( ) ,
293
+ ) ;
265
294
}
266
295
}
267
296
Err ( error_msg) => {
268
297
//kill process
269
- run_backend_server. kill ( ) . expect ( "Unable to stop backend application" ) ;
270
- let error_msg: String = format ! ( "ERROR: While checking backend{}" , error_msg) ;
298
+ run_backend_server
299
+ . kill ( )
300
+ . expect ( "Unable to stop backend application" ) ;
301
+ let error_msg: String =
302
+ format ! ( "ERROR: While checking backend{}" , error_msg) ;
271
303
PrintCommand :: Issue . print_agent_message (
272
- & self . attributes . position . as_str ( ) , error_msg. as_str ( ) ) ;
304
+ & self . attributes . position . as_str ( ) ,
305
+ error_msg. as_str ( ) ,
306
+ ) ;
273
307
}
274
308
}
275
309
}
276
310
277
311
save_api_endpoints ( & api_endpoints_str) ;
278
312
PrintCommand :: Success . print_agent_message (
279
- & self . attributes . position . as_str ( ) , "Backend Testing completed..." ) ;
313
+ & self . attributes . position . as_str ( ) ,
314
+ "Backend Testing completed..." ,
315
+ ) ;
280
316
281
- run_backend_server. kill ( ) . expect ( "failed to Kill server on completion" ) ;
317
+ run_backend_server
318
+ . kill ( )
319
+ . expect ( "failed to Kill server on completion" ) ;
282
320
self . attributes . state = AgentState :: Finished ;
283
321
}
284
322
0 commit comments