@@ -17,49 +17,52 @@ const agent = request(API_URL);
1717// Le beforeAll est placé au niveau global, en dehors du describe
1818beforeAll ( async ( ) => {
1919 console . log ( 'Setting up test environment - Installing Scarb...' ) ;
20-
20+
2121 try {
2222 const installResponse = await agent
2323 . post ( '/api/key/request' )
2424 . set ( 'Content-Type' , 'application/json' )
2525 . set ( 'x-api-key' , API_KEY )
2626 . send ( {
27- request : " Can you install scarb?" ,
27+ request : ' Can you install scarb?' ,
2828 } ) ;
29-
29+
3030 console . log ( 'Scarb Installation Status:' , installResponse . status ) ;
31- console . log ( 'Scarb Installation Response:' ,
32- installResponse . body . output ?
33- JSON . stringify ( installResponse . body . output [ 0 ] , null , 2 ) :
34- 'No output'
31+ console . log (
32+ 'Scarb Installation Response:' ,
33+ installResponse . body . output
34+ ? JSON . stringify ( installResponse . body . output [ 0 ] , null , 2 )
35+ : 'No output' ,
3536 ) ;
36-
37- const isSuccess = installResponse . status === 201 &&
38- installResponse . body . output &&
39- installResponse . body . output [ 0 ] . status === 'success' ;
40-
37+
38+ const isSuccess =
39+ installResponse . status === 201 &&
40+ installResponse . body . output &&
41+ installResponse . body . output [ 0 ] . status === 'success' ;
42+
4143 if ( ! isSuccess ) {
42- console . error ( '⚠️ Warning: Scarb installation failed. : ' , installResponse . body . output [ 0 ] . text ) ;
44+ console . error (
45+ '⚠️ Warning: Scarb installation failed. : ' ,
46+ installResponse . body . output [ 0 ] . text ,
47+ ) ;
4348 } else {
4449 console . log ( '✅ Scarb installation successful' ) ;
4550 }
46-
51+
4752 // Attendre que l'installation soit traitée
4853 await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
49-
5054 } catch ( error ) {
5155 console . error ( '❌ Error during Scarb installation:' , error ) ;
5256 console . warn ( '⚠️ Tests may fail if Scarb is not properly installed' ) ;
5357 }
5458} , 60000 ) ; // Timeout de 60 secondes pour l'installation
5559
5660describe ( 'Code Generation and Compilation Tests' , ( ) => {
57-
5861 async function generateAndCompile (
5962 project_name : string ,
6063 prompt_content : string ,
6164 index : number ,
62- ) : Promise < { success : boolean ; error ?: string } > {
65+ ) : Promise < { success : boolean ; error ?: string } > {
6366 console . log ( `\n=== Test #${ index } : ${ project_name } ===` ) ;
6467 console . log ( `Generating code for: ${ prompt_content } ` ) ;
6568
@@ -90,11 +93,14 @@ describe('Code Generation and Compilation Tests', () => {
9093 if ( generateResponse . status !== 201 ) {
9194 return {
9295 success : false ,
93- error : `Generation HTTP request failed with status ${ generateResponse . status } : ${ JSON . stringify ( generateResponse . body ) } `
96+ error : `Generation HTTP request failed with status ${ generateResponse . status } : ${ JSON . stringify ( generateResponse . body ) } ` ,
9497 } ;
9598 }
9699
97- console . log ( 'CODE GENERATION RESPONSE:' , JSON . stringify ( generateResponse . body . output [ 0 ] , null , 2 ) ) ;
100+ console . log (
101+ 'CODE GENERATION RESPONSE:' ,
102+ JSON . stringify ( generateResponse . body . output [ 0 ] , null , 2 ) ,
103+ ) ;
98104 const sucessfulGeneration = generateResponse . body . output [ 0 ] . text
99105 . toLowerCase ( )
100106 . includes ( '```cairo' ) ;
@@ -105,7 +111,7 @@ describe('Code Generation and Compilation Tests', () => {
105111 ) {
106112 return {
107113 success : false ,
108- error : `Generation failed: ${ JSON . stringify ( generateResponse . body . output [ 0 ] . text ) } `
114+ error : `Generation failed: ${ JSON . stringify ( generateResponse . body . output [ 0 ] . text ) } ` ,
109115 } ;
110116 }
111117
@@ -128,73 +134,77 @@ describe('Code Generation and Compilation Tests', () => {
128134 . send ( {
129135 request : compilation_prompt ,
130136 } ) ;
131-
132137
133138 console . log ( 'COMPILATION STATUS:' , compileResponse . status ) ;
134-
139+
135140 if ( compileResponse . status !== 201 ) {
136141 return {
137142 success : false ,
138- error : `Compilation HTTP request failed with status ${ compileResponse . status } : ${ JSON . stringify ( compileResponse . body ) } `
143+ error : `Compilation HTTP request failed with status ${ compileResponse . status } : ${ JSON . stringify ( compileResponse . body ) } ` ,
139144 } ;
140145 }
141146
142- console . log ( 'COMPILATION RESPONSE:' , JSON . stringify ( compileResponse . body . output [ 0 ] , null , 2 ) ) ;
147+ console . log (
148+ 'COMPILATION RESPONSE:' ,
149+ JSON . stringify ( compileResponse . body . output [ 0 ] , null , 2 ) ,
150+ ) ;
143151
144152 const sucessfulCompilation =
145153 compileResponse . body . output [ 0 ] . text
146154 . toLowerCase ( )
147155 . includes ( 'compilation' ) &&
148- ! compileResponse . body . output [ 0 ] . text . toLowerCase ( ) . includes ( 'failure' ) &&
156+ ! compileResponse . body . output [ 0 ] . text
157+ . toLowerCase ( )
158+ . includes ( 'failure' ) &&
149159 ! compileResponse . body . output [ 0 ] . text . toLowerCase ( ) . includes ( 'failed' ) &&
150160 ! compileResponse . body . output [ 0 ] . text . toLowerCase ( ) . includes ( 'error' ) ;
151-
161+
152162 if (
153163 compileResponse . body . output [ 0 ] . status !== 'success' ||
154164 ! sucessfulCompilation
155165 ) {
156166 return {
157167 success : false ,
158- error : `Compilation failed: ${ JSON . stringify ( compileResponse . body . output [ 0 ] . text ) } `
168+ error : `Compilation failed: ${ JSON . stringify ( compileResponse . body . output [ 0 ] . text ) } ` ,
159169 } ;
160170 }
161171
162172 console . log ( '✅ Compilation successful' ) ;
163173 await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
164174
165175 return { success : true } ;
166- } catch ( error ) {
167- console . error ( `❌ Unexpected error in Test #${ index } :` , error ) ;
168- return {
169- success : false ,
170- error : `Unexpected error: ${ error . message } `
171- } ;
176+ } catch ( error ) {
177+ console . error ( `❌ Unexpected error in Test #${ index } :` , error ) ;
178+ return {
179+ success : false ,
180+ error : `Unexpected error: ${ error . message } ` ,
181+ } ;
182+ }
172183 }
173- }
174-
175- describe ( 'Cairo Functions and Basic Algorithms' , ( ) => {
176184
185+ describe ( 'Cairo Functions and Basic Algorithms' , ( ) => {
177186 test ( 'Hello World test' , async ( ) => {
178187 const project_name = 'hello_world' ;
179188 const prompt_content = 'a cairo function that returns "Hello World"' ;
180189 const result = await generateAndCompile ( project_name , prompt_content , 0 ) ;
181-
190+
182191 if ( ! result . success ) {
183192 console . error ( `❌ TEST FAILED: ${ result . error } ` ) ;
184193 }
185-
194+
186195 expect ( result . success ) . toBe ( true ) ;
187196 } , 100000 ) ;
188197
189198 test ( 'Fibonacci function' , async ( ) => {
190199 const project_name = 'fibonacci' ;
191- const prompt_content = 'a Cairo function that calculates the Fibonacci sequence' ;
200+ const prompt_content =
201+ 'a Cairo function that calculates the Fibonacci sequence' ;
192202 const result = await generateAndCompile ( project_name , prompt_content , 1 ) ;
193-
203+
194204 if ( ! result . success ) {
195205 console . error ( `❌ TEST FAILED: ${ result . error } ` ) ;
196206 }
197-
207+
198208 expect ( result . success ) . toBe ( true ) ;
199209 } , 100000 ) ;
200210
0 commit comments