1- /* eslint-disable no-console */
2- import { BuilderContext } from 'src/build-system/context' ;
31import { BuildSequence } from '../types' ;
4- import * as fs from 'fs' ;
5- import * as path from 'path' ;
6- import { writeToFile } from './utils' ;
7- import { BuildMonitor } from '../monitor' ;
2+ import { executeBuildSequence , objectToMarkdown , writeToFile } from './utils' ;
83
9- describe ( 'Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas -> Frontend_File_struct -> Frontend_File_arch -> BackendCodeGenerator' , ( ) => {
10- // Generate a unique folder with a timestamp
11- const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, '-' ) ;
12- const logFolderPath = `./logs/Fullstack_code_generator-${ timestamp } ` ;
13- fs . mkdirSync ( logFolderPath , { recursive : true } ) ;
14-
15- it ( 'should execute the frontend and backend code generation sequence and log results to individual files' , async ( ) => {
16- // Define the build sequence up to Backend Code Generator
4+ describe ( 'Build Sequence Test' , ( ) => {
5+ it ( 'should execute build sequence successfully' , async ( ) => {
176 const sequence : BuildSequence = {
187 id : 'test-backend-sequence' ,
198 version : '1.0.0' ,
@@ -28,7 +17,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
2817 nodes : [
2918 {
3019 id : 'op:PROJECT::STATE:SETUP' ,
31- name : 'set up project folders ' ,
20+ name : 'Project Folders Setup ' ,
3221 } ,
3322 ] ,
3423 } ,
@@ -39,7 +28,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
3928 nodes : [
4029 {
4130 id : 'op:PRD' ,
42- name : 'PRD Generation Node' ,
31+ name : 'Project Requirements Document Node' ,
4332 } ,
4433 ] ,
4534 } ,
@@ -67,7 +56,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
6756 } ,
6857 {
6958 id : 'op:UX:DATAMAP:DOC' ,
70- name : 'UX Data Map Document Node' ,
59+ name : 'UX DataMap Document Node' ,
7160 requires : [ 'op:UX:SMD' ] ,
7261 } ,
7362 ] ,
@@ -84,12 +73,17 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
8473 } ,
8574 {
8675 id : 'op:FILE:STRUCT' ,
87- name : 'file structure generation ' ,
76+ name : 'File Structure Generation ' ,
8877 requires : [ 'op:UX:SMD' , 'op:UX:DATAMAP:DOC' ] ,
8978 options : {
9079 projectPart : 'frontend' ,
9180 } ,
9281 } ,
82+ {
83+ id : 'op:UX:SMS:LEVEL2' ,
84+ name : 'Level 2 UX Sitemap Structure Node details' ,
85+ requires : [ 'op:UX:SMS' ] ,
86+ } ,
9387 ] ,
9488 } ,
9589 {
@@ -104,7 +98,7 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
10498 } ,
10599 {
106100 id : 'op:FILE:ARCH' ,
107- name : 'File_Arch ' ,
101+ name : 'File Arch ' ,
108102 requires : [ 'op:FILE:STRUCT' , 'op:UX:DATAMAP:DOC' ] ,
109103 } ,
110104 {
@@ -149,104 +143,10 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
149143 } ,
150144 ] ,
151145 } ;
152- const context = new BuilderContext ( sequence , 'test-env' ) ;
153- const monitor = BuildMonitor . getInstance ( ) ;
154-
155- try {
156- console . time ( 'Total Execution Time' ) ;
157-
158- await context . execute ( ) ;
159-
160- console . timeEnd ( 'Total Execution Time' ) ;
161-
162- const monitorReport = monitor . generateTextReport ( sequence . id ) ;
163- fs . writeFileSync (
164- path . join ( logFolderPath , 'execution-metrics.txt' ) ,
165- monitorReport ,
166- 'utf8' ,
167- ) ;
168-
169- const sequenceMetrics = monitor . getSequenceMetrics ( sequence . id ) ;
170- if ( sequenceMetrics ) {
171- const metricsJson = {
172- totalDuration : `${ sequenceMetrics . duration } ms` ,
173- successRate : `${ sequenceMetrics . successRate . toFixed ( 2 ) } %` ,
174- totalSteps : sequenceMetrics . totalSteps ,
175- completedSteps : sequenceMetrics . completedSteps ,
176- failedSteps : sequenceMetrics . failedSteps ,
177- totalNodes : sequenceMetrics . totalNodes ,
178- startTime : new Date ( sequenceMetrics . startTime ) . toISOString ( ) ,
179- endTime : new Date ( sequenceMetrics . endTime ) . toISOString ( ) ,
180- } ;
181-
182- fs . writeFileSync (
183- path . join ( logFolderPath , 'metrics.json' ) ,
184- JSON . stringify ( metricsJson , null , 2 ) ,
185- 'utf8' ,
186- ) ;
187-
188- console . log ( '\nSequence Metrics:' ) ;
189- console . table ( metricsJson ) ;
190- }
191-
192- for ( const step of sequence . steps ) {
193- const stepMetrics = sequenceMetrics ?. stepMetrics . get ( step . id ) ;
194- for ( const node of step . nodes ) {
195- const resultData = await context . getNodeData ( node . id ) ;
196- const nodeMetrics = stepMetrics ?. nodeMetrics . get ( node . id ) ;
197- if ( resultData ) {
198- writeToFile ( logFolderPath , `${ node . name } ` , resultData ) ;
199- } else {
200- console . error (
201- ` Error: Handler ${ node . name } failed to produce result data` ,
202- ) ;
203- writeToFile ( logFolderPath , `${ node . name } -error` , {
204- error : 'No result data' ,
205- metrics : nodeMetrics ,
206- } ) ;
207- }
208- }
209- }
210-
211- const summary = {
212- timestamp : new Date ( ) . toISOString ( ) ,
213- sequenceId : sequence . id ,
214- sequenceName : sequence . name ,
215- totalExecutionTime : `${ sequenceMetrics ?. duration } ms` ,
216- successRate : `${ sequenceMetrics ?. successRate . toFixed ( 2 ) } %` ,
217- nodesExecuted : sequenceMetrics ?. totalNodes ,
218- completedNodes : sequenceMetrics ?. stepMetrics . size ,
219- logFolder : logFolderPath ,
220- } ;
221-
222- fs . writeFileSync (
223- path . join ( logFolderPath , 'execution-summary.json' ) ,
224- JSON . stringify ( summary , null , 2 ) ,
225- 'utf8' ,
226- ) ;
227- } catch ( error ) {
228- const errorReport = {
229- error : {
230- message : error . message ,
231- stack : error . stack ,
232- } ,
233- metrics : monitor . getSequenceMetrics ( sequence . id ) ,
234- timestamp : new Date ( ) . toISOString ( ) ,
235- } ;
236-
237- fs . writeFileSync (
238- path . join ( logFolderPath , 'error-with-metrics.json' ) ,
239- JSON . stringify ( errorReport , null , 2 ) ,
240- 'utf8' ,
241- ) ;
242146
243- console . error ( '\nError during sequence execution:' ) ;
244- console . error ( error ) ;
245- console . error (
246- '\nError report saved to:' ,
247- path . join ( logFolderPath , 'error-with-metrics.json' ) ,
248- ) ;
249- throw new Error ( 'Sequence execution failed.' ) ;
250- }
251- } , 300000 ) ; // Timeout set to 10 minutes
147+ const result = await executeBuildSequence ( 'fullstack-code-gen' , sequence ) ;
148+ expect ( result . success ) . toBe ( true ) ;
149+ expect ( result . metrics ) . toBeDefined ( ) ;
150+ console . log ( `Logs saved to: ${ result . logFolderPath } ` ) ;
151+ } , 300000 ) ;
252152} ) ;
0 commit comments